diff --git a/Framework/Core/include/Framework/DataRefUtils.h b/Framework/Core/include/Framework/DataRefUtils.h index 4c1bd0ed7ed10..d50699badc63b 100644 --- a/Framework/Core/include/Framework/DataRefUtils.h +++ b/Framework/Core/include/Framework/DataRefUtils.h @@ -11,6 +11,7 @@ #ifndef O2_FRAMEWORK_DATAREFUTILS_H_ #define O2_FRAMEWORK_DATAREFUTILS_H_ +#include "Framework/DataDescriptorMatcher.h" #include "Framework/DataRef.h" #include "Framework/RootSerializationSupport.h" #include "Framework/SerializationMethods.h" @@ -33,6 +34,9 @@ class ConfigurableParam; namespace o2::framework { +template +concept DataHeaderLike = requires(H& dh) {dh.dataOrigin; dh.dataDescription; dh.subSpecification; }; + // FIXME: Should enforce the fact that DataRefs are read only... struct DataRefUtils { @@ -52,7 +56,7 @@ struct DataRefUtils { if ((payloadSize % sizeof(T)) != 0) { throw runtime_error("Cannot extract POD from message as size do not match"); } - //FIXME: provide a const collection + // FIXME: provide a const collection return gsl::span(reinterpret_cast(const_cast(ref.payload)), payloadSize / sizeof(T)); } else if constexpr (has_root_dictionary::value == true && is_messageable::value == false) { @@ -220,17 +224,24 @@ struct DataRefUtils { return ref.spec != nullptr && ref.spec->binding == binding; } - /// check if the O2 message referred by DataRef matches a particular - /// input spec. The DataHeader is retrieved from the header message and matched - /// against @ref spec parameter. - static bool match(DataRef const& ref, InputSpec const& spec) + template + static bool matchHeader(DataRef const& ref, InputSpec const& spec) { - auto dh = DataRefUtils::getHeader(ref); + auto const* dh = o2::header::get(ref.header); if (dh == nullptr) { return false; } return DataSpecUtils::match(spec, dh->dataOrigin, dh->dataDescription, dh->subSpecification); } + + /// check if the O2 message referred by DataRef matches a particular + /// input spec. The DataHeader is retrieved from the header message and matched + /// against @ref spec parameter. + template + static bool match(DataRef const& ref, InputSpec const& spec) + { + return (DataRefUtils::matchHeader(ref, spec) || ... || matchHeader(ref, spec)); + } }; } // namespace o2::framework diff --git a/Framework/Core/include/Framework/InputRecordWalker.h b/Framework/Core/include/Framework/InputRecordWalker.h index a67a7dfb04820..4d36a1f17bc82 100644 --- a/Framework/Core/include/Framework/InputRecordWalker.h +++ b/Framework/Core/include/Framework/InputRecordWalker.h @@ -12,11 +12,11 @@ #define FRAMEWORK_INPUTRECORDWALKER_H /// @file InputRecordWalker.h -/// @author Matthias Richter /// @since 2020-03-25 /// @brief A helper class to iteratate over all parts of all input routes #include "Framework/InputRecord.h" +#include "Framework/DataRefUtils.h" namespace o2::framework { @@ -49,6 +49,7 @@ namespace o2::framework /// for (auto const& ref : InputRecordWalker(inputs, filter)) { /// // do something with the data /// } +template class InputRecordWalker { public: @@ -131,7 +132,7 @@ class InputRecordWalker if (mFilterSpecs.size() > 0) { bool isSelected = false; for (auto const& spec : mFilterSpecs) { - if ((isSelected = DataRefUtils::match(*mCurrent, spec)) == true) { + if ((isSelected = DataRefUtils::match(*mCurrent, spec)) == true) { break; } } diff --git a/Framework/Utils/include/DPLUtils/DPLRawPageSequencer.h b/Framework/Utils/include/DPLUtils/DPLRawPageSequencer.h index 785dc9e04bd45..2fb8374e45c12 100644 --- a/Framework/Utils/include/DPLUtils/DPLRawPageSequencer.h +++ b/Framework/Utils/include/DPLUtils/DPLRawPageSequencer.h @@ -191,7 +191,7 @@ class DPLRawPageSequencer } private: - InputRecordWalker mInput; + InputRecordWalker<> mInput; template void forwardInternal(Predicate pred, Inserter inserter, const char* data, size_t size, const o2::header::DataHeader* dh)