forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnalysisTask.h
More file actions
681 lines (605 loc) · 27 KB
/
AnalysisTask.h
File metadata and controls
681 lines (605 loc) · 27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#ifndef FRAMEWORK_ANALYSIS_TASK_H_
#define FRAMEWORK_ANALYSIS_TASK_H_
#include "Framework/AnalysisManagers.h"
#include "Framework/AlgorithmSpec.h"
#include "Framework/CallbackService.h"
#include "Framework/ConfigContext.h"
#include "Framework/Condition.h"
#include "Framework/ControlService.h"
#include "Framework/DataProcessorSpec.h"
#include "Framework/Expressions.h"
#include "Framework/ExpressionHelpers.h"
#include "Framework/EndOfStreamContext.h"
#include "Framework/GroupSlicer.h"
#include "Framework/Logger.h"
#include "Framework/StructToTuple.h"
#include "Framework/FunctionalHelpers.h"
#include "Framework/Traits.h"
#include "Framework/VariantHelpers.h"
#include "Framework/RuntimeError.h"
#include "Framework/TypeIdHelpers.h"
#include <arrow/compute/kernel.h>
#include <arrow/table.h>
#include <gandiva/node.h>
#include <type_traits>
#include <utility>
#include <memory>
namespace o2::framework
{
/// A more familiar task API for the DPL analysis framework.
/// This allows you to define your own tasks as subclasses
/// of o2::framework::AnalysisTask and to pass them in the specification
/// using:
///
/// adaptAnalysisTask<YourDerivedTask>(constructor args, ...);
///
// FIXME: for the moment this needs to stay outside AnalysisTask
// because we cannot inherit from it due to a C++17 bug
// in GCC 7.3. We need to move to 7.4+
struct AnalysisTask {
};
// Helper struct which builds a DataProcessorSpec from
// the contents of an AnalysisTask...
struct AnalysisDataProcessorBuilder {
template <typename T>
static ConfigParamSpec getSpec()
{
if constexpr (soa::is_type_with_metadata_v<aod::MetadataTrait<T>>) {
return ConfigParamSpec{std::string{"input:"} + aod::MetadataTrait<T>::metadata::tableLabel(), VariantType::String, aod::MetadataTrait<T>::metadata::sourceSpec(), {"\"\""}};
} else {
using O1 = framework::pack_element_t<0, typename T::originals>;
return ConfigParamSpec{std::string{"input:"} + aod::MetadataTrait<T>::metadata::tableLabel(), VariantType::String, aod::MetadataTrait<O1>::metadata::sourceSpec(), {"\"\""}};
}
}
template <typename... T>
static inline std::vector<ConfigParamSpec> getInputSpecs(framework::pack<T...>)
{
return std::vector{getSpec<T>()...};
}
template <typename T>
static inline auto getSources()
{
if constexpr (soa::is_soa_index_table_t<T>::value) {
return getInputSpecs(typename T::sources_t{});
} else if constexpr (soa::is_soa_extension_table_v<std::decay_t<T>>) {
return getInputSpecs(typename aod::MetadataTrait<T>::metadata::sources{});
} else {
always_static_assert<T>("Can be only used with index or extension table");
}
}
template <typename T>
static auto getInputMetadata()
{
std::vector<ConfigParamSpec> inputMetadata;
auto inputSources = getSources<T>();
std::sort(inputSources.begin(), inputSources.end(), [](ConfigParamSpec const& a, ConfigParamSpec const& b) { return a.name < b.name; });
auto last = std::unique(inputSources.begin(), inputSources.end(), [](ConfigParamSpec const& a, ConfigParamSpec const& b) { return a.name == b.name; });
inputSources.erase(last, inputSources.end());
inputMetadata.insert(inputMetadata.end(), inputSources.begin(), inputSources.end());
return inputMetadata;
}
template <typename Arg>
static void doAppendInputWithMetadata(const char* name, bool value, std::vector<InputSpec>& inputs)
{
using metadata = typename aod::MetadataTrait<std::decay_t<Arg>>::metadata;
static_assert(std::is_same_v<metadata, void> == false,
"Could not find metadata. Did you register your type?");
std::vector<ConfigParamSpec> inputMetadata;
inputMetadata.emplace_back(ConfigParamSpec{std::string{"control:"} + name, VariantType::Bool, value, {"\"\""}});
if constexpr (soa::is_soa_index_table_t<std::decay_t<Arg>>::value || soa::is_soa_extension_table_v<std::decay_t<Arg>>) {
auto inputSources = getInputMetadata<std::decay_t<Arg>>();
inputMetadata.insert(inputMetadata.end(), inputSources.begin(), inputSources.end());
}
auto newInput = InputSpec{metadata::tableLabel(), metadata::origin(), metadata::description(), metadata::version(), Lifetime::Timeframe, inputMetadata};
DataSpecUtils::updateInputList(inputs, std::move(newInput));
}
template <typename... Args>
static void doAppendInputWithMetadata(framework::pack<Args...>, const char* name, bool value, std::vector<InputSpec>& inputs)
{
(doAppendInputWithMetadata<Args>(name, value, inputs), ...);
}
template <typename T, int AI>
static void appendSomethingWithMetadata(const char* name, bool value, std::vector<InputSpec>& inputs, std::vector<ExpressionInfo>& eInfos, size_t hash)
{
static_assert(std::is_lvalue_reference_v<T>, "Argument to process needs to be a reference (&).");
using dT = std::decay_t<T>;
if constexpr (soa::is_soa_filtered_t<dT>::value) {
eInfos.push_back({AI, hash, dT::hashes(), o2::soa::createSchemaFromColumns(typename dT::table_t::persistent_columns_t{}), nullptr});
} else if constexpr (soa::is_soa_iterator_t<dT>::value) {
if constexpr (std::is_same_v<typename dT::policy_t, soa::FilteredIndexPolicy>) {
eInfos.push_back({AI, hash, dT::parent_t::hashes(), o2::soa::createSchemaFromColumns(typename dT::table_t::persistent_columns_t{}), nullptr});
}
}
doAppendInputWithMetadata(soa::make_originals_from_type<dT>(), name, value, inputs);
}
template <typename R, typename C, typename... Args>
static void inputsFromArgs(R (C::*)(Args...), const char* name, bool value, std::vector<InputSpec>& inputs, std::vector<ExpressionInfo>& eInfos)
{
(appendSomethingWithMetadata<Args, o2::framework::has_type_at_v<Args>(pack<Args...>{})>(name, value, inputs, eInfos, typeHash<R (C::*)(Args...)>()), ...);
}
template <typename R, typename C, typename Grouping, typename... Args>
static auto signatures(InputRecord&, R (C::*)(Grouping, Args...))
{
return std::declval<std::tuple<Grouping, Args...>>();
}
template <typename R, typename C, typename Grouping, typename... Args>
static auto bindGroupingTable(InputRecord& record, R (C::*)(Grouping, Args...), std::vector<ExpressionInfo>& infos)
{
return extractSomethingFromRecord<Grouping, 0>(record, infos, typeHash<R (C::*)(Grouping, Args...)>());
}
template <typename R, typename C>
static auto bindGroupingTable(InputRecord&, R (C::*)(), std::vector<ExpressionInfo>&)
{
static_assert(always_static_assert_v<C>, "Your task process method needs at least one argument");
return o2::soa::Table<>{nullptr};
}
template <typename T>
static auto extractTableFromRecord(InputRecord& record)
{
if constexpr (soa::is_type_with_metadata_v<aod::MetadataTrait<T>>) {
auto table = record.get<TableConsumer>(aod::MetadataTrait<T>::metadata::tableLabel())->asArrowTable();
if (table->num_rows() == 0) {
table = makeEmptyTable<T>(aod::MetadataTrait<T>::metadata::tableLabel());
}
return table;
} else if constexpr (soa::is_type_with_originals_v<T>) {
return extractFromRecord<T>(record, typename T::originals{});
}
O2_BUILTIN_UNREACHABLE();
}
template <typename T, typename... Os>
static auto extractFromRecord(InputRecord& record, pack<Os...> const&)
{
if constexpr (soa::is_soa_iterator_t<T>::value) {
return typename T::parent_t{{extractTableFromRecord<Os>(record)...}};
} else {
return T{{extractTableFromRecord<Os>(record)...}};
}
}
template <typename T, typename... Os>
static auto extractFilteredFromRecord(InputRecord& record, ExpressionInfo& info, pack<Os...> const&)
{
auto table = o2::soa::ArrowHelpers::joinTables(std::vector<std::shared_ptr<arrow::Table>>{extractTableFromRecord<Os>(record)...});
if (info.tree != nullptr && info.filter == nullptr) {
info.filter = framework::expressions::createFilter(table->schema(), framework::expressions::makeCondition(info.tree));
}
if (info.tree != nullptr && info.filter != nullptr && info.resetSelection == true) {
info.selection = framework::expressions::createSelection(table, info.filter);
info.resetSelection = false;
}
if constexpr (!framework::is_base_of_template<soa::SmallGroups, std::decay_t<T>>::value) {
if (info.selection == nullptr) {
throw runtime_error_f("Null selection for %d (arg %d), missing Filter declaration?", info.processHash, info.argumentIndex);
}
}
if constexpr (soa::is_soa_iterator_t<T>::value) {
return typename T::parent_t({table}, info.selection);
} else {
return T({table}, info.selection);
}
}
template <typename T, int AI>
static auto extractSomethingFromRecord(InputRecord& record, std::vector<ExpressionInfo>& infos, size_t phash)
{
using decayed = std::decay_t<T>;
if constexpr (soa::is_soa_filtered_t<decayed>::value) {
return extractFilteredFromRecord<decayed>(record, *std::find_if(infos.begin(), infos.end(), [&phash](ExpressionInfo const& i) { return (i.processHash == phash && i.argumentIndex == AI); }), soa::make_originals_from_type<decayed>());
} else if constexpr (soa::is_soa_iterator_t<decayed>::value) {
if constexpr (std::is_same_v<typename decayed::policy_t, soa::FilteredIndexPolicy>) {
return extractFilteredFromRecord<decayed>(record, *std::find_if(infos.begin(), infos.end(), [&phash](ExpressionInfo const& i) { return (i.processHash == phash && i.argumentIndex == AI); }), soa::make_originals_from_type<decayed>());
} else {
return extractFromRecord<decayed>(record, soa::make_originals_from_type<decayed>());
}
} else {
return extractFromRecord<decayed>(record, soa::make_originals_from_type<decayed>());
}
O2_BUILTIN_UNREACHABLE();
}
template <typename R, typename C, typename Grouping, typename... Args>
static auto bindAssociatedTables(InputRecord& record, R (C::*)(Grouping, Args...), std::vector<ExpressionInfo>& infos)
{
return std::make_tuple(extractSomethingFromRecord<Args, has_type_at_v<Args>(pack<Args...>{}) + 1>(record, infos, typeHash<R (C::*)(Grouping, Args...)>())...);
}
template <typename R, typename C>
static auto bindAssociatedTables(InputRecord&, R (C::*)(), std::vector<ExpressionInfo>&)
{
static_assert(always_static_assert_v<C>, "Your task process method needs at least one argument");
return std::tuple<>{};
}
template <typename T, typename C>
using is_external_index_to_t = std::is_same<typename C::binding_t, T>;
template <typename Task, typename... T>
static void invokeProcessTuple(Task& task, InputRecord& inputs, std::tuple<T...> const& processTuple, std::vector<ExpressionInfo>& infos)
{
(invokeProcess<o2::framework::has_type_at_v<T>(pack<T...>{})>(task, inputs, std::get<T>(processTuple), infos), ...);
}
template <typename... As>
static void overwriteInternalIndices(std::tuple<As...>& dest, std::tuple<As...> const& src)
{
(std::get<As>(dest).bindInternalIndicesTo(&std::get<As>(src)), ...);
}
template <typename Task, typename R, typename C, typename Grouping, typename... Associated>
static void invokeProcess(Task& task, InputRecord& inputs, R (C::*processingFunction)(Grouping, Associated...), std::vector<ExpressionInfo>& infos)
{
using G = std::decay_t<Grouping>;
auto groupingTable = AnalysisDataProcessorBuilder::bindGroupingTable(inputs, processingFunction, infos);
auto presliceTable = [&task](auto& table) {
homogeneous_apply_refs([&table](auto& x) {
return PresliceManager<std::decay_t<decltype(x)>>::processTable(x, table);
},
task);
};
// pre-slice grouping table if required
presliceTable(groupingTable);
// set filtered tables for partitions with grouping
homogeneous_apply_refs([&groupingTable](auto& x) {
PartitionManager<std::decay_t<decltype(x)>>::setPartition(x, groupingTable);
PartitionManager<std::decay_t<decltype(x)>>::bindInternalIndices(x, &groupingTable);
return true;
},
task);
if constexpr (sizeof...(Associated) == 0) {
// single argument to process
homogeneous_apply_refs([&groupingTable](auto& x) {
PartitionManager<std::decay_t<decltype(x)>>::bindExternalIndices(x, &groupingTable);
GroupedCombinationManager<std::decay_t<decltype(x)>>::setGroupedCombination(x, groupingTable);
return true;
},
task);
if constexpr (soa::is_soa_iterator_t<G>::value) {
for (auto& element : groupingTable) {
std::invoke(processingFunction, task, *element);
}
} else {
static_assert(soa::is_soa_table_like_t<G>::value,
"Single argument of process() should be a table-like or an iterator");
std::invoke(processingFunction, task, groupingTable);
}
} else {
// multiple arguments to process
static_assert(((soa::is_soa_iterator_t<std::decay_t<Associated>>::value == false) && ...),
"Associated arguments of process() should not be iterators");
auto associatedTables = AnalysisDataProcessorBuilder::bindAssociatedTables(inputs, processingFunction, infos);
//pre-bind self indices
std::apply(
[&](auto&... t) {
(homogeneous_apply_refs(
[&](auto& p) {
PartitionManager<std::decay_t<decltype(p)>>::bindInternalIndices(p, &t);
return true;
},
task),
...);
},
associatedTables);
auto binder = [&](auto&& x) {
x.bindExternalIndices(&groupingTable, &std::get<std::decay_t<Associated>>(associatedTables)...);
homogeneous_apply_refs([&x](auto& t) {
PartitionManager<std::decay_t<decltype(t)>>::setPartition(t, x);
PartitionManager<std::decay_t<decltype(t)>>::bindExternalIndices(t, &x);
return true;
},
task);
};
groupingTable.bindExternalIndices(&std::get<std::decay_t<Associated>>(associatedTables)...);
// always pre-bind full tables to support index hierarchy
std::apply(
[&](auto&&... x) {
(binder(x), ...);
},
associatedTables);
// GroupedCombinations bound separately, as they should be set once for all associated tables
homogeneous_apply_refs([&groupingTable, &associatedTables](auto& t) {
GroupedCombinationManager<std::decay_t<decltype(t)>>::setGroupedCombination(t, groupingTable, associatedTables);
return true;
},
task);
if constexpr (soa::is_soa_iterator_t<std::decay_t<G>>::value) {
// grouping case
// pre-slice associated tables
std::apply([&presliceTable](auto&... x) {
(presliceTable(x), ...);
},
associatedTables);
auto slicer = GroupSlicer(groupingTable, associatedTables);
for (auto& slice : slicer) {
auto associatedSlices = slice.associatedTables();
overwriteInternalIndices(associatedSlices, associatedTables);
std::apply(
[&](auto&&... x) {
(binder(x), ...);
},
associatedSlices);
// bind partitions and grouping table
homogeneous_apply_refs([&groupingTable](auto& x) {
PartitionManager<std::decay_t<decltype(x)>>::bindExternalIndices(x, &groupingTable);
return true;
},
task);
invokeProcessWithArgsGeneric(task, processingFunction, slice.groupingElement(), associatedSlices);
}
} else {
// non-grouping case
// pre-slice associated tables
std::apply([&presliceTable](auto&... x) {
(presliceTable(x), ...);
},
associatedTables);
overwriteInternalIndices(associatedTables, associatedTables);
// bind partitions and grouping table
homogeneous_apply_refs([&groupingTable](auto& x) {
PartitionManager<std::decay_t<decltype(x)>>::bindExternalIndices(x, &groupingTable);
return true;
},
task);
invokeProcessWithArgsGeneric(task, processingFunction, groupingTable, associatedTables);
}
}
}
template <typename C, typename T, typename G, typename... A>
static void invokeProcessWithArgsGeneric(C& task, T processingFunction, G g, std::tuple<A...>& at)
{
std::invoke(processingFunction, task, g, std::get<A>(at)...);
}
template <typename T, typename G, typename... A>
static void invokeProcessWithArgs(T& task, G g, std::tuple<A...>& at)
{
task.process(g, std::get<A>(at)...);
}
};
namespace
{
template <typename T>
class has_process
{
template <typename C>
static std::true_type test(decltype(&C::process));
template <typename C>
static std::false_type test(...);
public:
static constexpr bool value = decltype(test<T>(nullptr))::value;
};
template <class T>
inline constexpr bool has_process_v = has_process<T>::value;
template <typename T>
class has_run
{
template <typename C>
static std::true_type test(decltype(&C::run));
template <typename C>
static std::false_type test(...);
public:
static constexpr bool value = decltype(test<T>(nullptr))::value;
};
template <class T>
inline constexpr bool has_run_v = has_run<T>::value;
template <typename T>
class has_init
{
template <typename C>
static std::true_type test(decltype(&C::init));
template <typename C>
static std::false_type test(...);
public:
static constexpr bool value = decltype(test<T>(nullptr))::value;
};
template <class T>
inline constexpr bool has_init_v = has_init<T>::value;
} // namespace
struct SetDefaultProcesses {
std::vector<std::pair<std::string, bool>> map;
};
/// Struct to differentiate task names from possible task string arguments
struct TaskName {
TaskName(std::string const& name) : value{name} {}
std::string value;
};
template <typename T, typename... A>
auto getTaskNameSetProcesses(TaskName first, SetDefaultProcesses second, A... args)
{
auto task = std::make_shared<T>(std::forward<A>(args)...);
for (auto& setting : second.map) {
homogeneous_apply_refs(
[&](auto& x) {
return UpdateProcessSwitches<std::decay_t<decltype(x)>>::set(setting, x);
},
*task.get());
}
return std::make_tuple(first.value, task);
}
template <typename T, typename... A>
auto getTaskNameSetProcesses(SetDefaultProcesses first, TaskName second, A... args)
{
auto task = std::make_shared<T>(std::forward<A>(args)...);
for (auto& setting : first.map) {
homogeneous_apply_refs(
[&](auto& x) {
return UpdateProcessSwitches<std::decay_t<decltype(x)>>::set(setting, x);
},
*task.get());
}
return std::make_tuple(second.value, task);
}
template <typename T, typename... A>
auto getTaskNameSetProcesses(SetDefaultProcesses first, A... args)
{
auto task = std::make_shared<T>(std::forward<A>(args)...);
for (auto& setting : first.map) {
homogeneous_apply_refs(
[&](auto& x) {
return UpdateProcessSwitches<std::decay_t<decltype(x)>>::set(setting, x);
},
*task.get());
}
auto type_name_str = type_name<T>();
std::string name = type_to_task_name(type_name_str);
return std::make_tuple(name, task);
}
template <typename T, typename... A>
auto getTaskNameSetProcesses(TaskName first, A... args)
{
auto task = std::make_shared<T>(std::forward<A>(args)...);
return std::make_tuple(first.value, task);
}
template <typename T, typename... A>
auto getTaskNameSetProcesses(A... args)
{
auto task = std::make_shared<T>(std::forward<A>(args)...);
auto type_name_str = type_name<T>();
std::string name = type_to_task_name(type_name_str);
return std::make_tuple(name, task);
}
template <typename T, typename... A>
auto getTaskName(TaskName first, A... args)
{
auto task = std::make_shared<T>(std::forward<A>(args)...);
return std::make_tuple(first.value, task);
}
template <typename T, typename... A>
auto getTaskName(A... args)
{
auto task = std::make_shared<T>(std::forward<A>(args)...);
auto type_name_str = type_name<T>();
std::string name = type_to_task_name(type_name_str);
return std::make_tuple(name, task);
}
/// Adaptor to make an AlgorithmSpec from a o2::framework::Task
///
template <typename T, typename... Args>
DataProcessorSpec adaptAnalysisTask(ConfigContext const& ctx, Args&&... args)
{
TH1::AddDirectory(false);
auto [name_str, task] = getTaskNameSetProcesses<T>(args...);
auto suffix = ctx.options().get<std::string>("workflow-suffix");
if (!suffix.empty()) {
name_str += suffix;
}
const char* name = name_str.c_str();
auto hash = compile_time_hash(name);
std::vector<OutputSpec> outputs;
std::vector<InputSpec> inputs;
std::vector<ConfigParamSpec> options;
std::vector<ExpressionInfo> expressionInfos;
/// make sure options and configurables are set before expression infos are created
homogeneous_apply_refs([&options, &hash](auto& x) { return OptionManager<std::decay_t<decltype(x)>>::appendOption(options, x); }, *task.get());
/// extract conditions and append them as inputs
homogeneous_apply_refs([&inputs](auto& x) { return ConditionManager<std::decay_t<decltype(x)>>::appendCondition(inputs, x); }, *task.get());
/// parse process functions defined by corresponding configurables
if constexpr (has_process_v<T>) {
AnalysisDataProcessorBuilder::inputsFromArgs(&T::process, "default", true, inputs, expressionInfos);
}
homogeneous_apply_refs(
[name = name_str, &expressionInfos, &inputs](auto& x) {
using D = std::decay_t<decltype(x)>;
if constexpr (is_base_of_template<ProcessConfigurable, D>::value) {
// this pushes (argumentIndex,processHash,schemaPtr,nullptr) into expressionInfos for arguments that are Filtered/filtered_iterators
AnalysisDataProcessorBuilder::inputsFromArgs(x.process, (name + "/" + x.name).c_str(), x.value, inputs, expressionInfos);
return true;
}
return false;
},
*task.get());
// request base tables for spawnable extended tables
// this checks for duplications
homogeneous_apply_refs([&inputs](auto& x) {
return SpawnManager<std::decay_t<decltype(x)>>::requestInputs(inputs, x);
},
*task.get());
//request base tables for indices to be built
homogeneous_apply_refs([&inputs](auto& x) {
return IndexManager<std::decay_t<decltype(x)>>::requestInputs(inputs, x);
},
*task.get());
// no static way to check if the task defines any processing, we can only make sure it subscribes to at least something
if (inputs.empty() == true) {
LOG(warn) << "Task " << name_str << " has no inputs";
}
homogeneous_apply_refs([&outputs, &hash](auto& x) { return OutputManager<std::decay_t<decltype(x)>>::appendOutput(outputs, x, hash); }, *task.get());
std::vector<ServiceSpec> requiredServices = CommonServices::defaultServices();
homogeneous_apply_refs([&requiredServices](auto& x) { return ServiceManager<std::decay_t<decltype(x)>>::add(requiredServices, x); }, *task.get());
auto algo = AlgorithmSpec::InitCallback{[task = task, expressionInfos](InitContext& ic) mutable {
homogeneous_apply_refs([&ic](auto&& x) { return OptionManager<std::decay_t<decltype(x)>>::prepare(ic, x); }, *task.get());
homogeneous_apply_refs([&ic](auto&& x) { return ServiceManager<std::decay_t<decltype(x)>>::prepare(ic, x); }, *task.get());
auto& callbacks = ic.services().get<CallbackService>();
auto endofdatacb = [task](EndOfStreamContext& eosContext) {
homogeneous_apply_refs([&eosContext](auto&& x) { return OutputManager<std::decay_t<decltype(x)>>::postRun(eosContext, x); }, *task.get());
eosContext.services().get<ControlService>().readyToQuit(QuitRequest::Me);
};
callbacks.set(CallbackService::Id::EndOfStream, endofdatacb);
/// update configurables in filters
homogeneous_apply_refs(
[&ic](auto& x) -> bool { return FilterManager<std::decay_t<decltype(x)>>::updatePlaceholders(x, ic); },
*task.get());
/// update configurables in partitions
homogeneous_apply_refs(
[&ic](auto& x) -> bool { PartitionManager<std::decay_t<decltype(x)>>::updatePlaceholders(x, ic); return true; },
*task.get());
/// create for filters gandiva trees matched to schemas and store the pointers into expressionInfos
homogeneous_apply_refs([&expressionInfos](auto& x) {
return FilterManager<std::decay_t<decltype(x)>>::createExpressionTrees(x, expressionInfos);
},
*task.get());
if constexpr (has_init_v<T>) {
task->init(ic);
}
return [task, expressionInfos](ProcessingContext& pc) mutable {
// load the ccdb object from their cache
homogeneous_apply_refs([&pc](auto&& x) { return ConditionManager<std::decay_t<decltype(x)>>::newDataframe(pc.inputs(), x); }, *task.get());
// reset partitions once per dataframe
homogeneous_apply_refs([](auto&& x) { return PartitionManager<std::decay_t<decltype(x)>>::newDataframe(x); }, *task.get());
// reset selections for the next dataframe
for (auto& info : expressionInfos) {
info.resetSelection = true;
}
// reset pre-slice for the next dataframe
homogeneous_apply_refs([](auto& x) { return PresliceManager<std::decay_t<decltype(x)>>::setNewDF(x); }, *(task.get()));
// prepare outputs
homogeneous_apply_refs([&pc](auto&& x) { return OutputManager<std::decay_t<decltype(x)>>::prepare(pc, x); }, *task.get());
// execute run()
if constexpr (has_run_v<T>) {
task->run(pc);
}
// execture process()
if constexpr (has_process_v<T>) {
AnalysisDataProcessorBuilder::invokeProcess(*(task.get()), pc.inputs(), &T::process, expressionInfos);
}
// execute optional process()
homogeneous_apply_refs(
[&pc, &expressionInfos, &task](auto& x) mutable {
if constexpr (is_base_of_template<ProcessConfigurable, std::decay_t<decltype(x)>>::value) {
if (x.value == true) {
AnalysisDataProcessorBuilder::invokeProcess(*task.get(), pc.inputs(), x.process, expressionInfos);
return true;
}
}
return false;
},
*task.get());
// finalize outputs
homogeneous_apply_refs([&pc](auto&& x) { return OutputManager<std::decay_t<decltype(x)>>::finalize(pc, x); }, *task.get());
};
}};
DataProcessorSpec spec{
name,
// FIXME: For the moment we hardcode this. We could build
// this list from the list of methods actually implemented in the
// task itself.
inputs,
outputs,
algo,
options,
requiredServices};
return spec;
}
} // namespace o2::framework
#endif // FRAMEWORK_ANALYSISTASK_H_