18 std::shared_ptr<std::vector<uint32_t>> event_id,
19 std::shared_ptr<std::vector<float>> event_time_of_flight,
size_t numEvents,
20 size_t startAt, std::shared_ptr<std::vector<uint64_t>> event_index,
21 std::shared_ptr<BankPulseTimes> thisBankPulseTimes,
bool have_weight,
22 std::shared_ptr<std::vector<float>> event_weight, detid_t min_event_id,
24 :
Task(), m_loader(m_loader), entry_name(
std::move(entry_name)),
25 pixelID_to_wi_vector(m_loader.pixelID_to_wi_vector), pixelID_to_wi_offset(m_loader.pixelID_to_wi_offset),
26 prog(prog), event_id(
std::move(event_id)), event_time_of_flight(
std::move(event_time_of_flight)),
28 thisBankPulseTimes(
std::move(thisBankPulseTimes)), have_weight(have_weight),
29 event_weight(
std::move(event_weight)), m_min_id(min_event_id), m_max_id(max_event_id) {
37inline size_t getPulseIndex(
const size_t event_index,
const size_t last_pulse_index,
38 const std::shared_ptr<std::vector<uint64_t>> &event_index_vec) {
39 if (last_pulse_index + 1 >= event_index_vec->size())
40 return last_pulse_index;
45 const auto event_index_end = event_index_vec->cend();
46 auto event_index_iter = event_index_vec->cbegin() + last_pulse_index;
48 while ((event_index < *event_index_iter) || (event_index >= *(event_index_iter + 1))) {
52 if (event_index_iter + 1 == event_index_end)
55 return std::distance(event_index_vec->cbegin(), event_index_iter);
64 double my_shortest_tof =
static_cast<double>(std::numeric_limits<uint32_t>::max()) * 0.1;
65 double my_longest_tof = 0.;
68 size_t my_discarded_events(0);
85 const size_t numEventLists = outputWS.getNumberHistograms();
91 if (wi < numEventLists) {
92 outputWS.reserveEventListAt(wi, counts[pixID -
m_min_id]);
101 const bool pulsetimesincreasing =
104 throw std::runtime_error(
"Event index is not sorted");
111 const bool compress = (alg->compressTolerance >= 0);
114 std::vector<bool> usedDetIds;
117 const double TOF_MIN = alg->filter_tof_min;
118 const double TOF_MAX = alg->filter_tof_max;
120 for (std::size_t pulseIndex = getPulseIndex(
startAt, 0,
event_index); pulseIndex < NUM_PULSES; pulseIndex++) {
124 const int periodIndex = logPeriodNumber - 1;
131 if (firstEventIndex == lastEventIndex)
133 else if (firstEventIndex > lastEventIndex) {
134 std::stringstream msg;
135 msg <<
"Something went really wrong: " << firstEventIndex <<
" > " << lastEventIndex <<
"| " <<
entry_name
137 << firstEventIndex +
startAt <<
",?)"
138 <<
" pulseIndex=" << pulseIndex <<
" of " <<
event_index->size();
139 throw std::runtime_error(msg.str());
142 for (std::size_t eventIndex = firstEventIndex; eventIndex < lastEventIndex; ++eventIndex) {
145 const detid_t detId = (*event_id)[eventIndex];
148 const auto tof =
static_cast<double>((*event_time_of_flight)[eventIndex]);
150 if ((tof - TOF_MIN) * (tof - TOF_MAX) <= 0.) {
156 const auto weight =
static_cast<double>((*event_weight)[eventIndex]);
157 const double errorSq = weight * weight;
158 eventVector->emplace_back(tof, pulsetime, weight, errorSq);
160 ++my_discarded_events;
167 eventVector->emplace_back(tof, pulsetime);
169 ++my_discarded_events;
177 if (tof > my_longest_tof) {
178 my_longest_tof = tof;
180 if (tof < my_shortest_tof) {
181 my_shortest_tof = tof;
187 usedDetIds[detId -
m_min_id] =
true;
193 if (alg->getCancel())
199 const size_t numEventLists = outputWS.getNumberHistograms();
204 if (wi < numEventLists) {
205 auto &el = outputWS.getSpectrum(wi);
207 el.compressEvents(alg->compressTolerance, &el);
209 if (pulsetimesincreasing)
219 alg->getLogger().debug() <<
entry_name << (pulsetimesincreasing ?
" had " :
" DID NOT have ")
220 <<
"monotonically increasing pulse times\n";
225 std::lock_guard<std::mutex> _lock(alg->m_tofMutex);
226 if (my_shortest_tof < alg->shortest_tof) {
227 alg->shortest_tof = my_shortest_tof;
229 if (my_longest_tof > alg->longest_tof) {
230 alg->longest_tof = my_longest_tof;
232 alg->bad_tofs += badTofs;
233 alg->discarded_events += my_discarded_events;
237 alg->getLogger().debug() <<
"Time to process " <<
entry_name <<
" " <<
m_timer <<
"\n";
242 const auto firstEventIndex =
event_index->operator[](pulseIndex);
243 if (firstEventIndex >=
startAt)
244 return firstEventIndex -
startAt;
250 if (pulseIndex + 1 >= numPulses)
255 return std::min(lastEventIndex,
numEvents);
269 std::stringstream msg;
270 msg <<
"Error finding workspace index; pixelID " << pixID <<
" with offset " <<
pixelID_to_wi_offset
272 throw std::runtime_error(msg.str());
Helper class for reporting progress from algorithms.
Helper class for LoadEventNexus that is specific to the current default loading code for NXevent_data...
std::vector< std::vector< std::vector< Mantid::Types::Event::TofEvent > * > > eventVectors
Vector where index = event_id; value = ptr to std::vector<TofEvent> in the event list.
bool precount
Do we pre-count the # of events in each pixel ID?
std::vector< std::vector< std::vector< Mantid::DataObjects::WeightedEvent > * > > weightedEventVectors
Vector where index = event_id; value = ptr to std::vector<WeightedEvent> in the event list.
EventWorkspaceCollection & m_ws
size_t getWorkspaceIndexFromPixelID(const detid_t pixID)
Get the workspace index for a given pixel ID.
bool have_weight
Flag for simulated data.
size_t getFirstEventIndex(const size_t pulseIndex) const
Mantid::Kernel::Timer m_timer
timer for performance
DefaultEventLoader & m_loader
Algorithm being run.
detid_t m_max_id
Maximum pixel id.
std::shared_ptr< std::vector< uint64_t > > event_index
vector of event index (length of # of pulses)
std::string entry_name
NXS path to bank.
size_t startAt
index of the first event from event_index
std::shared_ptr< std::vector< uint32_t > > event_id
event pixel ID array
detid_t m_min_id
Minimum pixel id.
detid_t pixelID_to_wi_offset
Offset in the pixelID_to_wi_vector to use.
const std::vector< size_t > & pixelID_to_wi_vector
Vector where (index = pixel ID+pixelID_to_wi_offset), value = workspace index)
API::Progress * prog
Progress reporting.
ProcessBankData(DefaultEventLoader &loader, std::string entry_name, API::Progress *prog, std::shared_ptr< std::vector< uint32_t > > event_id, std::shared_ptr< std::vector< float > > event_time_of_flight, size_t numEvents, size_t startAt, std::shared_ptr< std::vector< uint64_t > > event_index, std::shared_ptr< BankPulseTimes > thisBankPulseTimes, bool have_weight, std::shared_ptr< std::vector< float > > event_weight, detid_t min_event_id, detid_t max_event_id)
Constructor.
std::shared_ptr< BankPulseTimes > thisBankPulseTimes
Pulse times for this bank.
size_t getLastEventIndex(const size_t pulseIndex, const size_t numPulses) const
void run() override
Run the data processing FIXME/TODO - split run() into readable methods.
void report()
Increments the loop counter by 1, then sends the progress notification on behalf of its algorithm.
A Task is a unit of work to be scheduled and run by a ThreadPool.
double m_cost
Cached computational cost for the thread.
std::size_t numEvents(::NeXus::File &file, bool &hasTotalCounts, bool &oldNeXusFileNames, const std::string &prefix, const NexusHDF5Descriptor &descriptor)
Get the number of events in the currently opened group.
int32_t detid_t
Typedef for a detector ID.