15 const std::size_t firstEventIndex,
const std::size_t
numEvents,
16 const std::string &entry_name,
const std::vector<size_t> &pulse_roi)
17 : m_event_index(
std::move(event_index)), m_firstEventIndex(firstEventIndex), m_numEvents(
numEvents),
18 m_roi_complex(false), m_entry_name(entry_name) {
28 if (!pulse_roi.empty()) {
29 if (pulse_roi.size() % 2 != 0)
30 throw std::runtime_error(
"Invalid size for pulsetime roi, must be even or empty");
35 if (roi_combined.empty()) {
42 m_roi.assign(roi_combined.cbegin(), roi_combined.cend());
47 auto firstPulseIndex =
m_roi.front();
49 while (eventRange.first == eventRange.second && eventRange.first <
m_numEvents) {
55 auto lastPulseIndex =
m_roi.back();
56 if (lastPulseIndex > 0) {
58 while (eventRange.first == eventRange.second && eventRange.second > 0 && lastPulseIndex > 1) {
65 if ((firstPulseIndex !=
m_roi.front()) || (lastPulseIndex !=
m_roi.back())) {
68 if (roi_combined.empty()) {
73 m_roi.assign(roi_combined.cbegin(), roi_combined.cend());
89 size_t firstPulseIndex = 0;
103 if (event_index_iter + 1 == event_index_end)
106 firstPulseIndex =
static_cast<size_t>(std::distance(
m_event_index->cbegin(), event_index_iter));
111 for (; firstPulseIndex <
m_event_index->size() - 1; ++firstPulseIndex) {
112 if ((*
m_event_index)[firstPulseIndex] != (*m_event_index)[firstPulseIndex + 1]) {
118 return firstPulseIndex;
134 while ((eventIndexValue < *event_index_iter)) {
138 if (event_index_iter + 1 == event_index_end)
157 std::stringstream msg;
158 msg <<
"Something went really wrong with pulseIndex=" << pulseIndex <<
": " << start <<
" > " << stop <<
"| "
161 <<
" pulseIndex=" << pulseIndex <<
" of " <<
m_event_index->size();
162 throw std::runtime_error(msg.str());
165 return std::make_pair(start, stop);
170 if (pulseIndex >=
m_roi.back())
175 if (pulseIndex <=
m_roi.front()) {
176 eventIndex = (*m_event_index)[
m_roi.front()];
178 eventIndex = (*m_event_index)[pulseIndex];
190 if (pulseIndex >=
m_roi.back()) {
192 }
else if (pulseIndex <
m_roi.front()) {
198 const auto iterUpper = std::upper_bound(
m_roi.cbegin(),
m_roi.cend(), pulseIndex);
200 return (std::distance(
m_roi.cbegin(), iterUpper) % 2 != 0);
208 if (pulseIndex >=
m_roi.back())
215 const auto pulseIndexEnd = pulseIndex + 1;
219 if (pulseIndexEnd ==
m_roi.back()) {
260 const auto lastPulseIndex = m_indexer->m_roi.back();
263 while ((
m_value.pulseIndex < lastPulseIndex) && (!m_indexer->includedPulse(
m_value.pulseIndex)))
267 if (
m_value.pulseIndex >= lastPulseIndex)
270 while (this->calculateEventRange() && (
m_value.pulseIndex < lastPulseIndex)) {
278 if (this->m_indexer != other.m_indexer)
const std::string & m_value
size_t getFirstPulseIndex() const
Which element in the event_index array is the first one to use.
const Iterator cend() const
std::size_t m_firstEventIndex
How far into the array of events the tof/detid are already.
size_t getStopEventIndex(const size_t pulseIndex) const
The one past the last event(tof,detid) index to read for this pulse.
size_t determineFirstPulseIndex() const
This performs a linear search because it is much more likely that the index to look for is at the beg...
const Iterator cbegin() const
std::vector< std::size_t > m_roi
Alternating values describe ranges of [use, don't) of pulse index ranges.
const std::shared_ptr< std::vector< uint64_t > const > m_event_index
vector of indices (length of # of pulses) into the event arrays
bool includedPulse(const size_t pulseIndex) const
returns true when the roi says the pulse should be used
bool m_roi_complex
true when there is more to check than the pulse being between the ends
size_t determineLastPulseIndex() const
This looks at the event_indexes and number of events to read then determines what is the maximum puls...
size_t getStartEventIndex(const size_t pulseIndex) const
The first event(tof,detid) index to read for this pulse.
std::size_t m_numEvents
Total number of events tof/detid that should be processed.
const std::string m_entry_name
Name of the NXentry to be used in exceptions.
std::size_t m_numPulses
Total number of pulsetime/pulseindex.
size_t getLastPulseIndex() const
Which element in the event_index array is the last one to use.
std::pair< size_t, size_t > getEventIndexRange(const size_t pulseIndex) const
The range of event(tof,detid) indices to read for this pulse.
std::size_t numEvents(Nexus::File &file, bool &hasTotalCounts, bool &oldNeXusFileNames, const std::string &prefix)
Get the number of events in the currently opened group.
std::vector< TYPE > calculate_intersection(const std::vector< TYPE > &left, const std::vector< TYPE > &right)
This calculates the intersection of two sorted vectors that represent regions of interest (ROI).
std::size_t eventIndexStop
std::size_t eventIndexStart
bool calculateEventRange()
returns true if the range is empty
const PulseIndexer * m_indexer
bool operator!=(const PulseIndexer::Iterator &other) const
bool operator==(const PulseIndexer::Iterator &other) const
const IteratorValue & operator*() const