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 private:
119 bool next(bool isInitialPart = false)
120 {
121 if (!isInitialPart) {
122 ++mCurrent;
123 }
124 while (mInputIterator != mEnd) {
125 for (; mCurrent != mCurrentRange.end(); ++mCurrent) {
126 // check filter rules
127 if (mFilterSpecs.size() > 0) {
128 bool isSelected = false;
129 for (auto const& spec : mFilterSpecs) {
130 if ((isSelected = DataRefUtils::match<EXTRA_HEADERS...>(*mCurrent, spec)) == true) {
131 break;
132 }
133 }
134 if (!isSelected) {
135 continue;
136 }
137 }
138 return true;
139 }
140 ++mInputIterator;
141 mCurrentRange = mInputIterator.parts();
142 mCurrent = mCurrentRange.begin();
143 } // end loop over record
144 return false;
145 }
146
147 input_iterator mInputIterator;
148 input_iterator mEnd;
149 part_range mCurrentRange; // declared before mCurrent — initialized first
150 part_iterator mCurrent;
151 std::vector<InputSpec> const& mFilterSpecs;
152 };
153
155
157 {
158 return const_iterator(mRecord.begin(), mRecord.end(), mFilterSpecs);
159 }
160
162 {
163 return const_iterator(mRecord.end(), mRecord.end(), mFilterSpecs);
164 }
165
166 private:
167 InputRecord& mRecord;
168 std::vector<InputSpec> mFilterSpecs;
169};
170
171} // namespace o2::framework
172
173#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
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
VectorOfTObjectPtrs other