18#include "MantidNexus/NexusFile.h"
26const std::string MICROSEC(
"microseconds");
44 const std::size_t
numEvents,
const bool oldNeXusFileNames,
47 : m_loader(loader), entry_name(
std::move(entry_name)), entry_type(
std::move(entry_type)), prog(prog),
48 scheduler(scheduler), m_loadError(false), m_have_weight(false),
49 m_framePeriodNumbers(
std::move(framePeriodNumbers)) {
58 m_min_id = std::numeric_limits<uint32_t>::max();
67 file.openData(
"event_time_zero");
74 std::string thisStartTime;
75 size_t thispulseTimes = 0;
77 if (!file.hasAttr(
"offset")) {
78 thisStartTime =
"1970-01-01T00:00:00Z";
80 "event_time_zero, using UNIX epoch instead\n";
82 file.getAttr(
"offset", thisStartTime);
85 if (!file.getInfo().dims.empty())
86 thispulseTimes =
static_cast<size_t>(file.getInfo().dims[0]);
92 if (bankPulseTime->equals(thispulseTimes, thisStartTime)) {
113 std::make_unique<std::vector<uint64_t>>(Nexus::IOHelper::readNexusVector<uint64_t>(file,
"event_index"));
116 if (event_index->size() == 1) {
117 if (event_index->at(0) == 0) {
136 const uint64_t &start_event_index) {
141 start_event = start_event_index;
157 if (stop_event > dim0)
182 auto event_id = std::make_unique<std::vector<uint32_t>>(dim0);
185 Nexus::IOHelper::readNexusSlab<uint32_t, Nexus::IOHelper::Narrowing::Prevent>(*event_id, file,
m_detIdFieldName,
191 const auto [min_id, max_id] = Mantid::Kernel::parallel_minmax<uint32_t>(event_id);
232 <<
"'s event_time_offset field is too small "
233 "to load the desired data.\n";
238 auto event_time_of_flight = std::make_unique<std::vector<float>>(tof_dim0);
246 Nexus::IOHelper::readNexusSlab<float, Nexus::IOHelper::Narrowing::Allow>(
248 std::string tof_unit;
250 file.getAttr(
"units", tof_unit);
256 if (tof_unit != MICROSEC)
259 return event_time_of_flight;
270 file.openData(
"event_weight");
274 return std::unique_ptr<std::vector<float>>();
280 auto event_weight = std::make_unique<std::vector<float>>(
m_loadSize[0]);
286 <<
"'s event_weight field is too small to load the desired data.\n";
295 <<
"'s event_weight field is not FLOAT32! It will be skipped.\n";
320 std::shared_ptr<std::vector<uint32_t>> event_id;
321 std::shared_ptr<std::vector<float>> event_time_of_flight;
322 std::shared_ptr<std::vector<float>> event_weight;
323 std::shared_ptr<std::vector<uint64_t>> event_index;
341 event_index =
nullptr;
353 <<
" has a mismatch between the number of event_index entries "
354 "and the number of pulse times in event_time_zero.\n";
356 uint64_t start_event = 0;
357 uint64_t stop_event = 0;
359 this->
prepareEventId(file, start_event, stop_event, event_index->operator[](0));
388 event_time_of_flight = this->
loadTof(file);
397 <<
"Loading bank " <<
entry_name <<
" is stopped due to either zero/negative loading size ("
404 catch (std::exception &e) {
425 const auto emptyInt =
static_cast<uint32_t
>(
EMPTY_INT());
428 if (minSpectraToLoad != emptyInt &&
m_min_id < minSpectraToLoad) {
436 if (maxSpectraToLoad != emptyInt &&
m_max_id > maxSpectraToLoad) {
459 const auto startAt =
static_cast<size_t>(
m_loadStart[0]);
470 auto tof_min_fixed = tof_min;
471 auto tof_max_fixed = tof_max;
480 if (log_compression && tof_min_fixed <= 0.) {
488 if (tof_min_fixed < m_loader.alg->shortest_tof) {
503 auto histogram_bin_edges = std::make_shared<std::vector<double>>();
505 *histogram_bin_edges);
508 std::shared_ptr<Task> newTask1 = std::make_shared<ProcessBankCompressed>(
513 std::shared_ptr<Task> newTask2 = std::make_shared<ProcessBankCompressed>(
520 std::shared_ptr<Task> newTask1 = std::make_shared<ProcessBankData>(
525 std::shared_ptr<Task> newTask2 = std::make_shared<ProcessBankData>(
548 uint64_t
const shift = uint64_t(1) << 32;
bool getCancel() const
Returns the cancellation state.
Kernel::Logger & getLogger() const
Returns a reference to the logger.
Helper class for reporting progress from algorithms.
Helper class for LoadEventNexus that is specific to the current default loading code for NXevent_data...
int32_t eventid_max
Maximum (inclusive) event ID possible for this instrument.
std::vector< std::shared_ptr< BankPulseTimes > > m_bankPulseTimes
One entry of pulse times for each preprocessor.
detid_t pixelID_to_wi_offset
Offset in the pixelID_to_wi_vector to use.
bool splitProcessing
whether or not to launch multiple ProcessBankData jobs per bank
size_t eventsPerChunk
number of chunks per bank
int firstChunkForBank
for multiple chunks per bank
bool m_haveWeights
Flag for dealing with a simulated file.
EventWorkspaceCollection & m_ws
void run() override
Main method that performs the work for the task.
void loadPulseTimes(Nexus::File &file)
Load the pulse times, if needed.
std::unique_ptr< std::vector< uint64_t > > loadEventIndex(Nexus::File &file)
Load the event_index field (a list of size of # of pulses giving the index in the event list for that...
Nexus::DimVector m_loadStart
Index to load start at in the file.
bool m_have_weight
Flag for simulated data.
std::unique_ptr< std::vector< float > > loadTof(Nexus::File &file)
Open and load the times-of-flight data.
uint32_t m_max_id
Maximum pixel ID in this data.
Kernel::ThreadScheduler & scheduler
ThreadScheduler running this task.
void prepareEventId(Nexus::File &file, uint64_t &start_event, uint64_t &stop_event, const uint64_t &start_event_index)
Open the event_id field and validate the contents.
std::string entry_name
NXS address to bank.
std::unique_ptr< std::vector< float > > loadEventWeights(Nexus::File &file)
Load weight of weigthed events if they exist.
std::string m_detIdFieldName
uint32_t m_min_id
Minimum pixel ID in this data.
API::Progress * prog
Progress reporting.
LoadBankFromDiskTask(DefaultEventLoader &loader, std::string entry_name, std::string entry_type, const std::size_t numEvents, const bool oldNeXusFileNames, API::Progress *prog, std::shared_ptr< std::mutex > ioMutex, Kernel::ThreadScheduler &scheduler, std::vector< int > framePeriodNumbers)
Constructor.
Nexus::DimVector m_loadSize
How much to load in the file.
const std::vector< int > m_framePeriodNumbers
Frame period numbers.
std::shared_ptr< BankPulseTimes > thisBankPulseTimes
Object with the pulse times for this bank.
DefaultEventLoader & m_loader
Algorithm being run.
std::string entry_type
NXS type.
bool m_loadError
Did we get an error in loading.
std::unique_ptr< std::vector< uint32_t > > loadEventId(Nexus::File &file)
Load the event_id field, which has been opened.
uint64_t recalculateDataSize(const int64_t size)
Interpret the value describing the number of events.
std::string m_timeOfFlightFieldName
bool m_is_time_filtered
if wall-clock filtering was requested
double longest_tof
Limits found to tof.
double filter_tof_max
Filter by a maximum time-of-flight.
int32_t m_specMax
Maximum spectrum to load.
double compressTolerance
Tolerance for CompressEvents; use -1 to mean don't compress.
std::string m_filename
The name and path of the input file.
std::shared_ptr< BankPulseTimes > m_allBanksPulseTimes
Pulse times for ALL banks, taken from proton_charge log.
double shortest_tof
Limits found to tof.
std::mutex m_tofMutex
Mutex protecting tof limits.
bool filter_tof_range
Tof range is being filtered.
int32_t m_specMin
Minimum spectrum to load.
double filter_tof_min
Filter by a minimum time-of-flight.
std::string m_top_entry_name
name of top level NXentry to use
void debug(const std::string &msg)
Logs at debug level.
void error(const std::string &msg)
Logs at error level.
void warning(const std::string &msg)
Logs at warning level.
bool isDebug() const
Returns true if log level is at least debug.
void report()
Increments the loop counter by 1, then sends the progress notification on behalf of its algorithm.
double m_cost
Cached computational cost for the thread.
void setMutex(const std::shared_ptr< std::mutex > &mutex)
Set the mutex object for this Task.
The ThreadScheduler object defines how tasks are allocated to threads and in what order.
virtual void push(std::shared_ptr< Task > newTask)=0
Add a Task to the queue.
A simple class that provides a wall-clock (not processor time) timer.
void reset()
Explicitly reset the timer.
Class that provides for a standard Nexus exception.
static unsigned short constexpr FLOAT32
std::size_t numEvents(Nexus::File &file, bool &hasTotalCounts, bool &oldNeXusFileNames, const std::string &prefix, const Nexus::NexusDescriptor &descriptor)
Get the number of events in the currently opened group.
void timeConversionVector(std::vector< T > &vec, const std::string &input_unit, const std::string &output_unit)
int MANTID_KERNEL_DLL createAxisFromRebinParams(const std::vector< double > ¶ms, std::vector< double > &xnew, const bool resize_xnew=true, const bool full_bins_only=false, const double xMinHint=std::nan(""), const double xMaxHint=std::nan(""), const bool useReverseLogarithmic=false, const double power=-1)
Creates a new output X array given a 'standard' set of rebinning parameters.
std::pair< T, T > parallel_minmax(std::vector< T > const *const vec, size_t const grainsize=1000)
parallel_minmax
constexpr int EMPTY_INT() noexcept
Returns what we consider an "empty" integer within a property.
constexpr double EMPTY_DBL() noexcept
Returns what we consider an "empty" double within a property.
This structure holds the type and dimensions of a primative field/array.
DimVector dims
The dimensions of the file.