From 599f55561bf6a99870f1b71b82942a8d736ecc7c Mon Sep 17 00:00:00 2001
From: Janik Zikovsky <zikovskyjl@ornl.gov>
Date: Thu, 28 Jul 2011 14:18:16 +0000
Subject: [PATCH] Refs #3203: Removed a few more calls to spectraMap().

---
 .../Algorithms/inc/MantidAlgorithms/Q1DTOF.h  |  3 +-
 Code/Mantid/Framework/Algorithms/src/Q1D2.cpp | 19 ++++++++----
 .../Framework/Algorithms/src/Q1DTOF.cpp       | 30 ++++++------------
 .../DataHandling/test/GroupDetectors2Test.h   | 31 ++++++++++---------
 4 files changed, 40 insertions(+), 43 deletions(-)

diff --git a/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/Q1DTOF.h b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/Q1DTOF.h
index 7ba2b971bfd..7818a7c331b 100644
--- a/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/Q1DTOF.h
+++ b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/Q1DTOF.h
@@ -68,7 +68,7 @@ private:
 
   void initizeCutOffs(const double RCut, const double WCut);
   void examineInput(API::MatrixWorkspace_const_sptr binAdj, API::MatrixWorkspace_const_sptr detectAdj);
-  API::MatrixWorkspace_sptr setUpOutputWorkspace(const std::vector<double> & binParams,  const API::SpectraDetectorMap * const specMap) const;
+  API::MatrixWorkspace_sptr setUpOutputWorkspace(const std::vector<double> & binParams) const;
   //these are the steps that are run on each individual spectrum
   size_t waveLengthCutOff(const size_t specInd) const;
   void calculateNormalization(const size_t wavStart, const size_t specInd, API::MatrixWorkspace_const_sptr pixelAdj, double const * const binNorms, double const * const binNormEs, MantidVec & norm, MantidVec & normETo2) const;
@@ -77,7 +77,6 @@ private:
   void normToBinWidth(const size_t offSet, const size_t specIndex, MantidVec & theNorms, MantidVec & errorSquared) const;
   void getInputDataIterators(const size_t offset, const size_t specInd, MantidVec & QVec, MantidVec::const_iterator & Qs, MantidVec::const_iterator & YData, MantidVec::const_iterator & EData) const;
   void convertWavetoQ(const size_t specIndex, const bool doGravity, MantidVec::const_iterator waves, MantidVec & QVec) const;
-  void updateSpecMap(const size_t specIndex, API::SpectraDetectorMap * const specMap, const Geometry::ISpectraDetectorMap & inSpecMap, API::MatrixWorkspace_sptr outputWS) const;
   void normalize(const MantidVec & normSum, const MantidVec & normError2, MantidVec & YOut, MantidVec & errors) const;
 };
 
diff --git a/Code/Mantid/Framework/Algorithms/src/Q1D2.cpp b/Code/Mantid/Framework/Algorithms/src/Q1D2.cpp
index 2d3fa1bd7d7..d2393418f4b 100644
--- a/Code/Mantid/Framework/Algorithms/src/Q1D2.cpp
+++ b/Code/Mantid/Framework/Algorithms/src/Q1D2.cpp
@@ -86,10 +86,10 @@ void Q1D2::exec()
   double const * const binNormEs = waveAdj ? &(waveAdj->readE(0)[0]) : NULL;
 
   //define the (large number of) data objects that are going to be used in all iterations of the loop below
-    // Construct a new spectra map. This will be faster than remapping the old one
-  API::SpectraDetectorMap *specMap = new SpectraDetectorMap;
+
   // this will become the output workspace from this algorithm
   MatrixWorkspace_sptr outputWS = setUpOutputWorkspace(getProperty("OutputBinning"));
+
   const MantidVec & QOut = outputWS->readX(0);
   MantidVec & YOut = outputWS->dataY(0);
   MantidVec & EOutTo2 = outputWS->dataE(0);
@@ -98,8 +98,6 @@ void Q1D2::exec()
   // the error on the normalisation
   MantidVec normError2(YOut.size(), 0.0);
 
-  const Geometry::ISpectraDetectorMap & inSpecMap = m_dataWS->spectraMap();
-
   const int numSpec = static_cast<int>(m_dataWS->getNumberHistograms());
   Progress progress(this, 0.05, 1.0, numSpec+1);
 
@@ -176,7 +174,12 @@ void Q1D2::exec()
     PARALLEL_CRITICAL(q1d_spectra_map)
     {
       progress.report("Computing I(Q)");
-      updateSpecMap(i, specMap, inSpecMap, outputWS);
+
+      // Add up the detector IDs in the output spectrum at workspace index 0
+      const ISpectrum * inSpec = m_dataWS->getSpectrum(i);
+      ISpectrum * outSpec = outputWS->getSpectrum(0);
+      outSpec->addDetectorIDs( inSpec->getDetectorIDs() );
+      //updateSpecMap(i, specMap, inSpecMap, outputWS);
     }
 
     PARALLEL_END_INTERUPT_REGION
