Project
Loading...
Searching...
No Matches
DataDescriptorMatcher.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 o2_framework_DataDescriptorMatcher_H_INCLUDED
12#define o2_framework_DataDescriptorMatcher_H_INCLUDED
13
18#include "Headers/DataHeader.h"
19
20#include <array>
21#include <cstdint>
22#include <iosfwd>
23#include <string>
24#include <variant>
25#include <vector>
26#include <ostream>
27
28namespace o2::header
29{
30struct Stack;
31}
32
34{
35
37struct None {
38};
39
41struct ContextRef {
42 size_t index;
43
46 inline bool operator==(ContextRef const& other) const;
47};
48
57
63 using Value = std::variant<uint32_t, uint64_t, std::string, None>;
64 char label[24];
66 size_t commitVersion = -1;
67 size_t publishVersion = -1;
68};
69
74
75constexpr int MAX_MATCHING_VARIABLE = 16;
76constexpr int MAX_UPDATES_PER_QUERY = 16;
77
79{
80 public:
82
83 [[nodiscard]] ContextElement::Value const& get(size_t pos) const;
84
89 void publish(void (*callback)(VariableContext const&, TimesliceSlot slot, void* context), void* context, TimesliceSlot slot);
90
91 inline void put(ContextUpdate&& update);
92
97 void commit();
98
101 inline void discard();
102
105 void reset();
106
107 private:
108 /* We make this class fixed size to avoid memory churning while
109 matching as much as posible when doing the matching, as that might become
110 performance critical. Given we will have only a few of these (one per
111 cacheline of the input messages) it should not be critical memory wise.
112 */
113 std::array<ContextElement, MAX_MATCHING_VARIABLE> mElements;
114 std::array<ContextUpdate, MAX_UPDATES_PER_QUERY> mUpdates;
115 int mPerformedUpdates;
116};
117
120template <typename T>
122{
123 public:
124 inline ValueHolder(T const& s);
125
128 inline ValueHolder(ContextRef variableId);
129
130 inline bool operator==(ValueHolder<T> const& other) const;
131
132 template <typename V>
133 friend std::ostream& operator<<(std::ostream& os, ValueHolder<V> const& holder);
134
135 template <typename VISITOR>
136 decltype(auto) visit(VISITOR visitor) const
137 {
138#if !defined(__CLING__) && !defined(__ROOTCLING__)
139 return std::visit(visitor, mValue);
140#else
141 return ContextRef{};
142#endif
143 }
144
145 protected:
146#if !defined(__CLING__) && !defined(__ROOTCLING__)
147 std::variant<T, ContextRef> mValue;
148#endif
149};
150
152class OriginValueMatcher : public ValueHolder<std::string>
153{
154 public:
155 inline OriginValueMatcher(std::string const& s);
156 inline OriginValueMatcher(ContextRef variableId);
157 template <std::size_t L>
158 inline constexpr OriginValueMatcher(const char (&s)[L]);
159
160 bool match(header::DataHeader const& header, VariableContext& context) const;
161};
162
164class DescriptionValueMatcher : public ValueHolder<std::string>
165{
166 public:
167 inline DescriptionValueMatcher(std::string const& s);
169 template <std::size_t L>
170 inline constexpr DescriptionValueMatcher(const char (&s)[L]);
171
172 bool match(header::DataHeader const& header, VariableContext& context) const;
173};
174
176class SubSpecificationTypeValueMatcher : public ValueHolder<header::DataHeader::SubSpecificationType>
177{
178 public:
180
183 inline SubSpecificationTypeValueMatcher(std::string const& s);
184
187
188 bool match(header::DataHeader const& header, VariableContext& context) const;
189};
190
192class StartTimeValueMatcher : public ValueHolder<uint64_t>
193{
194 public:
195 inline StartTimeValueMatcher(ContextRef variableId, uint64_t scale = 1);
196
199 inline StartTimeValueMatcher(std::string const& s, uint64_t scale = 1);
200
204 inline StartTimeValueMatcher(uint64_t v, uint64_t scale = 1);
205
209 bool match(header::DataHeader const& dh, DataProcessingHeader const& dph, VariableContext& context) const;
210
211 private:
212 uint64_t mScale;
213};
214
216{
217 public:
221
222 inline bool match() const;
223
224 inline bool operator==(ConstantValueMatcher const& other) const;
225
226 private:
227 bool mValue;
228};
229
230template <typename DESCRIPTOR>
233
234template <>
238
239template <>
243
244template <>
248
249#if !defined(__CLING__) && !defined(__ROOTCLING__)
251using Node = std::variant<OriginValueMatcher, DescriptionValueMatcher, SubSpecificationTypeValueMatcher, std::unique_ptr<DataDescriptorMatcher>, ConstantValueMatcher, StartTimeValueMatcher>;
252#else
254#endif
255
256// A matcher for a given O2 Data Model descriptor. We use a variant to hold
257// the different kind of matchers so that we can have a hierarchy or
258// DataDescriptionMatcher in the future (e.g. to handle OR / AND clauses) or we
259// can apply it to the whole DataHeader.
261{
262 public:
263 enum struct Op { Just,
264 Not,
265 Or,
266 And,
267 Xor };
268
276
279
280 inline ~DataDescriptorMatcher() = default;
281
286 bool match(ConcreteDataMatcher const& matcher, VariableContext& context) const;
287 bool match(ConcreteDataTypeMatcher const& matcher, VariableContext& context) const;
288 bool match(header::DataHeader const& header, VariableContext& context) const;
289 bool match(header::Stack const& stack, VariableContext& context) const;
290
291 // actual polymorphic matcher which is able to cast the pointer to the correct
292 // kind of header.
293 bool match(char const* d, VariableContext& context) const;
294
295 bool operator==(DataDescriptorMatcher const& other) const;
296
297 friend std::ostream& operator<<(std::ostream& os, DataDescriptorMatcher const& matcher);
298 friend std::ostream& operator<<(std::ostream& os, Op const& matcher);
299
300 Node const& getLeft() const { return mLeft; };
301 Node const& getRight() const { return mRight; };
302 Node& getLeft() { return mLeft; };
303 Node& getRight() { return mRight; };
304 Op getOp() const { return mOp; };
305
306 private:
307 Op mOp;
308 Node mLeft;
309 Node mRight;
310};
311
312} // namespace o2::framework::data_matcher
313
314// This is to work around CLING issues when parsing
315// GCC 7.3.0 std::variant implementation as described by:
316// https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=877838
317#ifndef __CLING__
318#include "DataDescriptorMatcher.inc"
319#endif
320
321#endif // o2_framework_DataDescriptorMatcher_H_INCLUDED
uint32_t op
uint16_t pos
Definition RawData.h:3
uint32_t stack
Definition RawData.h:1
bool operator==(ConstantValueMatcher const &other) const
bool match(ConcreteDataMatcher const &matcher, VariableContext &context) const
bool operator==(DataDescriptorMatcher const &other) const
friend std::ostream & operator<<(std::ostream &os, DataDescriptorMatcher const &matcher)
DataDescriptorMatcher(DataDescriptorMatcher &&other)=default
DataDescriptorMatcher & operator=(DataDescriptorMatcher const &other)
DataDescriptorMatcher & operator=(DataDescriptorMatcher &&other)=default
Something which can be matched against a header::DataDescription.
bool match(header::DataHeader const &header, VariableContext &context) const
constexpr DescriptionValueMatcher(const char(&s)[L])
Something which can be matched against a header::DataOrigin.
constexpr OriginValueMatcher(const char(&s)[L])
bool match(header::DataHeader const &header, VariableContext &context) const
Matcher on actual time, as reported in the DataProcessingHeader.
bool match(header::DataHeader const &dh, DataProcessingHeader const &dph, VariableContext &context) const
StartTimeValueMatcher(uint64_t v, uint64_t scale=1)
StartTimeValueMatcher(ContextRef variableId, uint64_t scale=1)
StartTimeValueMatcher(std::string const &s, uint64_t scale=1)
Something which can be matched against a header::SubSpecificationType.
bool match(header::DataHeader const &header, VariableContext &context) const
SubSpecificationTypeValueMatcher(header::DataHeader::SubSpecificationType v)
This means that the matcher is looking for a constant.
decltype(auto) visit(VISITOR visitor) const
bool operator==(ValueHolder< T > const &other) const
friend std::ostream & operator<<(std::ostream &os, ValueHolder< V > const &holder)
void publish(void(*callback)(VariableContext const &, TimesliceSlot slot, void *context), void *context, TimesliceSlot slot)
ContextElement::Value const & get(size_t pos) const
const GLdouble * v
Definition glcorearb.h:832
GLsizei const GLfloat * value
Definition glcorearb.h:819
GLuint GLsizei const GLchar * label
Definition glcorearb.h:2519
std::variant< OriginValueMatcher, DescriptionValueMatcher, SubSpecificationTypeValueMatcher, std::unique_ptr< DataDescriptorMatcher >, ConstantValueMatcher, StartTimeValueMatcher > Node
ContextPos
Special positions for variables in context.
@ CREATIONTIME_POS
The DataHeader::runNumber associated to the timeslice.
@ FIRSTTFORBIT_POS
The DataHeader::tfCounter associated to the timeslice.
@ TFCOUNTER_POS
The DataProcessingHeader::startTime associated to the timeslice.
@ RUNNUMBER_POS
The DataHeader::firstTForbit associated to the timeslice.
O2 data header classes and API, v0.1.
Definition DetID.h:49
std::variant< uint32_t, uint64_t, std::string, None > Value
size_t publishVersion
The committed version of the element. Every time we commit something to it, we bump the version.
size_t commitVersion
The actual contents of the element.
A typesafe reference to an element of the context.
bool operator==(ContextRef const &other) const
Marks an empty item in the context.
the main header struct
Definition DataHeader.h:618
uint32_t SubSpecificationType
Definition DataHeader.h:620
a move-only header stack with serialized headers This is the flat buffer where all the headers in a m...
Definition Stack.h:36
VectorOfTObjectPtrs other