Mantid
Loading...
Searching...
No Matches
LoadNGEM.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2019 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
8#include "MantidAPI/Axis.h"
11#include "MantidAPI/Run.h"
12
19#include "MantidKernel/Unit.h"
21
22#include <boost/algorithm/string.hpp>
23#include <fstream>
24#include <ranges>
25
26namespace Mantid::DataHandling {
27
29
30// Constants and helper functions.
31namespace {
32constexpr int NUM_OF_SPECTRA = 16384;
33
42uint64_t swapUint64(uint64_t word) {
43 word = ((word << 8) & 0xFF00FF00FF00FF00ULL) | ((word >> 8) & 0x00FF00FF00FF00FFULL);
44 word = ((word << 16) & 0xFFFF0000FFFF0000ULL) | ((word >> 16) & 0x0000FFFF0000FFFFULL);
45 return (word << 32) | (word >> 32);
46}
47
55void correctForBigEndian(const EventUnion &bigEndian, EventUnion &smallEndian) {
56 smallEndian.splitWord.words[0] = swapUint64(bigEndian.splitWord.words[1]);
57 smallEndian.splitWord.words[1] = swapUint64(bigEndian.splitWord.words[0]);
58}
59
72void addFrameToOutputWorkspace(int &rawFrames, int &goodFrames, const int eventCountInFrame, const int minEventsReq,
73 const int maxEventsReq, MantidVec &frameEventCounts,
74 std::vector<DataObjects::EventList> &events,
75 std::vector<DataObjects::EventList> &eventsInFrame) {
76 ++rawFrames;
77 if (eventCountInFrame >= minEventsReq && eventCountInFrame <= maxEventsReq) {
78 // Add number of event counts to workspace.
79 frameEventCounts.emplace_back(eventCountInFrame);
80 ++goodFrames;
81
83 // Add events that match parameters to workspace
84 for (auto i = 0; i < NUM_OF_SPECTRA; ++i) {
85 if (eventsInFrame[i].getNumberEvents() > 0) {
86 events[i] += eventsInFrame[i];
87 eventsInFrame[i].clear();
88 }
89 }
90 } else {
91 // clear event list in frame in preparation for next frame
93 // Add events that match parameters to workspace
94 for (auto i = 0; i < NUM_OF_SPECTRA; ++i) {
95 eventsInFrame[i].clear();
96 }
97 }
98}
99
112void addFrameToOutputWorkspace(int &rawFrames, int &goodFrames, const int eventCountInFrame, const int minEventsReq,
113 const int maxEventsReq, MantidVec &frameEventCounts,
114 std::vector<std::vector<double>> &counts,
115 std::vector<std::vector<double>> &countsInFrame) {
116 ++rawFrames;
117 if (eventCountInFrame >= minEventsReq && eventCountInFrame <= maxEventsReq) {
118 // Add number of event counts to workspace.
119 frameEventCounts.emplace_back(eventCountInFrame);
120 ++goodFrames;
121
123 // Add events that match parameters to workspace
124 for (auto i = 0; i < NUM_OF_SPECTRA; ++i) {
125 auto &countsInFramePixel = countsInFrame[i];
126 for (size_t j = 0; j < countsInFramePixel.size(); ++j) {
127 auto &countsInFramePixelByBin = countsInFramePixel[j];
128 if (countsInFramePixelByBin > 0) {
129 counts[i][j] += countsInFramePixelByBin;
130 countsInFramePixelByBin = 0;
131 }
132 }
133 }
134 } else {
135 // clear event list in frame in preparation for next frame
137 for (auto i = 0; i < NUM_OF_SPECTRA; ++i) {
138 auto &countsInFramePixel = countsInFrame[i];
139 std::fill(countsInFramePixel.begin(), countsInFramePixel.end(), 0);
140 }
141 }
142}
143
151API::MatrixWorkspace_sptr createEventWorkspace(const double maxToF, const double binWidth,
152 const std::vector<DataObjects::EventList> &events) {
153 // Round up number of bins needed
154 std::vector<double> xAxis(int(std::ceil(maxToF / binWidth)));
155 std::generate(xAxis.begin(), xAxis.end(), [i = 0, &binWidth]() mutable { return binWidth * i++; });
156
157 DataObjects::EventWorkspace_sptr dataWorkspace = DataObjects::create<DataObjects::EventWorkspace>(
158 NUM_OF_SPECTRA, HistogramData::Histogram(HistogramData::BinEdges(xAxis)));
160 for (auto i = 0; i < NUM_OF_SPECTRA; ++i) {
161 dataWorkspace->getSpectrum(i) = events[i];
162 dataWorkspace->getSpectrum(i).setSpectrumNo(i + 1);
163 dataWorkspace->getSpectrum(i).setDetectorID(i + 1);
164 }
165 dataWorkspace->setAllX(HistogramData::BinEdges{xAxis});
166 dataWorkspace->getAxis(0)->unit() = Kernel::UnitFactory::Instance().create("TOF");
167 dataWorkspace->setYUnit("Counts");
168 return std::dynamic_pointer_cast<API::MatrixWorkspace>(dataWorkspace);
169}
170
177API::MatrixWorkspace_sptr createHistogramWorkspace(std::vector<double> &&binEdges,
178 std::vector<std::vector<double>> &&counts) {
179 const HistogramData::BinEdges bins{std::move(binEdges)};
180 API::MatrixWorkspace_sptr dataWorkspace = DataObjects::create<DataObjects::Workspace2D>(NUM_OF_SPECTRA, bins);
182 for (auto i = 0; i < NUM_OF_SPECTRA; ++i) {
183 dataWorkspace->setHistogram(i, bins, HistogramData::Counts{std::move(counts[i])});
184 dataWorkspace->getSpectrum(i).setSpectrumNo(i + 1);
185 dataWorkspace->getSpectrum(i).setDetectorID(i + 1);
186 }
187 dataWorkspace->getAxis(0)->unit() = Kernel::UnitFactory::Instance().create("TOF");
188 dataWorkspace->setYUnit("Counts");
189 return dataWorkspace;
190}
191
199template <typename ValueType>
200void addToSampleLog(const std::string &name, const ValueType &value, API::MatrixWorkspace_sptr &ws) {
201 ws->mutableRun().addProperty(name, value, false);
202}
203
209void insertValidationResult(const std::vector<std::pair<std::string, std::string>> &result,
210 std::map<std::string, std::string> &results) {
211 std::copy(result.cbegin(), result.cend(), std::inserter(results, results.end()));
212}
213
221std::vector<double> calculateBinEdges(const double minToF, const double maxToF, const double binWidth) {
222 const int numBins = static_cast<int>(std::ceil((maxToF - minToF) / binWidth));
223 auto custom_range =
224 std::views::iota(0) | std::views::transform([&binWidth, &minToF](int n) { return minToF + (n * binWidth); });
225 return {custom_range.begin(), custom_range.begin() + numBins + 1};
226}
227} // namespace
228
237 if (descriptor.extension() == ".edb") {
238 return 95;
239 } else {
240 return 0;
241 }
242}
243
248 // Filename property.
249 const std::vector<std::string> extentions{".edb"};
250 declareProperty(std::make_unique<API::MultipleFileProperty>("Filename", extentions),
251 "The name of the nGEM file to load. Selecting multiple files will "
252 "combine them into one workspace.");
253 // Output workspace
255 std::make_unique<API::WorkspaceProperty<API::Workspace>>("OutputWorkspace", "", Kernel::Direction::Output),
256 "The output workspace");
257
258 auto mustBePositive = std::make_shared<Kernel::BoundedValidator<int>>();
259 mustBePositive->setLower(0);
260
261 auto mustBePositiveDbl = std::make_shared<Kernel::BoundedValidator<double>>();
262 mustBePositiveDbl->setLower(0.0);
263
264 // Bin Width
265 declareProperty("BinWidth", 10.0, mustBePositiveDbl, "The width of the time bins in the output.");
266 declareProperty("MinToF", std::numeric_limits<double>::max(),
267 "The minimum ToF bin edge, inclusive. Required if PreserveEvents=False. If PreserveEvents=True and "
268 "MinToF is default, value will "
269 "be dervied from event data.");
270 declareProperty("MaxToF", -std::numeric_limits<double>::max(),
271 "The maximum ToF bin edge, exclusive. Required if PreserveEvents=False. If PreserveEvents=True and "
272 "MaxToF is default, value will "
273 "be dervied from event data.");
274
275 declareProperty("MinEventsPerFrame", 0, mustBePositive,
276 "The minimum number of events required in a frame before a "
277 "it is considered 'good'.");
278 declareProperty("MaxEventsPerFrame", EMPTY_INT(), mustBePositive,
279 "The maximum number of events allowed in a frame to be "
280 "considered 'good'.");
282 std::make_unique<Kernel::PropertyWithValue<bool>>("GenerateEventsPerFrame", false, Kernel::Direction::Input),
283 "Generate a workspace to show the number of events captured by each "
284 "frame. (optional, default False).");
285 declareProperty(std::make_unique<Kernel::PropertyWithValue<bool>>("PreserveEvents", true, Kernel::Direction::Input),
286 "Algorithm preserves events, generating an event workspace. If False, events are not preserved and a "
287 "Workspace 2D is generated (reduced memory usage). "
288 "(optional, default True).");
289}
290
295 progress(0);
296
297 std::vector<std::vector<std::string>> filePaths = getProperty("Filename");
298 const int minEventsReq(getProperty("MinEventsPerFrame"));
299 const int maxEventsReq(getProperty("MaxEventsPerFrame"));
300 double minToF(getProperty("MinToF"));
301 double maxToF(getProperty("MaxToF"));
302 const double binWidth(getProperty("BinWidth"));
303 const bool preserveEvents(getProperty("PreserveEvents"));
304
305 LoadDataResult res;
306 if (preserveEvents) {
307 res = readDataAsEvents(minToF, maxToF, binWidth, minEventsReq, maxEventsReq, filePaths);
308 } else {
309 res = readDataAsHistograms(minToF, maxToF, binWidth, minEventsReq, maxEventsReq, filePaths);
310 }
311
312 addToSampleLog("raw_frames", res.rawFrames, res.dataWorkspace);
313 addToSampleLog("good_frames", res.goodFrames, res.dataWorkspace);
314 addToSampleLog("max_ToF", maxToF, res.dataWorkspace);
315 addToSampleLog("min_ToF", minToF, res.dataWorkspace);
316
318
319 setProperty("OutputWorkspace", res.dataWorkspace);
320 if (this->getProperty("GenerateEventsPerFrame")) {
322 }
323 m_fileCount = 0;
324 progress(1.00);
325}
326
343void LoadNGEM::loadSingleFile(const std::vector<std::string> &filePath, int &eventCountInFrame, double &minToF,
344 double &maxToF, const double binWidth, int &rawFrames, int &goodFrames,
345 const int minEventsReq, const int maxEventsReq, MantidVec &frameEventCounts,
346 const size_t totalFilePaths, std::shared_ptr<LoadDataStrategyBase> strategy) {
347 // Create file reader
348 if (filePath.size() > 1) {
349 throw std::runtime_error("Invalid filename parameter.");
350 }
351 std::ifstream file(filePath[0].c_str(), std::ifstream::binary);
352 if (!file.is_open()) {
353 throw std::runtime_error("File could not be found.");
354 }
355
356 const size_t totalNumEvents = verifyFileSize(file) / 16;
357 constexpr size_t SKIP_WORD_SIZE = 4;
358 size_t numProcessedEvents = 0;
359 size_t numWordsSkipped = 0;
360
361 while (true) {
362 // Load an event into the variable.
363 // Occasionally we may get a file where the first event has been chopped,
364 // so we seek to the start of a valid event.
365 // Chopping only seems to occur on a 4 byte word, hence seekg() of 4
366 EventUnion event, eventBigEndian;
367 bool isEventInvalid = true;
368 bool isNotEOFAfterSkip = true;
369 do {
370 file.read(reinterpret_cast<char *>(&eventBigEndian), sizeof(eventBigEndian));
371 // Correct for the big endian format of nGEM datafile.
372 correctForBigEndian(eventBigEndian, event);
373 isEventInvalid = !event.generic.check();
374 if (isEventInvalid) {
375 isNotEOFAfterSkip = !file.seekg(SKIP_WORD_SIZE, std::ios_base::cur).eof();
376 if (isNotEOFAfterSkip) {
377 ++numWordsSkipped;
378 }
379 }
380 } while (isEventInvalid && isNotEOFAfterSkip);
381 if (file.eof()) {
382 break; // we have either not read an event, or only read part of one
383 }
384 if (event.coincidence.check()) { // Check for coincidence event.
385 ++eventCountInFrame;
386 size_t pixel = event.coincidence.getPixel();
387 // Convert to microseconds (us)
388 const double tof = event.coincidence.timeOfFlight / 1000.0;
389 strategy->addEvent(minToF, maxToF, tof, binWidth,
390 pixel); // If no min and max provided by user, values calculated and mutated
391 } else if (event.tZero.check()) { // Check for T0 event.
392 strategy->addFrame(rawFrames, goodFrames, eventCountInFrame, minEventsReq, maxEventsReq, frameEventCounts);
393 if (reportProgressAndCheckCancel(numProcessedEvents, eventCountInFrame, totalNumEvents, totalFilePaths)) {
394 return;
395 }
396 } else if (event.generic.check()) { // match all other events and notify.
397 g_log.warning() << "Unexpected event type ID=" << event.generic.id << " loaded.\n";
398 } else { // if we were to get to here, must be a corrupt event
399 g_log.warning() << "Corrupt event detected.\n";
400 }
401 }
402 if (numWordsSkipped > 0) {
403 g_log.warning() << SKIP_WORD_SIZE * numWordsSkipped
404 << " bytes of file data were skipped when locating valid events.\n";
405 }
406 g_log.information() << "Finished loading a file.\n";
407 ++m_fileCount;
408}
416size_t LoadNGEM::verifyFileSize(std::ifstream &file) {
417 // Check that the file fits into 16 byte sections.
418 file.seekg(0, file.end);
419 size_t size = file.tellg();
420 if (size % 16 != 0) {
421 g_log.warning() << "Invalid file size. File is size is " << size
422 << " bytes which is not a multiple of 16. There may be some bytes "
423 "missing from the data. \n";
424 }
425 file.seekg(0);
426 return size;
427}
428
439bool LoadNGEM::reportProgressAndCheckCancel(size_t &numProcessedEvents, int &eventCountInFrame,
440 const size_t totalNumEvents, const size_t totalFilePaths) {
441 numProcessedEvents += eventCountInFrame;
442 std::string message(std::to_string(m_fileCount) + "/" + std::to_string(totalFilePaths));
443 progress(double(numProcessedEvents) / double(totalNumEvents) / 1.11111, message);
444 eventCountInFrame = 0;
445 // Check for cancel flag.
446 return this->getCancel();
447}
448
455void LoadNGEM::createCountWorkspace(const std::vector<double> &frameEventCounts) {
456 std::vector<double> xAxisCounts(frameEventCounts.size() + 1);
457 std::generate(xAxisCounts.begin(), xAxisCounts.end(), [n = 0.0]() mutable { return ++n; });
458
459 DataObjects::Workspace2D_sptr countsWorkspace =
460 DataObjects::create<DataObjects::Workspace2D>(1, HistogramData::Histogram(HistogramData::BinEdges(xAxisCounts)));
461
462 countsWorkspace->mutableY(0) = frameEventCounts;
463 std::string countsWorkspaceName(this->getProperty("OutputWorkspace"));
464 countsWorkspaceName.append("_event_counts");
465 countsWorkspace->setYUnit("Counts");
466 std::shared_ptr<Kernel::Units::Label> XLabel =
467 std::dynamic_pointer_cast<Kernel::Units::Label>(Kernel::UnitFactory::Instance().create("Label"));
468 XLabel->setLabel("Frame");
469 countsWorkspace->getAxis(0)->unit() = XLabel;
470
471 this->declareProperty(std::make_unique<API::WorkspaceProperty<API::Workspace>>("CountsWorkspace", countsWorkspaceName,
473 "Counts of events per frame.");
474 progress(1.00);
475 this->setProperty("CountsWorkspace", countsWorkspace);
476}
477
484 auto loadInstrument = this->createChildAlgorithm("LoadInstrument");
485 loadInstrument->setPropertyValue("InstrumentName", "NGEM");
486 loadInstrument->setProperty<API::MatrixWorkspace_sptr>("Workspace", dataWorkspace);
487 loadInstrument->setProperty("RewriteSpectraMap", Kernel::OptionalBool(false));
488 loadInstrument->execute();
489}
490
498std::map<std::string, std::string> LoadNGEM::validateInputs() {
499 std::map<std::string, std::string> results;
500 insertValidationResult(validateEventsPerFrame(), results);
501 insertValidationResult(validateMinMaxToF(), results);
502 return results;
503}
504
510std::vector<std::pair<std::string, std::string>> LoadNGEM::validateEventsPerFrame() {
511 const int MinEventsPerFrame = getProperty("MinEventsPerFrame");
512 const int MaxEventsPerFrame = getProperty("MaxEventsPerFrame");
513 if (MaxEventsPerFrame < MinEventsPerFrame) {
514 return {{"MaxEventsPerFrame", "MaxEventsPerFrame is less than MinEvents per frame"}};
515 }
516 return {};
517}
518
524std::vector<std::pair<std::string, std::string>> LoadNGEM::validateMinMaxToF() {
525 const double minToF = getProperty("MinToF");
526 const double maxToF = getProperty("MaxToF");
527 const bool preserveEvents = getProperty("PreserveEvents");
528 std::vector<std::pair<std::string, std::string>> result;
529 if (preserveEvents) {
530 if (isDefault("MinToF") && isDefault("MaxToF")) {
531 return result;
532 }
533 if (isDefault("MinToF")) {
534 result.emplace_back("MinToF", "Please supply both, or neither, Min and MaxToF if PreserveEvents is True");
535 }
536 if (isDefault("MaxToF")) {
537 result.emplace_back("MaxToF", "Please supply both, or neither, Min and MaxToF if PreserveEvents is True");
538 }
539 } else {
540 if (isDefault("MinToF")) {
541 result.emplace_back("MinToF", "MinToF must be supplied if PreserveEvents is False");
542 }
543 if (isDefault("MaxToF")) {
544 result.emplace_back("MaxToF", "MaxToF must be supplied if PreserveEvents is False");
545 }
546 }
547 if (maxToF <= minToF) {
548 result.emplace_back("MaxToF", "MaxToF is less than or equal to MinToF");
549 }
550 return result;
551}
552
564LoadDataResult LoadNGEM::readDataAsEvents(double &minToF, double &maxToF, const double binWidth, const int minEventsReq,
565 const int maxEventsReq,
566 const std::vector<std::vector<std::string>> &filePaths) {
567 int eventCountInFrame{0};
568 int rawFrames{0};
569 int goodFrames{0};
570 std::vector<double> frameEventCounts;
571 API::MatrixWorkspace_sptr dataWorkspace;
572 size_t totalFilePaths(filePaths.size());
573
574 progress(0.04);
575 auto strategy = std::make_shared<LoadDataStrategyEvent>();
576 for (const auto &filePath : filePaths) {
577 loadSingleFile(filePath, eventCountInFrame, minToF, maxToF, binWidth, rawFrames, goodFrames, minEventsReq,
578 maxEventsReq, frameEventCounts, totalFilePaths, strategy);
579 }
580 // Add the final frame of events (as they are not followed by a T0 event)
581 strategy->addFrame(rawFrames, goodFrames, eventCountInFrame, minEventsReq, maxEventsReq, frameEventCounts);
582 progress(0.90);
583 dataWorkspace = createEventWorkspace(maxToF, binWidth, strategy->getEvents());
584
585 return {rawFrames, goodFrames, frameEventCounts, dataWorkspace};
586}
587
599LoadDataResult LoadNGEM::readDataAsHistograms(double &minToF, double &maxToF, const double binWidth,
600 const int minEventsReq, const int maxEventsReq,
601 const std::vector<std::vector<std::string>> &filePaths) {
602 int rawFrames{0};
603 int goodFrames{0};
604 int eventCountInFrame{0};
605 std::vector<double> frameEventCounts;
606 API::MatrixWorkspace_sptr dataWorkspace;
607 size_t totalFilePaths(filePaths.size());
608
609 progress(0.04);
610 auto strategy = std::make_shared<LoadDataStrategyHisto>(minToF, maxToF, binWidth);
611 for (const auto &filePath : filePaths) {
612 loadSingleFile(filePath, eventCountInFrame, minToF, maxToF, binWidth, rawFrames, goodFrames, minEventsReq,
613 maxEventsReq, frameEventCounts, totalFilePaths, strategy);
614 }
615 // Add the final frame of events (as they are not followed by a T0 event)
616 strategy->addFrame(rawFrames, goodFrames, eventCountInFrame, minEventsReq, maxEventsReq, frameEventCounts);
617 progress(0.90);
618 dataWorkspace = createHistogramWorkspace(std::move(strategy->getBinEdges()), std::move(strategy->getCounts()));
619 return {rawFrames, goodFrames, frameEventCounts, dataWorkspace};
620}
621
631void LoadDataStrategyHisto::addEvent(double &minToF, double &maxToF, const double tof, const double binWidth,
632 const size_t pixel) {
633 if (tof >= maxToF || tof < minToF) {
634 return;
635 }
636 const int bin_idx = static_cast<int>(std::floor((tof - minToF) / binWidth));
637 m_countsInFrame[pixel][bin_idx]++;
638}
639
650void LoadDataStrategyHisto::addFrame(int &rawFrames, int &goodFrames, const int eventCountInFrame,
651 const int minEventsReq, const int maxEventsReq, MantidVec &frameEventCounts) {
652 addFrameToOutputWorkspace(rawFrames, goodFrames, eventCountInFrame, minEventsReq, maxEventsReq, frameEventCounts,
654}
655
656LoadDataStrategyHisto::LoadDataStrategyHisto(const double minToF, const double maxToF, const double binWidth)
657 : m_binEdges{calculateBinEdges(minToF, maxToF, binWidth)} {
658 m_counts.resize(NUM_OF_SPECTRA);
659 for (auto &item : m_counts) {
660 item.resize(m_binEdges.size() - 1);
661 }
663}
664
674void LoadDataStrategyEvent::addEvent(double &minToF, double &maxToF, const double tof, const double binWidth,
675 const size_t pixel) {
676 (void)binWidth;
677 if (tof > maxToF) {
678 maxToF = tof;
679 }
680 if (tof < minToF) {
681 minToF = tof;
682 }
683 m_eventsInFrame[pixel].addEventQuickly(Types::Event::TofEvent(tof));
684}
685
696void LoadDataStrategyEvent::addFrame(int &rawFrames, int &goodFrames, const int eventCountInFrame,
697 const int minEventsReq, const int maxEventsReq, MantidVec &frameEventCounts) {
698 addFrameToOutputWorkspace(rawFrames, goodFrames, eventCountInFrame, minEventsReq, maxEventsReq, frameEventCounts,
700}
701
703 m_events.resize(NUM_OF_SPECTRA);
704 m_eventsInFrame.resize(NUM_OF_SPECTRA);
705}
706
707} // namespace Mantid::DataHandling
std::string name
Definition Run.cpp:60
double value
The value of the point.
Definition FitMW.cpp:51
#define PARALLEL_FOR_NO_WSP_CHECK()
#define DECLARE_FILELOADER_ALGORITHM(classname)
DECLARE_FILELOADER_ALGORITHM should be used in place of the standard DECLARE_ALGORITHM macro when wri...
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
virtual std::shared_ptr< Algorithm > createChildAlgorithm(const std::string &name, const double startProgress=-1., const double endProgress=-1., const bool enableLogging=true, const int &version=-1)
Create a Child Algorithm.
Kernel::Logger & g_log
Definition Algorithm.h:422
void progress(double p, const std::string &msg="", double estimatedTime=0.0, int progressPrecision=0)
Sends ProgressNotification.
bool isDefault(const std::string &name) const
bool getCancel() const
Returns the cancellation state.
A property class for workspaces.
void addFrame(int &rawFrames, int &goodFrames, const int eventCountInFrame, const int minEventsReq, const int maxEventsReq, MantidVec &frameEventCounts) override
Add a completed frame to the event list.
Definition LoadNGEM.cpp:696
std::vector< DataObjects::EventList > m_eventsInFrame
Definition LoadNGEM.h:127
std::vector< DataObjects::EventList > m_events
Definition LoadNGEM.h:126
void addEvent(double &minToF, double &maxToF, const double tof, const double binWidth, const size_t pixel) override
Add an event to the event list.
Definition LoadNGEM.cpp:674
void addEvent(double &minToF, double &maxToF, const double tof, const double binWidth, const size_t pixel) override
Add an event to the relevant histogram.
Definition LoadNGEM.cpp:631
void addFrame(int &rawFrames, int &goodFrames, const int eventCountInFrame, const int minEventsReq, const int maxEventsReq, MantidVec &frameEventCounts) override
Add a completed frame to the count-by-spectra vector.
Definition LoadNGEM.cpp:650
std::vector< std::vector< double > > m_counts
Definition LoadNGEM.h:112
LoadDataStrategyHisto(const double minToF, const double maxToF, const double binWidth)
Definition LoadNGEM.cpp:656
std::vector< std::vector< double > > m_countsInFrame
Definition LoadNGEM.h:113
int confidence(Kernel::FileDescriptor &descriptor) const override
The confidence that an algorithm is able to load the file.
Definition LoadNGEM.cpp:236
LoadDataResult readDataAsEvents(double &minToF, double &maxToF, const double binWidth, const int minEventsReq, const int maxEventsReq, const std::vector< std::vector< std::string > > &filePaths)
Read data from files into an event workspace, preserving events.
Definition LoadNGEM.cpp:564
void createCountWorkspace(const std::vector< double > &frameEventCounts)
Create a workspace to store the number of counts per frame.
Definition LoadNGEM.cpp:455
void exec() override
Execute the algorithm.
Definition LoadNGEM.cpp:294
LoadDataResult readDataAsHistograms(double &minToF, double &maxToF, const double binWidth, const int minEventsReq, const int maxEventsReq, const std::vector< std::vector< std::string > > &filePaths)
Read data from files into as histograms into a workspace2D.
Definition LoadNGEM.cpp:599
void loadInstrument(API::MatrixWorkspace_sptr &dataWorkspace)
Load the instrument and attach to the data workspace.
Definition LoadNGEM.cpp:483
std::vector< std::pair< std::string, std::string > > validateMinMaxToF()
Validate minimum and maximum TOF.
Definition LoadNGEM.cpp:524
std::map< std::string, std::string > validateInputs() override
Validate the imputs into the algorithm, overrides.
Definition LoadNGEM.cpp:498
void loadSingleFile(const std::vector< std::string > &filePath, int &eventCountInFrame, double &minToF, double &maxToF, const double binWidth, int &rawFrames, int &goodFrames, const int minEventsReq, const int maxEventsReq, MantidVec &frameEventCounts, const size_t totalFilePaths, std::shared_ptr< LoadDataStrategyBase > strategy)
Load a file into the event lists.
Definition LoadNGEM.cpp:343
size_t verifyFileSize(std::ifstream &file)
Check that a file to be loaded is in 128 bit words.
Definition LoadNGEM.cpp:416
bool reportProgressAndCheckCancel(size_t &numProcessedEvents, int &eventCountInFrame, const size_t totalNumEvents, const size_t totalFilePaths)
Reports progress and checks cancel flag.
Definition LoadNGEM.cpp:439
std::vector< std::pair< std::string, std::string > > validateEventsPerFrame()
Validate events per frame inputs.
Definition LoadNGEM.cpp:510
void init() override
Initialise the algorithm.
Definition LoadNGEM.cpp:247
Defines a wrapper around an open file.
const std::string & extension() const
Access the file extension.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void warning(const std::string &msg)
Logs at warning level.
Definition Logger.cpp:117
void information(const std::string &msg)
Logs at information level.
Definition Logger.cpp:136
OptionalBool : Tri-state bool.
The concrete, templated class for properties.
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::shared_ptr< Workspace2D > Workspace2D_sptr
shared pointer to Mantid::DataObjects::Workspace2D
std::shared_ptr< EventWorkspace > EventWorkspace_sptr
shared pointer to the EventWorkspace class
std::unique_ptr< T > create(const P &parent, const IndexArg &indexArg, const HistArg &histArg)
This is the create() method that all the other create() methods call.
constexpr int EMPTY_INT() noexcept
Returns what we consider an "empty" integer within a property.
Definition EmptyValues.h:24
Mantid::DataObjects::EventWorkspace_sptr createEventWorkspace()
Create event workspace with: 500 pixels 1000 histogrammed bins.
std::string to_string(const wide_integer< Bits, Signed > &n)
Holds variables tracking the data load across all files.
Definition LoadNGEM.h:87
API::MatrixWorkspace_sptr dataWorkspace
Definition LoadNGEM.h:91
std::vector< double > frameEventCounts
Definition LoadNGEM.h:90
@ Input
An input workspace.
Definition Property.h:53
@ Output
An output workspace.
Definition Property.h:54
Is able to hold all versions of the data words in the same memory location.
Definition LoadNGEM.h:79
CoincidenceEvent coincidence
Definition LoadNGEM.h:82