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();
57 while (eventRange.first == eventRange.second && eventRange.second > 0) {
63 if ((firstPulseIndex !=
m_roi.front()) || (lastPulseIndex !=
m_roi.back())) {
66 if (roi_combined.empty()) {
71 m_roi.assign(roi_combined.cbegin(), roi_combined.cend());
87 size_t firstPulseIndex = 0;
101 if (event_index_iter + 1 == event_index_end)
104 firstPulseIndex =
static_cast<size_t>(std::distance(
m_event_index->cbegin(), event_index_iter));
109 for (; firstPulseIndex <
m_event_index->size() - 1; ++firstPulseIndex) {
110 if ((*
m_event_index)[firstPulseIndex] != (*m_event_index)[firstPulseIndex + 1]) {
116 return firstPulseIndex;
132 while ((eventIndexValue < *event_index_iter)) {
136 if (event_index_iter + 1 == event_index_end)
155 std::stringstream msg;
156 msg <<
"Something went really wrong with pulseIndex=" << pulseIndex <<
": " << start <<
" > " << stop <<
"| "
159 <<
" pulseIndex=" << pulseIndex <<
" of " <<
m_event_index->size();
160 throw std::runtime_error(msg.str());
163 return std::make_pair(start, stop);
168 if (pulseIndex >=
m_roi.back())
173 if (pulseIndex <=
m_roi.front()) {
174 eventIndex = (*m_event_index)[
m_roi.front()];
176 eventIndex = (*m_event_index)[pulseIndex];
188 if (pulseIndex >=
m_roi.back()) {
190 }
else if (pulseIndex <
m_roi.front()) {
196 const auto iterUpper = std::upper_bound(
m_roi.cbegin(),
m_roi.cend(), pulseIndex);
198 return (std::distance(
m_roi.cbegin(), iterUpper) % 2 != 0);
206 if (pulseIndex >=
m_roi.back())
213 const auto pulseIndexEnd = pulseIndex + 1;
217 if (pulseIndexEnd ==
m_roi.back()) {
258 const auto lastPulseIndex = m_indexer->m_roi.back();
261 while ((
m_value.pulseIndex < lastPulseIndex) && (!m_indexer->includedPulse(
m_value.pulseIndex)))
265 if (
m_value.pulseIndex >= lastPulseIndex)
268 while (this->calculateEventRange() && (
m_value.pulseIndex < lastPulseIndex)) {
276 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, const Nexus::NexusDescriptor &descriptor)
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