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 Iterator() = delete;
77
78 Iterator(InputRecord& parent, input_iterator it, input_iterator end, std::vector<InputSpec> const& filterSpecs)
79 : mParent(parent), mInputIterator(it), mEnd(end), mCurrent(mInputIterator.begin()), mFilterSpecs(filterSpecs)
80 {
81 next(true);
82 }
83
84 ~Iterator() = default;
85
86 // prefix increment
88 {
89 next();
90 return *this;
91 }
92 // postfix increment
93 self_type operator++(int /*unused*/)
94 {
95 self_type copy(*this);
96 operator++();
97 return copy;
98 }
99 // return reference
101 {
102 return *mCurrent;
103 }
104 // comparison
105 bool operator==(const self_type& other) const
106 {
107 bool result = mInputIterator == other.mInputIterator;
108 result = result && mCurrent == other.mCurrent;
109 return result;
110 }
111
112 bool operator!=(const self_type& rh) const
113 {
114 return not operator==(rh);
115 }
116
117 private:
118 // the iterator over the parts in one channel
119 using part_iterator = typename input_iterator::const_iterator;
120
121 bool next(bool isInitialPart = false)
122 {
123 while (mInputIterator != mEnd) {
124 while (mCurrent != mInputIterator.end()) {
125 // increment on the level of one input
126 if (!isInitialPart && (mCurrent == mInputIterator.end() || ++mCurrent == mInputIterator.end())) {
127 // no more parts, go to next input
128 break;
129 }
130 isInitialPart = false;
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 mCurrent = mInputIterator.begin();
147 isInitialPart = true;
148 } // end loop over record
149 return false;
150 }
151
152 InputRecord& mParent;
153 input_iterator mInputIterator;
154 input_iterator mEnd;
155 part_iterator mCurrent;
156 std::vector<InputSpec> const& mFilterSpecs;
157 };
158
160
162 {
163 return const_iterator(mRecord, mRecord.begin(), mRecord.end(), mFilterSpecs);
164 }
165
167 {
168 return const_iterator(mRecord, 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
Iterator(InputRecord &parent, input_iterator it, input_iterator end, std::vector< InputSpec > const &filterSpecs)
decltype(std::declval< InputRecord >().begin()) input_iterator
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
GLuint64EXT * result
Definition glcorearb.h:5662
GLuint GLuint end
Definition glcorearb.h:469
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
VectorOfTObjectPtrs other