Skip to content

Commit aa7b24e

Browse files
committed
add ability to use concrete matcher to extract tables from the input record
1 parent 91a991f commit aa7b24e

File tree

7 files changed

+37
-2
lines changed

7 files changed

+37
-2
lines changed

Framework/Core/include/Framework/ASoA.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#ifndef O2_FRAMEWORK_ASOA_H_
1313
#define O2_FRAMEWORK_ASOA_H_
1414

15+
#include "Framework/ConcreteDataMatcher.h"
1516
#include "Framework/Pack.h" // IWYU pragma: export
1617
#include "Framework/FunctionalHelpers.h" // IWYU pragma: export
1718
#include "Headers/DataHeader.h" // IWYU pragma: export
@@ -375,6 +376,12 @@ consteval const char* signature()
375376
return o2::aod::Hash<R.desc_hash>::str;
376377
}
377378

379+
template <soa::TableRef R>
380+
constexpr framework::ConcreteDataMatcher matcher()
381+
{
382+
return {origin<R>(), header::DataDescription{description_str(signature<R>())}, R.version};
383+
}
384+
378385
/// hash identification concepts
379386
template <typename T>
380387
concept is_aod_hash = requires(T t) { t.hash; t.str; };

Framework/Core/include/Framework/AnalysisTask.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ struct AnalysisDataProcessorBuilder {
214214
template <soa::TableRef R>
215215
static auto extractTableFromRecord(InputRecord& record)
216216
{
217-
auto table = record.get<TableConsumer>(o2::aod::label<R>())->asArrowTable();
217+
auto table = record.get<TableConsumer>(o2::aod::matcher<R>())->asArrowTable();
218218
if (table->num_rows() == 0) {
219219
table = makeEmptyTable<R>();
220220
}

Framework/Core/include/Framework/ConcreteDataMatcher.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ struct ConcreteDataMatcher {
5656
header::DataDescription description;
5757
header::DataHeader::SubSpecificationType subSpec;
5858

59-
ConcreteDataMatcher(header::DataOrigin origin_,
59+
constexpr ConcreteDataMatcher(header::DataOrigin origin_,
6060
header::DataDescription description_,
6161
header::DataHeader::SubSpecificationType subSpec_)
6262
: origin(origin_),

Framework/Core/include/Framework/DataSpecUtils.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ struct DataSpecUtils {
127127
/// unique way a description should be done, so we keep this outside.
128128
static std::string describe(OutputSpec const& spec);
129129

130+
/// Describes a ConcreteDataMatcher
131+
static std::string describe(ConcreteDataMatcher const& matcher);
132+
130133
/// Provide a unique label for the input spec. Again this is outside because there
131134
/// is no standard way of doing it, so better not to pollute the API.
132135
static std::string label(InputSpec const& spec);

Framework/Core/include/Framework/InputRecord.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ class InputRecord
189189
};
190190

191191
int getPos(const char* name) const;
192+
int getPos(ConcreteDataMatcher matcher) const;
192193
[[nodiscard]] static InputPos getPos(std::vector<InputRoute> const& routes, ConcreteDataMatcher matcher);
193194
[[nodiscard]] static DataRef getByPos(std::vector<InputRoute> const& routes, InputSpan const& span, int pos, int part = 0);
194195

@@ -511,6 +512,20 @@ class InputRecord
511512
return cache.idToMetadata[id];
512513
}
513514

515+
template <typename T>
516+
requires(std::same_as<T, TableConsumer>)
517+
decltype(auto) get(ConcreteDataMatcher matcher, int part = 0)
518+
{
519+
auto pos = getPos(matcher);
520+
if (pos < 0) {
521+
auto msg = describeAvailableInputs();
522+
throw runtime_error_f("InputRecord::get: no input with binding %s found. %s", DataSpecUtils::describe(matcher), msg.c_str());
523+
}
524+
auto ref = getByPos(pos, part);
525+
auto data = reinterpret_cast<uint8_t const*>(ref.payload);
526+
return std::make_unique<TableConsumer>(data, DataRefUtils::getPayloadSize(ref));
527+
}
528+
514529
/// Helper method to be used to check if a given part of the InputRecord is present.
515530
[[nodiscard]] bool isValid(std::string const& s) const
516531
{

Framework/Core/src/DataSpecUtils.cxx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ std::string DataSpecUtils::describe(OutputSpec const& spec)
8989
spec.matcher);
9090
}
9191

92+
static std::string describe(ConcreteDataMatcher const& matcher)
93+
{
94+
return join(matcher, "/");
95+
}
96+
9297
template <HasMatcher T>
9398
size_t DataSpecUtils::describe(char* buffer, size_t size, T const& spec)
9499
{

Framework/Core/src/InputRecord.cxx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ int InputRecord::getPos(const char* binding) const
5858
return -1;
5959
}
6060

61+
int InputRecord::getPos(ConcreteDataMatcher matcher) const
62+
{
63+
return getPos(mInputsSchema, matcher).index;
64+
}
65+
6166
InputRecord::InputPos InputRecord::getPos(std::vector<InputRoute> const& schema, ConcreteDataMatcher concrete)
6267
{
6368
size_t inputIndex = 0;

0 commit comments

Comments
 (0)