diff --git a/Framework/DataHandling/src/DefaultEventLoader.cpp b/Framework/DataHandling/src/DefaultEventLoader.cpp index cbdaf9316dfe..fde3472383c1 100644 --- a/Framework/DataHandling/src/DefaultEventLoader.cpp +++ b/Framework/DataHandling/src/DefaultEventLoader.cpp @@ -62,7 +62,9 @@ DefaultEventLoader::DefaultEventLoader(LoadEventNexus *alg, EventWorkspaceCollec if (alg->compressEvents && alg->compressTolerance != 0) { // Convert to weighted events for (size_t i = 0; i < m_ws.getNumberHistograms(); i++) { - m_ws.getSpectrum(i).switchTo(API::WEIGHTED_NOTIME); + for (size_t period = 0; period < m_ws.nPeriods(); ++period) { + m_ws.getSpectrum(i, period).switchTo(API::WEIGHTED_NOTIME); + } } makeMapToEventLists(weightedNoTimeEventVectors); } else { @@ -71,7 +73,9 @@ DefaultEventLoader::DefaultEventLoader(LoadEventNexus *alg, EventWorkspaceCollec } else { // Convert to weighted events for (size_t i = 0; i < m_ws.getNumberHistograms(); i++) { - m_ws.getSpectrum(i).switchTo(API::WEIGHTED); + for (size_t period = 0; period < m_ws.nPeriods(); ++period) { + m_ws.getSpectrum(i, period).switchTo(API::WEIGHTED); + } } makeMapToEventLists(weightedEventVectors); } diff --git a/Framework/DataHandling/src/LoadBankFromDiskTask.cpp b/Framework/DataHandling/src/LoadBankFromDiskTask.cpp index d6145224c7f0..54aa6571ced9 100644 --- a/Framework/DataHandling/src/LoadBankFromDiskTask.cpp +++ b/Framework/DataHandling/src/LoadBankFromDiskTask.cpp @@ -337,7 +337,7 @@ void LoadBankFromDiskTask::run() { const bool needPulseInfo = (!m_loader.alg->compressEvents) || m_loader.alg->compressTolerance == 0 || m_loader.m_ws.nPeriods() > 1 || m_loader.alg->m_is_time_filtered || - m_loader.alg->filter_bad_pulses; + m_loader.alg->filter_bad_pulses || m_have_weight; // Load the event_index field. if (needPulseInfo) @@ -347,10 +347,10 @@ void LoadBankFromDiskTask::run() { if (!m_loadError) { // Load and validate the pulse times - if (m_loader.alg->compressEvents && m_loader.alg->compressTolerance != 0 && !m_loader.alg->filter_bad_pulses) - thisBankPulseTimes = nullptr; - else + if (needPulseInfo) this->loadPulseTimes(file); + else + thisBankPulseTimes = nullptr; // The event_index should be the same length as the pulse times from DAS // logs. if (event_index && event_index->size() != thisBankPulseTimes->numberOfPulses()) diff --git a/Framework/DataHandling/test/LoadEventNexusTest.h b/Framework/DataHandling/test/LoadEventNexusTest.h index 914710e305c5..8a8bb66a05b7 100644 --- a/Framework/DataHandling/test/LoadEventNexusTest.h +++ b/Framework/DataHandling/test/LoadEventNexusTest.h @@ -173,7 +173,7 @@ class LoadEventNexusTest : public CxxTest::TestSuite { * number of events. */ void validateUncompressedCompressed(EventWorkspace_sptr ws_uncompressed, EventWorkspace_sptr ws_compressed, - const std::size_t NUM_HIST) { + const std::size_t NUM_HIST, const EventType uncompressed_type = EventType::TOF) { TS_ASSERT_EQUALS(ws_uncompressed->getNumberHistograms(), NUM_HIST); TS_ASSERT_EQUALS(ws_compressed->getNumberHistograms(), NUM_HIST); @@ -185,7 +185,7 @@ class LoadEventNexusTest : public CxxTest::TestSuite { TS_ASSERT_EQUALS(ws_compressed->readY(wi), ws_uncompressed->readY(wi)); // all uncompressed spectra should be raw events - TS_ASSERT_EQUALS(ws_uncompressed->getSpectrum(wi).getEventType(), EventType::TOF); + TS_ASSERT_EQUALS(ws_uncompressed->getSpectrum(wi).getEventType(), uncompressed_type); // pixels with at least one event will have switched to weighted if (ws_compressed->getSpectrum(wi).getNumberEvents() > 0) @@ -915,6 +915,110 @@ class LoadEventNexusTest : public CxxTest::TestSuite { TS_ASSERT_EQUALS(WS, ads.retrieveWS("cncs_compressed")->monitorWorkspace()); } + void test_Load_And_CompressEvents_weighted() { + constexpr std::size_t NUM_HIST{117760}; + const std::string filename{"ARCS_sim_event.nxs"}; + + Mantid::API::FrameworkManager::Instance(); + + // create uncompressed - first so turning off compression isn't needed + std::string uncompressed_name = "arcs_uncompressed"; + { + LoadEventNexus ld; + ld.initialize(); + ld.setPropertyValue("Filename", filename); + ld.setPropertyValue("OutputWorkspace", uncompressed_name); + ld.setProperty("Precount", false); + ld.setProperty("LoadLogs", false); // Time-saver + ld.setProperty("NumberOfBins", 1); + ld.execute(); + TS_ASSERT(ld.isExecuted()); + } + // get a reference to the uncompressed workspace + EventWorkspace_sptr ws_uncompressed; + TS_ASSERT_THROWS_NOTHING(ws_uncompressed = + AnalysisDataService::Instance().retrieveWS(uncompressed_name)); + TS_ASSERT(ws_uncompressed); // it is an EventWorkspace + + // create compressed + std::string compressed_name = "arcs_compressed"; + { + LoadEventNexus ld; + ld.initialize(); + ld.setPropertyValue("Filename", filename); + ld.setPropertyValue("OutputWorkspace", compressed_name); + ld.setProperty("Precount", false); + ld.setProperty("LoadLogs", false); // Time-saver + ld.setPropertyValue("CompressTolerance", "0.05"); + ld.setProperty("NumberOfBins", 1); + ld.execute(); + TS_ASSERT(ld.isExecuted()); + } + // get a reference to the uncompressed workspace + EventWorkspace_sptr ws_compressed; + TS_ASSERT_THROWS_NOTHING(ws_compressed = + AnalysisDataService::Instance().retrieveWS(compressed_name)); + TS_ASSERT(ws_compressed); // it is an EventWorkspace + + // validate the compressed workspace makes sense compared to uncompressed + validateUncompressedCompressed(ws_uncompressed, ws_compressed, NUM_HIST, EventType::WEIGHTED); + + // cleanup + AnalysisDataService::Instance().remove(uncompressed_name); + AnalysisDataService::Instance().remove(compressed_name); + } + + void test_Load_And_CompressEvents_with_nperiod_data() { + constexpr std::size_t NUM_HIST{40960}; + const std::string filename{"LARMOR00003368.nxs"}; + + Mantid::API::FrameworkManager::Instance(); + + // create uncompressed - first so turning off compression isn't needed + std::string uncompressed_name = "larmor_uncompressed"; + { + LoadEventNexus ld; + ld.initialize(); + ld.setPropertyValue("Filename", filename); + ld.setPropertyValue("OutputWorkspace", uncompressed_name); + ld.setProperty("Precount", false); + ld.setProperty("NumberOfBins", 1); + ld.execute(); + TS_ASSERT(ld.isExecuted()); + } + // get a reference to the uncompressed workspace, first workspace only + EventWorkspace_sptr ws_uncompressed; + TS_ASSERT_THROWS_NOTHING(ws_uncompressed = + AnalysisDataService::Instance().retrieveWS(uncompressed_name + "_1")); + TS_ASSERT(ws_uncompressed); // it is an EventWorkspace + + // create compressed + std::string compressed_name = "larmor_compressed"; + { + LoadEventNexus ld; + ld.initialize(); + ld.setPropertyValue("Filename", filename); + ld.setPropertyValue("OutputWorkspace", compressed_name); + ld.setProperty("Precount", false); + ld.setPropertyValue("CompressTolerance", "0.05"); + ld.setProperty("NumberOfBins", 1); + ld.execute(); + TS_ASSERT(ld.isExecuted()); + } + // get a reference to the uncompressed workspace, first workspace only + EventWorkspace_sptr ws_compressed; + TS_ASSERT_THROWS_NOTHING(ws_compressed = + AnalysisDataService::Instance().retrieveWS(compressed_name + "_1")); + TS_ASSERT(ws_compressed); // it is an EventWorkspace + + // validate the compressed workspace makes sense compared to uncompressed + validateUncompressedCompressed(ws_uncompressed, ws_compressed, NUM_HIST); + + // cleanup + AnalysisDataService::Instance().remove(uncompressed_name); + AnalysisDataService::Instance().remove(compressed_name); + } + void test_Load_And_CompressEvents_tolerance_0() { // the is to verify that the compresssion works when the CompressTolerance=0 // create compressed diff --git a/Framework/DataObjects/src/EventList.cpp b/Framework/DataObjects/src/EventList.cpp index 0517b354e395..71b451ed8844 100644 --- a/Framework/DataObjects/src/EventList.cpp +++ b/Framework/DataObjects/src/EventList.cpp @@ -830,7 +830,7 @@ const std::vector &EventList::getWeightedEvents() const { * */ std::vector &EventList::getWeightedEventsNoTime() { if (eventType != WEIGHTED_NOTIME) - throw std::runtime_error("EventList::getWeightedEvents() called for an " + throw std::runtime_error("EventList::getWeightedEventsNoTime() called for an " "EventList not of type WeightedEventNoTime. Use " "getEvents() or getWeightedEvents()."); return this->weightedEventsNoTime;