Project
Loading...
Searching...
No Matches
AnalysisTask.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#ifndef FRAMEWORK_ANALYSIS_TASK_H_
13#define FRAMEWORK_ANALYSIS_TASK_H_
14
30#include <fairmq/Version.h>
31
32#include <arrow/compute/kernel.h>
33#include <arrow/table.h>
34#include <gandiva/node.h>
35#include <type_traits>
36#include <utility>
37#include <memory>
38#include <tuple> // IWYU pragma: export
39
40namespace o2::framework
41{
43std::string type_to_task_name(std::string_view const& camelCase);
44
53};
54
55template <int64_t BEGIN, int64_t END, int64_t STEP = 1>
57 static constexpr int64_t begin = BEGIN;
58 static constexpr int64_t end = END;
59 static constexpr int64_t step = STEP;
60};
61
62template <typename T>
63static constexpr bool is_enumeration_v = false;
64
65template <int64_t BEGIN, int64_t END, int64_t STEP>
66static constexpr bool is_enumeration_v<Enumeration<BEGIN, END, STEP>> = true;
67
68template <typename T>
69concept is_enumeration = is_enumeration_v<std::decay_t<T>>;
70
71template <typename T>
73
74// Helper struct which builds a DataProcessorSpec from
75// the contents of an AnalysisTask...
76namespace
77{
78struct AnalysisDataProcessorBuilder {
79 template <soa::is_iterator G, soa::is_table... Args>
80 static void addGroupingCandidates(Cache& bk, Cache& bku, bool enabled)
81 {
82 []<soa::is_table... As>(framework::pack<As...>, Cache& bk, Cache& bku, bool enabled) {
83 auto key = std::string{"fIndex"} + o2::framework::cutString(soa::getLabelFromType<std::decay_t<G>>());
84 ([](Cache& bk, Cache& bku, bool enabled, std::string const& key) {
85 if constexpr (soa::relatedByIndex<std::decay_t<G>, std::decay_t<As>>()) {
86 Entry e{soa::getLabelFromTypeForKey<std::decay_t<As>>(key), soa::getMatcherFromTypeForKey<std::decay_t<As>>(key), key, enabled};
89 } else {
91 }
92 }
93 }(bk, bku, enabled, key),
94 ...);
95 }(framework::pack<Args...>{}, bk, bku, enabled);
96 }
97
98 template <soa::TableRef R>
99 static void addOriginalRef(const char* name, bool value, std::vector<InputSpec>& inputs, std::vector<InputInfo>& iInfos, int ai, uint32_t hash, header::DataOrigin newOrigin = header::DataOrigin{"AOD"})
100 {
101 auto spec = soa::tableRef2InputSpec<R>(newOrigin);
102 if (R.origin_hash != "AOD"_h) {
103 spec.metadata.emplace_back(ConfigParamSpec{"aod-origin-replaced", VariantType::Bool, true, {"\"\""}});
104 }
105 spec.metadata.emplace_back(ConfigParamSpec{std::string{"control:"} + name, VariantType::Bool, value, {"\"\""}});
106 auto matcher = DataSpecUtils::asConcreteDataMatcher(spec);
107 DataSpecUtils::updateInputList(inputs, std::move(spec));
108 auto locate = std::ranges::find_if(iInfos, [&hash](auto const& info) { return info.hash == hash; });
109 if (locate == iInfos.end()) {
110 iInfos.emplace_back(hash, std::vector{std::pair{ai, matcher}});
111 } else {
112 if (std::ranges::none_of(locate->matchers, [&ai, &matcher](auto const& match) { return (match.first == ai) && (match.second == matcher); })) {
113 locate->matchers.emplace_back(std::pair{ai, matcher});
114 }
115 }
116 }
117
119 template <soa::is_table A>
121 static void addExpression(int, uint32_t, std::vector<ExpressionInfo>&)
122 {
123 }
124
125 template <soa::is_filtered_table A>
126 static void addExpression(int ai, uint32_t hash, std::vector<ExpressionInfo>& eInfos)
127 {
128 auto fields = soa::createFieldsFromColumns(typename std::decay_t<A>::persistent_columns_t{});
129 eInfos.emplace_back(ai, hash, std::decay_t<A>::hashes(), std::make_shared<arrow::Schema>(fields));
130 }
131
132 template <soa::is_iterator A>
133 static void addExpression(int ai, uint32_t hash, std::vector<ExpressionInfo>& eInfos)
134 {
135 addExpression<typename std::decay_t<A>::parent_t>(ai, hash, eInfos);
136 }
137
139 template <soa::is_table A>
140 static void addInput(const char* name, bool value, std::vector<InputSpec>& inputs, std::vector<InputInfo>& iInfos, int ai, uint32_t hash, header::DataOrigin&& newOrigin = header::DataOrigin{"AOD"})
141 {
142 [&name, &value, &inputs, &iInfos, &ai, &hash, newOrigin = std::move(newOrigin)]<size_t N, std::array<soa::TableRef, N> refs, size_t... Is>(std::index_sequence<Is...>) mutable {
143 (addOriginalRef<refs[Is]>(name, value, inputs, iInfos, ai, hash, newOrigin), ...);
144 }.template operator()<A::originals.size(), std::decay_t<A>::originals>(std::make_index_sequence<std::decay_t<A>::originals.size()>());
145 }
146
148 template <soa::is_table... As>
149 static void addInputsAndExpressions(uint32_t hash, const char* name, bool value, std::vector<InputSpec>& inputs, std::vector<ExpressionInfo>& eInfos, std::vector<InputInfo>& iInfos, header::DataOrigin&& newOrigin = header::DataOrigin{"AOD"})
150 {
151 int ai = -1;
152 ([&ai, &hash, &eInfos, &name, &value, &inputs, &iInfos, newOrigin]() mutable {
153 ++ai;
154 using T = std::decay_t<As>;
155 addExpression<T>(ai, hash, eInfos);
156 addInput<T>(name, value, inputs, iInfos, ai, hash, std::move(newOrigin));
157 }(),
158 ...);
159 }
160
162 template <typename T>
163 inline static bool requestInputsFromArgs(T&, std::string const&, std::vector<InputSpec>&, std::vector<ExpressionInfo>&, std::vector<InputInfo>&, header::DataOrigin)
164 {
165 return false;
166 }
167 template <is_process_configurable T>
168 inline static bool requestInputsFromArgs(T& pc, std::string const& name, std::vector<InputSpec>& inputs, std::vector<ExpressionInfo>& eis, std::vector<InputInfo>& iifs, header::DataOrigin newOrigin = header::DataOrigin{"AOD"})
169 {
170 AnalysisDataProcessorBuilder::inputsFromArgs(pc.process, (name + "/" + pc.name).c_str(), pc.value, inputs, eis, iifs, newOrigin);
171 return true;
172 }
173 template <typename T>
174 inline static bool requestCacheFromArgs(T&, Cache&, Cache&)
175 {
176 return false;
177 }
178 template <is_process_configurable T>
179 inline static bool requestCacheFromArgs(T& pc, Cache& bk, Cache& bku)
180 {
181 AnalysisDataProcessorBuilder::cacheFromArgs(pc.process, pc.value, bk, bku);
182 return true;
183 }
185 template <typename C, is_enumeration A>
186 static void inputsFromArgs(void (C::*)(A), const char* /*name*/, bool /*value*/, std::vector<InputSpec>& inputs, std::vector<ExpressionInfo>&, std::vector<InputInfo>&, header::DataOrigin)
187 {
188 std::vector<ConfigParamSpec> inputMetadata;
189 // FIXME: for the moment we do not support begin, end and step.
190 DataSpecUtils::updateInputList(inputs, InputSpec{"enumeration", "DPL", "ENUM", 0, Lifetime::Enumeration, inputMetadata});
191 }
192
194 template <typename C, soa::is_iterator A, soa::is_table... Args>
195 static void inputsFromArgs(void (C::*)(A, Args...), const char* name, bool value, std::vector<InputSpec>& inputs, std::vector<ExpressionInfo>& eInfos, std::vector<InputInfo>& iInfos, header::DataOrigin newOrigin = header::DataOrigin{"AOD"})
196 requires(std::is_lvalue_reference_v<A> && (std::is_lvalue_reference_v<Args> && ...))
197 {
198 constexpr auto hash = o2::framework::TypeIdHelpers::uniqueId<void (C::*)(A, Args...)>();
199 addInputsAndExpressions<typename std::decay_t<A>::parent_t, Args...>(hash, name, value, inputs, eInfos, iInfos, std::move(newOrigin));
200 }
201
203 template <typename C, soa::is_table... Args>
204 static void inputsFromArgs(void (C::*)(Args...), const char* name, bool value, std::vector<InputSpec>& inputs, std::vector<ExpressionInfo>& eInfos, std::vector<InputInfo>& iInfos, header::DataOrigin newOrigin = header::DataOrigin{"AOD"})
205 requires(std::is_lvalue_reference_v<Args> && ...)
206 {
207 constexpr auto hash = o2::framework::TypeIdHelpers::uniqueId<void (C::*)(Args...)>();
208 addInputsAndExpressions<Args...>(hash, name, value, inputs, eInfos, iInfos, std::move(newOrigin));
209 }
210
212 template <typename C, is_enumeration A>
213 static void cacheFromArgs(void (C::*)(A), bool, Cache&, Cache&)
214 {
215 }
217 template <typename C, soa::is_iterator A, soa::is_table... Args>
218 static void cacheFromArgs(void (C::*)(A, Args...), bool value, Cache& bk, Cache& bku)
219 {
220 addGroupingCandidates<A, Args...>(bk, bku, value);
221 }
223 template <typename C, soa::is_table A, soa::is_table... Args>
224 static void cacheFromArgs(void (C::*)(A, Args...), bool, Cache&, Cache&)
225 {
226 }
227
228 template <std::ranges::input_range R>
229 static auto extractTablesFromRecord(InputRecord& record, R matchers)
230 {
231 std::vector<soa::ArrowTableRef> tables;
232 std::ranges::transform(matchers, std::back_inserter(tables), [&record](auto const& m) {
233 return record.get<TableConsumer>(m.second)->asArrowTable();
234 });
235 return tables;
236 }
237
238 template <soa::is_table T, std::ranges::input_range R>
239 static auto extractFromRecord(InputRecord& record, R matchers)
240 {
241 return T{extractTablesFromRecord(record, matchers)};
242 }
243
244 template <soa::is_iterator T, std::ranges::input_range R>
245 static auto extractFromRecord(InputRecord& record, R matchers)
246 {
247 return typename T::parent_t{extractTablesFromRecord(record, matchers)};
248 }
249
250 template <soa::is_filtered T, std::ranges::input_range R>
251 static auto extractFilteredFromRecord(InputRecord& record, R matchers, ExpressionInfo& info)
252 {
253 auto table = soa::ArrowHelpers::joinTables(extractTablesFromRecord(record, matchers));
254 expressions::updateFilterInfo(info, table.tablePtr);
256 if (info.selection == nullptr) {
257 soa::missingFilterDeclaration(info.processHash, info.argumentIndex);
258 }
259 }
260 if constexpr (soa::is_iterator<T>) {
261 return typename T::parent_t({table}, info.selection);
262 } else {
263 return T({table}, info.selection);
264 }
265 }
266
267 template <is_enumeration T, int AI, std::ranges::input_range R>
268 static auto extract(InputRecord&, R, std::vector<ExpressionInfo>&, size_t)
269 {
270 return T{};
271 }
272
273 template <soa::is_table_or_iterator T, int AI, std::ranges::input_range R>
274 static auto extract(InputRecord& record, R matchers, std::vector<ExpressionInfo>& infos, size_t phash)
275 {
276 // auto matchers = std::ranges::find_if(iInfos, [&phash](auto const& info) { return info.hash == phash; })->matchers | std::views::filter([](auto const& pair) { return pair.first == AI; });
277 if constexpr (soa::is_filtered<T>) {
278 return extractFilteredFromRecord<T>(record, matchers, *std::ranges::find_if(infos, [&phash](ExpressionInfo const& i) { return (i.processHash == phash && i.argumentIndex == AI); }));
279 } else {
280 return extractFromRecord<T>(record, matchers);
281 }
282 }
283
284 template <std::ranges::input_range R, typename C, is_table_iterator_or_enumeration Grouping, soa::is_table... Args>
285 static auto bindGroupingTable(InputRecord& record, R matchers, void (C::*)(Grouping, Args...), std::vector<ExpressionInfo>& infos)
286 requires(!std::same_as<Grouping, void>)
287 {
288 constexpr auto hash = o2::framework::TypeIdHelpers::uniqueId<void (C::*)(Grouping, Args...)>();
289 return extract<std::decay_t<Grouping>, 0>(record, matchers | std::views::filter([](auto const& pair) { return pair.first == 0; }), infos, hash);
290 }
291
292 template <std::ranges::input_range R, typename C, is_table_iterator_or_enumeration Grouping, soa::is_table... Args>
293 static auto bindAssociatedTables(InputRecord& record, R matchers, void (C::*)(Grouping, Args...), std::vector<ExpressionInfo>& infos)
294 requires(!std::same_as<Grouping, void> && sizeof...(Args) > 0)
295 {
296 constexpr auto hash = o2::framework::TypeIdHelpers::uniqueId<void (C::*)(Grouping, Args...)>();
297 return std::make_tuple(extract<std::decay_t<Args>, has_type_at_v<Args>(pack<Args...>{}) + 1>(record, matchers | std::views::filter([](auto const& pair) { return pair.first == has_type_at_v<Args>(pack<Args...>{}) + 1; }), infos, hash)...);
298 }
299
300 template <soa::is_table... As>
301 static void overwriteInternalIndices(std::tuple<As...>& dest, std::tuple<As...> const& src)
302 {
303 (std::get<As>(dest).bindInternalIndicesTo(&std::get<As>(src)), ...);
304 }
305
306 template <typename Task, is_table_iterator_or_enumeration Grouping, std::ranges::input_range R, soa::is_table... Associated>
307#if (FAIRMQ_VERSION_DEC >= 111000)
308 static void invokeProcess(Task& task, InputRecord& inputs, R matchers, PointerReconstructor const& pointerReconstructor, void (Task::*processingFunction)(Grouping, Associated...), std::vector<ExpressionInfo>& infos, ArrowTableSlicingCache& slices, header::DataOrigin newOrigin = header::DataOrigin{"AOD"})
309#else
310 static void invokeProcess(Task& task, InputRecord& inputs, R matchers, void (Task::*processingFunction)(Grouping, Associated...), std::vector<ExpressionInfo>& infos, ArrowTableSlicingCache& slices, header::DataOrigin newOrigin = header::DataOrigin{"AOD"})
311#endif
312 {
313 using G = std::decay_t<Grouping>;
314 auto groupingTable = AnalysisDataProcessorBuilder::bindGroupingTable(inputs, matchers, processingFunction, infos);
315#if (FAIRMQ_VERSION_DEC >= 111000)
316 if constexpr (!is_enumeration<G>) {
317 groupingTable.setPointerReconstructor(pointerReconstructor);
318 }
319#endif
320 constexpr const int numElements = nested_brace_constructible_size<false, std::decay_t<Task>>() / 10;
321
322 // set filtered tables for partitions with grouping
323 homogeneous_apply_refs_sized<numElements>([&groupingTable](auto& element) {
326 return true;
327 },
328 task);
329
330 if constexpr (sizeof...(Associated) == 0) {
331 // single argument to process
332 homogeneous_apply_refs_sized<numElements>([&groupingTable](auto& element) {
335 return true;
336 },
337 task);
338 if constexpr (soa::is_iterator<G>) {
339 for (auto& element : groupingTable) {
340 std::invoke(processingFunction, task, *element);
341 }
342 } else {
343 std::invoke(processingFunction, task, groupingTable);
344 }
345 } else {
346 // multiple arguments to process
347 auto associatedTables = AnalysisDataProcessorBuilder::bindAssociatedTables(inputs, matchers, processingFunction, infos);
348 // pre-bind self indices
349 std::apply(
350 [&task](auto&... t) mutable {
351 (homogeneous_apply_refs_sized<numElements>(
352 [&t](auto& p) {
354 return true;
355 },
356 task),
357 ...);
358 },
359 associatedTables);
360#if (FAIRMQ_VERSION_DEC >= 111000)
361 std::apply([&pointerReconstructor](auto&... table) {
362 (table.setPointerReconstructor(pointerReconstructor), ...);
363 },
364 associatedTables);
365#endif
366
367 auto binder = [&task, &groupingTable, &associatedTables](auto& x) mutable {
368 x.bindExternalIndices(&groupingTable, &std::get<std::decay_t<Associated>>(associatedTables)...);
369 homogeneous_apply_refs_sized<numElements>([&x](auto& t) mutable {
372 return true;
373 },
374 task);
375 };
376 groupingTable.bindExternalIndices(&std::get<std::decay_t<Associated>>(associatedTables)...);
377
378 // always pre-bind full tables to support index hierarchy
379 std::apply(
380 [&binder](auto&... x) mutable {
381 (binder(x), ...);
382 },
383 associatedTables);
384
385 // GroupedCombinations bound separately, as they should be set once for all associated tables
386 homogeneous_apply_refs_sized<numElements>([&groupingTable, &associatedTables](auto& t) {
387 analysis_task_parsers::setGroupedCombination(t, groupingTable, associatedTables);
388 return true;
389 },
390 task);
391 overwriteInternalIndices(associatedTables, associatedTables);
392 if constexpr (soa::is_iterator<G>) {
393 auto slicer = GroupSlicer(groupingTable, associatedTables, slices, newOrigin);
394 for (auto& slice : slicer) {
395 auto associatedSlices = slice.associatedTables();
396#if (FAIRMQ_VERSION_DEC >= 111000)
397 std::apply([&pointerReconstructor](auto&... table) {
398 (table.setPointerReconstructor(pointerReconstructor), ...);
399 },
400 associatedSlices);
401#endif
402 overwriteInternalIndices(associatedSlices, associatedTables);
403 std::apply(
404 [&binder](auto&... x) mutable {
405 (binder(x), ...);
406 },
407 associatedSlices);
408
409 // bind partitions and grouping table
410 homogeneous_apply_refs_sized<numElements>([&groupingTable](auto& x) {
412 return true;
413 },
414 task);
415
416 [](Task& task, void (Task::*processingFunction)(Grouping, Associated...), Grouping g, std::tuple<std::decay_t<Associated>...>& at) {
417 std::invoke(processingFunction, task, g, std::get<std::decay_t<Associated>>(at)...);
418 }(task, processingFunction, slice.groupingElement(), associatedSlices);
419 }
420 } else {
421 // bind partitions and grouping table
422 homogeneous_apply_refs_sized<numElements>([&groupingTable](auto& x) {
424 return true;
425 },
426 task);
427
428 [](Task& task, void (Task::*processingFunction)(Grouping, Associated...), Grouping g, std::tuple<std::decay_t<Associated>...>& at) {
429 std::invoke(processingFunction, task, g, std::get<std::decay_t<Associated>>(at)...);
430 }(task, processingFunction, groupingTable, associatedTables);
431 }
432 }
433 }
434};
435} // namespace
436
438 std::vector<std::pair<std::string, bool>> map;
439};
440
442struct TaskName {
443 TaskName(std::string name) : value{std::move(name)} {}
444 std::string value;
445};
446
447namespace
448{
449template <typename T, typename... A>
450auto getTaskNameSetProcesses(std::string& outputName, TaskName first, SetDefaultProcesses second, A... args)
451{
452 auto task = std::make_shared<T>(std::forward<A>(args)...);
453 for (auto& setting : second.map) {
455 [&](auto& element) {
456 return analysis_task_parsers::setProcessSwitch(setting, element);
457 },
458 *task.get());
459 }
460 outputName = first.value;
461 return task;
462}
463
464template <typename T, typename... A>
465auto getTaskNameSetProcesses(std::string& outputName, SetDefaultProcesses first, TaskName second, A... args)
466{
467 auto task = std::make_shared<T>(std::forward<A>(args)...);
468 for (auto& setting : first.map) {
470 [&](auto& element) {
471 return analysis_task_parsers::setProcessSwitch(setting, element);
472 },
473 *task.get());
474 }
475 outputName = second.value;
476 return task;
477}
478
479template <typename T, typename... A>
480auto getTaskNameSetProcesses(std::string& outputName, SetDefaultProcesses first, A... args)
481{
482 auto task = std::make_shared<T>(std::forward<A>(args)...);
483 for (auto& setting : first.map) {
485 [&](auto& element) {
486 return analysis_task_parsers::setProcessSwitch(setting, element);
487 },
488 *task.get());
489 }
490 auto type_name_str = type_name<T>();
491 outputName = type_to_task_name(type_name_str);
492 return task;
493}
494
495template <typename T, typename... A>
496auto getTaskNameSetProcesses(std::string& outputName, TaskName first, A... args)
497{
498 auto task = std::make_shared<T>(std::forward<A>(args)...);
499 outputName = first.value;
500 return task;
501}
502
503template <typename T, typename... A>
504auto getTaskNameSetProcesses(std::string& outputName, A... args)
505{
506 auto task = std::make_shared<T>(std::forward<A>(args)...);
507 auto type_name_str = type_name<T>();
508 outputName = type_to_task_name(type_name_str);
509 return task;
510}
511} // namespace
512
515template <typename T, typename... Args>
517{
518 TH1::AddDirectory(false);
519
520 std::string name_str;
521 auto task = getTaskNameSetProcesses<T>(name_str, args...);
522
523 auto suffix = ctx.options().get<std::string>("workflow-suffix");
524 if (!suffix.empty()) {
525 name_str += suffix;
526 }
527 const char* name = name_str.c_str();
528
529 auto hash = runtime_hash(name);
530
531 std::vector<OutputSpec> outputs;
532 std::vector<InputSpec> inputs;
533 std::vector<ConfigParamSpec> options;
534 std::vector<ExpressionInfo> expressionInfos;
535 std::vector<InputInfo> inputInfos;
536
537 std::string newOriginStr;
538 header::DataOrigin newOrigin{"AOD"};
539 if (ctx.options().hasOption("aod-origin-replace")) {
540 newOriginStr = ctx.options().get<std::string>("aod-origin-replace");
541 if (newOriginStr.size() > 4UL) {
542 wrongOriginReplacement(newOriginStr);
543 }
544 }
545 if (!newOriginStr.empty()) {
546 newOrigin.runtimeInit(newOriginStr.c_str(), std::min(newOriginStr.size(), 4UL));
547 }
548
549 constexpr const int numElements = nested_brace_constructible_size<false, std::decay_t<T>>() / 10;
550
552 homogeneous_apply_refs_sized<numElements>([&options](auto& element) { return analysis_task_parsers::appendOption(options, element); }, *task.get());
554 homogeneous_apply_refs_sized<numElements>([&inputs](auto& element) { return analysis_task_parsers::appendCondition(inputs, element); }, *task.get());
555
557 if constexpr (requires { &T::process; }) {
558 AnalysisDataProcessorBuilder::inputsFromArgs(&T::process, "default", true, inputs, expressionInfos, inputInfos, newOrigin);
559 }
560 homogeneous_apply_refs_sized<numElements>(
561 [name = name_str, &expressionInfos, &inputs, &inputInfos, &newOrigin](auto& x) mutable {
562 // this pushes (argumentIndex, processHash, schemaPtr, nullptr) into expressionInfos for arguments that are Filtered/filtered_iterators
563 return AnalysisDataProcessorBuilder::requestInputsFromArgs(x, name, inputs, expressionInfos, inputInfos, newOrigin);
564 },
565 *task.get());
566
567 // request base tables for spawnable extended tables and indices to be built
568 // this checks for duplications
569 homogeneous_apply_refs_sized<numElements>([&inputs, &newOrigin](auto& element) {
570 return analysis_task_parsers::requestInputs(inputs, element, newOrigin);
571 },
572 *task.get());
573
574 // no static way to check if the task defines any processing, we can only make sure it subscribes to at least something
575 if (inputs.empty() == true) {
576 LOG(warn) << "Task " << name_str << " has no inputs";
577 }
578
579 // update OutputSpecs in output declarations
580 homogeneous_apply_refs_sized<numElements>([&newOrigin](auto& element) { return analysis_task_parsers::updateOutputSpec(element, newOrigin); }, *task.get());
581
582 // Auto-register default ccdb: path options from subscribed timestamped-table inputs.
583 // This allows tasks to accept --ccdb:fXxx overrides without requiring an explicit
584 // ConfigurableCCDBPath<> member for every column in the subscribed table.
585 for (auto& input : inputs) {
586 for (auto& meta : input.metadata) {
587 if (meta.name.starts_with("ccdb:") && meta.name != "ccdb:") {
589 }
590 }
591 }
592
593 // append outputs
594 homogeneous_apply_refs_sized<numElements>([&outputs, &hash](auto& element) { return analysis_task_parsers::appendOutput(outputs, element, hash); }, *task.get());
595
596 // request services
597 auto requiredServices = CommonServices::defaultServices();
598 auto arrowServices = CommonServices::arrowServices();
599 requiredServices.insert(requiredServices.end(), arrowServices.begin(), arrowServices.end());
600 homogeneous_apply_refs_sized<numElements>([&requiredServices](auto& element) { return analysis_task_parsers::addService(requiredServices, element); }, *task.get());
601
602 // replace origins in Preslice declarations
603 homogeneous_apply_refs_sized<numElements>([&newOrigin](auto& element) { return analysis_task_parsers::replaceOrigin(element, newOrigin); }, *task.get());
604
606 {
607 [task = task, expressionInfos, inputInfos, newOrigin, newOriginStr](InitContext& ic) mutable {
608 Cache bindingsKeys;
609 Cache bindingsKeysUnsorted;
610 // add preslice declarations to slicing cache definition
611 homogeneous_apply_refs_sized<numElements>([&bindingsKeys, &bindingsKeysUnsorted](auto& element) { return analysis_task_parsers::registerCache(element, bindingsKeys, bindingsKeysUnsorted); }, *task.get());
612
613 homogeneous_apply_refs_sized<numElements>([&ic](auto&& element) { return analysis_task_parsers::prepareOption(ic, element); }, *task.get());
614 homogeneous_apply_refs_sized<numElements>([&ic](auto&& element) { return analysis_task_parsers::prepareService(ic, element); }, *task.get());
615
616 auto& callbacks = ic.services().get<CallbackService>();
617 auto eoscb = [task](EndOfStreamContext& eosContext) {
618 homogeneous_apply_refs_sized<numElements>([&eosContext](auto& element) {
621 return true; },
622 *task.get());
623 eosContext.services().get<ControlService>().readyToQuit(QuitRequest::Me);
624 };
625
626 callbacks.set<CallbackService::Id::EndOfStream>(eoscb);
627
629 if constexpr (requires { task->init(ic); }) {
630 task->init(ic);
631 }
632
634 homogeneous_apply_refs_sized<numElements>(
635 [&ic](auto& element) -> bool { return analysis_task_parsers::updatePlaceholders(ic, element); },
636 *task.get());
638 homogeneous_apply_refs_sized<numElements>([&expressionInfos](auto& element) {
640 },
641 *task.get());
642
644 if constexpr (requires { &T::process; }) {
645 AnalysisDataProcessorBuilder::cacheFromArgs(&T::process, true, bindingsKeys, bindingsKeysUnsorted);
646 }
647 homogeneous_apply_refs_sized<numElements>(
648 [&bindingsKeys, &bindingsKeysUnsorted](auto& x) {
649 return AnalysisDataProcessorBuilder::requestCacheFromArgs(x, bindingsKeys, bindingsKeysUnsorted);
650 },
651 *task.get());
652
654 std::ranges::transform(bindingsKeys, bindingsKeys.begin(), [&newOrigin](Entry& entry) {
655 if ((entry.matcher.origin == header::DataOrigin{"AOD"}) && (newOrigin != header::DataOrigin{"AOD"})) {
656 entry.matcher = replaceOrigin(entry.matcher, newOrigin);
657 }
658 return entry;
659 });
660 std::ranges::transform(bindingsKeysUnsorted, bindingsKeysUnsorted.begin(), [&newOrigin](Entry& entry) {
661 if ((entry.matcher.origin == header::DataOrigin{"AOD"}) && (newOrigin != header::DataOrigin{"AOD"})) {
662 entry.matcher = replaceOrigin(entry.matcher, newOrigin);
663 }
664 return entry;
665 });
666
667 ic.services().get<ArrowTableSlicingCacheDef>().setCaches(std::move(bindingsKeys));
668 ic.services().get<ArrowTableSlicingCacheDef>().setCachesUnsorted(std::move(bindingsKeysUnsorted));
669 ic.services().get<ArrowTableSlicingCacheDef>().setOrigin(newOrigin);
670#if (FAIRMQ_VERSION_DEC >= 111000)
671 PointerReconstructor pointerReconstructor(nullptr);
672 bool hasCCDBTables = !ic.services().get<DanglingEdgesContext>().requestedTIMs.empty();
673
674 return [task, expressionInfos, inputInfos, newOrigin, hasCCDBTables, pointerReconstructor](ProcessingContext& pc) mutable {
675 if (hasCCDBTables && (!pointerReconstructor)) {
676 auto& proxy = pc.services().get<FairMQDeviceProxy>();
677 auto& spec = pc.services().get<DanglingEdgesContext>().requestedTIMs.front();
678 pointerReconstructor = proxy.getShmPointerReconstructor(spec, 0);
679 }
680#else
681 return [task, expressionInfos, inputInfos, newOrigin](ProcessingContext& pc) mutable {
682#endif
683 // load the ccdb object from their cache
684 homogeneous_apply_refs_sized<numElements>([&pc](auto& element) { return analysis_task_parsers::newDataframeCondition(pc.inputs(), element); }, *task.get());
685 // reset partitions once per dataframe
686 homogeneous_apply_refs_sized<numElements>([](auto& element) { return analysis_task_parsers::newDataframePartition(element); }, *task.get());
687 // reset selections for the next dataframe
688 std::ranges::for_each(expressionInfos, [](auto& info) { info.resetSelection = true; });
689 // reset pre-slice for the next dataframe
690 auto& slices = pc.services().get<ArrowTableSlicingCache>();
691 homogeneous_apply_refs_sized<numElements>([&slices](auto& element) {
693 },
694 *(task.get()));
695 // initialize local caches
696 homogeneous_apply_refs_sized<numElements>([&pc](auto& element) { return analysis_task_parsers::initializeCache(pc, element); }, *(task.get()));
697 // prepare outputs
698 homogeneous_apply_refs_sized<numElements>([&pc](auto& element) { return analysis_task_parsers::prepareOutput(pc, element); }, *task.get());
699 // execute run()
700 if constexpr (requires { task->run(pc); }) {
701 task->run(pc);
702 }
703 // execute process()
704 if constexpr (requires { &T::process; }) {
705 auto loc = std::ranges::find_if(inputInfos, [](auto const& info) { return info.hash == o2::framework::TypeIdHelpers::uniqueId<decltype(&T::process)>(); });
706 auto matchers = loc == inputInfos.end() ? std::vector<std::pair<int, ConcreteDataMatcher>>{} : loc->matchers;
707#if (FAIRMQ_VERSION_DEC >= 111000)
708 AnalysisDataProcessorBuilder::invokeProcess(*(task.get()), pc.inputs(), matchers, pointerReconstructor, &T::process, expressionInfos, slices, newOrigin);
709#else
710 AnalysisDataProcessorBuilder::invokeProcess(*(task.get()), pc.inputs(), matchers, &T::process, expressionInfos, slices, newOrigin);
711#endif
712 }
713 // execute optional process()
714 homogeneous_apply_refs_sized<numElements>(
715#if (FAIRMQ_VERSION_DEC >= 111000)
716 [&pc, &expressionInfos, &task, &slices, &inputInfos, &newOrigin, &pointerReconstructor](auto& x) {
717#else
718 [&pc, &expressionInfos, &task, &slices, &inputInfos, &newOrigin](auto& x) {
719#endif
720 if constexpr (is_process_configurable<decltype(x)>) {
721 if (x.value == true) {
722 auto loc = std::ranges::find_if(inputInfos, [](auto const& info) { return info.hash == o2::framework::TypeIdHelpers::uniqueId<decltype(x.process)>(); });
723 auto matchers = loc == inputInfos.end() ? std::vector<std::pair<int, ConcreteDataMatcher>>{} : loc->matchers;
724#if (FAIRMQ_VERSION_DEC >= 111000)
725 AnalysisDataProcessorBuilder::invokeProcess(*task.get(), pc.inputs(), matchers, pointerReconstructor, x.process, expressionInfos, slices, newOrigin);
726#else
727 AnalysisDataProcessorBuilder::invokeProcess(*task.get(), pc.inputs(), matchers, x.process, expressionInfos, slices, newOrigin);
728#endif
729 return true;
730 }
731 return false;
732 }
733 return false;
734 },
735 *task.get());
736 // prepare delayed outputs
737 homogeneous_apply_refs_sized<numElements>([&pc](auto& element) { return analysis_task_parsers::prepareDelayedOutput(pc, element); }, *task.get());
738 // finalize outputs
739 homogeneous_apply_refs_sized<numElements>([&pc](auto& element) { return analysis_task_parsers::finalizeOutput(pc, element); }, *task.get());
740 };
741 }
742 };
743
744 return {
745 name,
746 inputs,
747 outputs,
748 algo,
749 options,
750 requiredServices};
751}
752
753} // namespace o2::framework
754#endif // FRAMEWORK_ANALYSISTASK_H_
std::vector< framework::ConcreteDataMatcher > matchers
uint32_t hash
atype::type element
std::vector< std::shared_ptr< arrow::Field > > fields
int32_t i
constexpr uint32_t runtime_hash(char const *str)
StringRef key
Definition A.h:16
bool match(const std::vector< std::string > &queries, const char *pattern)
Definition dcs-ccdb.cxx:229
GLint GLenum GLint x
Definition glcorearb.h:403
const GLfloat * m
Definition glcorearb.h:4066
GLenum src
Definition glcorearb.h:1767
GLuint entry
Definition glcorearb.h:5735
GLuint GLuint end
Definition glcorearb.h:469
GLuint const GLchar * name
Definition glcorearb.h:781
GLenum GLenum GLsizei const GLuint GLboolean enabled
Definition glcorearb.h:2513
GLsizei const GLfloat * value
Definition glcorearb.h:819
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
GLboolean GLboolean g
Definition glcorearb.h:1233
bool prepareService(InitContext &, T &)
void setGroupedCombination(C &, TG &, Ts &...)
Combinations handling.
bool initializeCache(ProcessingContext &, T &)
Cache handling.
bool replaceOrigin(T &, header::DataOrigin const &)
Preslice handling.
bool requestInputs(std::vector< InputSpec > &, T &, header::DataOrigin)
bool prepareDelayedOutput(ProcessingContext &, T &)
bool prepareOption(InitContext &, O &)
bool finalizeOutput(ProcessingContext &, T &)
bool registerCache(T &, Cache &, Cache &)
bool postRunOutput(EndOfStreamContext &, T &)
bool createExpressionTrees(std::vector< ExpressionInfo > &, T &)
bool prepareOutput(ProcessingContext &, T &)
bool appendOption(std::vector< ConfigParamSpec > &, O &)
Options handling.
bool updateSliceInfo(T &, ArrowTableSlicingCache &)
bool appendCondition(std::vector< InputSpec > &, C &)
Conditions handling.
bool postRunService(EndOfStreamContext &, T &)
bool addService(std::vector< ServiceSpec > &, T &)
Service handling.
bool updatePlaceholders(InitContext &, T &)
Filter handling.
constexpr bool appendOutput(std::vector< OutputSpec > &, T &, uint32_t)
Outputs handling.
bool newDataframeCondition(InputRecord &, C &)
bool updateOutputSpec(T &, header::DataOrigin)
void updateFilterInfo(ExpressionInfo &info, std::shared_ptr< arrow::Table > &table)
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
void updatePairList(Cache &list, Entry &entry)
DataProcessorSpec adaptAnalysisTask(ConfigContext const &ctx, Args &&... args)
std::vector< Entry > Cache
std::string type_to_task_name(std::string_view const &camelCase)
Convert a CamelCase task struct name to snake-case task name.
@ Me
Only quit this data processor.
constexpr auto homogeneous_apply_refs(L l, T &&object)
ConfigParamSpec replaceOrigin(ConfigParamSpec &source, std::string const &originStr)
void wrongOriginReplacement(std::string_view replacement)
std::string cutString(std::string &&str)
Definition ASoA.cxx:314
Descriptor< gSizeDataOriginString > DataOrigin
Definition DataHeader.h:550
auto createFieldsFromColumns(framework::pack< C... >)
Definition ASoA.h:79
void missingFilterDeclaration(int hash, int ai)
Definition ASoA.cxx:33
std::function< ProcessCallback(InitContext &)> InitCallback
static std::vector< ServiceSpec > defaultServices(std::string extraPlugins="", int numWorkers=0)
Split a string into a vector of strings using : as a separator.
static std::vector< ServiceSpec > arrowServices()
static void addOptionIfMissing(std::vector< ConfigParamSpec > &specs, const ConfigParamSpec &spec)
static ConcreteDataMatcher asConcreteDataMatcher(InputSpec const &input)
static void updateInputList(std::vector< InputSpec > &list, InputSpec &&input)
Updates list of InputSpecs by merging metadata.
static constexpr int64_t step
static constexpr int64_t begin
std::vector< std::pair< std::string, bool > > map
Struct to differentiate task names from possible task string arguments.
TaskName(std::string name)
static constexpr uint32_t uniqueId()
static o2::soa::ArrowTableRef joinTables(std::vector< std::shared_ptr< arrow::Table > > &&tables)
Definition ASoA.cxx:140
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"