Skip to content

Commit

Permalink
Merge ornl-next into main
Browse files Browse the repository at this point in the history
  • Loading branch information
mantid-builder authored Jun 5, 2024
2 parents b8d9c92 + 351c75a commit 21b11ee
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 9 deletions.
8 changes: 6 additions & 2 deletions Framework/DataHandling/src/DefaultEventLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
}
Expand Down
8 changes: 4 additions & 4 deletions Framework/DataHandling/src/LoadBankFromDiskTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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())
Expand Down
108 changes: 106 additions & 2 deletions Framework/DataHandling/test/LoadEventNexusTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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)
Expand Down Expand Up @@ -915,6 +915,110 @@ class LoadEventNexusTest : public CxxTest::TestSuite {
TS_ASSERT_EQUALS(WS, ads.retrieveWS<MatrixWorkspace>("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<bool>("Precount", false);
ld.setProperty<bool>("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<EventWorkspace>(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<bool>("Precount", false);
ld.setProperty<bool>("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<EventWorkspace>(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<bool>("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<EventWorkspace>(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<bool>("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<EventWorkspace>(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
Expand Down
2 changes: 1 addition & 1 deletion Framework/DataObjects/src/EventList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ const std::vector<WeightedEvent> &EventList::getWeightedEvents() const {
* */
std::vector<WeightedEventNoTime> &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;
Expand Down

0 comments on commit 21b11ee

Please sign in to comment.