From f9b89a2765349f952dedece0a8af0020914d1a0c Mon Sep 17 00:00:00 2001 From: Janik Zikovsky <zikovskyjl@ornl.gov> Date: Thu, 28 Jul 2011 15:12:55 +0000 Subject: [PATCH] Refs #3203: Nearly all calls to spectraMap() are gone. --- .../Framework/API/test/MatrixWorkspaceTest.h | 65 +++-------- Code/Mantid/Framework/Algorithms/src/Q1D2.cpp | 1 + .../Framework/Algorithms/src/Q1DTOF.cpp | 12 +- .../DataHandling/src/LoadRawHelper.cpp | 18 ++- .../test/LoadEmptyInstrumentTest.h | 16 ++- .../DataHandling/test/LoadEventPreNexusTest.h | 14 +-- .../DataHandling/test/LoadISISNexusTest.h | 2 +- .../DataHandling/test/LoadInstrumentTest.h | 13 ++- .../DataHandling/test/LoadMappingTableTest.h | 29 ++--- .../DataHandling/test/LoadMuonNexus2Test.h | 68 ++++------- .../test/LoadRSaveNLoadNcspTest.h | 38 +----- .../DataHandling/test/LoadRaw2Test.h | 30 ++--- .../DataHandling/test/LoadRaw3Test.h | 86 +++++--------- .../DataHandling/test/LoadRawBin0Test.h | 2 - .../DataHandling/test/LoadRawSpectrum0Test.h | 2 - .../Framework/DataHandling/test/LoadRawTest.h | 30 ++--- .../DataHandling/test/LoadSNSNexusTest.h | 110 +++++++++--------- .../test/ManagedRawFileWorkspace2DTest.h | 29 ++--- .../DataObjects/test/GroupingWorkspaceTest.h | 3 +- .../DataObjects/test/Workspace2DTest.h | 31 ----- .../MPIAlgorithms/test/GatherWorkspacesTest.h | 2 +- 21 files changed, 212 insertions(+), 389 deletions(-) diff --git a/Code/Mantid/Framework/API/test/MatrixWorkspaceTest.h b/Code/Mantid/Framework/API/test/MatrixWorkspaceTest.h index 768bd95b7be..397ca2ad8b1 100644 --- a/Code/Mantid/Framework/API/test/MatrixWorkspaceTest.h +++ b/Code/Mantid/Framework/API/test/MatrixWorkspaceTest.h @@ -96,36 +96,31 @@ public: void test_That_A_Workspace_Gets_SpectraMap_When_Initialized_With_NVector_Elements() { MatrixWorkspace_sptr testWS(new WorkspaceTester); - // Starts with an empty one - TS_ASSERT_EQUALS(testWS->spectraMap().nElements(), 0); const size_t nhist(10); testWS->initialize(nhist,1,1); - TS_ASSERT_EQUALS(testWS->spectraMap().nElements(), nhist); - } - - void test_spectraMap() - { - MatrixWorkspace_sptr ws2 = WorkspaceFactory::Instance().create(ws,1,1,1); - const Geometry::ISpectraDetectorMap &specs = ws2->spectraMap(); - TS_ASSERT_EQUALS( &(ws->spectraMap()), &specs ); + for (size_t i=0; i<testWS->getNumberHistograms(); i++) + { + TS_ASSERT_EQUALS(testWS->getSpectrum(i)->getSpectrumNo(), specid_t(i)); + TS_ASSERT(testWS->getSpectrum(i)->hasDetectorID(detid_t(i))); + } } void test_replaceSpectraMap() { boost::scoped_ptr<MatrixWorkspace> testWS(new WorkspaceTester); testWS->initialize(1,1,1); - const Geometry::ISpectraDetectorMap &specs = testWS->spectraMap(); // Default one - TS_ASSERT_EQUALS(specs.nElements(), 1); + TS_ASSERT_EQUALS(testWS->getSpectrum(0)->getSpectrumNo(), 0); ISpectraDetectorMap * spectraMap = new OneToOneSpectraDetectorMap(1,10); testWS->replaceAxis(1, new SpectraAxis(10, true)); testWS->replaceSpectraMap(spectraMap); // Has it been replaced - TS_ASSERT_EQUALS(testWS->spectraMap().nElements(), 10); - // Have the components in the spectrum's been updated too? - TS_ASSERT_EQUALS(testWS->getSpectrum(0)->getSpectrumNo(), 1); - TS_ASSERT(testWS->getSpectrum(0)->hasDetectorID(1)); + for (size_t i=0; i<testWS->getNumberHistograms(); i++) + { + TS_ASSERT_EQUALS(testWS->getSpectrum(i)->getSpectrumNo(), specid_t(i+1)); + TS_ASSERT(testWS->getSpectrum(i)->hasDetectorID(detid_t(i+1))); + } } void testSpectraMapCopiedWhenAWorkspaceIsCopied() @@ -136,9 +131,14 @@ public: parent->replaceAxis(1, new SpectraAxis(10, true)); parent->replaceSpectraMap(spectraMap); - TS_ASSERT_EQUALS(parent->spectraMap().nElements(), 10); MatrixWorkspace_sptr copied = WorkspaceFactory::Instance().create(parent,1,1,1); - TS_ASSERT_EQUALS(copied->spectraMap().nElements(), 10); + + // Has it been copied? + for (size_t i=0; i<copied->getNumberHistograms(); i++) + { + TS_ASSERT_EQUALS(copied->getSpectrum(i)->getSpectrumNo(), specid_t(i+1)); + TS_ASSERT(copied->getSpectrum(i)->hasDetectorID(detid_t(i+1))); + } } void testGetMemorySize() @@ -239,35 +239,6 @@ public: } - /** After setting spectrum number and detector IDs, you can - * rebuild the spectraDetectorMap for future compatibility. - */ - void test_generateSpectraMap() - { - WorkspaceTester ws; - ws.initialize(3, 10, 9); - ws.getSpectrum(0)->setSpectrumNo(1); - ws.getSpectrum(0)->clearDetectorIDs(); - ws.getSpectrum(0)->addDetectorID(123); - ws.getSpectrum(1)->setSpectrumNo(10); - ws.getSpectrum(1)->clearDetectorIDs(); - ws.getSpectrum(1)->addDetectorID(456); - ws.getSpectrum(2)->setSpectrumNo(100); - ws.getSpectrum(2)->clearDetectorIDs(); - ws.getSpectrum(2)->addDetectorID(789); - ws.generateSpectraMap(); - - Axis * ax1 = ws.getAxis(1); - TS_ASSERT_EQUALS( ax1->spectraNo(0), 1); - TS_ASSERT_EQUALS( ax1->spectraNo(1), 10); - TS_ASSERT_EQUALS( ax1->spectraNo(2), 100); - - const ISpectraDetectorMap & specMap = ws.spectraMap(); - TS_ASSERT_EQUALS( *specMap.getDetectors(1).begin(), 123); - TS_ASSERT_EQUALS( *specMap.getDetectors(10).begin(), 456); - TS_ASSERT_EQUALS( *specMap.getDetectors(100).begin(), 789); - } - void testWholeSpectraMasking() { diff --git a/Code/Mantid/Framework/Algorithms/src/Q1D2.cpp b/Code/Mantid/Framework/Algorithms/src/Q1D2.cpp index d2393418f4b..f467f232c1a 100644 --- a/Code/Mantid/Framework/Algorithms/src/Q1D2.cpp +++ b/Code/Mantid/Framework/Algorithms/src/Q1D2.cpp @@ -194,6 +194,7 @@ void Q1D2::exec() setProperty("OutputWorkspace",outputWS); } + /** If the distribution/raw counts status and binning on all the input workspaces * is the same and this reads some workspace description but throws if not @param binWS workpace that will be checked to see if it has one spectrum and the same number of bins as dataWS diff --git a/Code/Mantid/Framework/Algorithms/src/Q1DTOF.cpp b/Code/Mantid/Framework/Algorithms/src/Q1DTOF.cpp index d4eaf382026..00c1815dfdd 100644 --- a/Code/Mantid/Framework/Algorithms/src/Q1DTOF.cpp +++ b/Code/Mantid/Framework/Algorithms/src/Q1DTOF.cpp @@ -75,23 +75,20 @@ void Q1DTOF::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")); + + // The output spectrum const MantidVec & QOut = outputWS->readX(0); MantidVec & YOut = outputWS->dataY(0); MantidVec & EOutTo2 = outputWS->dataE(0); + // normalisation that is applied to counts in each Q bin MantidVec normSum(YOut.size(), 0.0); // the error on the normalisation MantidVec normError2(YOut.size(), 0.0); - const Geometry::ISpectraDetectorMap & inSpecMap = m_dataWS->spectraMap(); - //const Axis* const spectraAxis = m_dataWS->getAxis(1); - - - const int numSpec = static_cast<int>(m_dataWS->getNumberHistograms()); Progress progress(this, 0.1, 1.0, numSpec+1); @@ -190,6 +187,7 @@ void Q1DTOF::exec() setProperty("OutputWorkspace",outputWS); } + /** If the distribution/raw counts status and binning on all the input workspaces * is the same and this reads some workspace description but throws if not @param binWS workpace that will be checked to see if it has one spectrum and the same number of bins as dataWS diff --git a/Code/Mantid/Framework/DataHandling/src/LoadRawHelper.cpp b/Code/Mantid/Framework/DataHandling/src/LoadRawHelper.cpp index 46c58c83295..72c9a5c903b 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadRawHelper.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadRawHelper.cpp @@ -22,6 +22,7 @@ #include <Poco/DateTimeParser.h> #include <cmath> #include <cstdio> //Required for gcc 4.4 +#include "MantidKernel/Strings.h" namespace Mantid { @@ -444,13 +445,20 @@ namespace Mantid { if (!m_monitordetectorList.empty()) { + std::vector<specid_t> specList; + + std::cout << Strings::join(m_monitordetectorList.begin(), m_monitordetectorList.end(), ",") << "(detectors) " << std::endl; + + //get the monitor spectrum list from SpectraDetectorMap + localWorkspace->getSpectraFromDetectorIDs(m_monitordetectorList, specList); + std::cout << specList.size() << " entries (new way)\n"; + std::cout << Strings::join(specList.begin(), specList.end(), ",") << std::endl; + // Old way to get the spectra # for these detectors const Geometry::ISpectraDetectorMap& specdetMap = localWorkspace->spectraMap(); - std::vector<specid_t> specList = specdetMap.getSpectra(m_monitordetectorList); - -// //get the monitor spectrum list from SpectraDetectorMap -// std::vector<specid_t> specList; -// localWorkspace->getSpectraFromDetectorIDs(m_monitordetectorList, specList); + specList = specdetMap.getSpectra(m_monitordetectorList); + std::cout << specList.size() << " entries (old way)\n"; + std::cout << Strings::join(specList.begin(), specList.end(), ",") << std::endl; // remove duplicates by calling sort & unique algorithms sort(specList.begin(), specList.end(), std::less<int>()); diff --git a/Code/Mantid/Framework/DataHandling/test/LoadEmptyInstrumentTest.h b/Code/Mantid/Framework/DataHandling/test/LoadEmptyInstrumentTest.h index 3511ff6a382..cfaa60b98c6 100644 --- a/Code/Mantid/Framework/DataHandling/test/LoadEmptyInstrumentTest.h +++ b/Code/Mantid/Framework/DataHandling/test/LoadEmptyInstrumentTest.h @@ -28,6 +28,16 @@ class LoadEmptyInstrumentTest : public CxxTest::TestSuite { public: + /// Helper that checks that each spectrum has one detector + void check_workspace_detectors(MatrixWorkspace_sptr output, size_t numberDetectors) + { + TS_ASSERT_EQUALS(output->getNumberHistograms(),numberDetectors); + for (size_t i=0;i < output->getNumberHistograms(); i++) + { + TS_ASSERT_EQUALS(output->getSpectrum(i)->getDetectorIDs().size(), 1); + } + } + void testExecSLS() { LoadEmptyInstrument loaderSLS; @@ -55,7 +65,7 @@ public: output = boost::dynamic_pointer_cast<MatrixWorkspace>(AnalysisDataService::Instance().retrieve(wsName)); // Check the total number of elements in the map for SLS - TS_ASSERT_EQUALS(output->spectraMap().nElements(),683); + check_workspace_detectors(output, 683); AnalysisDataService::Instance().remove(wsName); } @@ -86,7 +96,7 @@ public: output = boost::dynamic_pointer_cast<MatrixWorkspace>(AnalysisDataService::Instance().retrieve(wsName)); // Check the total number of elements in the map for SLS - TS_ASSERT_EQUALS(output->spectraMap().nElements(),2502); + check_workspace_detectors(output, 2502); } void testExecMUSR() @@ -116,7 +126,7 @@ public: output = boost::dynamic_pointer_cast<MatrixWorkspace>(AnalysisDataService::Instance().retrieve(wsName)); // Check the total number of elements in the map for SLS - TS_ASSERT_EQUALS(output->spectraMap().nElements(),64); + check_workspace_detectors(output, 64); } diff --git a/Code/Mantid/Framework/DataHandling/test/LoadEventPreNexusTest.h b/Code/Mantid/Framework/DataHandling/test/LoadEventPreNexusTest.h index 556c5bfb9bd..7d5441f83ce 100644 --- a/Code/Mantid/Framework/DataHandling/test/LoadEventPreNexusTest.h +++ b/Code/Mantid/Framework/DataHandling/test/LoadEventPreNexusTest.h @@ -173,10 +173,6 @@ public: int numpixels_with_events = 51200; TS_ASSERT_EQUALS( ew->getNumberHistograms(), numpixels_with_events); - //This seems to be the size of the spectra map. - //TS_ASSERT_EQUALS( ew->spectraMap().nElements(), 50172); //or is it 50173 - //TODO: Figure out why that fails there above... - //Check if the instrument was loaded correctly boost::shared_ptr<Instrument> inst = ew->getBaseInstrument(); TS_ASSERT_EQUALS ( inst->getName(), "CNCS" ); @@ -256,13 +252,15 @@ public: TS_ASSERT_EQUALS( ew->getAxis(1)->length(), 2); //Are the pixel IDs ok? - std::vector<detid_t> dets = ew->spectraMap().getDetectors(45); + TS_ASSERT_EQUALS( ew->getSpectrum(0)->getSpectrumNo(), 45); + std::set<detid_t> dets = ew->getSpectrum(0)->getDetectorIDs(); TS_ASSERT_EQUALS( dets.size(), 1); - TS_ASSERT_EQUALS( dets[0], 45); + TS_ASSERT_EQUALS( *dets.begin(), 45); - dets = ew->spectraMap().getDetectors(110); + TS_ASSERT_EQUALS( ew->getSpectrum(1)->getSpectrumNo(), 110); + dets = ew->getSpectrum(1)->getDetectorIDs(); TS_ASSERT_EQUALS( dets.size(), 1); - TS_ASSERT_EQUALS( dets[0], 110); + TS_ASSERT_EQUALS( *dets.begin(), 110); } diff --git a/Code/Mantid/Framework/DataHandling/test/LoadISISNexusTest.h b/Code/Mantid/Framework/DataHandling/test/LoadISISNexusTest.h index 652529f36db..c4f5de6ce58 100644 --- a/Code/Mantid/Framework/DataHandling/test/LoadISISNexusTest.h +++ b/Code/Mantid/Framework/DataHandling/test/LoadISISNexusTest.h @@ -41,7 +41,7 @@ public: TS_ASSERT_EQUALS(ws->readY(6)[0],1.); TS_ASSERT_EQUALS(ws->readY(8)[3],1.); - TS_ASSERT_EQUALS(ws->spectraMap().nElements(),17792); + TS_ASSERT_EQUALS(ws->getSpectrum(1234)->getDetectorIDs().size(), 1); const std::vector< Property* >& logs = ws->run().getLogData(); TS_ASSERT_EQUALS(logs.size(), 58); diff --git a/Code/Mantid/Framework/DataHandling/test/LoadInstrumentTest.h b/Code/Mantid/Framework/DataHandling/test/LoadInstrumentTest.h index a21183c39cf..d8f40389250 100644 --- a/Code/Mantid/Framework/DataHandling/test/LoadInstrumentTest.h +++ b/Code/Mantid/Framework/DataHandling/test/LoadInstrumentTest.h @@ -72,9 +72,9 @@ public: //put this workspace in the data service TS_ASSERT_THROWS_NOTHING(AnalysisDataService::Instance().add(wsName, ws2D)); // We want to test id the spectra mapping changes - TS_ASSERT_EQUALS(ws2D->getAxis(1)->spectraNo(0), 1); - TS_ASSERT_EQUALS(ws2D->getAxis(1)->spectraNo(256), 257); - TS_ASSERT_EQUALS(ws2D->spectraMap().nElements(), 2584); + TS_ASSERT_EQUALS(ws2D->getSpectrum(0)->getSpectrumNo(), 1); + TS_ASSERT_EQUALS(ws2D->getSpectrum(256)->getSpectrumNo(), 257); + TS_ASSERT_EQUALS(ws2D->getNumberHistograms(), 2584); loader.setPropertyValue("Filename", "HET_Definition.xml"); inputFile = loader.getPropertyValue("Filename"); @@ -131,10 +131,11 @@ public: TS_ASSERT_EQUALS(output->getAxis(1)->spectraNo(255), 256); TS_ASSERT_EQUALS(output->getAxis(1)->spectraNo(256), 601); TS_ASSERT_EQUALS(output->getAxis(1)->spectraNo(257), 602); - std::vector<detid_t> ids_from_map = output->spectraMap().getDetectors(602); + + std::set<detid_t> ids_from_map = output->getSpectrum(257)->getDetectorIDs(); IDetector_sptr det_from_ws = output->getDetector(257); TS_ASSERT_EQUALS(ids_from_map.size(), 1); - TS_ASSERT_EQUALS(ids_from_map[0], 602); + TS_ASSERT_EQUALS(*ids_from_map.begin(), 602); TS_ASSERT_EQUALS(det_from_ws->getID(), 602); // also a few tests on the last detector and a test for the one beyond the last @@ -242,8 +243,8 @@ public: TS_ASSERT( ptrDetShape->isValid(V3D(0.0,0.0,0.0)+ptrDetShape->getPos()) ); // Only one element in spectrum - TS_ASSERT_EQUALS(output->spectraMap().nElements(), 1); TS_ASSERT_EQUALS(output->getAxis(1)->spectraNo(0), 1); + TS_ASSERT_EQUALS(output->getSpectrum(0)->getDetectorIDs().size(), 1); AnalysisDataService::Instance().remove(wsName); } diff --git a/Code/Mantid/Framework/DataHandling/test/LoadMappingTableTest.h b/Code/Mantid/Framework/DataHandling/test/LoadMappingTableTest.h index b4581f97b2d..44cfb43a9b2 100644 --- a/Code/Mantid/Framework/DataHandling/test/LoadMappingTableTest.h +++ b/Code/Mantid/Framework/DataHandling/test/LoadMappingTableTest.h @@ -34,14 +34,16 @@ public: //initialise framework manager to allow logging Mantid::API::FrameworkManager::Instance(); // Create the workspace and add it to the analysis data service - work1=Mantid::API::WorkspaceFactory::Instance().create("Workspace2D",1,1,1); + work1=Mantid::API::WorkspaceFactory::Instance().create("Workspace2D",24964,1,1); Mantid::API::AnalysisDataService::Instance().add(outputSpace, work1); } + void testInit() { TS_ASSERT_THROWS_NOTHING( loader.initialize()); TS_ASSERT( loader.isInitialized() ); } + void testExec() { // Load the instrument from RAW file @@ -60,31 +62,20 @@ public: TS_ASSERT_THROWS_NOTHING(loader.execute()); TS_ASSERT( loader.isExecuted()); - // Get the map from the wokspace - const Geometry::ISpectraDetectorMap& map=work1->spectraMap(); - - // Check the total number of elements in the map for HET - TS_ASSERT_EQUALS(map.nElements(),24964); - // Test one to one mapping, for example spectra 6 has only 1 pixel - TS_ASSERT_EQUALS(map.ndet(6),1); + TS_ASSERT_EQUALS( work1->getSpectrum(6)->getDetectorIDs().size(), 1); // rummap.ndet(6),1); + + // Test one to many mapping, for example 10 pixels contribute to spectra 2084 (workspace index 2083) + TS_ASSERT_EQUALS( work1->getSpectrum(2083)->getDetectorIDs().size(), 10); //map.ndet(2084),10); - // Test one to many mapping, for example 10 pixels contribute to spectra 2084 - TS_ASSERT_EQUALS(map.ndet(2084),10); // Check the id number of all pixels contributing - std::vector<detid_t> detectorgroup; - detectorgroup=map.getDetectors(2084); - std::vector<detid_t>::const_iterator it; + std::set<detid_t> detectorgroup; + detectorgroup = work1->getSpectrum(2083)->getDetectorIDs(); + std::set<detid_t>::const_iterator it; int pixnum=101191; for (it=detectorgroup.begin();it!=detectorgroup.end();it++) TS_ASSERT_EQUALS(*it,pixnum++); - // Test with spectra that does not exist - // Test that number of pixel=0 - TS_ASSERT_EQUALS(map.ndet(5),0); - // Test that trying to get the Detector throws. - std::vector<detid_t> test = map.getDetectors(5); - TS_ASSERT(test.empty()); AnalysisDataService::Instance().remove(outputSpace); return; } diff --git a/Code/Mantid/Framework/DataHandling/test/LoadMuonNexus2Test.h b/Code/Mantid/Framework/DataHandling/test/LoadMuonNexus2Test.h index b0b79239edb..32588a45518 100644 --- a/Code/Mantid/Framework/DataHandling/test/LoadMuonNexus2Test.h +++ b/Code/Mantid/Framework/DataHandling/test/LoadMuonNexus2Test.h @@ -31,6 +31,23 @@ class LoadMuonNexus2Test : public CxxTest::TestSuite { public: + void check_spectra_and_detectors(MatrixWorkspace_sptr output) + { + + //---------------------------------------------------------------------- + // Tests to check that Loading SpectraDetectorMap is done correctly + //---------------------------------------------------------------------- + // Check the total number of elements in the map for HET + TS_ASSERT_EQUALS(output->getNumberHistograms(), 192); + + // Test one to one mapping, for example spectra 6 has only 1 pixel + TS_ASSERT_EQUALS(output->getSpectrum(6)->getDetectorIDs().size(), 1); + + std::set<detid_t> detectorgroup = output->getSpectrum(99)->getDetectorIDs(); + TS_ASSERT_EQUALS(detectorgroup.size(),1); + TS_ASSERT_EQUALS(*detectorgroup.begin(),100); + } + void testExec() { LoadMuonNexus2 nxLoad; @@ -123,22 +140,7 @@ public: //check that sample name has been set correctly TS_ASSERT_EQUALS(output->sample().getName(), "GaAs"); - - //---------------------------------------------------------------------- - // Tests to check that Loading SpectraDetectorMap is done correctly - //---------------------------------------------------------------------- - const Geometry::ISpectraDetectorMap& map = output->spectraMap(); - - // Check the total number of elements in the map for HET - TS_ASSERT_EQUALS(map.nElements(),192); - - // Test one to one mapping, for example spectra 6 has only 1 pixel - TS_ASSERT_EQUALS(map.ndet(6),1); - - std::vector<detid_t> detectorgroup = map.getDetectors(100); - TS_ASSERT_EQUALS(detectorgroup.size(),1); - TS_ASSERT_EQUALS(detectorgroup.front(),100); - + check_spectra_and_detectors(output); AnalysisDataService::Instance().remove(outputSpace); } @@ -355,22 +357,7 @@ public: //check that sample name has been set correctly TS_ASSERT_EQUALS(output->sample().getName(), "GaAs"); - - //---------------------------------------------------------------------- - // Tests to check that Loading SpectraDetectorMap is done correctly - //---------------------------------------------------------------------- - const Geometry::ISpectraDetectorMap& map = output->spectraMap(); - - // Check the total number of elements in the map for HET - TS_ASSERT_EQUALS(map.nElements(),192); - - // Test one to one mapping, for example spectra 6 has only 1 pixel - TS_ASSERT_EQUALS(map.ndet(6),1); - - std::vector<detid_t> detectorgroup = map.getDetectors(100); - TS_ASSERT_EQUALS(detectorgroup.size(),1); - TS_ASSERT_EQUALS(detectorgroup.front(),100); - + check_spectra_and_detectors(output); AnalysisDataService::Instance().remove(outputSpace); } @@ -454,23 +441,8 @@ public: TS_ASSERT_EQUALS( timeSeriesString.substr(0,25), "2009-Jul-08 10:23:50 10." ); //check that sample name has been set correctly TS_ASSERT_EQUALS(output->sample().getName(), "GaAs"); - - //---------------------------------------------------------------------- - // Tests to check that Loading SpectraDetectorMap is done correctly - //---------------------------------------------------------------------- - const Geometry::ISpectraDetectorMap& map = output->spectraMap(); - - // Check the total number of elements in the map for HET - TS_ASSERT_EQUALS(map.nElements(),192); - - // Test one to one mapping, for example spectra 6 has only 1 pixel - TS_ASSERT_EQUALS(map.ndet(6),1); - - std::vector<detid_t> detectorgroup = map.getDetectors(100); - TS_ASSERT_EQUALS(detectorgroup.size(),1); - TS_ASSERT_EQUALS(detectorgroup.front(),100); - + check_spectra_and_detectors(output); AnalysisDataService::Instance().remove(outputSpace); } diff --git a/Code/Mantid/Framework/DataHandling/test/LoadRSaveNLoadNcspTest.h b/Code/Mantid/Framework/DataHandling/test/LoadRSaveNLoadNcspTest.h index b5648eed627..8cb5c9db68f 100644 --- a/Code/Mantid/Framework/DataHandling/test/LoadRSaveNLoadNcspTest.h +++ b/Code/Mantid/Framework/DataHandling/test/LoadRSaveNLoadNcspTest.h @@ -162,39 +162,13 @@ void testExecOnLoadraw() } } - // - // Get the map from the workspace : TESTS from LoadMappingTest.h - const Geometry::ISpectraDetectorMap& map=output->spectraMap(); - TS_ASSERT( &map != NULL); - if(&map != NULL ) - { + //---------------------------------------------------------------------- + // Tests to check that Loading SpectraDetectorMap is done correctly + //---------------------------------------------------------------------- + TS_ASSERT_EQUALS( output2D->getSpectrum(0)->getDetectorIDs().size(), 1); + TS_ASSERT_EQUALS( output2D->getSpectrum(0)->getSpectrumNo(), 1); + TS_ASSERT( output2D->getSpectrum(0)->hasDetectorID(1)); - // Check the total number of elements in the map for CSP78173 - TS_ASSERT_EQUALS(map.nElements(),4); - - // Test one to one mapping, for example spectra 6 has only 1 pixel - TS_ASSERT_EQUALS(map.ndet(2),1); - - // Test one to many mapping, for example 10 pixels contribute to spectra 2084 - TS_ASSERT_EQUALS(map.ndet(3),1); - - // Check the id number of all pixels contributing - std::vector<detid_t> detectorgroup; - //std::vector<boost::shared_ptr<Mantid::Geometry::IDetector> > detectorgroup; - detectorgroup=map.getDetectors(2084); - std::vector<detid_t>::const_iterator it; - int pixnum=101191; - for (it=detectorgroup.begin();it!=detectorgroup.end();it++) - TS_ASSERT_EQUALS(*it,pixnum++); - - // Test with spectra that does not exist - // Test that number of pixel=0 - TS_ASSERT_EQUALS(map.ndet(5),0); - // Test that trying to get the Detector throws. - std::vector<detid_t> test = map.getDetectors(5); - TS_ASSERT(test.empty()); - // - } // obtain the expected log data which was read from the Nexus file (NXlog) diff --git a/Code/Mantid/Framework/DataHandling/test/LoadRaw2Test.h b/Code/Mantid/Framework/DataHandling/test/LoadRaw2Test.h index 0e181123aef..6bf12a8ed94 100644 --- a/Code/Mantid/Framework/DataHandling/test/LoadRaw2Test.h +++ b/Code/Mantid/Framework/DataHandling/test/LoadRaw2Test.h @@ -110,30 +110,20 @@ public: //---------------------------------------------------------------------- // Tests to check that Loading SpectraDetectorMap is done correctly //---------------------------------------------------------------------- - const Geometry::ISpectraDetectorMap& map= output2D->spectraMap(); - - // Check the total number of elements in the map for HET - TS_ASSERT_EQUALS(map.nElements(),24964); - // Test one to one mapping, for example spectra 6 has only 1 pixel - TS_ASSERT_EQUALS(map.ndet(6),1); + TS_ASSERT_EQUALS( output2D->getSpectrum(6)->getDetectorIDs().size(), 1); // rummap.ndet(6),1); + + // Test one to many mapping, for example 10 pixels contribute to spectra 2084 (workspace index 2083) + TS_ASSERT_EQUALS( output2D->getSpectrum(2083)->getDetectorIDs().size(), 10); //map.ndet(2084),10); - // Test one to many mapping, for example 10 pixels contribute to spectra 2084 - TS_ASSERT_EQUALS(map.ndet(2084),10); // Check the id number of all pixels contributing - std::vector<detid_t> detectorgroup; - detectorgroup=map.getDetectors(2084); - std::vector<detid_t>::const_iterator it; + std::set<detid_t> detectorgroup; + detectorgroup = output2D->getSpectrum(2083)->getDetectorIDs(); + std::set<detid_t>::const_iterator it; int pixnum=101191; for (it=detectorgroup.begin();it!=detectorgroup.end();it++) - TS_ASSERT_EQUALS(*it,pixnum++); - - // Test with spectra that does not exist - // Test that number of pixel=0 - TS_ASSERT_EQUALS(map.ndet(5),0); - // Test that trying to get the Detector throws. - std::vector<detid_t> test = map.getDetectors(5); - TS_ASSERT(test.empty()); + TS_ASSERT_EQUALS(*it,pixnum++); + AnalysisDataService::Instance().remove(outputSpace); } @@ -269,11 +259,9 @@ public: // Check these are the same TS_ASSERT_EQUALS( output1->getBaseInstrument(), output2->getBaseInstrument() ) - TS_ASSERT_EQUALS( &(output1->spectraMap()), &(output2->spectraMap()) ) TS_ASSERT_EQUALS( &(output1->sample()), &(output2->sample()) ) TS_ASSERT_DIFFERS( &(output1->run()), &(output2->run()) ) TS_ASSERT_EQUALS( output1->getBaseInstrument(), output6->getBaseInstrument() ) - TS_ASSERT_EQUALS( &(output1->spectraMap()), &(output6->spectraMap()) ) TS_ASSERT_EQUALS( &(output1->sample()), &(output6->sample()) ) TS_ASSERT_DIFFERS( &(output1->run()), &(output6->run()) ) diff --git a/Code/Mantid/Framework/DataHandling/test/LoadRaw3Test.h b/Code/Mantid/Framework/DataHandling/test/LoadRaw3Test.h index 7b24d3beb7e..d5744c13a3f 100644 --- a/Code/Mantid/Framework/DataHandling/test/LoadRaw3Test.h +++ b/Code/Mantid/Framework/DataHandling/test/LoadRaw3Test.h @@ -113,30 +113,20 @@ public: //---------------------------------------------------------------------- // Tests to check that Loading SpectraDetectorMap is done correctly //---------------------------------------------------------------------- - const Geometry::ISpectraDetectorMap& map= output2D->spectraMap(); - - // Check the total number of elements in the map for HET - TS_ASSERT_EQUALS(map.nElements(),24964); - // Test one to one mapping, for example spectra 6 has only 1 pixel - TS_ASSERT_EQUALS(map.ndet(6),1); + TS_ASSERT_EQUALS( output2D->getSpectrum(6)->getDetectorIDs().size(), 1); // rummap.ndet(6),1); + + // Test one to many mapping, for example 10 pixels contribute to spectra 2084 (workspace index 2083) + TS_ASSERT_EQUALS( output2D->getSpectrum(2083)->getDetectorIDs().size(), 10); //map.ndet(2084),10); - // Test one to many mapping, for example 10 pixels contribute to spectra 2084 - TS_ASSERT_EQUALS(map.ndet(2084),10); // Check the id number of all pixels contributing - std::vector<detid_t> detectorgroup; - detectorgroup=map.getDetectors(2084); - std::vector<detid_t>::const_iterator it; + std::set<detid_t> detectorgroup; + detectorgroup = output2D->getSpectrum(2083)->getDetectorIDs(); + std::set<detid_t>::const_iterator it; int pixnum=101191; for (it=detectorgroup.begin();it!=detectorgroup.end();it++) - TS_ASSERT_EQUALS(*it,pixnum++); - - // Test with spectra that does not exist - // Test that number of pixel=0 - TS_ASSERT_EQUALS(map.ndet(5),0); - // Test that trying to get the Detector throws. - std::vector<detid_t> test = map.getDetectors(5); - TS_ASSERT(test.empty()); + TS_ASSERT_EQUALS(*it,pixnum++); + AnalysisDataService::Instance().remove(outputSpace); } @@ -379,14 +369,12 @@ public: TS_ASSERT_DIFFERS( outsptr1->dataY(1)[555], outsptr6->dataY(1)[555] ) TS_ASSERT_EQUALS( outsptr1->getBaseInstrument(), outsptr2->getBaseInstrument() ) - TS_ASSERT_EQUALS( &(outsptr1->spectraMap()), &(outsptr2->spectraMap()) ) TS_ASSERT_EQUALS( &(outsptr1->sample()), &(outsptr2->sample()) ) TS_ASSERT_DIFFERS( &(outsptr1->run()), &(outsptr2->run())) TS_ASSERT_DIFFERS( &(outsptr1->run()), &(outsptr3->run()) ) TS_ASSERT_DIFFERS( &(outsptr1->run()), &(outsptr4->run()) ) TS_ASSERT_DIFFERS( &(outsptr1->run()), &(outsptr5->run()) ) TS_ASSERT_EQUALS( outsptr1->getBaseInstrument(), outsptr6->getBaseInstrument() ) - TS_ASSERT_EQUALS( &(outsptr1->spectraMap()), &(outsptr6->spectraMap()) ) TS_ASSERT_EQUALS( &(outsptr1->sample()), &(outsptr6->sample()) ) TS_ASSERT_DIFFERS( &(outsptr1->run()), &(outsptr6->run()) ) @@ -526,57 +514,47 @@ public: //---------------------------------------------------------------------- // Tests to check that Loading SpectraDetectorMap is done correctly //---------------------------------------------------------------------- - const Geometry::ISpectraDetectorMap& map= output2D->spectraMap(); - - // Check the total number of elements in the map for HET - TS_ASSERT_EQUALS(map.nElements(),24964); - // Test one to one mapping, for example spectra 6 has only 1 pixel - TS_ASSERT_EQUALS(map.ndet(6),1); + TS_ASSERT_EQUALS( output2D->getSpectrum(6)->getDetectorIDs().size(), 1); // rummap.ndet(6),1); + + // Test one to many mapping, for example 10 pixels contribute to spectra 2084 (workspace index 2083) + TS_ASSERT_EQUALS( output2D->getSpectrum(2079)->getDetectorIDs().size(), 10); //map.ndet(2084),10); - // Test one to many mapping, for example 10 pixels contribute to spectra 2084 - TS_ASSERT_EQUALS(map.ndet(2084),10); // Check the id number of all pixels contributing - std::vector<detid_t> detectorgroup; - detectorgroup=map.getDetectors(2084); - std::vector<detid_t>::const_iterator it; + std::set<detid_t> detectorgroup; + detectorgroup = output2D->getSpectrum(2079)->getDetectorIDs(); + std::set<detid_t>::const_iterator it; int pixnum=101191; for (it=detectorgroup.begin();it!=detectorgroup.end();it++) - TS_ASSERT_EQUALS(*it,pixnum++); + TS_ASSERT_EQUALS(*it,pixnum++); - // Test with spectra that does not exist - // Test that number of pixel=0 - TS_ASSERT_EQUALS(map.ndet(5),0); - // Test that trying to get the Detector throws. - std::vector<detid_t> test = map.getDetectors(5); - TS_ASSERT(test.empty()); - - AnalysisDataService::Instance().remove(outputSpace); - AnalysisDataService::Instance().remove(outputSpace+"_Monitors"); + AnalysisDataService::Instance().remove(outputSpace); + AnalysisDataService::Instance().remove(outputSpace+"_Monitors"); } + void testSeparateMonitorsMultiPeriod() { - LoadRaw3 loader7; + LoadRaw3 loader7; loader7.initialize(); loader7.setPropertyValue("Filename", "EVS13895.raw"); loader7.setPropertyValue("OutputWorkspace", "multiperiod"); - loader7.setPropertyValue("LoadMonitors", "Separate"); - + loader7.setPropertyValue("LoadMonitors", "Separate"); + TS_ASSERT_THROWS_NOTHING( loader7.execute() ) TS_ASSERT( loader7.isExecuted() ) - + WorkspaceGroup_sptr work_out; TS_ASSERT_THROWS_NOTHING(work_out = boost::dynamic_pointer_cast<WorkspaceGroup>(AnalysisDataService::Instance().retrieve("multiperiod"))); WorkspaceGroup_sptr monitor_work_out; - TS_ASSERT_THROWS_NOTHING(monitor_work_out = boost::dynamic_pointer_cast<WorkspaceGroup>(AnalysisDataService::Instance().retrieve("multiperiod_Monitors"))); + TS_ASSERT_THROWS_NOTHING(monitor_work_out = boost::dynamic_pointer_cast<WorkspaceGroup>(AnalysisDataService::Instance().retrieve("multiperiod_Monitors"))); - Workspace_sptr monitorwsSptr=AnalysisDataService::Instance().retrieve("multiperiod_Monitors"); - WorkspaceGroup_sptr monitorsptrWSGrp=boost::dynamic_pointer_cast<WorkspaceGroup>(monitorwsSptr); + Workspace_sptr monitorwsSptr=AnalysisDataService::Instance().retrieve("multiperiod_Monitors"); + WorkspaceGroup_sptr monitorsptrWSGrp=boost::dynamic_pointer_cast<WorkspaceGroup>(monitorwsSptr); - - const std::vector<std::string>monitorwsNamevec = monitorsptrWSGrp->getNames(); - int period=1; + + const std::vector<std::string>monitorwsNamevec = monitorsptrWSGrp->getNames(); + int period=1; std::vector<std::string>::const_iterator it=monitorwsNamevec.begin(); for (;it!=monitorwsNamevec.end();it++) { std::stringstream count; @@ -621,13 +599,11 @@ public: TS_ASSERT_DIFFERS( monoutsptr1->dataY(1)[555], monoutsptr6->dataY(1)[555] ) TS_ASSERT_EQUALS( monoutsptr1->getBaseInstrument(), monoutsptr2->getBaseInstrument() ) - TS_ASSERT_EQUALS( &(monoutsptr1->spectraMap()), &(monoutsptr2->spectraMap()) ) TS_ASSERT_DIFFERS( &(monoutsptr1->run()), &(monoutsptr2->run()) ) TS_ASSERT_DIFFERS( &(monoutsptr1->run()), &(monoutsptr3->run()) ) TS_ASSERT_DIFFERS( &(monoutsptr1->run()), &(monoutsptr4->run()) ) TS_ASSERT_DIFFERS( &(monoutsptr1->run()), &(monoutsptr5->run()) ) TS_ASSERT_EQUALS( monoutsptr1->getBaseInstrument(), monoutsptr6->getBaseInstrument() ) - TS_ASSERT_EQUALS( &(monoutsptr1->spectraMap()), &(monoutsptr6->spectraMap()) ) TS_ASSERT_DIFFERS( &(monoutsptr1->run()), &(monoutsptr6->run()) ) Workspace_sptr wsSptr=AnalysisDataService::Instance().retrieve("multiperiod"); @@ -678,13 +654,11 @@ public: TS_ASSERT_DIFFERS( outsptr1->dataY(1)[555], outsptr6->dataY(1)[555] ) TS_ASSERT_EQUALS( outsptr1->getBaseInstrument(), outsptr2->getBaseInstrument() ) - TS_ASSERT_EQUALS( &(outsptr1->spectraMap()), &(outsptr2->spectraMap()) ) TS_ASSERT_DIFFERS( &(outsptr1->run()), &(outsptr2->run() )) TS_ASSERT_DIFFERS( &(outsptr1->run()), &(outsptr3->run() ) ) TS_ASSERT_DIFFERS( &(outsptr1->run()), &(outsptr4->run() ) ) TS_ASSERT_DIFFERS( &(outsptr1->run()), &(outsptr5->run() ) ) TS_ASSERT_EQUALS( outsptr1->getBaseInstrument(), outsptr6->getBaseInstrument() ) - TS_ASSERT_EQUALS( &(outsptr1->spectraMap()), &(outsptr6->spectraMap()) ) TS_ASSERT_DIFFERS( &(outsptr1->run()), &(outsptr6->run() ) ) it=monitorwsNamevec.begin(); diff --git a/Code/Mantid/Framework/DataHandling/test/LoadRawBin0Test.h b/Code/Mantid/Framework/DataHandling/test/LoadRawBin0Test.h index cd063702b73..1beee574865 100644 --- a/Code/Mantid/Framework/DataHandling/test/LoadRawBin0Test.h +++ b/Code/Mantid/Framework/DataHandling/test/LoadRawBin0Test.h @@ -140,14 +140,12 @@ public: TS_ASSERT_EQUALS( outsptr1->getBaseInstrument(), outsptr2->getBaseInstrument() ) - TS_ASSERT_EQUALS( &(outsptr1->spectraMap()), &(outsptr2->spectraMap()) ) TS_ASSERT_EQUALS( &(outsptr1->sample()), &(outsptr2->sample())) TS_ASSERT_DIFFERS( &(outsptr1->run()), &(outsptr2->run())) TS_ASSERT_DIFFERS( &(outsptr1->run()), &(outsptr3->run()) ) TS_ASSERT_DIFFERS( &(outsptr1->run()), &(outsptr4->run()) ) TS_ASSERT_DIFFERS( &(outsptr1->run()), &(outsptr5->run()) ) TS_ASSERT_EQUALS( outsptr1->getBaseInstrument(), outsptr6->getBaseInstrument() ) - TS_ASSERT_EQUALS( &(outsptr1->spectraMap()), &(outsptr6->spectraMap()) ) TS_ASSERT_EQUALS( &(outsptr1->sample()), &(outsptr6->sample()) ) TS_ASSERT_DIFFERS( &(outsptr1->run()), &(outsptr6->run()) ) diff --git a/Code/Mantid/Framework/DataHandling/test/LoadRawSpectrum0Test.h b/Code/Mantid/Framework/DataHandling/test/LoadRawSpectrum0Test.h index b3f8f9c9cff..916a6c15d7b 100644 --- a/Code/Mantid/Framework/DataHandling/test/LoadRawSpectrum0Test.h +++ b/Code/Mantid/Framework/DataHandling/test/LoadRawSpectrum0Test.h @@ -145,14 +145,12 @@ public: TS_ASSERT_DIFFERS( outsptr1->dataY(0)[555], outsptr6->dataY(0)[555] ) TS_ASSERT_EQUALS( outsptr1->getBaseInstrument(), outsptr2->getBaseInstrument() ) - TS_ASSERT_EQUALS( &(outsptr1->spectraMap()), &(outsptr2->spectraMap()) ) TS_ASSERT_EQUALS( &(outsptr1->sample()), &(outsptr2->sample())) TS_ASSERT_DIFFERS( &(outsptr1->run()), &(outsptr2->run())) TS_ASSERT_DIFFERS( &(outsptr1->run()), &(outsptr3->run()) ) TS_ASSERT_DIFFERS( &(outsptr1->run()), &(outsptr4->run()) ) TS_ASSERT_DIFFERS( &(outsptr1->run()), &(outsptr5->run()) ) TS_ASSERT_EQUALS( outsptr1->getBaseInstrument(), outsptr6->getBaseInstrument() ) - TS_ASSERT_EQUALS( &(outsptr1->spectraMap()), &(outsptr6->spectraMap()) ) TS_ASSERT_DIFFERS( &(outsptr1->run()), &(outsptr6->run()) ) } diff --git a/Code/Mantid/Framework/DataHandling/test/LoadRawTest.h b/Code/Mantid/Framework/DataHandling/test/LoadRawTest.h index a94b327ca17..0b198036123 100644 --- a/Code/Mantid/Framework/DataHandling/test/LoadRawTest.h +++ b/Code/Mantid/Framework/DataHandling/test/LoadRawTest.h @@ -108,30 +108,19 @@ public: //---------------------------------------------------------------------- // Tests to check that Loading SpectraDetectorMap is done correctly //---------------------------------------------------------------------- - const Geometry::ISpectraDetectorMap& map= output2D->spectraMap(); - - // Check the total number of elements in the map for HET - TS_ASSERT_EQUALS(map.nElements(),24964); - // Test one to one mapping, for example spectra 6 has only 1 pixel - TS_ASSERT_EQUALS(map.ndet(6),1); + TS_ASSERT_EQUALS( output2D->getSpectrum(6)->getDetectorIDs().size(), 1); // rummap.ndet(6),1); + + // Test one to many mapping, for example 10 pixels contribute to spectra 2084 (workspace index 2083) + TS_ASSERT_EQUALS( output2D->getSpectrum(2083)->getDetectorIDs().size(), 10); //map.ndet(2084),10); - // Test one to many mapping, for example 10 pixels contribute to spectra 2084 - TS_ASSERT_EQUALS(map.ndet(2084),10); // Check the id number of all pixels contributing - std::vector<detid_t> detectorgroup; - detectorgroup=map.getDetectors(2084); - std::vector<detid_t>::const_iterator it; + std::set<detid_t> detectorgroup; + detectorgroup = output2D->getSpectrum(2083)->getDetectorIDs(); + std::set<detid_t>::const_iterator it; int pixnum=101191; for (it=detectorgroup.begin();it!=detectorgroup.end();it++) - TS_ASSERT_EQUALS(*it,pixnum++); - - // Test with spectra that does not exist - // Test that number of pixel=0 - TS_ASSERT_EQUALS(map.ndet(5),0); - // Test that trying to get the Detector throws. - std::vector<detid_t> test = map.getDetectors(5); - TS_ASSERT(test.empty()); + TS_ASSERT_EQUALS(*it,pixnum++); AnalysisDataService::Instance().remove(outputSpace); } @@ -299,7 +288,6 @@ public: // Check these are the same TS_ASSERT_EQUALS( output1->getBaseInstrument(), output2->getBaseInstrument() ) - TS_ASSERT_EQUALS( &(output1->spectraMap()), &(output2->spectraMap()) ) TS_ASSERT_EQUALS( output1->run().getProtonCharge(), output2->run().getProtonCharge() ) TS_ASSERT_EQUALS( output1->sample().getGeometryFlag(), output2->sample().getGeometryFlag() ) TS_ASSERT_EQUALS( output1->sample().getThickness(), output2->sample().getThickness() ) @@ -307,7 +295,6 @@ public: TS_ASSERT_EQUALS( output1->sample().getWidth(), output2->sample().getWidth() ) TS_ASSERT_EQUALS( output1->getBaseInstrument(), output6->getBaseInstrument() ) - TS_ASSERT_EQUALS( &(output1->spectraMap()), &(output6->spectraMap()) ) TS_ASSERT_EQUALS( output1->run().getProtonCharge(), output6->run().getProtonCharge() ) TS_ASSERT_EQUALS( output1->sample().getGeometryFlag(), output6->sample().getGeometryFlag() ) TS_ASSERT_EQUALS( output1->sample().getThickness(), output6->sample().getThickness() ) @@ -315,7 +302,6 @@ public: TS_ASSERT_EQUALS( output1->sample().getWidth(), output6->sample().getWidth() ) TS_ASSERT_EQUALS( output1->getBaseInstrument(), output12->getBaseInstrument() ) - TS_ASSERT_EQUALS( &(output1->spectraMap()), &(output12->spectraMap()) ) TS_ASSERT_EQUALS( output1->run().getProtonCharge(), output12->run().getProtonCharge() ) TS_ASSERT_EQUALS( output1->sample().getGeometryFlag(), output12->sample().getGeometryFlag() ) TS_ASSERT_EQUALS( output1->sample().getThickness(), output12->sample().getThickness() ) diff --git a/Code/Mantid/Framework/DataHandling/test/LoadSNSNexusTest.h b/Code/Mantid/Framework/DataHandling/test/LoadSNSNexusTest.h index 57ad13d7464..9c7c515cc6e 100644 --- a/Code/Mantid/Framework/DataHandling/test/LoadSNSNexusTest.h +++ b/Code/Mantid/Framework/DataHandling/test/LoadSNSNexusTest.h @@ -23,62 +23,60 @@ class LoadSNSNexusTest : public CxxTest::TestSuite public: void xtestCNCS() { - Mantid::API::FrameworkManager::Instance(); - LoadSNSNexus ld; - std::string outws_name = "CNCS_7860"; - ld.initialize(); - ld.setPropertyValue("Filename","CNCS_7860.nxs"); - ld.setPropertyValue("OutputWorkspace",outws_name); - TS_ASSERT_THROWS_NOTHING(ld.execute()); - TS_ASSERT(ld.isExecuted()); + Mantid::API::FrameworkManager::Instance(); + LoadSNSNexus ld; + std::string outws_name = "CNCS_7860"; + ld.initialize(); + ld.setPropertyValue("Filename","CNCS_7860.nxs"); + ld.setPropertyValue("OutputWorkspace",outws_name); + TS_ASSERT_THROWS_NOTHING(ld.execute()); + TS_ASSERT(ld.isExecuted()); } void xtestRefl() - { - Mantid::API::FrameworkManager::Instance(); - LoadSNSNexus ld; - std::string outws_name = "nickr0x0r"; - ld.initialize(); - ld.setPropertyValue("Filename","../../../../Test/Nexus/SNS/REF_L_16055.nxs"); - ld.setPropertyValue("OutputWorkspace",outws_name); - TS_ASSERT_THROWS_NOTHING(ld.execute()); - TS_ASSERT(ld.isExecuted()); - - MatrixWorkspace_sptr ws = boost::dynamic_pointer_cast<MatrixWorkspace>(AnalysisDataService::Instance().retrieve(outws_name)); - TS_ASSERT(ws); - TS_ASSERT_EQUALS(ws->blocksize(),501); - TS_ASSERT_EQUALS(ws->getNumberHistograms(),77824); - TS_ASSERT_EQUALS(ws->readX(0)[0],0.); - TS_ASSERT_EQUALS(ws->readX(0)[1],200.); - TS_ASSERT_EQUALS(ws->readX(0)[2],400.); - - TS_ASSERT_EQUALS(ws->readY(41799)[62],191.); - TS_ASSERT_EQUALS(ws->readY(51223)[66],8.); - TS_ASSERT_EQUALS(ws->readY(13873)[227],1.); - - TS_ASSERT_EQUALS(ws->spectraMap().nElements(),77824); - - const std::vector< Property* >& logs = ws->run().getLogData(); - TS_ASSERT_EQUALS(logs.size(),1); - - //------------ Instrument Loading Sub-Test ----------------------- - IInstrument_sptr inst = ws->getInstrument(); - - TS_ASSERT_EQUALS(inst->getName(), "REF_L"); - std::map<int, Geometry::IDetector_sptr> detectors = inst->getDetectors(); - TS_ASSERT_EQUALS(detectors.size(), 304*256); //304*256 - - V3D pos(0,0,0); - //Test a few pixels in bank 1 - pos.spherical_rad(1.3571243, 0.1025134, -0.6979992); - TS_ASSERT(detectors[0]->getRelativePos() == pos); - TS_ASSERT_EQUALS(detectors[0]->getName(), "bank1, (0,0)"); - //Pixel 303 - pos.spherical_rad(1.3570696, 0.10212083, -2.4403417); - TS_ASSERT(detectors[303]->getRelativePos() == pos); - TS_ASSERT_EQUALS(detectors[304]->getName(), "bank1, (1,0)"); - -/* + { + Mantid::API::FrameworkManager::Instance(); + LoadSNSNexus ld; + std::string outws_name = "nickr0x0r"; + ld.initialize(); + ld.setPropertyValue("Filename","../../../../Test/Nexus/SNS/REF_L_16055.nxs"); + ld.setPropertyValue("OutputWorkspace",outws_name); + TS_ASSERT_THROWS_NOTHING(ld.execute()); + TS_ASSERT(ld.isExecuted()); + + MatrixWorkspace_sptr ws = boost::dynamic_pointer_cast<MatrixWorkspace>(AnalysisDataService::Instance().retrieve(outws_name)); + TS_ASSERT(ws); + TS_ASSERT_EQUALS(ws->blocksize(),501); + TS_ASSERT_EQUALS(ws->getNumberHistograms(),77824); + TS_ASSERT_EQUALS(ws->readX(0)[0],0.); + TS_ASSERT_EQUALS(ws->readX(0)[1],200.); + TS_ASSERT_EQUALS(ws->readX(0)[2],400.); + + TS_ASSERT_EQUALS(ws->readY(41799)[62],191.); + TS_ASSERT_EQUALS(ws->readY(51223)[66],8.); + TS_ASSERT_EQUALS(ws->readY(13873)[227],1.); + + const std::vector< Property* >& logs = ws->run().getLogData(); + TS_ASSERT_EQUALS(logs.size(),1); + + //------------ Instrument Loading Sub-Test ----------------------- + IInstrument_sptr inst = ws->getInstrument(); + + TS_ASSERT_EQUALS(inst->getName(), "REF_L"); + std::map<int, Geometry::IDetector_sptr> detectors = inst->getDetectors(); + TS_ASSERT_EQUALS(detectors.size(), 304*256); //304*256 + + V3D pos(0,0,0); + //Test a few pixels in bank 1 + pos.spherical_rad(1.3571243, 0.1025134, -0.6979992); + TS_ASSERT(detectors[0]->getRelativePos() == pos); + TS_ASSERT_EQUALS(detectors[0]->getName(), "bank1, (0,0)"); + //Pixel 303 + pos.spherical_rad(1.3570696, 0.10212083, -2.4403417); + TS_ASSERT(detectors[303]->getRelativePos() == pos); + TS_ASSERT_EQUALS(detectors[304]->getName(), "bank1, (1,0)"); + + /* TimeSeriesProperty<std::string>* slog = dynamic_cast<TimeSeriesProperty<std::string>*>(ws->run().getLogData("icp_event")); TS_ASSERT(slog); std::string str = slog->value(); @@ -100,9 +98,9 @@ public: TimeSeriesProperty<bool>* blog = dynamic_cast<TimeSeriesProperty<bool>*>(ws->run().getLogData("period 1")); TS_ASSERT(blog); TS_ASSERT_EQUALS(blog->size(),1); -*/ - //TS_ASSERT_EQUALS(ws->sample().getName(),"NONE"); - } + */ + //TS_ASSERT_EQUALS(ws->sample().getName(),"NONE"); + } }; #endif /*LOADSNSNEXUSTEST_H_*/ diff --git a/Code/Mantid/Framework/DataHandling/test/ManagedRawFileWorkspace2DTest.h b/Code/Mantid/Framework/DataHandling/test/ManagedRawFileWorkspace2DTest.h index d6811988664..f2dfc6eba58 100644 --- a/Code/Mantid/Framework/DataHandling/test/ManagedRawFileWorkspace2DTest.h +++ b/Code/Mantid/Framework/DataHandling/test/ManagedRawFileWorkspace2DTest.h @@ -178,31 +178,20 @@ public: //---------------------------------------------------------------------- // Tests to check that Loading SpectraDetectorMap is done correctly //---------------------------------------------------------------------- - const Geometry::ISpectraDetectorMap& map= output2D->spectraMap(); - - // Check the total number of elements in the map for HET - TS_ASSERT_EQUALS(map.nElements(),24964); - // Test one to one mapping, for example spectra 6 has only 1 pixel - TS_ASSERT_EQUALS(map.ndet(6),1); + TS_ASSERT_EQUALS( output2D->getSpectrum(6)->getDetectorIDs().size(), 1); // rummap.ndet(6),1); + + // Test one to many mapping, for example 10 pixels contribute to spectra 2084 (workspace index 2083) + TS_ASSERT_EQUALS( output2D->getSpectrum(2083)->getDetectorIDs().size(), 10); //map.ndet(2084),10); - // Test one to many mapping, for example 10 pixels contribute to spectra 2084 - TS_ASSERT_EQUALS(map.ndet(2084),10); // Check the id number of all pixels contributing - std::vector<detid_t> detectorgroup; - detectorgroup=map.getDetectors(2084); - std::vector<detid_t>::const_iterator it; + std::set<detid_t> detectorgroup; + detectorgroup = output2D->getSpectrum(2083)->getDetectorIDs(); + std::set<detid_t>::const_iterator it; int pixnum=101191; for (it=detectorgroup.begin();it!=detectorgroup.end();it++) - TS_ASSERT_EQUALS(*it,pixnum++); - - // Test with spectra that does not exist - // Test that number of pixel=0 - TS_ASSERT_EQUALS(map.ndet(5),0); - // Test that trying to get the Detector throws. - std::vector<detid_t> test = map.getDetectors(5); - TS_ASSERT(test.empty()); - + TS_ASSERT_EQUALS(*it,pixnum++); + //---------------------------------------------------------------------- // Test new-style spectrum/detector number retrieval //---------------------------------------------------------------------- diff --git a/Code/Mantid/Framework/DataObjects/test/GroupingWorkspaceTest.h b/Code/Mantid/Framework/DataObjects/test/GroupingWorkspaceTest.h index 58bf005289d..4a614b5042d 100644 --- a/Code/Mantid/Framework/DataObjects/test/GroupingWorkspaceTest.h +++ b/Code/Mantid/Framework/DataObjects/test/GroupingWorkspaceTest.h @@ -40,8 +40,7 @@ public: TS_ASSERT_EQUALS( ws->getNumberHistograms(), 45); TS_ASSERT_EQUALS( ws->blocksize(), 1); TS_ASSERT_EQUALS( ws->getInstrument()->getName(), "basic"); // Name of the test instrument - TS_ASSERT_EQUALS( ws->spectraMap().nElements(), 45); - std::vector<detid_t> dets = ws->spectraMap().getDetectors(1); + std::set<detid_t> dets = ws->getSpectrum(0)->getDetectorIDs(); TS_ASSERT_EQUALS(dets.size(), 1); // Set the group numbers diff --git a/Code/Mantid/Framework/DataObjects/test/Workspace2DTest.h b/Code/Mantid/Framework/DataObjects/test/Workspace2DTest.h index b94aaaa0b32..53e47f3f3dc 100644 --- a/Code/Mantid/Framework/DataObjects/test/Workspace2DTest.h +++ b/Code/Mantid/Framework/DataObjects/test/Workspace2DTest.h @@ -244,37 +244,6 @@ public: ws2->generateSpectraMap(); } - void test_spectraMap_getDetectorIDs() - { - CPUTimer tim; - SpectraAxis * axis = dynamic_cast<SpectraAxis *>(ws1->getAxis(1)); - const ISpectraDetectorMap & specMap = ws1->spectraMap(); - for (size_t i=0; i < ws1->getNumberHistograms(); i++) - { - specid_t specNo = axis->spectraNo(i); - std::vector<detid_t> detIDs = specMap.getDetectors(specNo); - detid_t oneDetId = detIDs[0]; - UNUSED_ARG(oneDetId) - } - std::cout << tim << " to get detector ID's for " << nhist << " spectra using the classic SpectraDetectorMap." << std::endl; - } - - void test_spectraMap_getDetectorIDs_in10groups() - { - CPUTimer tim; - SpectraAxis * axis = dynamic_cast<SpectraAxis *>(ws2->getAxis(1)); - const ISpectraDetectorMap & specMap = ws2->spectraMap(); - for (size_t i=0; i < ws2->getNumberHistograms(); i++) - { - specid_t specNo = axis->spectraNo(i); - std::vector<detid_t> detIDs = specMap.getDetectors(specNo); - detid_t oneDetId = detIDs[0]; - UNUSED_ARG(oneDetId) - } - std::cout << tim << " to get detector ID's for 10 spectra (each with 100,000 detectors) using the classic SpectraDetectorMap." << std::endl; - } - - void test_ISpectrum_getDetectorIDs() { CPUTimer tim; diff --git a/Code/Mantid/Framework/MPIAlgorithms/test/GatherWorkspacesTest.h b/Code/Mantid/Framework/MPIAlgorithms/test/GatherWorkspacesTest.h index 3068093d06b..bc0f4392e24 100644 --- a/Code/Mantid/Framework/MPIAlgorithms/test/GatherWorkspacesTest.h +++ b/Code/Mantid/Framework/MPIAlgorithms/test/GatherWorkspacesTest.h @@ -59,9 +59,9 @@ public: TS_ASSERT_EQUALS( inWS->readX(0)[i], outWS->readX(0)[i] ); TS_ASSERT_EQUALS( inWS->readY(0)[i], outWS->readY(0)[i] ); TS_ASSERT_EQUALS( inWS->readE(0)[i], outWS->readE(0)[i] ); + //TODO: Check spectrum numbers and detector IDs are copied correctly (perhaps?) } - //TS_ASSERT( outWS->spectraMap().nElements() == 0 ); TS_ASSERT_EQUALS( inWS->getBaseInstrument(), outWS->getBaseInstrument() ); } -- GitLab