Skip to content

Commit d906710

Browse files
committed
DPL: add copy constructor to DataDescriptorMatcher
Treats the std::unique_ptr<Node> as values, by creating new ones when coping.
1 parent 5d533bf commit d906710

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

Framework/Core/include/Framework/DataDescriptorMatcher.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,39 @@ class DataDescriptorMatcher
213213
And,
214214
Xor };
215215

216+
/// We treat all the nodes as values, hence we copy the
217+
/// contents mLeft and mRight into a new unique_ptr, if
218+
/// needed.
219+
DataDescriptorMatcher(DataDescriptorMatcher const& other)
220+
: mOp{other.mOp},
221+
mLeft{ConstantValueMatcher{false}},
222+
mRight{ConstantValueMatcher{false}}
223+
{
224+
if (auto pval0 = std::get_if<OriginValueMatcher>(&other.mLeft)) {
225+
mLeft = *pval0;
226+
} else if (auto pval1 = std::get_if<DescriptionValueMatcher>(&other.mLeft)) {
227+
mLeft = *pval1;
228+
} else if (auto pval2 = std::get_if<SubSpecificationTypeValueMatcher>(&other.mLeft)) {
229+
mLeft = *pval2;
230+
} else if (auto pval3 = std::get_if<std::unique_ptr<DataDescriptorMatcher>>(&other.mLeft)) {
231+
mLeft = std::move(std::make_unique<DataDescriptorMatcher>(*pval3->get()));
232+
} else if (auto pval4 = std::get_if<ConstantValueMatcher>(&other.mLeft)) {
233+
mLeft = *pval4;
234+
}
235+
236+
if (auto pval0 = std::get_if<OriginValueMatcher>(&other.mRight)) {
237+
mRight = *pval0;
238+
} else if (auto pval1 = std::get_if<DescriptionValueMatcher>(&other.mRight)) {
239+
mRight = *pval1;
240+
} else if (auto pval2 = std::get_if<SubSpecificationTypeValueMatcher>(&other.mRight)) {
241+
mRight = *pval2;
242+
} else if (auto pval3 = std::get_if<std::unique_ptr<DataDescriptorMatcher>>(&other.mRight)) {
243+
mRight = std::move(std::make_unique<DataDescriptorMatcher>(*pval3->get()));
244+
} else if (auto pval4 = std::get_if<ConstantValueMatcher>(&other.mRight)) {
245+
mRight = *pval4;
246+
}
247+
}
248+
216249
/// Unary operator on a node
217250
DataDescriptorMatcher(Op op, Node&& lhs, Node&& rhs = std::move(ConstantValueMatcher{ false }))
218251
: mOp{ op },
@@ -313,6 +346,10 @@ class DataDescriptorMatcher
313346
}
314347
};
315348

349+
Node const& getLeft() const { return mLeft; };
350+
Node const& getRight() const { return mRight; };
351+
Op getOp() const { return mOp; };
352+
316353
private:
317354
Op mOp;
318355
Node mLeft;

Framework/Core/test/test_DataDescriptorMatcher.cxx

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,58 @@ using namespace o2::framework;
2121
using namespace o2::header;
2222
using namespace o2::framework::data_matcher;
2323

24+
BOOST_AUTO_TEST_CASE(TestMatcherInvariants) {
25+
DataHeader header0;
26+
header0.dataOrigin = "TPC";
27+
header0.dataDescription = "CLUSTERS";
28+
header0.subSpecification = 1;
29+
std::vector<ContextElement> context;
30+
31+
DataHeader header1;
32+
header1.dataOrigin = "ITS";
33+
header1.dataDescription = "TRACKLET";
34+
header1.subSpecification = 2;
35+
36+
DataHeader header2;
37+
header2.dataOrigin = "TPC";
38+
header2.dataDescription = "TRACKLET";
39+
header2.subSpecification = 1;
40+
41+
DataHeader header3;
42+
header3.dataOrigin = "TPC";
43+
header3.dataDescription = "CLUSTERS";
44+
header3.subSpecification = 0;
45+
46+
DataHeader header4;
47+
header4.dataOrigin = "TRD";
48+
header4.dataDescription = "TRACKLET";
49+
header4.subSpecification = 0;
50+
51+
DataDescriptorMatcher matcher{
52+
DataDescriptorMatcher::Op::And,
53+
OriginValueMatcher{ "TPC" },
54+
std::make_unique<DataDescriptorMatcher>(
55+
DataDescriptorMatcher::Op::And,
56+
DescriptionValueMatcher{ "CLUSTERS" },
57+
std::make_unique<DataDescriptorMatcher>(
58+
DataDescriptorMatcher::Op::And,
59+
SubSpecificationTypeValueMatcher{ 1 },
60+
ConstantValueMatcher{ true }))
61+
};
62+
DataDescriptorMatcher matcher2 = matcher;
63+
BOOST_CHECK(matcher.match(header0, context) == true);
64+
BOOST_CHECK(matcher.match(header1, context) == false);
65+
BOOST_CHECK(matcher.match(header2, context) == false);
66+
BOOST_CHECK(matcher.match(header3, context) == false);
67+
BOOST_CHECK(matcher.match(header4, context) == false);
68+
BOOST_CHECK(matcher2.match(header0, context) == true);
69+
BOOST_CHECK(matcher2.match(header1, context) == false);
70+
BOOST_CHECK(matcher2.match(header2, context) == false);
71+
BOOST_CHECK(matcher2.match(header3, context) == false);
72+
BOOST_CHECK(matcher2.match(header4, context) == false);
73+
74+
}
75+
2476
BOOST_AUTO_TEST_CASE(TestSimpleMatching)
2577
{
2678
DataHeader header0;

0 commit comments

Comments
 (0)