Skip to content

Commit b1c7759

Browse files
authored
DPL: create matcher from description (#4363)
1 parent 89f37ae commit b1c7759

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

Framework/Core/include/Framework/DataSpecUtils.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ struct DataSpecUtils {
185185

186186
/// Build a DataDescriptMatcher which does not care about the subSpec and description.
187187
static data_matcher::DataDescriptorMatcher dataDescriptorMatcherFrom(header::DataOrigin const& origin);
188+
189+
/// Build a DataDescriptMatcher which does not care about the subSpec and origin.
190+
static data_matcher::DataDescriptorMatcher dataDescriptorMatcherFrom(header::DataDescription const& origin);
188191
};
189192

190193
} // namespace framework

Framework/Core/src/DataSpecUtils.cxx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,24 @@ DataDescriptorMatcher DataSpecUtils::dataDescriptorMatcherFrom(header::DataOrigi
480480
return std::move(matchOnlyOrigin);
481481
}
482482

483+
DataDescriptorMatcher DataSpecUtils::dataDescriptorMatcherFrom(header::DataDescription const& description)
484+
{
485+
char buf[17] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
486+
strncpy(buf, description.str, 16);
487+
DataDescriptorMatcher matchOnlyOrigin{
488+
DataDescriptorMatcher::Op::And,
489+
OriginValueMatcher{ContextRef{1}},
490+
std::make_unique<DataDescriptorMatcher>(
491+
DataDescriptorMatcher::Op::And,
492+
DescriptionValueMatcher{buf},
493+
std::make_unique<DataDescriptorMatcher>(
494+
DataDescriptorMatcher::Op::And,
495+
SubSpecificationTypeValueMatcher{ContextRef{2}},
496+
std::make_unique<DataDescriptorMatcher>(DataDescriptorMatcher::Op::Just,
497+
StartTimeValueMatcher{ContextRef{0}})))};
498+
return std::move(matchOnlyOrigin);
499+
}
500+
483501
InputSpec DataSpecUtils::matchingInput(OutputSpec const& spec)
484502
{
485503
return std::visit(overloaded{

Framework/Core/test/unittest_DataSpecUtils.cxx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,16 @@ BOOST_AUTO_TEST_CASE(GetOptionalSubSpecWithMatcher)
242242
BOOST_CHECK_EQUAL(std::string(dataType2.description.as<std::string>()), "FOOO");
243243
}
244244

245+
BOOST_AUTO_TEST_CASE(TestMatcherFromDescription)
246+
{
247+
auto fromQueryInputSpec = DataSpecUtils::dataDescriptorMatcherFrom(header::DataDescription{"TSET"});
248+
InputSpec ddSpec{
249+
"binding",
250+
std::move(fromQueryInputSpec)};
251+
252+
BOOST_CHECK_EQUAL(DataSpecUtils::asConcreteDataDescription(ddSpec).as<std::string>(), "TSET");
253+
}
254+
245255
BOOST_AUTO_TEST_CASE(FindOutputSpec)
246256
{
247257
std::vector<OutputSpec> specs = {

0 commit comments

Comments
 (0)