Skip to content

Commit 1b3dd05

Browse files
committed
DPL: allow DataDescriptorMatcher to match an InputSpec
We actually need to match on both DataHeader and InputSpec, since we want to use the same logic at workflow building and data processing time.
1 parent fe659d6 commit 1b3dd05

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

Framework/Core/include/Framework/DataDescriptorMatcher.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#ifndef o2_framework_DataDescriptorMatcher_H_INCLUDED
1111
#define o2_framework_DataDescriptorMatcher_H_INCLUDED
1212

13+
#include "Framework/InputSpec.h"
1314
#include "Headers/DataHeader.h"
1415

1516
#include <cstdint>
@@ -144,6 +145,18 @@ class DataDescriptorMatcher
144145

145146
inline ~DataDescriptorMatcher() = default;
146147

148+
/// @return true if the (sub-)query associated to this matcher will
149+
/// match the provided @a spec, false otherwise.
150+
bool match(InputSpec const& spec) const
151+
{
152+
header::DataHeader dh;
153+
dh.dataOrigin = spec.origin;
154+
dh.dataDescription = spec.description;
155+
dh.subSpecification = spec.subSpec;
156+
157+
return this->match(dh);
158+
}
159+
147160
bool match(header::DataHeader const& d) const
148161
{
149162
auto eval = [&d](auto&& arg) -> bool {

Framework/Core/test/test_DataDescriptorMatcher.cxx

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,53 @@ BOOST_AUTO_TEST_CASE(TestQueryBuilder)
144144
BOOST_CHECK(matcher4->match(header3) == false);
145145
BOOST_CHECK(matcher4->match(header4) == false);
146146
}
147+
148+
BOOST_AUTO_TEST_CASE(TestInputSpecMatching)
149+
{
150+
InputSpec spec0{ "spec0", "TPC", "CLUSTERS", 1 };
151+
InputSpec spec1{ "spec1", "ITS", "TRACKLET", 2 };
152+
InputSpec spec2{ "spec2", "ITS", "TRACKLET", 1 };
153+
InputSpec spec3{ "spec3", "TPC", "CLUSTERS", 0 };
154+
InputSpec spec4{ "spec4", "TRD", "TRACKLET", 0 };
155+
156+
DataDescriptorMatcher matcher{
157+
DataDescriptorMatcher::Op::And,
158+
OriginValueMatcher{ "TPC" },
159+
std::make_unique<DataDescriptorMatcher>(
160+
DataDescriptorMatcher::Op::And,
161+
DescriptionValueMatcher{ "CLUSTERS" },
162+
std::make_unique<DataDescriptorMatcher>(
163+
DataDescriptorMatcher::Op::And,
164+
SubSpecificationTypeValueMatcher{ 1 },
165+
ConstantValueMatcher{ true }))
166+
};
167+
168+
BOOST_CHECK(matcher.match(spec0) == true);
169+
BOOST_CHECK(matcher.match(spec1) == false);
170+
BOOST_CHECK(matcher.match(spec2) == false);
171+
BOOST_CHECK(matcher.match(spec3) == false);
172+
BOOST_CHECK(matcher.match(spec4) == false);
173+
174+
DataDescriptorMatcher matcher1{
175+
DataDescriptorMatcher::Op::Or,
176+
OriginValueMatcher{ "TPC" },
177+
OriginValueMatcher{ "ITS" }
178+
};
179+
180+
BOOST_CHECK(matcher1.match(spec0) == true);
181+
BOOST_CHECK(matcher1.match(spec1) == true);
182+
BOOST_CHECK(matcher1.match(spec2) == true);
183+
BOOST_CHECK(matcher1.match(spec3) == true);
184+
BOOST_CHECK(matcher1.match(spec4) == false);
185+
186+
DataDescriptorMatcher matcher2{
187+
DataDescriptorMatcher::Op::Just,
188+
DescriptionValueMatcher{ "TRACKLET" }
189+
};
190+
191+
BOOST_CHECK(matcher2.match(spec0) == false);
192+
BOOST_CHECK(matcher2.match(spec1) == true);
193+
BOOST_CHECK(matcher2.match(spec2) == true);
194+
BOOST_CHECK(matcher2.match(spec3) == false);
195+
BOOST_CHECK(matcher2.match(spec4) == true);
196+
}

0 commit comments

Comments
 (0)