@@ -282,6 +285,9 @@ API::MatrixWorkspace_sptr Q1D2::setUpOutputWorkspace(const std::vector<double> &
   outputWS->setX(0, XOut);
   outputWS->isDistribution(true);
 
+  outputWS->getSpectrum(0)->clearDetectorIDs();
+  outputWS->getSpectrum(0)->setSpectrumNo(1);
+
   return outputWS;
 }
 /** Finds the first index number of the first wavelength bin that should included based on the
@@ -424,6 +430,7 @@ void Q1D2::normToBinWidth(const size_t offSet, const size_t specIndex, const Man
     }
   }
 }
+
 /** Fills a vector with the Q values calculated from the wavelength bin centers from the input workspace and
 *  the workspace geometry as Q = 4*pi*sin(theta)/lambda
 *  @param[in] specInd the spectrum to calculate
@@ -514,7 +521,7 @@ void Q1D2::updateSpecMap(const size_t specIndex, API::SpectraDetectorMap * const
   Axis* const spectraAxis = m_dataWS->getAxis(1);
   if (spectraAxis->isSpectra())
   {
-    specid_t newSpectrumNo = outputWS->getAxis(1)->spectraNo(0) = spectraAxis->spectraNo(specIndex);
+    specid_t newSpectrumNo = outputWS->getAxis(1)->spectraNo(0); // = spectraAxis->spectraNo(specIndex);
     specMap->addSpectrumEntries(newSpectrumNo,inSpecMap.getDetectors(spectraAxis->spectraNo(specIndex)));
   }
 }
diff --git a/Code/Mantid/Framework/Algorithms/src/Q1DTOF.cpp b/Code/Mantid/Framework/Algorithms/src/Q1DTOF.cpp
index 2a029eb9975..d4eaf382026 100644
--- a/Code/Mantid/Framework/Algorithms/src/Q1DTOF.cpp
+++ b/Code/Mantid/Framework/Algorithms/src/Q1DTOF.cpp
@@ -78,7 +78,7 @@ void Q1DTOF::exec()
     // Construct a new spectra map. This will be faster than remapping the old one
   API::SpectraDetectorMap *specMap = new SpectraDetectorMap;
   // this will become the output workspace from this algorithm
-  MatrixWorkspace_sptr outputWS = setUpOutputWorkspace(getProperty("OutputBinning"), specMap);
+  MatrixWorkspace_sptr outputWS = setUpOutputWorkspace(getProperty("OutputBinning"));
   const MantidVec & QOut = outputWS->readX(0);
   MantidVec & YOut = outputWS->dataY(0);
   MantidVec & EOutTo2 = outputWS->dataE(0);
@@ -172,7 +172,11 @@ void Q1DTOF::exec()
     
     PARALLEL_CRITICAL(q1d_spectra_map)
     {
-      updateSpecMap(i, specMap, inSpecMap, outputWS);
+      // Add up the detector IDs in the output spectrum at workspace index 0
+      const ISpectrum * inSpec = m_dataWS->getSpectrum(i);
+      ISpectrum * outSpec = outputWS->getSpectrum(0);
+      outSpec->addDetectorIDs( inSpec->getDetectorIDs() );
+      //updateSpecMap(i, specMap, inSpecMap, outputWS);
     }
 
     progress.report("Computing I(Q)");
@@ -259,10 +263,9 @@ void Q1DTOF::initizeCutOffs(const double RCut, const double WCut)
 }
 /** Creates the output workspace, its size, units, etc.
 *  @param binParams the bin boundary specification using the same same syntax as param the Rebin algorithm
-*  @param specMap a spectra map that the new workspace should use and take owner ship of
 *  @return A pointer to the newly-created workspace
 */
