Skip to content

Commit 0a831b2

Browse files
authored
DPL: extend DataRefUtils::match to support multiple headers (#14160)
1 parent 04b2596 commit 0a831b2

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

Framework/Core/include/Framework/DataRefUtils.h

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#ifndef O2_FRAMEWORK_DATAREFUTILS_H_
1212
#define O2_FRAMEWORK_DATAREFUTILS_H_
1313

14+
#include "Framework/DataDescriptorMatcher.h"
1415
#include "Framework/DataRef.h"
1516
#include "Framework/RootSerializationSupport.h"
1617
#include "Framework/SerializationMethods.h"
@@ -33,6 +34,9 @@ class ConfigurableParam;
3334
namespace o2::framework
3435
{
3536

37+
template <typename H>
38+
concept DataHeaderLike = requires(H& dh) {dh.dataOrigin; dh.dataDescription; dh.subSpecification; };
39+
3640
// FIXME: Should enforce the fact that DataRefs are read only...
3741
struct DataRefUtils {
3842

@@ -52,7 +56,7 @@ struct DataRefUtils {
5256
if ((payloadSize % sizeof(T)) != 0) {
5357
throw runtime_error("Cannot extract POD from message as size do not match");
5458
}
55-
//FIXME: provide a const collection
59+
// FIXME: provide a const collection
5660
return gsl::span<T>(reinterpret_cast<T*>(const_cast<char*>(ref.payload)), payloadSize / sizeof(T));
5761
} else if constexpr (has_root_dictionary<T>::value == true &&
5862
is_messageable<T>::value == false) {
@@ -220,17 +224,24 @@ struct DataRefUtils {
220224
return ref.spec != nullptr && ref.spec->binding == binding;
221225
}
222226

223-
/// check if the O2 message referred by DataRef matches a particular
224-
/// input spec. The DataHeader is retrieved from the header message and matched
225-
/// against @ref spec parameter.
226-
static bool match(DataRef const& ref, InputSpec const& spec)
227+
template <DataHeaderLike H>
228+
static bool matchHeader(DataRef const& ref, InputSpec const& spec)
227229
{
228-
auto dh = DataRefUtils::getHeader<o2::header::DataHeader*>(ref);
230+
auto const* dh = o2::header::get<H*>(ref.header);
229231
if (dh == nullptr) {
230232
return false;
231233
}
232234
return DataSpecUtils::match(spec, dh->dataOrigin, dh->dataDescription, dh->subSpecification);
233235
}
236+
237+
/// check if the O2 message referred by DataRef matches a particular
238+
/// input spec. The DataHeader is retrieved from the header message and matched
239+
/// against @ref spec parameter.
240+
template <DataHeaderLike... H>
241+
static bool match(DataRef const& ref, InputSpec const& spec)
242+
{
243+
return (DataRefUtils::matchHeader<H>(ref, spec) || ... || matchHeader<o2::header::DataHeader>(ref, spec));
244+
}
234245
};
235246

236247
} // namespace o2::framework

Framework/Core/include/Framework/InputRecordWalker.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
#define FRAMEWORK_INPUTRECORDWALKER_H
1313

1414
/// @file InputRecordWalker.h
15-
/// @author Matthias Richter
1615
/// @since 2020-03-25
1716
/// @brief A helper class to iteratate over all parts of all input routes
1817

1918
#include "Framework/InputRecord.h"
19+
#include "Framework/DataRefUtils.h"
2020

2121
namespace o2::framework
2222
{
@@ -49,6 +49,7 @@ namespace o2::framework
4949
/// for (auto const& ref : InputRecordWalker(inputs, filter)) {
5050
/// // do something with the data
5151
/// }
52+
template <DataHeaderLike... EXTRA_HEADERS>
5253
class InputRecordWalker
5354
{
5455
public:
@@ -131,7 +132,7 @@ class InputRecordWalker
131132
if (mFilterSpecs.size() > 0) {
132133
bool isSelected = false;
133134
for (auto const& spec : mFilterSpecs) {
134-
if ((isSelected = DataRefUtils::match(*mCurrent, spec)) == true) {
135+
if ((isSelected = DataRefUtils::match<EXTRA_HEADERS...>(*mCurrent, spec)) == true) {
135136
break;
136137
}
137138
}

Framework/Utils/include/DPLUtils/DPLRawPageSequencer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ class DPLRawPageSequencer
191191
}
192192

193193
private:
194-
InputRecordWalker mInput;
194+
InputRecordWalker<> mInput;
195195

196196
template <typename Predicate, typename Inserter>
197197
void forwardInternal(Predicate pred, Inserter inserter, const char* data, size_t size, const o2::header::DataHeader* dh)

0 commit comments

Comments
 (0)