From de27312d7649845171ed23a02cceb8d593f90f94 Mon Sep 17 00:00:00 2001 From: Marie Backman Date: Thu, 21 Dec 2023 09:34:49 -0500 Subject: [PATCH 1/2] An if-statement was accidentally changed to an else if-statement in ProcessBankData, causing LoadEventNexus to not load TOF:s correctly for files with monotonically increasing TOF:s. Change back the 'else if' to 'if' and add unit test for loading file with monotonically increasing TOF:s. --- .../DataHandling/src/ProcessBankData.cpp | 3 ++- .../DataHandling/test/LoadEventNexusTest.h | 21 +++++++++++++++++++ ...onically_increasing_pulse_times.nxs.h5.md5 | 1 + 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 Testing/Data/UnitTest/CG2_monotonically_increasing_pulse_times.nxs.h5.md5 diff --git a/Framework/DataHandling/src/ProcessBankData.cpp b/Framework/DataHandling/src/ProcessBankData.cpp index 8bb324775df2..624a345fd7b7 100644 --- a/Framework/DataHandling/src/ProcessBankData.cpp +++ b/Framework/DataHandling/src/ProcessBankData.cpp @@ -189,7 +189,8 @@ void ProcessBankData::run() { // tof limits from things observed here if (tof > my_longest_tof) { my_longest_tof = tof; - } else if (tof < my_shortest_tof) { + } + if (tof < my_shortest_tof) { my_shortest_tof = tof; } } else diff --git a/Framework/DataHandling/test/LoadEventNexusTest.h b/Framework/DataHandling/test/LoadEventNexusTest.h index ce6e2ed2b311..e6b511be7d0f 100644 --- a/Framework/DataHandling/test/LoadEventNexusTest.h +++ b/Framework/DataHandling/test/LoadEventNexusTest.h @@ -1057,6 +1057,27 @@ class LoadEventNexusTest : public CxxTest::TestSuite { TS_ASSERT_EQUALS(eventWS->detectorInfo().size(), 921) } + void test_monotonically_increasing_tofs() { + const std::string file = "CG2_monotonically_increasing_pulse_times.nxs.h5"; + LoadEventNexus alg; + alg.setChild(true); + alg.setRethrows(true); + alg.initialize(); + alg.setProperty("Filename", file); + alg.setProperty("OutputWorkspace", "dummy_for_child"); + alg.setProperty("NumberOfBins", 1); + alg.execute(); + Workspace_sptr ws = alg.getProperty("OutputWorkspace"); + auto eventWS = std::dynamic_pointer_cast(ws); + TS_ASSERT(eventWS); + const int expectedNumberEvents = 32494; + TS_ASSERT_EQUALS(eventWS->getNumberEvents(), expectedNumberEvents); + double sum = 0.0; + for (size_t i = 0; i < eventWS->getNumberHistograms(); ++i) + sum += eventWS->readY(i)[0]; + TS_ASSERT_DELTA(sum, expectedNumberEvents, 1e-6) + } + private: std::string wsSpecFilterAndEventMonitors; }; diff --git a/Testing/Data/UnitTest/CG2_monotonically_increasing_pulse_times.nxs.h5.md5 b/Testing/Data/UnitTest/CG2_monotonically_increasing_pulse_times.nxs.h5.md5 new file mode 100644 index 000000000000..291f5f8653c9 --- /dev/null +++ b/Testing/Data/UnitTest/CG2_monotonically_increasing_pulse_times.nxs.h5.md5 @@ -0,0 +1 @@ +f2ded7e4ff34296a5f7b37d0b83952a5 From be13e1a60a44bfd3cb5116c07dcfb406b0778772 Mon Sep 17 00:00:00 2001 From: Marie Backman Date: Thu, 21 Dec 2023 12:56:50 -0500 Subject: [PATCH 2/2] delete workspace and check number of bins --- Framework/DataHandling/test/LoadEventNexusTest.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Framework/DataHandling/test/LoadEventNexusTest.h b/Framework/DataHandling/test/LoadEventNexusTest.h index e6b511be7d0f..ee089d7676e2 100644 --- a/Framework/DataHandling/test/LoadEventNexusTest.h +++ b/Framework/DataHandling/test/LoadEventNexusTest.h @@ -1059,23 +1059,27 @@ class LoadEventNexusTest : public CxxTest::TestSuite { void test_monotonically_increasing_tofs() { const std::string file = "CG2_monotonically_increasing_pulse_times.nxs.h5"; + const std::string wsName = "dummy_for_child"; LoadEventNexus alg; alg.setChild(true); alg.setRethrows(true); alg.initialize(); alg.setProperty("Filename", file); - alg.setProperty("OutputWorkspace", "dummy_for_child"); + alg.setProperty("OutputWorkspace", wsName); alg.setProperty("NumberOfBins", 1); alg.execute(); Workspace_sptr ws = alg.getProperty("OutputWorkspace"); auto eventWS = std::dynamic_pointer_cast(ws); TS_ASSERT(eventWS); - const int expectedNumberEvents = 32494; + constexpr int expectedNumberEvents = 32494; TS_ASSERT_EQUALS(eventWS->getNumberEvents(), expectedNumberEvents); double sum = 0.0; - for (size_t i = 0; i < eventWS->getNumberHistograms(); ++i) + for (size_t i = 0; i < eventWS->getNumberHistograms(); ++i) { + TS_ASSERT_EQUALS(eventWS->readX(i).size(), 2) sum += eventWS->readY(i)[0]; + } TS_ASSERT_DELTA(sum, expectedNumberEvents, 1e-6) + AnalysisDataService::Instance().remove(wsName); } private: