1818#include " Framework/CallbackService.h"
1919#include " Framework/DataSpecUtils.h"
2020#include " ../src/ExpressionJSONHelpers.h"
21+ #include " ../src/IndexJSONHelpers.h"
2122#include " Framework/ConfigContext.h"
2223#include " Framework/AnalysisContext.h"
2324
2425namespace o2 ::framework::readers
2526{
27+ namespace
28+ {
2629template <size_t N, std::array<soa::TableRef, N> refs>
2730static inline auto extractOriginals (ProcessingContext& pc)
2831{
2932 return [&]<size_t ... Is>(std::index_sequence<Is...>) -> std::vector<std::shared_ptr<arrow::Table>> {
3033 return {pc.inputs ().get <TableConsumer>(o2::aod::label<refs[Is]>())->asArrowTable ()...};
3134 }(std::make_index_sequence<refs.size ()>());
3235}
33- namespace
34- {
36+
3537template <typename D>
3638 requires (D::exclusive)
3739auto make_build (D metadata, InputSpec const & input, ProcessingContext& pc)
@@ -58,16 +60,39 @@ auto make_build(D metadata, InputSpec const& input, ProcessingContext& pc)
5860 index_pack_t {});
5961}
6062
63+ static inline auto extractSources (ProcessingContext& pc, std::vector<std::string> const & labels)
64+ {
65+ std::vector<std::shared_ptr<arrow::Table>> tables;
66+ for (auto const & label : labels) {
67+ tables.emplace_back (pc.inputs ().get <TableConsumer>(label.c_str ())->asArrowTable ());
68+ }
69+ return tables;
70+ }
71+
6172struct Builder {
73+ std::string binding;
74+ std::vector<std::string> labels;
75+ std::vector<o2::soa::IndexRecord> records;
76+ header::DataOrigin origin;
77+ header::DataDescription description;
78+ header::DataHeader::SubSpecificationType version;
79+
80+ std::shared_ptr<arrow::Table> build (ProcessingContext& pc) const
81+ {
82+ std::shared_ptr<arrow::Table> result;
83+ auto tables = extractSources (pc, labels);
84+ return result;
85+ }
6286
6387};
6488
6589struct Buildable {
6690 std::string binding;
67-
91+ std::vector<std::string> labels;
6892 header::DataOrigin origin;
6993 header::DataDescription description;
7094 header::DataHeader::SubSpecificationType version;
95+ std::vector<o2::soa::IndexRecord> records;
7196
7297 Buildable (InputSpec const & spec)
7398 : binding{spec.binding }
@@ -77,14 +102,25 @@ struct Buildable {
77102 description = description_;
78103 version = version_;
79104
80- // The following components are needed to build an index table
81- // 1. the labels of the source tables to extract from inputRecord -> extracted from input metadata
82- // 2. the mapping, in the order of the definition of columns, of the
83- // position in each source table of an index column pointing to the Key
84- // and the types of index to write (self, single-valued, slice or array)
85- // the mapping has to be created at the point where the type information is available and
86- // put into the input spec metadata as a vector of (type, label, pos)
105+ auto loc = std::find_if (spec.metadata .begin (), spec.metadata .end (), [](ConfigParamSpec const & cps) { return cps.name .compare (" index-records" ) == 0 ; });
106+ std::stringstream iws (loc->defaultValue .get <std::string>());
107+ records = IndexJSONHelpers::read (iws);
87108
109+ for (auto const & r : records) {
110+ labels.emplace_back (r.label );
111+ }
112+ }
113+
114+ Builder createBuilder () const
115+ {
116+ return Builder{
117+ binding,
118+ labels,
119+ records,
120+ origin,
121+ description,
122+ version
123+ };
88124 }
89125
90126};
@@ -132,21 +168,6 @@ AlgorithmSpec AODReaderHelpers::indexBuilderCallback(ConfigContext const& ctx)
132168
133169namespace
134170{
135- template <o2::aod::is_aod_hash D>
136- auto make_spawn (InputSpec const & input, ProcessingContext& pc)
137- {
138- using metadata_t = o2::aod::MetadataTrait<D>::metadata;
139- constexpr auto sources = metadata_t ::sources;
140- static std::shared_ptr<gandiva::Projector> projector = nullptr ;
141- static std::shared_ptr<arrow::Schema> schema = std::make_shared<arrow::Schema>(o2::soa::createFieldsFromColumns (typename metadata_t ::expression_pack_t {}));
142- static auto projectors = []<typename ... C>(framework::pack<C...>) -> std::array<expressions::Projector, sizeof ...(C)>
143- {
144- return {{std::move (C::Projector ())...}};
145- }
146- (typename metadata_t ::expression_pack_t {});
147- return o2::framework::spawner<D>(extractOriginals<sources.size (), sources>(pc), input.binding .c_str (), projectors.data (), projector, schema);
148- }
149-
150171struct Maker {
151172 std::string binding;
152173 std::vector<std::string> labels;
0 commit comments