diff --git a/Code/Mantid/Framework/DataHandling/src/LoadILL.cpp b/Code/Mantid/Framework/DataHandling/src/LoadILL.cpp index df203d840d8f..1e7ac2758a10 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadILL.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadILL.cpp @@ -9,8 +9,6 @@ The property FilenameVanadium is optional. If it is present the EPP will be load To date this algorithm only supports: IN4, IN5 and IN6 - - *WIKI*/ //--------------------------------------------------- // Includes @@ -122,36 +120,6 @@ namespace Mantid } - /** - * - */ - int LoadILL::validateVanadium(const std::string &filenameVanadium) { - NeXus::NXRoot vanaRoot(filenameVanadium); - NXEntry vanaFirstEntry = vanaRoot.openFirstEntry(); - - double wavelength = vanaFirstEntry.getFloat("wavelength"); - - // read in the data - NXData dataGroup = vanaFirstEntry.openNXData("data"); - NXInt data = dataGroup.openIntData(); - - size_t numberOfTubes = static_cast(data.dim0()); - size_t numberOfPixelsPerTube = static_cast(data.dim1()); - size_t numberOfChannels = static_cast(data.dim2()); - - if (wavelength != m_wavelength || numberOfTubes != m_numberOfTubes - || numberOfPixelsPerTube != m_numberOfPixelsPerTube - || numberOfChannels != m_numberOfChannels) { - throw std::runtime_error( - "Vanadium and Data were not collected in the same conditions!"); - } - - data.load(); - int calculatedDetectorElasticPeakPosition = getDetectorElasticPeakPosition( - data); - return calculatedDetectorElasticPeakPosition; - } - /** * Execute the algorithm @@ -467,6 +435,43 @@ namespace Mantid return calculatedDetectorElasticPeakPosition; } + + /** + * It loads the vanadium nexus file and cross checks it against the + * data file already loaded (same wavelength and same instrument configuration). + * If matches looks for the elastic peak in the vanadium file and returns + * it position. + * + * @param filenameVanadium :: The path for the vanadium nexus file. + * @return The elastic peak position inside the tof channels. + */ + int LoadILL::validateVanadium(const std::string &filenameVanadium) { + NeXus::NXRoot vanaRoot(filenameVanadium); + NXEntry vanaFirstEntry = vanaRoot.openFirstEntry(); + + double wavelength = vanaFirstEntry.getFloat("wavelength"); + + // read in the data + NXData dataGroup = vanaFirstEntry.openNXData("data"); + NXInt data = dataGroup.openIntData(); + + size_t numberOfTubes = static_cast(data.dim0()); + size_t numberOfPixelsPerTube = static_cast(data.dim1()); + size_t numberOfChannels = static_cast(data.dim2()); + + if (wavelength != m_wavelength || numberOfTubes != m_numberOfTubes + || numberOfPixelsPerTube != m_numberOfPixelsPerTube + || numberOfChannels != m_numberOfChannels) { + throw std::runtime_error( + "Vanadium and Data were not collected in the same conditions!"); + } + + data.load(); + int calculatedDetectorElasticPeakPosition = getDetectorElasticPeakPosition( + data); + return calculatedDetectorElasticPeakPosition; + } + /** * Loads all the spectra into the workspace, including that from the monitor * @@ -550,29 +555,23 @@ namespace Mantid /** * Run the Child Algorithm LoadInstrument. */ - void LoadILL::runLoadInstrument() - { + void LoadILL::runLoadInstrument() { - IAlgorithm_sptr loadInst = createChildAlgorithm("LoadInstrument"); - - // Now execute the Child Algorithm. Catch and log any error, but don't stop. - try - { - - // TODO: depending on the m_numberOfPixelsPerTube we might need to load a different IDF - - loadInst->setPropertyValue("InstrumentName", m_instrumentName); - loadInst->setProperty("Workspace", - m_localWorkspace); - loadInst->execute(); - } catch (...) - { - g_log.information("Cannot load the instrument definition."); - } - } + IAlgorithm_sptr loadInst = createChildAlgorithm("LoadInstrument"); + // Now execute the Child Algorithm. Catch and log any error, but don't stop. + try { + // TODO: depending on the m_numberOfPixelsPerTube we might need to load a different IDF + loadInst->setPropertyValue("InstrumentName", m_instrumentName); + loadInst->setProperty("Workspace", + m_localWorkspace); + loadInst->execute(); + } catch (...) { + g_log.information("Cannot load the instrument definition."); + } + } diff --git a/Code/Mantid/Framework/DataHandling/test/LoadILLTest.h b/Code/Mantid/Framework/DataHandling/test/LoadILLTest.h index 5c1ae4558c38..17de7adb578b 100644 --- a/Code/Mantid/Framework/DataHandling/test/LoadILLTest.h +++ b/Code/Mantid/Framework/DataHandling/test/LoadILLTest.h @@ -17,8 +17,7 @@ class LoadILLTest: public CxxTest::TestSuite static void destroySuite( LoadILLTest *suite ) { delete suite; } LoadILLTest() : - m_testFile("ILLIN5_104007.nxs") - { + m_dataFile("ILLIN5_104007.nxs") { } void testName() { @@ -37,35 +36,32 @@ class LoadILLTest: public CxxTest::TestSuite TS_ASSERT( loader.isInitialized()); } -// void testFileCheck() { -// std::cerr << loader.fileCheck(testFile); -// } - - void testExec() { + /* + * This test only loads the Sample Data + * The elastic peak is obtained on the fly from the sample data. + */ + void testExecJustSample() { LoadILL loader; loader.initialize(); - loader.setPropertyValue("Filename", m_testFile); + loader.setPropertyValue("Filename", m_dataFile); std::string outputSpace = "LoadILLTest_out"; loader.setPropertyValue("OutputWorkspace", outputSpace); TS_ASSERT_THROWS_NOTHING( loader.execute()); - // test workspace, copied from LoadMuonNexusTest.h - MatrixWorkspace_sptr output; - - (output = AnalysisDataService::Instance().retrieveWS( - outputSpace)); - MatrixWorkspace_sptr output2D = boost::dynamic_pointer_cast< - MatrixWorkspace>(output); + MatrixWorkspace_sptr output = AnalysisDataService::Instance().retrieveWS(outputSpace); + MatrixWorkspace_sptr output2D = boost::dynamic_pointer_cast(output); TS_ASSERT_EQUALS( output2D->getNumberHistograms(), 98304); AnalysisDataService::Instance().clear(); } + + private: + std::string m_dataFile; - std::string m_testFile; }; //------------------------------------------------------------------------------ @@ -74,13 +70,21 @@ class LoadILLTest: public CxxTest::TestSuite class LoadILLTestPerformance: public CxxTest::TestSuite { public: + LoadILLTestPerformance() : + m_dataFile("ILLIN5_104007.nxs"){ + } + void testDefaultLoad() { Mantid::DataHandling::LoadILL loader; loader.initialize(); - loader.setPropertyValue("Filename", "ILLIN5_104007.nxs"); + loader.setPropertyValue("Filename", m_dataFile); loader.setPropertyValue("OutputWorkspace", "ws"); - TS_ASSERT( loader.execute()); + TS_ASSERT(loader.execute()); } + +private: + std::string m_dataFile; + }; #endif /*LoadILLTEST_H_*/