-API::MatrixWorkspace_sptr Q1DTOF::setUpOutputWorkspace(const std::vector<double> & binParams,  const API::SpectraDetectorMap * const specMap) const
+API::MatrixWorkspace_sptr Q1DTOF::setUpOutputWorkspace(const std::vector<double> & binParams) const
 {
   // Calculate the output binning
   MantidVecPtr XOut;
@@ -278,7 +281,9 @@ API::MatrixWorkspace_sptr Q1DTOF::setUpOutputWorkspace(const std::vector<double>
   outputWS->setX(0, XOut);
   outputWS->isDistribution(true);
 
-  outputWS->replaceSpectraMap(specMap);
+  outputWS->getSpectrum(0)->clearDetectorIDs();
+  outputWS->getSpectrum(0)->setSpectrumNo(1);
+
   return outputWS;
 }
 /** Finds the first index number of the first wavelength bin that should included based on the
@@ -472,21 +477,6 @@ void Q1DTOF::convertWavetoQ(const size_t specIndex, const bool doGravity, Mantid
   }
 }
 
-/** !!!PROTOTYPE needs more testing !!! Map all the detectors onto the spectrum of the output
-*  @param[in] specIndex the spectrum to add
-*  @param[out] specMap the map in the output workspace to write to
-*  @param[in] inSpecMap spectrum data
-*  @param[out] outputWS the workspace with the spectra axis
-*/
-void Q1DTOF::updateSpecMap(const size_t specIndex, API::SpectraDetectorMap * const specMap, const Geometry::ISpectraDetectorMap & inSpecMap, API::MatrixWorkspace_sptr outputWS) const
-{
-  Axis* const spectraAxis = m_dataWS->getAxis(1);
-  if (spectraAxis->isSpectra())
-  {
-    specid_t newSpectrumNo = outputWS->getAxis(1)->spectraNo(0) = spectraAxis->spectraNo(specIndex);
-    specMap->addSpectrumEntries(newSpectrumNo,inSpecMap.getDetectors(spectraAxis->spectraNo(specIndex)));
-  }
-}
 /** Divides the number of counts in each output Q bin by the wrighting ("number that would expected to arrive")
 *  The errors are propogated using the uncorrolated error estimate for multiplication/division
 *  @param[in] normSum the weighting for each bin
diff --git a/Code/Mantid/Framework/DataHandling/test/GroupDetectors2Test.h b/Code/Mantid/Framework/DataHandling/test/GroupDetectors2Test.h
index 6d9bd3d97f9..45177b0c4ce 100644
--- a/Code/Mantid/Framework/DataHandling/test/GroupDetectors2Test.h
+++ b/Code/Mantid/Framework/DataHandling/test/GroupDetectors2Test.h
@@ -429,21 +429,22 @@ public:
     Workspace2D_sptr output2D1 = boost::dynamic_pointer_cast<Workspace2D>(output1);
     TS_ASSERT_EQUALS( output2D1->getNumberHistograms(), 4);
 
-    const Geometry::ISpectraDetectorMap &specDetecMap = output2D1->spectraMap();
-    std::vector<detid_t> specDet = specDetecMap.getDetectors(1);
-    TS_ASSERT_EQUALS( specDet[0], 1);
-    specDet = specDetecMap.getDetectors(2);
-    TS_ASSERT_EQUALS( specDet[0], 2);
-    specDet = specDetecMap.getDetectors(3);
-    TS_ASSERT_EQUALS( specDet[1], 4);
-    TS_ASSERT_EQUALS( specDet[2], 5);
-    specDet = specDetecMap.getDetectors(8);
-    TS_ASSERT_EQUALS( specDet[0], 2);
-    TS_ASSERT_EQUALS( specDet[1], 8);
-    TS_ASSERT_EQUALS( specDet[2], 9);
-    TS_ASSERT_EQUALS( specDet[3], 11);
-    TS_ASSERT_EQUALS( specDet[4], 12);
-    TS_ASSERT_EQUALS( specDet[5], 13);
+    std::set<detid_t>::const_iterator specDet;
+    specDet = output2D1->getSpectrum(0)->getDetectorIDs().begin();
+    TS_ASSERT_EQUALS( *specDet, 1);
+    specDet = output2D1->getSpectrum(1)->getDetectorIDs().begin();
+    TS_ASSERT_EQUALS( *specDet, 2);
+    specDet = output2D1->getSpectrum(2)->getDetectorIDs().begin();
+    TS_ASSERT_EQUALS( *specDet, 3); specDet++;
+    TS_ASSERT_EQUALS( *specDet, 4); specDet++;
+    TS_ASSERT_EQUALS( *specDet, 5);
+    specDet = output2D1->getSpectrum(3)->getDetectorIDs().begin();
+    TS_ASSERT_EQUALS( *specDet, 2); specDet++;
+    TS_ASSERT_EQUALS( *specDet, 8); specDet++;
+    TS_ASSERT_EQUALS( *specDet, 9); specDet++;
+    TS_ASSERT_EQUALS( *specDet, 11); specDet++;
+    TS_ASSERT_EQUALS( *specDet, 12); specDet++;
+    TS_ASSERT_EQUALS( *specDet, 13);
 
     AnalysisDataService::Instance().remove(outputSpace);
     AnalysisDataService::Instance().remove("boevs");
-- 
GitLab