From d4b28cdfa04dc8f899e6b15fc2bc4b09a08634f4 Mon Sep 17 00:00:00 2001 From: Owen Arnold <owen.arnold@stfc.ac.uk> Date: Fri, 26 Jun 2015 13:42:23 +0100 Subject: [PATCH] refs #12776. Write multiperiod group workspace. Rough tests of output. --- .../inc/MantidDataHandling/LoadEventNexus.h | 18 ++++++++++++++- .../DataHandling/src/LoadEventNexus.cpp | 7 +++--- .../DataHandling/test/LoadEventNexusTest.h | 22 ++++++++++++------- 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadEventNexus.h b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadEventNexus.h index 505a3a6bb74..383ae1bf6c6 100644 --- a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadEventNexus.h +++ b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadEventNexus.h @@ -9,6 +9,7 @@ #include <nexus/NeXusFile.hpp> #include <nexus/NeXusException.hpp> #include "MantidDataObjects/Events.h" +#include "MantidAPI/WorkspaceGroup.h" #include "MantidKernel/TimeSeriesProperty.h" namespace Mantid { @@ -69,7 +70,22 @@ public: return m_WsVec.size(); } - DataObjects::EventWorkspace_sptr getSingleHeldWorkspace(){return m_WsVec.front();} // TODO remove + DataObjects::EventWorkspace_sptr getSingleHeldWorkspace(){return m_WsVec.front();} + + API::Workspace_sptr combinedWorkspace(){ + API::Workspace_sptr final; + if( this->nPeriods() == 1 ){ + final = getSingleHeldWorkspace(); + } + else{ + auto wsg = boost::make_shared<API::WorkspaceGroup>(); + for(size_t i = 0; i < m_WsVec.size(); ++i){ + wsg->addWorkspace(m_WsVec[i]); + } + final = wsg; + } + return final; + } DecoratorWorkspace(): m_WsVec(1, createEmptyEventWorkspace()){} diff --git a/Code/Mantid/Framework/DataHandling/src/LoadEventNexus.cpp b/Code/Mantid/Framework/DataHandling/src/LoadEventNexus.cpp index 736f028abb5..645dd5e6735 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadEventNexus.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadEventNexus.cpp @@ -1271,7 +1271,7 @@ void LoadEventNexus::exec() { // add filename m_ws->mutableRun().addProperty("Filename", m_filename); // Save output - this->setProperty<IEventWorkspace_sptr>("OutputWorkspace", m_ws->getSingleHeldWorkspace()); + this->setProperty("OutputWorkspace", m_ws->combinedWorkspace()); // Load the monitors if (load_monitors) { prog.report("Loading monitors"); @@ -1438,7 +1438,7 @@ std::vector<int> LoadEventNexus::fetchFramePeriods() m_file->openGroup("period_log", "NXlog"); m_file->openData("value"); std::vector<int> temp; - m_file->getData(periodLog); + m_file->getData(temp); periodLog = temp; m_file->closeData(); m_file->closeGroup(); @@ -1855,9 +1855,10 @@ void DecoratorWorkspace::setNPeriods(size_t nPeriods) { // Create vector where size is the number of periods and initialize workspaces in each. auto temp = m_WsVec[0]; m_WsVec = std::vector<DataObjects::EventWorkspace_sptr>( - nPeriods, createEmptyEventWorkspace()); + nPeriods); for (size_t i = 0; i < m_WsVec.size(); ++i) { + m_WsVec[i] = createEmptyEventWorkspace(); copyLogs(temp, m_WsVec[i]); // Copy all logs from dummy workspace to period workspaces. m_WsVec[i]->setInstrument(temp->getInstrument()); } diff --git a/Code/Mantid/Framework/DataHandling/test/LoadEventNexusTest.h b/Code/Mantid/Framework/DataHandling/test/LoadEventNexusTest.h index 40fd4f21ff7..631a751229d 100644 --- a/Code/Mantid/Framework/DataHandling/test/LoadEventNexusTest.h +++ b/Code/Mantid/Framework/DataHandling/test/LoadEventNexusTest.h @@ -620,15 +620,21 @@ void test_extract_nperiod_data() { loader.setPropertyValue("Filename", "LARMOR00003368.nxs"); loader.execute(); Workspace_sptr outWS = loader.getProperty("OutputWorkspace"); - IEventWorkspace_sptr outEventWS = boost::dynamic_pointer_cast<IEventWorkspace>(outWS); - TSM_ASSERT("Invalid Output Workspace Type", outEventWS); - auto run = outEventWS->run(); - const bool hasNPeriods = run.hasProperty("nperiods"); - TSM_ASSERT("Should have nperiods now we have run LoadNexusLogs", hasNPeriods); - if (hasNPeriods) { - const int nPeriods = run.getPropertyValueAsType<int>("nperiods"); - TSM_ASSERT_EQUALS("Wrong number of periods extracted", nPeriods, 4); + WorkspaceGroup_sptr outGroup = boost::dynamic_pointer_cast<WorkspaceGroup>(outWS); + TSM_ASSERT("Invalid Output Workspace Type", outGroup); + + IEventWorkspace_sptr firstWS = boost::dynamic_pointer_cast<IEventWorkspace>(outGroup->getItem(0)); + auto run = firstWS->run(); + const int nPeriods = run.getPropertyValueAsType<int>("nperiods"); + TSM_ASSERT_EQUALS("Wrong number of periods extracted", nPeriods, 4); + TSM_ASSERT_EQUALS("Groups size should be same as nperiods", outGroup->size(), nPeriods); + + for(size_t i = 0; i < outGroup->size(); ++i){ + EventWorkspace_sptr ws = boost::dynamic_pointer_cast<EventWorkspace>(outGroup->getItem(i)); + TS_ASSERT(ws); + TSM_ASSERT("Non-zero events in each period", ws->getNumberEvents() > 0); } + } private: -- GitLab