Mantid
Loading...
Searching...
No Matches
PulseIndexer.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2024 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 +
7#pragma once
8
9#include "MantidDataHandling/DllConfig.h"
10
11#include <cstddef>
12#include <memory>
13#include <string>
14#include <vector>
15
16namespace Mantid {
17namespace DataHandling {
18
33class MANTID_DATAHANDLING_DLL PulseIndexer {
34public:
35 // ----------------------------------------- input iterator allows for read-only access
37 std::size_t pulseIndex;
38 std::size_t eventIndexStart;
39 std::size_t eventIndexStop;
40 };
41
42 struct MANTID_DATAHANDLING_DLL Iterator {
43 using iterator_category = std::input_iterator_tag;
44 using difference_type = std::ptrdiff_t;
46
47 Iterator(const PulseIndexer *indexer, const size_t pulseIndex)
48 : m_indexer(indexer), m_lastPulseIndex(m_indexer->getLastPulseIndex()) {
49 m_value.pulseIndex = pulseIndex;
50 calculateEventRange();
51 }
52
53 const IteratorValue &operator*() const;
54
55 // prefix increment ++iter
56 Iterator &operator++();
57 // postfix increment iter++ is not needed
58
59 bool operator==(const PulseIndexer::Iterator &other) const;
60 bool operator!=(const PulseIndexer::Iterator &other) const;
61
62 private:
64 const size_t m_lastPulseIndex;
65
66 bool calculateEventRange();
67
69 };
70
71 // ----------------------------------------- pulse indexer class start
72 PulseIndexer(std::shared_ptr<std::vector<uint64_t> const> const &event_index, const std::size_t firstEventIndex,
73 const std::size_t numEvents, const std::string &entry_name, const std::vector<size_t> &pulse_roi);
74
76 size_t getFirstPulseIndex() const;
78 size_t getLastPulseIndex() const;
80 std::pair<size_t, size_t> getEventIndexRange(const size_t pulseIndex) const;
85 size_t getStartEventIndex(const size_t pulseIndex) const;
91 size_t getStopEventIndex(const size_t pulseIndex) const;
92
93 const Iterator cbegin() const;
94 const Iterator cend() const;
95 Iterator begin() const;
96 Iterator end() const;
97
98private:
99 PulseIndexer(); // do not allow empty constructor
100
101 size_t determineFirstPulseIndex() const;
102 size_t determineLastPulseIndex() const;
104 bool includedPulse(const size_t pulseIndex) const;
105
107 const std::shared_ptr<std::vector<uint64_t> const> m_event_index;
108
117 std::size_t m_firstEventIndex;
118
124 std::size_t m_numEvents;
125
130 std::vector<std::size_t> m_roi;
133
135 std::size_t m_numPulses;
136
138 const std::string m_entry_name;
139};
140
141} // namespace DataHandling
142} // namespace Mantid
const std::string & m_value
Definition Algorithm.cpp:71
MANTID_NEXUS_DLL bool operator!=(std::string const &s, Mantid::Nexus::NexusAddress const &p)
MANTID_NEXUS_DLL bool operator==(std::string const &s, Mantid::Nexus::NexusAddress const &p)
PulseIndexer contains information for mapping from pulse index/number to event index.
std::size_t m_firstEventIndex
How far into the array of events the tof/detid are already.
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 m_roi_complex
true when there is more to check than the pulse being between the ends
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.
MatrixWorkspace_sptr MANTID_API_DLL operator*(const MatrixWorkspace_sptr &lhs, const MatrixWorkspace_sptr &rhs)
Multiply two workspaces.
Helper class which provides the Collimation Length for SANS instruments.
Iterator(const PulseIndexer *indexer, const size_t pulseIndex)