From 5e6300d09ba474f2161c748294ab787cb16cf2b2 Mon Sep 17 00:00:00 2001 From: Ross Whitfield Date: Wed, 29 Jan 2025 10:56:58 +1100 Subject: [PATCH 1/6] Add failing test for PulseIndexer when zero events --- Framework/DataHandling/test/PulseIndexerTest.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Framework/DataHandling/test/PulseIndexerTest.h b/Framework/DataHandling/test/PulseIndexerTest.h index 3350025a28e0..a191ee10c661 100644 --- a/Framework/DataHandling/test/PulseIndexerTest.h +++ b/Framework/DataHandling/test/PulseIndexerTest.h @@ -169,6 +169,19 @@ class PulseIndexerTest : public CxxTest::TestSuite { run_test(eventIndices, start_event_index, total_events, first_pulse_index); } + void test_zerosEvents() { + // test that the pulse indexer can handle no events + auto eventIndices = std::make_shared>(); + eventIndices->push_back(0); + eventIndices->push_back(0); + + constexpr size_t start_event_index{0}; + constexpr size_t total_events{0}; + constexpr size_t first_pulse_index{1}; + + run_test(eventIndices, start_event_index, total_events, first_pulse_index); + } + void test_invalidPulseROI() { auto eventIndices = generate_nonConstant(); From 3c37a403db2474a10c82d77134162ecdbb9cc6c7 Mon Sep 17 00:00:00 2001 From: Ross Whitfield Date: Wed, 29 Jan 2025 10:57:19 +1100 Subject: [PATCH 2/6] Fix PulseIndexer --- Framework/DataHandling/src/PulseIndexer.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Framework/DataHandling/src/PulseIndexer.cpp b/Framework/DataHandling/src/PulseIndexer.cpp index b1ad1308dfd8..bc08498ddfe8 100644 --- a/Framework/DataHandling/src/PulseIndexer.cpp +++ b/Framework/DataHandling/src/PulseIndexer.cpp @@ -46,7 +46,7 @@ PulseIndexer::PulseIndexer(std::shared_ptr> event_index, c // determine if should trim the front end to remove empty pulses auto firstPulseIndex = m_roi.front(); auto eventRange = this->getEventIndexRange(firstPulseIndex); - while (eventRange.first == eventRange.second) { + while (eventRange.first == eventRange.second && eventRange.first < m_numEvents) { ++firstPulseIndex; eventRange = this->getEventIndexRange(firstPulseIndex); } @@ -54,7 +54,7 @@ PulseIndexer::PulseIndexer(std::shared_ptr> event_index, c // determine if should trim the back end to remove empty pulses auto lastPulseIndex = m_roi.back(); eventRange = this->getEventIndexRange(lastPulseIndex - 1); - while (eventRange.first == eventRange.second) { + while (eventRange.first == eventRange.second && eventRange.second > 0) { --lastPulseIndex; eventRange = this->getEventIndexRange(lastPulseIndex - 1); } @@ -146,7 +146,7 @@ size_t PulseIndexer::getLastPulseIndex() const { return m_roi.back(); } std::pair PulseIndexer::getEventIndexRange(const size_t pulseIndex) const { const auto start = this->getStartEventIndex(pulseIndex); // return early if the start is too big - if (start > m_numEvents) + if (start >= m_numEvents) return std::make_pair(start, m_numEvents); // get the end index From 5391000735c2cbdb7d7bdef5385bdf53c52af28c Mon Sep 17 00:00:00 2001 From: Ross Whitfield Date: Wed, 29 Jan 2025 11:08:00 +1100 Subject: [PATCH 3/6] Add test for LoadErrorEventsNexus with zero events --- .../test/LoadErrorEventsNexusTest.h | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Framework/DataHandling/test/LoadErrorEventsNexusTest.h b/Framework/DataHandling/test/LoadErrorEventsNexusTest.h index 96053d70f2a3..7eaa2219fb67 100644 --- a/Framework/DataHandling/test/LoadErrorEventsNexusTest.h +++ b/Framework/DataHandling/test/LoadErrorEventsNexusTest.h @@ -74,6 +74,26 @@ class LoadErrorEventsNexusTest : public CxxTest::TestSuite { TS_ASSERT_EQUALS(events[0].pulseTime(), Mantid::Types::Core::DateAndTime("2021-10-06T14:25:29.962441733-04:00")) } + void test_CG3_zeroEvents() { + // This file contains no events in bank_error_events so should create an EventWorkspace with 0 events + LoadErrorEventsNexus alg; + alg.setChild(true); + TS_ASSERT_THROWS_NOTHING(alg.initialize()) + TS_ASSERT(alg.isInitialized()) + TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("OutputWorkspace", "unused")) + TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("Filename", "CG3_960.nxs.h5")) + TS_ASSERT(alg.execute()); + + Mantid::DataObjects::EventWorkspace_sptr outputWS = alg.getProperty("OutputWorkspace"); + TS_ASSERT(outputWS); + + TS_ASSERT_EQUALS(outputWS->blocksize(), 1) + TS_ASSERT_EQUALS(outputWS->getNumberHistograms(), 1) + TS_ASSERT_EQUALS(outputWS->getNumberEvents(), 0) + TS_ASSERT_EQUALS(outputWS->readX(0)[0], 0) + TS_ASSERT_EQUALS(outputWS->readX(0)[1], std::numeric_limits::min()) + } + void test_HYSA() { // this should fail to load as bank_error_events does not exist in this file From 03ca40508ec99963024fc17d592bbf13bf7cf89e Mon Sep 17 00:00:00 2001 From: Ross Whitfield Date: Wed, 29 Jan 2025 11:10:22 +1100 Subject: [PATCH 4/6] Fix BinEdges in LoadErrorEventsNexus --- Framework/DataHandling/src/LoadErrorEventsNexus.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Framework/DataHandling/src/LoadErrorEventsNexus.cpp b/Framework/DataHandling/src/LoadErrorEventsNexus.cpp index cc8bb612db3e..5a2872b99aa6 100644 --- a/Framework/DataHandling/src/LoadErrorEventsNexus.cpp +++ b/Framework/DataHandling/src/LoadErrorEventsNexus.cpp @@ -132,7 +132,8 @@ void LoadErrorEventsNexus::exec() { g_log.information() << "Loaded " << numEvents << " events with TOF min = " << min_tof << ", max = " << max_tof << "\n"; - eventWS->setAllX(HistogramData::BinEdges{min_tof, max_tof}); + if (min_tof < max_tof) + eventWS->setAllX(HistogramData::BinEdges{min_tof, max_tof}); outWS->getAxis(0)->setUnit("TOF"); outWS->setYUnit("Counts"); From bbfb41785527463109b971a34e701a5e227d2991 Mon Sep 17 00:00:00 2001 From: Ross Whitfield Date: Wed, 29 Jan 2025 12:48:47 +1100 Subject: [PATCH 5/6] Add release note --- .../release/v6.12.0/Framework/Algorithms/Bugfixes/38738.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 docs/source/release/v6.12.0/Framework/Algorithms/Bugfixes/38738.rst diff --git a/docs/source/release/v6.12.0/Framework/Algorithms/Bugfixes/38738.rst b/docs/source/release/v6.12.0/Framework/Algorithms/Bugfixes/38738.rst new file mode 100644 index 000000000000..ef47fdabf9ec --- /dev/null +++ b/docs/source/release/v6.12.0/Framework/Algorithms/Bugfixes/38738.rst @@ -0,0 +1 @@ +- Fixed a bug in :ref:`LoadErrorEventsNexus ` that would cause it to hang when the error bank had zero events. From 2da9fbc70f9b671736c7cc6682e7d935558192e5 Mon Sep 17 00:00:00 2001 From: Ross Whitfield Date: Thu, 30 Jan 2025 08:13:14 +1100 Subject: [PATCH 6/6] Set bin edges for 0 event case --- Framework/DataHandling/src/LoadErrorEventsNexus.cpp | 2 ++ Framework/DataHandling/test/LoadErrorEventsNexusTest.h | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Framework/DataHandling/src/LoadErrorEventsNexus.cpp b/Framework/DataHandling/src/LoadErrorEventsNexus.cpp index 5a2872b99aa6..e1e93dfbf371 100644 --- a/Framework/DataHandling/src/LoadErrorEventsNexus.cpp +++ b/Framework/DataHandling/src/LoadErrorEventsNexus.cpp @@ -134,6 +134,8 @@ void LoadErrorEventsNexus::exec() { if (min_tof < max_tof) eventWS->setAllX(HistogramData::BinEdges{min_tof, max_tof}); + else + eventWS->setAllX(HistogramData::BinEdges{0, 16666.7}); outWS->getAxis(0)->setUnit("TOF"); outWS->setYUnit("Counts"); diff --git a/Framework/DataHandling/test/LoadErrorEventsNexusTest.h b/Framework/DataHandling/test/LoadErrorEventsNexusTest.h index 7eaa2219fb67..2b60d62e08c3 100644 --- a/Framework/DataHandling/test/LoadErrorEventsNexusTest.h +++ b/Framework/DataHandling/test/LoadErrorEventsNexusTest.h @@ -91,7 +91,7 @@ class LoadErrorEventsNexusTest : public CxxTest::TestSuite { TS_ASSERT_EQUALS(outputWS->getNumberHistograms(), 1) TS_ASSERT_EQUALS(outputWS->getNumberEvents(), 0) TS_ASSERT_EQUALS(outputWS->readX(0)[0], 0) - TS_ASSERT_EQUALS(outputWS->readX(0)[1], std::numeric_limits::min()) + TS_ASSERT_DELTA(outputWS->readX(0)[1], 16666.7, 1e-9) } void test_HYSA() {