Skip to content

Commit f6112e2

Browse files
Adding DataDescriptionMatcher operation 'Not'
Need to check if using this negator operation can have implications on the handling of concrete data types. No impact to existing code however.
1 parent 66c8ad7 commit f6112e2

3 files changed

Lines changed: 38 additions & 1 deletion

File tree

Framework/Core/include/Framework/DataDescriptorMatcher.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ class DataDescriptorMatcher
259259
{
260260
public:
261261
enum struct Op { Just,
262+
Not,
262263
Or,
263264
And,
264265
Xor };

Framework/Core/src/DataDescriptorMatcher.cxx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ bool DataDescriptorMatcher::match(char const* d, VariableContext& context) const
243243
// return std::visit(eval, mLeft) ^ std::visit(eval, mRight);
244244
// case Op::Just:
245245
// return std::visit(eval, mLeft);
246+
// case Op::Not:
247+
// return !std::visit(eval, mLeft);
246248
// }
247249
// When we drop support for macOS 10.13
248250
if (auto pval0 = std::get_if<OriginValueMatcher>(&mLeft)) {
@@ -287,6 +289,9 @@ bool DataDescriptorMatcher::match(char const* d, VariableContext& context) const
287289
if (mOp == Op::Just) {
288290
return leftValue;
289291
}
292+
if (mOp == Op::Not) {
293+
return !leftValue;
294+
}
290295

291296
if (auto pval0 = std::get_if<OriginValueMatcher>(&mRight)) {
292297
auto dh = o2::header::get<header::DataHeader*>(d);
@@ -317,6 +322,8 @@ bool DataDescriptorMatcher::match(char const* d, VariableContext& context) const
317322
return leftValue ^ rightValue;
318323
case Op::Just:
319324
return leftValue;
325+
case Op::Not:
326+
return !leftValue;
320327
}
321328
throw runtime_error("Bad parsing tree");
322329
};
@@ -383,7 +390,11 @@ bool DataDescriptorMatcher::operator==(DataDescriptorMatcher const& other) const
383390
}
384391

385392
if (mOp == Op::Just) {
386-
return true;
393+
return leftValue;
394+
}
395+
396+
if (mOp == Op::Not) {
397+
return leftValue;
387398
}
388399

389400
{
@@ -479,6 +490,9 @@ std::ostream& operator<<(std::ostream& os, DataDescriptorMatcher::Op const& op)
479490
case DataDescriptorMatcher::Op::Just:
480491
os << "just";
481492
break;
493+
case DataDescriptorMatcher::Op::Not:
494+
os << "not";
495+
break;
482496
case DataDescriptorMatcher::Op::Xor:
483497
os << "xor";
484498
break;

Framework/Core/test/test_DataDescriptorMatcher.cxx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,28 @@ BOOST_AUTO_TEST_CASE(TestMatcherInvariants)
153153
ConstantValueMatcher{true}))};
154154
BOOST_CHECK_EQUAL(matcherA, matcherB);
155155
}
156+
157+
{
158+
DataDescriptorMatcher matcherA{
159+
DataDescriptorMatcher::Op::Not,
160+
OriginValueMatcher{"TPC"}};
161+
DataDescriptorMatcher matcherB{
162+
DataDescriptorMatcher::Op::Not,
163+
DescriptionValueMatcher{"TRACKLET"}};
164+
DataDescriptorMatcher matcherC{
165+
DataDescriptorMatcher::Op::Not,
166+
SubSpecificationTypeValueMatcher{1}};
167+
168+
BOOST_CHECK(matcherA.match(header0, context) == false);
169+
BOOST_CHECK(matcherA.match(header1, context) == true);
170+
BOOST_CHECK(matcherA.match(header4, context) == true);
171+
BOOST_CHECK(matcherB.match(header0, context) == true);
172+
BOOST_CHECK(matcherB.match(header1, context) == false);
173+
BOOST_CHECK(matcherB.match(header4, context) == false);
174+
BOOST_CHECK(matcherC.match(header0, context) == false);
175+
BOOST_CHECK(matcherC.match(header1, context) == true);
176+
BOOST_CHECK(matcherC.match(header4, context) == true);
177+
}
156178
}
157179

158180
BOOST_AUTO_TEST_CASE(TestSimpleMatching)

0 commit comments

Comments
 (0)