diff --git a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadISISNexus2.h b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadISISNexus2.h index f17f40173afe..7085b7c87be3 100644 --- a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadISISNexus2.h +++ b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadISISNexus2.h @@ -102,7 +102,8 @@ namespace Mantid // Load a data block void loadBlock(Mantid::NeXus::NXDataSetTyped & data, int64_t blocksize, int64_t period, int64_t start, int64_t &hist, int64_t& spec_num, DataObjects::Workspace2D_sptr localWorkspace); - + // Load period logs + void loadPeriodLogs(int64_t period, DataObjects::Workspace2D_sptr local_workspace); /// The name and path of the input file std::string m_filename; diff --git a/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp b/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp index f234cd31c55f..f560308fcf68 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp @@ -228,6 +228,12 @@ namespace Mantid } int64_t firstentry = (m_entrynumber > 0) ? m_entrynumber : 1; loadPeriodData(firstentry, entry, local_workspace); + + // Clone the workspace at this point to provide a base object for future workspace generation. + DataObjects::Workspace2D_sptr period_free_workspace = boost::dynamic_pointer_cast + (WorkspaceFactory::Instance().create(local_workspace)); + + loadPeriodLogs(firstentry, local_workspace); if( m_numberOfPeriods > 1 && m_entrynumber == 0 ) { @@ -237,7 +243,7 @@ namespace Mantid //This forms the name of the group const std::string base_name = getPropertyValue("OutputWorkspace") + "_"; const std::string prop_name = "OutputWorkspace_"; - + for( size_t p = 1; p <= m_numberOfPeriods; ++p ) { std::ostringstream os; @@ -246,8 +252,9 @@ namespace Mantid if( p > 1 ) { local_workspace = boost::dynamic_pointer_cast - (WorkspaceFactory::Instance().create(local_workspace)); + (WorkspaceFactory::Instance().create(period_free_workspace)); loadPeriodData(p, entry, local_workspace); + loadPeriodLogs(p, local_workspace); } declareProperty(new WorkspaceProperty(prop_name + os.str(), base_name + os.str(), Direction::Output)); wksp_group->addWorkspace(local_workspace); @@ -496,6 +503,27 @@ namespace Mantid } } + /** + Loads period log data into the workspace + @param period :: period number + @param local_workspace :: workspace to add period log data to. + */ + void LoadISISNexus2::loadPeriodLogs(int64_t period, DataObjects::Workspace2D_sptr local_workspace) + { + // If we loaded an icp_event log then create the necessary period logs + if( local_workspace->run().hasProperty("icp_event") ) + { + Kernel::Property *log = local_workspace->run().getProperty("icp_event"); + LogParser parser(log); + local_workspace->mutableRun().addProperty(parser.createPeriodLog(static_cast(period))); + Property* periods = parser.createAllPeriodsLog(); + if(!local_workspace->mutableRun().hasProperty(periods->name())) + { + local_workspace->mutableRun().addProperty(periods); + } + } + } + /** * Perform a call to nxgetslab, via the NexusClasses wrapped methods for a given blocksize @@ -727,15 +755,6 @@ namespace Mantid return; } ws->populateInstrumentParameters(); - // If we loaded an icp_event log then create the necessary period logs - if( ws->run().hasProperty("icp_event") ) - { - Kernel::Property *log = ws->run().getProperty("icp_event"); - LogParser parser(log); - ws->mutableRun().addProperty(parser.createPeriodLog(period)); - ws->mutableRun().addProperty(parser.createAllPeriodsLog()); - } - } double LoadISISNexus2::dblSqrt(double in) diff --git a/Code/Mantid/Framework/DataHandling/test/LoadISISNexusTest.h b/Code/Mantid/Framework/DataHandling/test/LoadISISNexusTest.h index d98ec5fe9f5d..8f0401f71443 100644 --- a/Code/Mantid/Framework/DataHandling/test/LoadISISNexusTest.h +++ b/Code/Mantid/Framework/DataHandling/test/LoadISISNexusTest.h @@ -11,6 +11,7 @@ #include "MantidKernel/TimeSeriesProperty.h" #include "MantidAPI/FrameworkManager.h" #include "MantidAPI/WorkspaceGroup.h" +#include "MantidKernel/LogFilter.h" using namespace Mantid::API; using namespace Mantid::Kernel; @@ -18,6 +19,29 @@ using namespace Mantid::DataHandling; class LoadISISNexusTest : public CxxTest::TestSuite { +private: + + // Helper method to fetch the log property entry corresponding to period. + Property* fetchPeriod(MatrixWorkspace_sptr workspace, int expectedPeriodNumber) + { + std::stringstream period_number_stream; + period_number_stream << expectedPeriodNumber; + std::string log_name = "period " + period_number_stream.str(); + Property* p= workspace->run().getLogData(log_name); + return p; + } + + // Helper method to check that the log data contains a specific period number entry. + void checkPeriodLogData(MatrixWorkspace_sptr workspace, int expectedPeriodNumber) + { + Property* p; + TS_ASSERT_THROWS_NOTHING(p = fetchPeriod(workspace, expectedPeriodNumber)); + TSM_ASSERT_THROWS("Shouldn't have a period less than the expected entry", fetchPeriod(workspace, expectedPeriodNumber-1), Mantid::Kernel::Exception::NotFoundError); + TSM_ASSERT_THROWS("Shouldn't have a period greater than the expected entry", fetchPeriod(workspace, expectedPeriodNumber+1), Mantid::Kernel::Exception::NotFoundError); + Mantid::Kernel::TimeSeriesProperty* period_property = dynamic_cast*>(p); + TS_ASSERT(period_property); + } + public: void testExec() { @@ -80,6 +104,7 @@ class LoadISISNexusTest : public CxxTest::TestSuite Property *l_property = ws->run().getLogData( "run_number" ); TS_ASSERT_EQUALS( l_property->value(), "49886" ); + AnalysisDataService::Instance().remove("outWS"); } void testExec2() { @@ -109,6 +134,7 @@ class LoadISISNexusTest : public CxxTest::TestSuite TS_ASSERT_EQUALS(ws->readY(8)[1],2.); TS_ASSERT_EQUALS(ws->readY(10)[3],1.); TS_ASSERT_EQUALS(ws->readY(13)[4],1.); + AnalysisDataService::Instance().remove("outWS"); } void testMultiPeriodEntryNumberZero() { @@ -143,6 +169,7 @@ class LoadISISNexusTest : public CxxTest::TestSuite TS_ASSERT_EQUALS(ws->readY(7)[1],0.); TS_ASSERT_EQUALS(ws->readY(9)[3],0.); TS_ASSERT_EQUALS(ws->readY(9)[1],0.); + AnalysisDataService::Instance().remove("outWS"); } void testMultiPeriodEntryNumberNonZero() { @@ -175,6 +202,37 @@ class LoadISISNexusTest : public CxxTest::TestSuite TS_ASSERT_EQUALS(ws->readY(7)[1],0.); TS_ASSERT_EQUALS(ws->readY(9)[3],0.); TS_ASSERT_EQUALS(ws->readY(9)[1],0.); + AnalysisDataService::Instance().remove("outWS"); + } + + void testLoadMultiPeriodData() + { + Mantid::API::FrameworkManager::Instance(); + const std::string wsName = "outWS"; + LoadISISNexus2 loadingAlg; + loadingAlg.initialize(); + loadingAlg.setRethrows(true); + loadingAlg.setPropertyValue("Filename","POLREF00004699.nxs"); + loadingAlg.setPropertyValue("OutputWorkspace", wsName); + loadingAlg.execute(); + TS_ASSERT(loadingAlg.isExecuted()); + + AnalysisDataServiceImpl& ADS = AnalysisDataService::Instance(); + + WorkspaceGroup_sptr grpWs; + TS_ASSERT_THROWS_NOTHING(grpWs=ADS.retrieveWS(wsName)); + TSM_ASSERT_EQUALS("Should be two workspaces in the group",2, grpWs->size()); + + // Check the individual workspace group members. + MatrixWorkspace_sptr ws1 = boost::dynamic_pointer_cast(grpWs->getItem(0)); + MatrixWorkspace_sptr ws2 = boost::dynamic_pointer_cast(grpWs->getItem(1)); + TS_ASSERT(ws1 != NULL); + TS_ASSERT(ws2 != NULL); + // Check that workspace 1 has the correct period data, and no other period log data + checkPeriodLogData(ws1, 1); + // Check that workspace 2 has the correct period data, and no other period log data + checkPeriodLogData(ws2, 2); + AnalysisDataService::Instance().remove(wsName); } }; diff --git a/Test/AutoTestData/POLREF00004699.nxs b/Test/AutoTestData/POLREF00004699.nxs new file mode 100644 index 000000000000..f960bb84f3de Binary files /dev/null and b/Test/AutoTestData/POLREF00004699.nxs differ