Project
Loading...
Searching...
No Matches
AnalysisHelpers.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#ifndef o2_framework_AnalysisHelpers_H_DEFINED
12#define o2_framework_AnalysisHelpers_H_DEFINED
13
14#include "Framework/ASoA.h"
17#include "Framework/InputSpec.h"
18#include "Framework/Output.h"
20#include "Framework/OutputRef.h"
22#include "Framework/Plugins.h"
25#include "Framework/Traits.h"
26
27#include <string>
28namespace o2::soa
29{
30template <TableRef R>
32{
34 std::string{"input:"} + o2::aod::label<R>(),
36 aod::sourceSpec<R>(),
37 {"\"\""}};
38}
39
40namespace
41{
42template <soa::with_sources T>
43inline constexpr auto getSources()
44{
45 return []<size_t N, std::array<soa::TableRef, N> refs>() {
46 return []<size_t... Is>(std::index_sequence<Is...>) {
47 return std::vector{soa::tableRef2ConfigParamSpec<refs[Is]>()...};
48 }(std::make_index_sequence<N>());
49 }.template operator()<T::sources.size(), T::sources>();
50}
51
52template <soa::with_sources T>
53constexpr auto getInputMetadata() -> std::vector<framework::ConfigParamSpec>
54{
55 std::vector<framework::ConfigParamSpec> inputMetadata;
56 auto inputSources = getSources<T>();
57 std::sort(inputSources.begin(), inputSources.end(), [](framework::ConfigParamSpec const& a, framework::ConfigParamSpec const& b) { return a.name < b.name; });
58 auto last = std::unique(inputSources.begin(), inputSources.end(), [](framework::ConfigParamSpec const& a, framework::ConfigParamSpec const& b) { return a.name == b.name; });
59 inputSources.erase(last, inputSources.end());
60 inputMetadata.insert(inputMetadata.end(), inputSources.begin(), inputSources.end());
61 return inputMetadata;
62}
63
64template <typename T>
65 requires(!soa::with_sources<T>)
66constexpr auto getInputMetadata() -> std::vector<framework::ConfigParamSpec>
67{
68 return {};
69}
70} // namespace
71
72template <TableRef R>
73constexpr auto tableRef2InputSpec()
74{
76 o2::aod::label<R>(),
77 o2::aod::origin<R>(),
78 o2::aod::description(o2::aod::signature<R>()),
79 R.version,
80 framework::Lifetime::Timeframe,
81 getInputMetadata<typename o2::aod::MetadataTrait<o2::aod::Hash<R.desc_hash>>::metadata>()};
82}
83
84template <TableRef R>
85constexpr auto tableRef2OutputSpec()
86{
88 framework::OutputLabel{o2::aod::label<R>()},
89 o2::aod::origin<R>(),
90 o2::aod::description(o2::aod::signature<R>()),
91 R.version};
92}
93
94template <TableRef R>
95constexpr auto tableRef2Output()
96{
97 return framework::Output{
98 o2::aod::origin<R>(),
99 o2::aod::description(o2::aod::signature<R>()),
100 R.version};
101}
102
103template <TableRef R>
104constexpr auto tableRef2OutputRef()
105{
107 o2::aod::label<R>(),
108 R.version};
109}
110} // namespace o2::soa
111
112namespace o2::framework
113{
114class TableConsumer;
115
119template <typename T>
121
122template <is_producable T>
124 public:
125 using persistent_table_t = decltype([]() { if constexpr (soa::is_iterator<T>) { return typename T::parent_t{nullptr}; } else { return T{nullptr}; } }());
126 using cursor_t = decltype(std::declval<TableBuilder>().cursor<persistent_table_t>());
127
128 template <typename... Ts>
129 void operator()(Ts... args)
130 {
131 static_assert(sizeof...(Ts) == framework::pack_size(typename persistent_table_t::persistent_columns_t{}), "Argument number mismatch");
132 ++mCount;
133 cursor(0, extract(args)...);
134 }
135
137 int64_t lastIndex()
138 {
139 return mCount;
140 }
141
143 {
144 mBuilder = std::move(builder);
145 cursor = std::move(FFL(mBuilder->cursor<persistent_table_t>()));
146 mCount = -1;
147 return true;
148 }
149
150 void setLabel(const char* label)
151 {
152 mBuilder->setLabel(label);
153 }
154
157 void reserve(int64_t size)
158 {
159 mBuilder->reserve(typename persistent_table_t::column_types{}, size);
160 }
161
162 void release()
163 {
164 mBuilder.release();
165 }
166
167 decltype(FFL(std::declval<cursor_t>())) cursor;
168
169 private:
170 template <typename A>
171 requires requires { &A::globalIndex; }
172 static decltype(auto) extract(A const& arg)
173 {
174 return arg.globalIndex();
175 }
176
177 template <typename A>
178 static decltype(auto) extract(A const& arg)
179 {
180 return arg;
181 }
182
186 LifetimeHolder<TableBuilder> mBuilder = nullptr;
187 int64_t mCount = -1;
188};
189
191template <soa::is_table T>
192consteval auto typeWithRef() -> T
193{
194}
195
196template <soa::is_iterator T>
197consteval auto typeWithRef() -> typename T::parent_t
198{
199}
200
201template <typename T>
202 requires soa::is_table<T> || soa::is_iterator<T>
204 using table_t = decltype(typeWithRef<T>());
205 using metadata = aod::MetadataTrait<o2::aod::Hash<table_t::ref.desc_hash>>::metadata;
206
207 static OutputSpec const spec()
208 {
209 return OutputSpec{OutputLabel{aod::label<table_t::ref>()}, o2::aod::origin<table_t::ref>(), o2::aod::description(o2::aod::signature<table_t::ref>()), table_t::ref.version};
210 }
211
212 static OutputRef ref()
213 {
214 return OutputRef{aod::label<table_t::ref>(), table_t::ref.version};
215 }
216};
217
222template <is_producable T>
224};
225
226template <typename T>
227concept is_produces = requires(T t) { typename T::cursor_t; typename T::persistent_table_t; &T::cursor; };
228
238};
239
240template <typename T>
241concept is_produces_group = std::derived_from<T, ProducesGroup>;
242
244template <soa::is_metadata M, soa::TableRef Ref>
246 using metadata = M;
247 constexpr static auto sources = M::sources;
248
249 template <soa::TableRef R>
250 static constexpr auto base_spec()
251 {
252 return soa::tableRef2InputSpec<R>();
253 }
254
255 static auto base_specs()
256 {
257 return []<size_t... Is>(std::index_sequence<Is...>) -> std::vector<InputSpec> {
258 return {base_spec<sources[Is]>()...};
259 }(std::make_index_sequence<sources.size()>{});
260 }
261
262 constexpr auto spec() const
263 {
264 return soa::tableRef2OutputSpec<Ref>();
265 }
266
267 constexpr auto output() const
268 {
269 return soa::tableRef2Output<Ref>();
270 }
271
272 constexpr auto ref() const
273 {
274 return soa::tableRef2OutputRef<Ref>();
275 }
276};
277
280template <typename T>
281concept is_spawnable = soa::has_metadata<aod::MetadataTrait<o2::aod::Hash<T::ref.desc_hash>>> && soa::has_extension<typename aod::MetadataTrait<o2::aod::Hash<T::ref.desc_hash>>::metadata>;
282
283template <typename T>
284concept is_dynamically_spawnable = soa::has_metadata<aod::MetadataTrait<o2::aod::Hash<T::ref.desc_hash>>> && soa::has_configurable_extension<typename aod::MetadataTrait<o2::aod::Hash<T::ref.desc_hash>>::metadata>;
285
286template <is_spawnable T>
287constexpr auto transformBase()
288{
289 using metadata = typename aod::MetadataTrait<o2::aod::Hash<T::ref.desc_hash>>::metadata;
291}
292
293template <is_spawnable T>
294struct Spawns : decltype(transformBase<T>()) {
295 using spawnable_t = T;
296 using metadata = decltype(transformBase<T>())::metadata;
297 using extension_t = typename metadata::extension_table_t;
298 using base_table_t = typename metadata::base_table_t;
299 using expression_pack_t = typename metadata::expression_pack_t;
300 static constexpr size_t N = framework::pack_size(expression_pack_t{});
301
302 constexpr auto pack()
303 {
304 return expression_pack_t{};
305 }
306
307 typename T::table_t* operator->()
308 {
309 return table.get();
310 }
311 typename T::table_t const& operator*() const
312 {
313 return *table;
314 }
315
317 {
318 return extension->asArrowTable();
319 }
320 std::shared_ptr<typename T::table_t> table = nullptr;
321 std::shared_ptr<extension_t> extension = nullptr;
322 std::array<o2::framework::expressions::Projector, N> projectors = []<typename... C>(framework::pack<C...>) -> std::array<expressions::Projector, sizeof...(C)>
323 {
324 return {{std::move(C::Projector())...}};
325 }
327 std::shared_ptr<gandiva::Projector> projector = nullptr;
328 std::shared_ptr<arrow::Schema> schema = std::make_shared<arrow::Schema>(o2::soa::createFieldsFromColumns(expression_pack_t{}));
329};
330
331template <typename T>
332concept is_spawns = requires(T t) {
333 typename T::metadata;
334 requires std::same_as<decltype(t.pack()), typename T::expression_pack_t>;
335 requires std::same_as<decltype(t.projector), std::shared_ptr<gandiva::Projector>>;
336};
337
342
343template <is_dynamically_spawnable T>
344struct Defines : decltype(transformBase<T>()) {
345 using spawnable_t = T;
346 using metadata = decltype(transformBase<T>())::metadata;
347 using extension_t = typename metadata::extension_table_t;
348 using base_table_t = typename metadata::base_table_t;
349 using placeholders_pack_t = typename metadata::placeholders_pack_t;
350 static constexpr size_t N = framework::pack_size(placeholders_pack_t{});
351
352 constexpr auto pack()
353 {
354 return placeholders_pack_t{};
355 }
356
357 typename T::table_t* operator->()
358 {
359 return table.get();
360 }
361 typename T::table_t const& operator*() const
362 {
363 return *table;
364 }
365
367 {
368 return extension->asArrowTable();
369 }
370 std::shared_ptr<typename T::table_t> table = nullptr;
371 std::shared_ptr<extension_t> extension = nullptr;
372
373 std::array<o2::framework::expressions::Projector, N> projectors;
374 std::shared_ptr<gandiva::Projector> projector = nullptr;
375 std::shared_ptr<arrow::Schema> schema = std::make_shared<arrow::Schema>(o2::soa::createFieldsFromColumns(placeholders_pack_t{}));
376};
377
378template <typename T>
379concept is_defines = requires(T t) {
380 typename T::metadata;
381 requires std::same_as<decltype(t.pack()), typename T::placeholders_pack_t>;
382 requires std::same_as<decltype(t.projector), std::shared_ptr<gandiva::Projector>>;
383};
384
389struct Exclusive {
390};
391struct Sparse {
392};
393
394namespace
395{
396template <typename T, typename Key>
397inline std::shared_ptr<arrow::ChunkedArray> getIndexToKey(arrow::Table* table)
398{
399 using IC = framework::pack_element_t<framework::has_type_at_conditional_v<soa::is_binding_compatible, Key>(typename T::external_index_columns_t{}), typename T::external_index_columns_t>;
400 return table->column(framework::has_type_at_v<IC>(typename T::persistent_columns_t{}));
401}
402
403template <soa::is_column C>
404struct ColumnTrait {
405 using column_t = C;
406
407 static consteval auto listSize()
408 {
409 if constexpr (std::same_as<typename C::type, std::vector<int>>) {
410 return -1;
411 } else if constexpr (std::same_as<int[2], typename C::type>) {
412 return 2;
413 } else {
414 return 1;
415 }
416 }
417
418 template <typename T, typename Key>
419 static std::shared_ptr<SelfIndexColumnBuilder> makeColumnBuilder(arrow::Table* table, arrow::MemoryPool* pool)
420 {
421 if constexpr (!std::same_as<T, Key>) {
422 return std::make_shared<IndexColumnBuilder>(getIndexToKey<T, Key>(table), C::columnLabel(), listSize(), pool);
423 } else {
424 return std::make_shared<SelfIndexColumnBuilder>(C::columnLabel(), pool);
425 }
426 }
427};
428
429template <typename Key, typename C>
430struct Reduction {
431 using type = typename std::conditional<soa::is_binding_compatible_v<Key, typename C::binding_t>(), SelfIndexColumnBuilder, IndexColumnBuilder>::type;
432};
433
434template <typename Key, typename C>
435using reduced_t = Reduction<Key, C>::type;
436} // namespace
437
438template <typename Kind>
440 template <typename Key, size_t N, std::array<soa::TableRef, N> refs, typename C1, typename... Cs>
441 static auto indexBuilder(const char* label, std::vector<std::shared_ptr<arrow::Table>>&& tables, framework::pack<C1, Cs...>)
442 {
443 auto pool = arrow::default_memory_pool();
444 SelfIndexColumnBuilder self{C1::columnLabel(), pool};
445 std::unique_ptr<ChunkedArrayIterator> keyIndex = nullptr;
446 if constexpr (!Key::template hasOriginal<refs[0]>()) {
447 keyIndex = std::make_unique<ChunkedArrayIterator>(tables[0]->column(o2::aod::MetadataTrait<o2::aod::Hash<refs[0].desc_hash>>::metadata::template getIndexPosToKey<Key>()));
448 }
449
450 auto sq = std::make_index_sequence<sizeof...(Cs)>();
451
452 auto columnBuilders = [&tables, &pool ]<size_t... Is>(std::index_sequence<Is...>) -> std::array<std::shared_ptr<framework::SelfIndexColumnBuilder>, sizeof...(Cs)>
453 {
454 return {[](arrow::Table* table, arrow::MemoryPool* pool) {
455 using T = framework::pack_element_t<Is, framework::pack<Cs...>>;
456 if constexpr (!Key::template hasOriginal<refs[Is + 1]>()) {
457 constexpr auto pos = o2::aod::MetadataTrait<o2::aod::Hash<refs[Is + 1].desc_hash>>::metadata::template getIndexPosToKey<Key>();
458 return std::make_shared<IndexColumnBuilder>(table->column(pos), T::columnLabel(), ColumnTrait<T>::listSize(), pool);
459 } else {
460 return std::make_shared<SelfIndexColumnBuilder>(T::columnLabel(), pool);
461 }
462 }(tables[Is + 1].get(), pool)...};
463 }
464 (sq);
465
466 std::array<bool, sizeof...(Cs)> finds;
467
468 for (int64_t counter = 0; counter < tables[0]->num_rows(); ++counter) {
469 int64_t idx = -1;
470 if constexpr (Key::template hasOriginal<refs[0]>()) {
471 idx = counter;
472 } else {
473 idx = keyIndex->valueAt(counter);
474 }
475 finds = [&idx, &columnBuilders]<size_t... Is>(std::index_sequence<Is...>) {
476 return std::array{
477 [&idx, &columnBuilders]() {
478 using T = typename framework::pack_element_t<Is, framework::pack<Cs...>>;
479 return std::static_pointer_cast<reduced_t<Key, T>>(columnBuilders[Is])->template find<T>(idx);
480 }()...};
481 }(sq);
482 if constexpr (std::same_as<Kind, Sparse>) {
483 [&idx, &columnBuilders]<size_t... Is>(std::index_sequence<Is...>) {
484 ([&idx, &columnBuilders]() {
485 using T = typename framework::pack_element_t<Is, framework::pack<Cs...>>;
486 return std::static_pointer_cast<reduced_t<Key, T>>(columnBuilders[Is])->template fill<T>(idx); }(), ...);
487 }(sq);
488 self.fill<C1>(counter);
489 } else if constexpr (std::same_as<Kind, Exclusive>) {
490 if (std::none_of(finds.begin(), finds.end(), [](bool const x) { return x == false; })) {
491 [&idx, &columnBuilders]<size_t... Is>(std::index_sequence<Is...>) {
492 ([&idx, &columnBuilders]() {
493 using T = typename framework::pack_element_t<Is, framework::pack<Cs...>>;
494 return std::static_pointer_cast<reduced_t<Key, T>>(columnBuilders[Is])->template fill<T>(idx);
495 }(),
496 ...);
497 }(sq);
498 self.fill<C1>(counter);
499 }
500 }
501 }
502
503 return [&label, &columnBuilders, &self]<size_t... Is>(std::index_sequence<Is...>) {
504 return makeArrowTable(label,
505 {self.template result<C1>(), [&columnBuilders]() {
506 using T = typename framework::pack_element_t<Is, framework::pack<Cs...>>;
507 return std::static_pointer_cast<reduced_t<Key, T>>(columnBuilders[Is])->template result<T>();
508 }()...},
509 {self.field(), [&columnBuilders]() {
510 using T = typename framework::pack_element_t<Is, framework::pack<Cs...>>;
511 return std::static_pointer_cast<reduced_t<Key, T>>(columnBuilders[Is])->field();
512 }()...});
513 }(sq);
514 }
515};
516
518
519template <soa::is_index_table T>
520constexpr auto transformBase()
521{
522 using metadata = typename aod::MetadataTrait<o2::aod::Hash<T::ref.desc_hash>>::metadata;
524}
525
526template <soa::is_index_table T>
527struct Builds : decltype(transformBase<T>()) {
528 using buildable_t = T;
529 using metadata = decltype(transformBase<T>())::metadata;
530 using IP = std::conditional_t<metadata::exclusive, IndexBuilder<Exclusive>, IndexBuilder<Sparse>>;
531 using Key = metadata::Key;
532 using H = typename T::first_t;
533 using Ts = typename T::rest_t;
534 using index_pack_t = metadata::index_pack_t;
535
537 {
538 return table.get();
539 }
540 T const& operator*() const
541 {
542 return *table;
543 }
544
546 {
547 return table->asArrowTable();
548 }
549 std::shared_ptr<T> table = nullptr;
550
551 constexpr auto pack()
552 {
553 return index_pack_t{};
554 }
555
556 template <typename Key, typename... Cs>
557 auto build(framework::pack<Cs...>, std::vector<std::shared_ptr<arrow::Table>>&& tables)
558 {
559 this->table = std::make_shared<T>(IP::template indexBuilder<Key, metadata::sources.size(), metadata::sources>(o2::aod::label<T::ref>(), std::forward<std::vector<std::shared_ptr<arrow::Table>>>(tables), framework::pack<Cs...>{}));
560 return (this->table != nullptr);
561 }
562};
563
564template <typename T>
565concept is_builds = requires(T t) {
566 typename T::metadata;
567 typename T::Key;
568 requires std::same_as<decltype(t.pack()), typename T::index_pack_t>;
569};
570
578template <typename T>
579struct OutputObj {
580 using obj_t = T;
581
583 : object(std::make_shared<T>(t)),
584 label(t.GetName()),
585 policy{policy_},
586 sourceType{sourceType_},
587 mTaskHash{0}
588 {
589 }
590
592 : object(nullptr),
593 label(label_),
594 policy{policy_},
595 sourceType{sourceType_},
596 mTaskHash{0}
597 {
598 }
599
600 void setObject(T const& t)
601 {
602 object = std::make_shared<T>(t);
603 object->SetName(label.c_str());
604 }
605
606 void setObject(T&& t)
607 {
608 object = std::make_shared<T>(t);
609 object->SetName(label.c_str());
610 }
611
612 void setObject(T* t)
613 {
614 object.reset(t);
615 object->SetName(label.c_str());
616 }
617
618 void setObject(std::shared_ptr<T> t)
619 {
620 object = t;
621 object->SetName(label.c_str());
622 }
623
624 void setHash(uint32_t hash)
625 {
626 mTaskHash = hash;
627 }
628
631 {
633 auto lhash = runtime_hash(label.c_str());
634 std::memset(desc.str, '_', 16);
635 std::stringstream s;
636 s << std::hex << lhash;
637 s << std::hex << mTaskHash;
638 s << std::hex << reinterpret_cast<uint64_t>(this);
639 std::memcpy(desc.str, s.str().c_str(), 12);
640 return OutputSpec{OutputLabel{label}, "ATSK", desc, 0, Lifetime::QA};
641 }
642
644 {
645 return object.get();
646 }
647
649 {
650 return *object.get();
651 }
652
653 OutputRef ref(uint16_t index, uint16_t max)
654 {
655 return OutputRef{std::string{label}, 0,
657 }
658
659 std::shared_ptr<T> object;
660 std::string label;
663 uint32_t mTaskHash;
664};
665
666template <typename T>
667concept is_outputobj = requires(T t) {
668 &T::setHash;
669 &T::spec;
670 &T::ref;
671 requires std::same_as<decltype(t.operator->()), typename T::obj_t*>;
672 requires std::same_as<decltype(t.object), std::shared_ptr<typename T::obj_t>>;
673};
674
678template <typename T>
679struct Service {
680 using service_t = T;
682
683 decltype(auto) operator->() const
684 {
686 return service->get();
687 } else {
688 return service;
689 }
690 }
691};
692
693template <typename T>
694concept is_service = requires(T t) {
695 requires std::same_as<decltype(t.service), typename T::service_t*>;
696 &T::operator->;
697};
698
700{
701 return std::make_unique<o2::soa::Filtered<std::decay_t<decltype(table)>>>(std::vector{table}, std::forward<soa::SelectionVector>(selection));
702}
703
705{
706 return std::make_unique<o2::soa::Filtered<std::decay_t<decltype(table)>>>(std::vector{table.asArrowTable()}, std::forward<soa::SelectionVector>(selection));
707}
708
709void initializePartitionCaches(std::set<uint32_t> const& hashes, std::shared_ptr<arrow::Schema> const& schema, expressions::Filter const& filter, gandiva::NodePtr& tree, gandiva::FilterPtr& gfilter);
710
711template <typename T>
712struct Partition {
713 using content_t = T;
714 Partition(expressions::Node&& filter_) : filter{std::forward<expressions::Node>(filter_)}
715 {
716 }
717
718 Partition(expressions::Node&& filter_, T const& table)
719 : filter{std::forward<expressions::Node>(filter_)}
720 {
721 setTable(table);
722 }
723
724 void intializeCaches(std::set<uint32_t> const& hashes, std::shared_ptr<arrow::Schema> const& schema)
725 {
726 initializePartitionCaches(hashes, schema, filter, tree, gfilter);
727 }
728
729 void bindTable(T const& table)
730 {
731 intializeCaches(T::table_t::hashes(), table.asArrowTable()->schema());
732 if (dataframeChanged) {
734 dataframeChanged = false;
735 }
736 }
737
738 template <typename... Ts>
739 void bindExternalIndices(Ts*... tables)
740 {
741 if (mFiltered != nullptr) {
742 mFiltered->bindExternalIndices(tables...);
743 }
744 }
745
746 template <typename E>
748 {
749 if (mFiltered != nullptr) {
750 mFiltered->bindInternalIndicesTo(ptr);
751 }
752 }
753
755 {
757 }
758
759 [[nodiscard]] std::shared_ptr<arrow::Table> asArrowTable() const
760 {
761 return mFiltered->asArrowTable();
762 }
763
765 {
766 return mFiltered.get();
767 }
768
769 template <typename T1>
770 [[nodiscard]] auto rawSliceBy(o2::framework::Preslice<T1> const& container, int value) const
771 {
772 return mFiltered->rawSliceBy(container, value);
773 }
774
775 [[nodiscard]] auto sliceByCached(framework::expressions::BindingNode const& node, int value, o2::framework::SliceCache& cache) const
776 {
777 return mFiltered->sliceByCached(node, value, cache);
778 }
779
781 {
782 return mFiltered->sliceByCachedUnsorted(node, value, cache);
783 }
784
785 template <typename T1, typename Policy, bool OPT>
786 [[nodiscard]] auto sliceBy(o2::framework::PresliceBase<T1, Policy, OPT> const& container, int value) const
787 {
788 return mFiltered->sliceBy(container, value);
789 }
790
792 std::unique_ptr<o2::soa::Filtered<T>> mFiltered = nullptr;
793 gandiva::NodePtr tree = nullptr;
795 bool dataframeChanged = true;
796
802 {
803 return mFiltered->begin();
804 }
806 {
807 return mFiltered->end();
808 }
810 {
811 return mFiltered->begin();
812 }
814 {
815 return mFiltered->end();
816 }
817
818 int64_t size() const
819 {
820 return mFiltered->size();
821 }
822};
823
824template <typename T>
825concept is_partition = requires(T t) {
826 &T::updatePlaceholders;
827 requires std::same_as<decltype(t.filter), expressions::Filter>;
828 requires std::same_as<decltype(t.mFiltered), std::unique_ptr<o2::soa::Filtered<typename T::content_t>>>;
829};
830} // namespace o2::framework
831
832namespace o2::soa
833{
835template <soa::is_table T, soa::is_spawnable_column... Cs>
836auto Extend(T const& table)
837{
838 using output_t = Join<T, soa::Table<o2::aod::Hash<"JOIN"_h>, o2::aod::Hash<"JOIN/0"_h>, o2::aod::Hash<"JOIN"_h>, Cs...>>;
839 static std::array<framework::expressions::Projector, sizeof...(Cs)> projectors{{std::move(Cs::Projector())...}};
840 static std::shared_ptr<gandiva::Projector> projector = nullptr;
841 static auto schema = std::make_shared<arrow::Schema>(o2::soa::createFieldsFromColumns(framework::pack<Cs...>{}));
842 return output_t{{o2::framework::spawner(framework::pack<Cs...>{}, {table.asArrowTable()}, "dynamicExtension", projectors.data(), projector, schema), table.asArrowTable()}, 0};
843}
844
847template <soa::is_table T, soa::is_dynamic_column... Cs>
848auto Attach(T const& table)
849{
850 using output_t = Join<T, o2::soa::Table<o2::aod::Hash<"JOIN"_h>, o2::aod::Hash<"JOIN/0"_h>, o2::aod::Hash<"JOIN"_h>, Cs...>>;
851 return output_t{{table.asArrowTable()}, table.offset()};
852}
853} // namespace o2::soa
854
855#endif // o2_framework_AnalysisHelpers_H_DEFINED
uint16_t pos
Definition RawData.h:3
uint32_t gfilter
Definition RawData.h:6
constexpr uint32_t runtime_hash(char const *str)
TBranch * ptr
Definition A.h:16
iterator const_iterator
Definition ASoA.h:3624
T::template iterator_template_o< FilteredIndexPolicy, self_t > iterator
Definition ASoA.h:3622
Helper to check if a type T is an iterator.
Definition ASoA.h:1254
GLint GLenum GLint x
Definition glcorearb.h:403
GLuint64EXT * result
Definition glcorearb.h:5662
GLsizeiptr size
Definition glcorearb.h:659
GLuint index
Definition glcorearb.h:781
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLsizei const GLfloat * value
Definition glcorearb.h:819
GLint GLint GLsizei GLint GLenum GLenum type
Definition glcorearb.h:275
GLuint GLsizei const GLchar * label
Definition glcorearb.h:2519
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition glcorearb.h:1308
GLuint object
Definition glcorearb.h:4041
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233
GLsizei GLenum * sources
Definition glcorearb.h:2516
GLuint counter
Definition glcorearb.h:3987
std::shared_ptr< gandiva::Filter > FilterPtr
Definition Expressions.h:47
std::variant< OriginValueMatcher, DescriptionValueMatcher, SubSpecificationTypeValueMatcher, std::unique_ptr< DataDescriptorMatcher >, ConstantValueMatcher, StartTimeValueMatcher > Node
gandiva::Selection createSelection(std::shared_ptr< arrow::Table > const &table, Filter const &expression)
Function for creating gandiva selection from our internal filter tree.
void updatePlaceholders(Filter &filter, InitContext &context)
Update placeholder nodes from context.
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
auto spawner(std::shared_ptr< arrow::Table > const &fullTable, const char *name, o2::framework::expressions::Projector *projectors, std::shared_ptr< gandiva::Projector > &projector, std::shared_ptr< arrow::Schema > const &schema)
Expression-based column generator to materialize columns.
typename pack_element< I, T >::type pack_element_t
Definition Pack.h:56
constexpr std::size_t pack_size(pack< Ts... > const &)
template function to determine number of types in a pack
Definition Pack.h:28
constexpr auto transformBase()
This helper struct allows you to declare index tables to be created in a task.
memfun_type< decltype(&F::operator())>::type FFL(F const &func)
auto getTableFromFilter(soa::is_filtered_table auto const &table, soa::SelectionVector &&selection)
consteval auto typeWithRef() -> T
Helper to define output for a Table.
OutputObjHandlingPolicy
Policy enum to determine OutputObj handling when writing.
void initializePartitionCaches(std::set< uint32_t > const &hashes, std::shared_ptr< arrow::Schema > const &schema, expressions::Filter const &filter, gandiva::NodePtr &tree, gandiva::FilterPtr &gfilter)
std::shared_ptr< arrow::Table > makeArrowTable(const char *label, std::vector< std::shared_ptr< arrow::ChunkedArray > > &&columns, std::vector< std::shared_ptr< arrow::Field > > &&fields)
auto createFieldsFromColumns(framework::pack< C... >)
Definition ASoA.h:406
SelectionVector selectionToVector(gandiva::Selection const &sel)
Definition ASoA.cxx:43
constexpr auto tableRef2InputSpec()
constexpr auto tableRef2Output()
std::vector< int64_t > SelectionVector
Definition ASoA.h:411
auto Attach(T const &table)
constexpr auto tableRef2ConfigParamSpec()
auto Extend(T const &table)
On-the-fly adding of expression columns.
constexpr auto tableRef2OutputSpec()
constexpr auto tableRef2OutputRef()
@ C
Definition Defs.h:36
Defining DataPointCompositeObject explicitly as copiable.
std::shared_ptr< T > table
constexpr auto pack()
typename T::first_t H
T const & operator*() const
auto build(framework::pack< Cs... >, std::vector< std::shared_ptr< arrow::Table > > &&tables)
metadata::index_pack_t index_pack_t
typename T::rest_t Ts
decltype(transformBase< T >())::metadata metadata
std::array< o2::framework::expressions::Projector, N > projectors
std::shared_ptr< extension_t > extension
typename metadata::extension_table_t extension_t
T::table_t const & operator*() const
std::shared_ptr< arrow::Schema > schema
typename metadata::placeholders_pack_t placeholders_pack_t
static constexpr size_t N
std::shared_ptr< gandiva::Projector > projector
typename metadata::base_table_t base_table_t
std::shared_ptr< typename T::table_t > table
decltype(transformBase< T >())::metadata metadata
static auto indexBuilder(const char *label, std::vector< std::shared_ptr< arrow::Table > > &&tables, framework::pack< C1, Cs... >)
static OutputSpec const spec()
aod::MetadataTrait< o2::aod::Hash< table_t::ref.desc_hash > >::metadata metadata
decltype(typeWithRef< T >()) table_t
O2 header for OutputObj metadata.
OutputObj(T &&t, OutputObjHandlingPolicy policy_=OutputObjHandlingPolicy::AnalysisObject, OutputObjSourceType sourceType_=OutputObjSourceType::OutputObjSource)
void setObject(std::shared_ptr< T > t)
OutputObjSourceType sourceType
OutputRef ref(uint16_t index, uint16_t max)
std::shared_ptr< T > object
OutputObj(std::string const &label_, OutputObjHandlingPolicy policy_=OutputObjHandlingPolicy::AnalysisObject, OutputObjSourceType sourceType_=OutputObjSourceType::OutputObjSource)
OutputSpec const spec()
OutputObjHandlingPolicy policy
void setHash(uint32_t hash)
Partition(expressions::Node &&filter_, T const &table)
typename o2::soa::Filtered< T >::const_iterator filtered_const_iterator
void bindTable(T const &table)
filtered_const_iterator begin() const
auto rawSliceBy(o2::framework::Preslice< T1 > const &container, int value) const
auto sliceByCached(framework::expressions::BindingNode const &node, int value, o2::framework::SliceCache &cache) const
void intializeCaches(std::set< uint32_t > const &hashes, std::shared_ptr< arrow::Schema > const &schema)
Partition(expressions::Node &&filter_)
typename o2::soa::Filtered< T >::iterator filtered_iterator
o2::soa::Filtered< T > * operator->()
typename o2::soa::Filtered< T >::iterator iterator
auto sliceBy(o2::framework::PresliceBase< T1, Policy, OPT > const &container, int value) const
std::shared_ptr< arrow::Table > asArrowTable() const
o2::soa::RowViewSentinel end() const
void updatePlaceholders(InitContext &context)
std::unique_ptr< o2::soa::Filtered< T > > mFiltered
expressions::Filter filter
o2::soa::RowViewSentinel end()
auto sliceByCachedUnsorted(framework::expressions::BindingNode const &node, int value, o2::framework::SliceCache &cache) const
typename o2::soa::Filtered< T >::const_iterator const_iterator
gandiva::FilterPtr gfilter
void bindExternalIndices(Ts *... tables)
filtered_iterator begin()
T::table_t * operator->()
std::shared_ptr< gandiva::Projector > projector
std::shared_ptr< extension_t > extension
T::table_t const & operator*() const
static constexpr size_t N
typename metadata::base_table_t base_table_t
std::shared_ptr< arrow::Schema > schema
typename metadata::expression_pack_t expression_pack_t
constexpr auto pack()
std::array< o2::framework::expressions::Projector, N > projectors
decltype(transformBase< T >())::metadata metadata
std::shared_ptr< typename T::table_t > table
typename metadata::extension_table_t extension_t
Helper template for table transformations.
constexpr auto spec() const
constexpr auto output() const
static constexpr auto base_spec()
constexpr auto ref() const
int64_t lastIndex()
Last index inserted in the table.
decltype(FFL(std::declval< cursor_t >())) cursor
bool resetCursor(LifetimeHolder< TableBuilder > builder)
void setLabel(const char *label)
decltype([]() { if constexpr(soa::is_iterator< T >) { return typename T::parent_t{nullptr} persistent_table_t
decltype(std::declval< TableBuilder >().cursor< persistent_table_t >()) cursor_t
An expression tree node corresponding to a column binding.
A struct, containing the root of the expression tree.
a move-only header stack with serialized headers This is the flat buffer where all the headers in a m...
Definition Stack.h:36
constexpr size_t max
std::unique_ptr< TTree > tree((TTree *) flIn.Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()))