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
18
20
21namespace o2::framework
22{
23
53{
54 public:
56 InputRecordWalker(InputRecord& record, std::vector<InputSpec> filterSpecs = {}) : mRecord(record), mFilterSpecs(filterSpecs) {}
57
62 template <typename T>
64 {
65 public:
67 using iterator_category = std::forward_iterator_tag;
68 using value_type = T;
69 using reference = T&;
70 using pointer = T*;
71 using difference_type = std::ptrdiff_t;
72 // the iterator over the input routes
73 using input_iterator = decltype(std::declval<InputRecord>().begin());
74
75 Iterator() = delete;
76
77 Iterator(InputRecord& parent, input_iterator it, input_iterator end, std::vector<InputSpec> const& filterSpecs)
78 : mParent(parent), mInputIterator(it), mEnd(end), mCurrent(mInputIterator.begin()), mFilterSpecs(filterSpecs)
79 {
80 next(true);
81 }
82
83 ~Iterator() = default;
84
85 // prefix increment
87 {
88 next();
89 return *this;
90 }
91 // postfix increment
92 self_type operator++(int /*unused*/)
93 {
94 self_type copy(*this);
95 operator++();
96 return copy;
97 }
98 // return reference
100 {
101 return *mCurrent;
102 }
103 // comparison
104 bool operator==(const self_type& other) const
105 {
106 bool result = mInputIterator == other.mInputIterator;
107 result = result && mCurrent == other.mCurrent;
108 return result;
109 }
110
111 bool operator!=(const self_type& rh) const
112 {
113 return not operator==(rh);
114 }
115
116 private:
117 // the iterator over the parts in one channel
118 using part_iterator = typename input_iterator::const_iterator;
119
120 bool next(bool isInitialPart = false)
121 {
122 while (mInputIterator != mEnd) {
123 while (mCurrent != mInputIterator.end()) {
124 // increment on the level of one input
125 if (!isInitialPart && (mCurrent == mInputIterator.end() || ++mCurrent == mInputIterator.end())) {
126 // no more parts, go to next input
127 break;
128 }
129 isInitialPart = false;
130 // check filter rules
131 if (mFilterSpecs.size() > 0) {
132 bool isSelected = false;
133 for (auto const& spec : mFilterSpecs) {
134 if ((isSelected = DataRefUtils::match(*mCurrent, spec)) == true) {
135 break;
136 }
137 }
138 if (!isSelected) {
139 continue;
140 }
141 }
142 return true;
143 }
144 ++mInputIterator;
145 mCurrent = mInputIterator.begin();
146 isInitialPart = true;
147 } // end loop over record
148 return false;
149 }
150
151 InputRecord& mParent;
152 input_iterator mInputIterator;
153 input_iterator mEnd;
154 part_iterator mCurrent;
155 std::vector<InputSpec> const& mFilterSpecs;
156 };
157
159
161 {
162 return const_iterator(mRecord, mRecord.begin(), mRecord.end(), mFilterSpecs);
163 }
164
166 {
167 return const_iterator(mRecord, mRecord.end(), mRecord.end(), mFilterSpecs);
168 }
169
170 private:
171 InputRecord& mRecord;
172 std::vector<InputSpec> mFilterSpecs;
173};
174
175} // namespace o2::framework
176
177#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
Iterator(InputRecord &parent, input_iterator it, input_iterator end, std::vector< InputSpec > const &filterSpecs)
A helper class to iteratate over all parts of all input routes.
Iterator< DataRef const > const_iterator
InputRecordWalker(InputRecord &record, std::vector< InputSpec > filterSpecs={})
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
static bool match(DataRef const &ref, const char *binding)
VectorOfTObjectPtrs other