Project
Loading...
Searching...
No Matches
InputRecordWalker.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11#ifndef FRAMEWORK_INPUTRECORDWALKER_H
12#define FRAMEWORK_INPUTRECORDWALKER_H
13
17
20
21namespace o2::framework
22{
23
52template <DataHeaderLike... EXTRA_HEADERS>
54{
55 public:
57 InputRecordWalker(InputRecord& record, std::vector<InputSpec> filterSpecs = {}) : mRecord(record), mFilterSpecs(filterSpecs) {}
58
63 template <typename T>
65 {
66 public:
68 using iterator_category = std::forward_iterator_tag;
69 using value_type = T;
70 using reference = T&;
71 using pointer = T*;
72 using difference_type = std::ptrdiff_t;
73 // the iterator over the input routes
74 using input_iterator = decltype(std::declval<InputRecord>().begin());
75
76 // the range over parts in one slot — must be stored as a member so the
77 // part_iterator (which holds a pointer into it) does not dangle
80
81 Iterator() = delete;
82
83 Iterator(input_iterator it, input_iterator end, std::vector<InputSpec> const& filterSpecs)
84 : mInputIterator(it), mEnd(end), mCurrentRange(it.parts()), mCurrent(mCurrentRange.begin()), mFilterSpecs(filterSpecs)
85 {
86 next(true);
87 }
88
89 // prefix increment
91 {
92 next();
93 return *this;
94 }
95 // postfix increment
96 self_type operator++(int /*unused*/)
97 {
98 self_type copy(*this);
99 operator++();
100 return copy;
101 }
102 // return reference
104 {
105 return *mCurrent;
106 }
107 // comparison
108 bool operator==(const self_type& other) const
109 {
110 return mInputIterator == other.mInputIterator && mCurrent == other.mCurrent;
111 }
112
113 bool operator!=(const self_type& rh) const
114 {
115 return not operator==(rh);
116 }
117
118 fair::mq::Message* getPayload() const
119 {
120 return mCurrentRange.getPayloadAtIndices(mCurrent.indices());
121 }
122
123 private:
124 bool next(bool isInitialPart = false)
125 {
126 if (!isInitialPart) {
127 ++mCurrent;
128 }
129 while (mInputIterator != mEnd) {
130 for (; mCurrent != mCurrentRange.end(); ++mCurrent) {
131 // check filter rules
132 if (mFilterSpecs.size() > 0) {
133 bool isSelected = false;
134 for (auto const& spec : mFilterSpecs) {
135 if ((isSelected = DataRefUtils::match<EXTRA_HEADERS...>(*mCurrent, spec)) == true) {
136 break;
137 }
138 }
139 if (!isSelected) {
140 continue;
141 }
142 }
143 return true;
144 }
145 ++mInputIterator;
146 mCurrentRange = mInputIterator.parts();
147 mCurrent = mCurrentRange.begin();
148 } // end loop over record
149 return false;
150 }
151
152 input_iterator mInputIterator;
153 input_iterator mEnd;
154 part_range mCurrentRange; // declared before mCurrent — initialized first
155 part_iterator mCurrent;
156 std::vector<InputSpec> const& mFilterSpecs;
157 };
158
160
162 {
163 return const_iterator(mRecord.begin(), mRecord.end(), mFilterSpecs);
164 }
165
167 {
168 return const_iterator(mRecord.end(), mRecord.end(), mFilterSpecs);
169 }
170
171 private:
172 InputRecord& mRecord;
173 std::vector<InputSpec> mFilterSpecs;
174};
175
176} // namespace o2::framework
177
178#endif // FRAMEWORK_INPUTRECORDWALKER_H
bool operator==(const self_type &other) const
bool operator!=(const self_type &rh) const
decltype(std::declval< InputRecord >().begin()) input_iterator
InputSpan::Iterator< part_range, const DataRef > part_iterator
Iterator(input_iterator it, input_iterator end, std::vector< InputSpec > const &filterSpecs)
A helper class to iteratate over all parts of all input routes.
InputRecordWalker(InputRecord &record, std::vector< InputSpec > filterSpecs={})
Iterator< DataRef const > const_iterator
The input API of the Data Processing Layer This class holds the inputs which are valid for processing...
const_iterator begin() const
const_iterator end() const
DataRefIndices indices() const
Definition InputSpan.h:192
GLuint GLuint end
Definition glcorearb.h:469
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
A range over the parts of a single slot that sets ref.spec on each DataRef.
InputSpan::Iterator< PartRange, const DataRef > end() const
InputSpan::Iterator< PartRange, const DataRef > begin() const
fair::mq::Message * getPayloadAtIndices(DataRefIndices idx) const
VectorOfTObjectPtrs other