Project
Loading...
Searching...
No Matches
ASoA.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 O2_FRAMEWORK_ASOA_H_
13#define O2_FRAMEWORK_ASOA_H_
14
16#include "Framework/Pack.h" // IWYU pragma: export
17#include "Framework/FunctionalHelpers.h" // IWYU pragma: export
18#include "Headers/DataHeader.h" // IWYU pragma: export
19#include "Headers/DataHeaderHelpers.h" // IWYU pragma: export
20#include "Framework/CompilerBuiltins.h" // IWYU pragma: export
21#include "Framework/Traits.h" // IWYU pragma: export
22#include "Framework/Expressions.h" // IWYU pragma: export
23#include "Framework/ArrowTypes.h" // IWYU pragma: export
24#include "Framework/ArrowTableSlicingCache.h" // IWYU pragma: export
25#include "Framework/SliceCache.h" // IWYU pragma: export
26#include "Framework/VariantHelpers.h" // IWYU pragma: export
27#include <arrow/array/array_binary.h>
28#include <arrow/table.h> // IWYU pragma: export
29#include <arrow/array.h> // IWYU pragma: export
30#include <arrow/util/config.h> // IWYU pragma: export
31#include <gandiva/selection_vector.h> // IWYU pragma: export
32#include <array> // IWYU pragma: export
33#include <cassert>
34#include <fmt/format.h>
35#include <concepts>
36#include <cstring>
37#include <gsl/span> // IWYU pragma: export
38
39namespace o2::framework
40{
41using ListVector = std::vector<std::vector<int64_t>>;
42
43std::string cutString(std::string&& str);
44std::string strToUpper(std::string&& str);
45} // namespace o2::framework
46
47struct TClass;
48
49namespace o2::soa
50{
51void accessingInvalidIndexFor(const char* getter);
52void dereferenceWithWrongType(const char* getter, const char* target);
53void missingFilterDeclaration(int hash, int ai);
54void notBoundTable(const char* tableName);
55void* extractCCDBPayload(char* payload, size_t size, TClass const* cl, const char* what);
56
57template <typename... C>
59{
60 return std::vector<std::shared_ptr<arrow::Field>>{C::asArrowField()...};
61}
62} // namespace o2::soa
63
64namespace o2::soa
65{
67struct TableRef {
68 consteval TableRef()
69 : label_hash{0},
70 desc_hash{0},
71 origin_hash{0},
72 version{0}
73 {
74 }
75 consteval TableRef(uint32_t _label, uint32_t _desc, uint32_t _origin, uint32_t _version)
76 : label_hash{_label},
77 desc_hash{_desc},
78 origin_hash{_origin},
79 version{_version}
80 {
81 }
82 uint32_t label_hash;
83 uint32_t desc_hash;
84 uint32_t origin_hash;
85 uint32_t version;
86
87 constexpr bool operator==(TableRef const& other) const noexcept
88 {
89 return (this->label_hash == other.label_hash) &&
90 (this->desc_hash == other.desc_hash) &&
91 (this->origin_hash == other.origin_hash) &&
92 (this->version == other.version);
93 }
94
95 constexpr bool descriptionCompatible(TableRef const& other) const noexcept
96 {
97 return this->desc_hash == other.desc_hash;
98 }
99
100 constexpr bool descriptionCompatible(uint32_t _desc_hash) const noexcept
101 {
102 return this->desc_hash == _desc_hash;
103 }
104
105 constexpr TableRef(TableRef const&) = default;
106 constexpr TableRef& operator=(TableRef const&) = default;
107 constexpr TableRef(TableRef&&) = default;
108 constexpr TableRef& operator=(TableRef&&) = default;
109};
110
112template <size_t N1, size_t N2, std::array<TableRef, N1> ar1, std::array<TableRef, N2> ar2>
113consteval auto merge()
114{
115 constexpr const int duplicates = std::ranges::count_if(ar2.begin(), ar2.end(), [&](TableRef const& a) { return std::any_of(ar1.begin(), ar1.end(), [&](TableRef const& e) { return e == a; }); });
116 std::array<TableRef, N1 + N2 - duplicates> out;
117
118 auto pos = std::copy(ar1.begin(), ar1.end(), out.begin());
119 std::copy_if(ar2.begin(), ar2.end(), pos, [&](TableRef const& a) { return std::none_of(ar1.begin(), ar1.end(), [&](TableRef const& e) { return e == a; }); });
120 return out;
121}
122
123template <size_t N1, size_t N2, std::array<TableRef, N1> ar1, std::array<TableRef, N2> ar2, typename L>
124consteval auto merge_if(L l)
125{
126 constexpr const int to_remove = std::ranges::count_if(ar1.begin(), ar1.end(), [&](TableRef const& a) { return !l(a); });
127 constexpr const int duplicates = std::ranges::count_if(ar2.begin(), ar2.end(), [&](TableRef const& a) { return std::any_of(ar1.begin(), ar1.end(), [&](TableRef const& e) { return e == a; }) || !l(a); });
128 std::array<TableRef, N1 + N2 - duplicates - to_remove> out;
129
130 auto pos = std::copy_if(ar1.begin(), ar1.end(), out.begin(), [&](TableRef const& a) { return l(a); });
131 std::copy_if(ar2.begin(), ar2.end(), pos, [&](TableRef const& a) { return std::none_of(ar1.begin(), ar1.end(), [&](TableRef const& e) { return e == a; }) && l(a); });
132 return out;
133}
134
135template <size_t N, std::array<TableRef, N> ar, typename L>
136consteval auto remove_if(L l)
137{
138 constexpr const int to_remove = std::ranges::count_if(ar.begin(), ar.end(), [&l](TableRef const& e) { return l(e); });
139 std::array<TableRef, N - to_remove> out;
140 std::copy_if(ar.begin(), ar.end(), out.begin(), [&l](TableRef const& e) { return !l(e); });
141 return out;
142}
143
144template <size_t N1, size_t N2, std::array<TableRef, N1> ar1, std::array<TableRef, N2> ar2>
145consteval auto intersect()
146{
147 constexpr const int duplicates = std::ranges::count_if(ar2.begin(), ar2.end(), [&](TableRef const& a) { return std::any_of(ar1.begin(), ar1.end(), [&](TableRef const& e) { return e == a; }); });
148 std::array<TableRef, duplicates> out;
149 std::copy_if(ar1.begin(), ar1.end(), out.begin(), [](TableRef const& a) { return std::find(ar2.begin(), ar2.end(), a) != ar2.end(); });
150 return out;
151}
152
153template <typename T, typename... Ts>
154consteval auto mergeOriginals()
155 requires(sizeof...(Ts) == 1)
156{
158 return merge<T::originals.size(), T1::originals.size(), T::originals, T1::originals>();
159}
160
161template <typename T, typename... Ts>
162consteval auto mergeOriginals()
163 requires(sizeof...(Ts) > 1)
164{
165 constexpr auto tail = mergeOriginals<Ts...>();
166 return merge<T::originals.size(), tail.size(), T::originals, tail>();
167}
168
169template <typename T, typename... Ts>
170 requires(sizeof...(Ts) == 1)
171consteval auto intersectOriginals()
172{
174 return intersect<T::originals.size(), T1::originals.size(), T::originals, T1::originals>();
175}
176
177template <typename T, typename... Ts>
178 requires(sizeof...(Ts) > 1)
179consteval auto intersectOriginals()
180{
181 constexpr auto tail = intersectOriginals<Ts...>();
182 return intersect<T::originals.size(), tail.size(), T::originals, tail>();
183}
184} // namespace o2::soa
185
186namespace o2::soa
187{
188struct Binding;
189
190template <typename T>
191concept not_void = requires { !std::same_as<T, void>; };
192
194template <typename C>
195concept is_persistent_column = requires(C c) { c.mColumnIterator; };
196
197template <typename C>
199
200template <typename C>
201using is_persistent_column_t = std::conditional_t<is_persistent_column<C>, std::true_type, std::false_type>;
202
203template <typename C>
204concept is_self_index_column = not_void<typename C::self_index_t> && std::same_as<typename C::self_index_t, std::true_type>;
205
206template <typename C>
208 { c.setCurrentRaw(b) } -> std::same_as<bool>;
209 requires std::same_as<decltype(c.mBinding), o2::soa::Binding>;
210};
211
212template <typename C>
213using is_external_index_t = typename std::conditional_t<is_index_column<C>, std::true_type, std::false_type>;
214
215template <typename C>
216using is_self_index_t = typename std::conditional_t<is_self_index_column<C>, std::true_type, std::false_type>;
217} // namespace o2::soa
218
219namespace o2::aod
220{
221namespace
222{
223template <typename Key, size_t N, std::array<bool, N> map>
224static consteval int getIndexPosToKey_impl()
225{
226 constexpr const auto pos = std::find(map.begin(), map.end(), true);
227 if constexpr (pos != map.end()) {
228 return std::distance(map.begin(), pos);
229 } else {
230 return -1;
231 }
232}
233} // namespace
234
236template <typename D, typename... Cs>
238 using columns = framework::pack<Cs...>;
242
243 template <typename Key, typename... PCs>
244 static consteval std::array<bool, sizeof...(PCs)> getMap(framework::pack<PCs...>)
245 {
246 return std::array<bool, sizeof...(PCs)>{[]() {
247 if constexpr (requires { PCs::index_targets.size(); }) {
248 return Key::template isIndexTargetOf<PCs::index_targets.size(), PCs::index_targets>();
249 } else {
250 return false;
251 }
252 }()...};
253 }
254
255 template <typename Key>
256 static consteval int getIndexPosToKey()
257 {
258 return getIndexPosToKey_impl<Key, framework::pack_size(persistent_columns_t{}), getMap<Key>(persistent_columns_t{})>();
259 }
260
261 static std::shared_ptr<arrow::Schema> getSchema()
262 {
263 return std::make_shared<arrow::Schema>([]<typename... C>(framework::pack<C...>&& p) { return o2::soa::createFieldsFromColumns(p); }(persistent_columns_t{}));
264 }
265};
266
267template <typename D>
269 using metadata = void;
270};
271
274template <uint32_t H>
275struct Hash {
276 static constexpr uint32_t hash = H;
277 static constexpr char const* const str{""};
278};
279
281template <size_t N, std::array<soa::TableRef, N> ar, typename Key>
282consteval auto filterForKey()
283{
284 constexpr std::array<bool, N> test = []<size_t... Is>(std::index_sequence<Is...>) {
285 return std::array<bool, N>{(Key::template hasOriginal<ar[Is]>() || (o2::aod::MetadataTrait<o2::aod::Hash<ar[Is].desc_hash>>::metadata::template getIndexPosToKey<Key>() >= 0))...};
286 }(std::make_index_sequence<N>());
287 constexpr int correct = std::ranges::count(test.begin(), test.end(), true);
288 std::array<soa::TableRef, correct> out;
289 std::ranges::copy_if(ar.begin(), ar.end(), out.begin(), [&test](soa::TableRef const& r) { return test[std::distance(ar.begin(), std::find(ar.begin(), ar.end(), r))]; });
290 return out;
291}
292
294#define O2HASH(_Str_) \
295 template <> \
296 struct Hash<_Str_ ""_h> { \
297 static constexpr uint32_t hash = _Str_ ""_h; \
298 static constexpr char const* const str{_Str_}; \
299 };
300
302#define O2ORIGIN(_Str_) \
303 template <> \
304 struct Hash<_Str_ ""_h> { \
305 static constexpr header::DataOrigin origin{_Str_}; \
306 static constexpr uint32_t hash = _Str_ ""_h; \
307 static constexpr char const* const str{_Str_}; \
308 };
309
311static inline constexpr uint32_t version(const char* const str)
312{
313 if (str[0] == '\0') {
314 return 0;
315 }
316 size_t len = 0;
317 uint32_t res = 0;
318 while (str[len] != '/' && str[len] != '\0') {
319 ++len;
320 }
321 if (str[len - 1] == '\0') {
322 return -1;
323 }
324 for (auto i = len + 1; str[i] != '\0'; ++i) {
325 res = res * 10 + (int)(str[i] - '0');
326 }
327 return res;
328}
329
331static inline constexpr std::string_view description_str(const char* const str)
332{
333 size_t len = 0;
334 while (len < 15 && str[len] != '/') {
335 ++len;
336 }
337 return std::string_view{str, len};
338}
339
340static inline constexpr header::DataDescription description(const char* const str)
341{
342 size_t len = 0;
343 while (len < 15 && str[len] != '/') {
344 ++len;
345 }
346 char out[16];
347 for (auto i = 0; i < 16; ++i) {
348 out[i] = 0;
349 }
350 std::memcpy(out, str, len);
351 return {out};
352}
353
354// Helpers to get strings from TableRef
355template <soa::TableRef R>
356consteval const char* label()
357{
358 return o2::aod::Hash<R.label_hash>::str;
359}
360
361template <soa::TableRef R>
362consteval const char* origin_str()
363{
364 return o2::aod::Hash<R.origin_hash>::str;
365}
366
367template <soa::TableRef R>
369{
370 return o2::aod::Hash<R.origin_hash>::origin;
371}
372
373template <soa::TableRef R>
374consteval const char* signature()
375{
376 return o2::aod::Hash<R.desc_hash>::str;
377}
378
379template <soa::TableRef R>
381{
382 return {origin<R>(), description(signature<R>()), R.version};
383}
384
386template <typename T>
387concept is_aod_hash = requires(T t) { t.hash; t.str; };
388
389template <typename T>
390concept is_origin_hash = is_aod_hash<T> && requires(T t) { t.origin; };
391
393template <soa::TableRef R>
394static constexpr auto sourceSpec()
395{
396 return fmt::format("{}/{}/{}/{}", label<R>(), origin_str<R>(), description_str(signature<R>()), R.version);
397}
398} // namespace o2::aod
399
400namespace o2::soa
401{
402template <aod::is_aod_hash L, aod::is_aod_hash D, aod::is_origin_hash O, typename... Ts>
403class Table;
404
406struct Binding {
407 void const* ptr = nullptr;
408 size_t hash = 0;
409 std::span<TableRef const> refs;
410
411 template <typename T>
412 void bind(T const* table)
413 {
414 ptr = table;
415 hash = o2::framework::TypeIdHelpers::uniqueId<T>();
416 refs = std::span{T::originals};
417 }
418
419 template <typename T>
420 T const* get() const
421 {
422 if (hash == o2::framework::TypeIdHelpers::uniqueId<T>()) {
423 return static_cast<T const*>(ptr);
424 }
425 return nullptr;
426 }
427};
428
429using SelectionVector = std::vector<int64_t>;
430
431template <typename T>
433
434template <typename T>
436
437template <typename T>
439
440template <typename T>
442
443template <typename T>
445
446template <typename T>
447concept has_configurable_extension = has_extension<T> && requires(T t) { typename T::configurable_t; requires std::same_as<std::true_type, typename T::configurable_t>; };
448
449template <typename T>
450concept is_spawnable_column = std::same_as<typename T::spawnable_t, std::true_type>;
451
452template <typename B, typename E>
454 constexpr static bool value = false;
455};
456
457template <aod::is_aod_hash A, aod::is_aod_hash B>
459 constexpr static bool value = false;
460};
461
462template <typename B, typename E>
464
465template <aod::is_aod_hash A, aod::is_aod_hash B>
467
471struct Chunked {
472 constexpr static bool chunked = true;
473};
474
477struct Flat {
478 constexpr static bool chunked = false;
479};
480
482template <typename T>
483struct unwrap {
484 using type = T;
485};
486
487template <typename T>
488struct unwrap<std::vector<T>> {
489 using type = T;
490};
491
492template <>
493struct unwrap<bool> {
494 using type = char;
495};
496
497template <typename T>
498using unwrap_t = typename unwrap<T>::type;
499
504template <typename T, typename ChunkingPolicy = Chunked>
505class ColumnIterator : ChunkingPolicy
506{
507 static constexpr char SCALE_FACTOR = std::same_as<std::decay_t<T>, bool> ? 3 : 0;
508
509 public:
514 ColumnIterator(arrow::ChunkedArray const* column)
515 : mColumn{column},
516 mCurrent{nullptr},
517 mCurrentPos{nullptr},
518 mLast{nullptr},
519 mFirstIndex{0},
520 mCurrentChunk{0},
521 mOffset{0}
522 {
523 auto array = getCurrentArray();
524 mCurrent = reinterpret_cast<unwrap_t<T> const*>(array->values()->data()) + (mOffset >> SCALE_FACTOR);
525 mLast = mCurrent + array->length();
526 }
527
528 ColumnIterator() = default;
531
534
536 void nextChunk() const
537 {
538 auto previousArray = getCurrentArray();
539 mFirstIndex += previousArray->length();
540
542 auto array = getCurrentArray();
543 mCurrent = reinterpret_cast<unwrap_t<T> const*>(array->values()->data()) + (mOffset >> SCALE_FACTOR) - (mFirstIndex >> SCALE_FACTOR);
544 mLast = mCurrent + array->length() + (mFirstIndex >> SCALE_FACTOR);
545 }
546
547 void prevChunk() const
548 {
549 auto previousArray = getCurrentArray();
550 mFirstIndex -= previousArray->length();
551
553 auto array = getCurrentArray();
554 mCurrent = reinterpret_cast<unwrap_t<T> const*>(array->values()->data()) + (mOffset >> SCALE_FACTOR) - (mFirstIndex >> SCALE_FACTOR);
555 mLast = mCurrent + array->length() + (mFirstIndex >> SCALE_FACTOR);
556 }
557
558 void moveToChunk(int chunk)
559 {
560 if (mCurrentChunk < chunk) {
561 while (mCurrentChunk != chunk) {
562 nextChunk();
563 }
564 } else {
565 while (mCurrentChunk != chunk) {
566 prevChunk();
567 }
568 }
569 }
570
573 {
574 mCurrentChunk = mColumn->num_chunks() - 1;
575 auto array = getCurrentArray();
576 mFirstIndex = mColumn->length() - array->length();
577 mCurrent = reinterpret_cast<unwrap_t<T> const*>(array->values()->data()) + (mOffset >> SCALE_FACTOR) - (mFirstIndex >> SCALE_FACTOR);
578 mLast = mCurrent + array->length() + (mFirstIndex >> SCALE_FACTOR);
579 }
580
581 auto operator*() const
582 requires std::same_as<bool, std::decay_t<T>>
583 {
584 checkSkipChunk();
585 return (*(mCurrent - (mOffset >> SCALE_FACTOR) + ((*mCurrentPos + mOffset) >> SCALE_FACTOR)) & (1 << ((*mCurrentPos + mOffset) & 0x7))) != 0;
586 }
587
588 auto operator*() const
589 requires((!std::same_as<bool, std::decay_t<T>>) && std::same_as<arrow_array_for_t<T>, arrow::ListArray>)
590 {
591 checkSkipChunk();
592 auto list = std::static_pointer_cast<arrow::ListArray>(mColumn->chunk(mCurrentChunk));
593 auto offset = list->value_offset(*mCurrentPos - mFirstIndex);
594 auto length = list->value_length(*mCurrentPos - mFirstIndex);
595 return gsl::span<unwrap_t<T> const>{mCurrent + mFirstIndex + offset, mCurrent + mFirstIndex + (offset + length)};
596 }
597
598 decltype(auto) operator*() const
599 requires((!std::same_as<bool, std::decay_t<T>>) && std::same_as<arrow_array_for_t<T>, arrow::BinaryViewArray>)
600 {
601 checkSkipChunk();
602 auto array = std::static_pointer_cast<arrow::BinaryViewArray>(mColumn->chunk(mCurrentChunk));
603 return array->GetView(*mCurrentPos - mFirstIndex);
604 }
605
606 decltype(auto) operator*() const
607 requires((!std::same_as<bool, std::decay_t<T>>) && !std::same_as<arrow_array_for_t<T>, arrow::ListArray> && !std::same_as<arrow_array_for_t<T>, arrow::BinaryViewArray>)
608 {
609 checkSkipChunk();
610 return *(mCurrent + (*mCurrentPos >> SCALE_FACTOR));
611 }
612
613 // Move to the chunk which containts element pos
615 {
616 checkSkipChunk();
617 return *this;
618 }
619
620 mutable unwrap_t<T> const* mCurrent;
621 int64_t const* mCurrentPos;
622 mutable unwrap_t<T> const* mLast;
623 arrow::ChunkedArray const* mColumn;
624 mutable int mFirstIndex;
625 mutable int mCurrentChunk;
626 mutable int mOffset;
627
628 private:
629 void checkSkipChunk() const
630 requires((ChunkingPolicy::chunked == true) && std::same_as<arrow_array_for_t<T>, arrow::ListArray>)
631 {
632 auto list = std::static_pointer_cast<arrow::ListArray>(mColumn->chunk(mCurrentChunk));
633 if (O2_BUILTIN_UNLIKELY(*mCurrentPos - mFirstIndex >= list->length())) {
634 nextChunk();
635 }
636 }
637
638 void checkSkipChunk() const
639 requires((ChunkingPolicy::chunked == true) && !std::same_as<arrow_array_for_t<T>, arrow::ListArray>)
640 {
641 if (O2_BUILTIN_UNLIKELY(((mCurrent + (*mCurrentPos >> SCALE_FACTOR)) >= mLast))) {
642 nextChunk();
643 }
644 }
645
646 void checkSkipChunk() const
647 requires(ChunkingPolicy::chunked == false)
648 {
649 }
651 auto getCurrentArray() const
652 requires(std::same_as<arrow_array_for_t<T>, arrow::FixedSizeListArray>)
653 {
654 std::shared_ptr<arrow::Array> chunkToUse = mColumn->chunk(mCurrentChunk);
655 mOffset = chunkToUse->offset();
656 chunkToUse = std::dynamic_pointer_cast<arrow::FixedSizeListArray>(chunkToUse)->values();
657 return std::static_pointer_cast<arrow_array_for_t<value_for_t<T>>>(chunkToUse);
658 }
659
660 auto getCurrentArray() const
661 requires(std::same_as<arrow_array_for_t<T>, arrow::ListArray>)
662 {
663 std::shared_ptr<arrow::Array> chunkToUse = mColumn->chunk(mCurrentChunk);
664 mOffset = chunkToUse->offset();
665 chunkToUse = std::dynamic_pointer_cast<arrow::ListArray>(chunkToUse)->values();
666 mOffset = chunkToUse->offset();
667 return std::static_pointer_cast<arrow_array_for_t<value_for_t<T>>>(chunkToUse);
668 }
669
670 auto getCurrentArray() const
671 requires(!std::same_as<arrow_array_for_t<T>, arrow::FixedSizeListArray> && !std::same_as<arrow_array_for_t<T>, arrow::ListArray>)
672 {
673 std::shared_ptr<arrow::Array> chunkToUse = mColumn->chunk(mCurrentChunk);
674 mOffset = chunkToUse->offset();
675 return std::static_pointer_cast<arrow_array_for_t<T>>(chunkToUse);
676 }
677};
678
679template <typename T, typename INHERIT>
680struct Column {
681 using inherited_t = INHERIT;
683 : mColumnIterator{it}
684 {
685 }
686
687 Column() = default;
688 Column(Column const&) = default;
689 Column& operator=(Column const&) = default;
690
691 Column(Column&&) = default;
692 Column& operator=(Column&&) = default;
693
694 using type = T;
695 static constexpr const char* const& columnLabel() { return INHERIT::mLabel; }
697 {
698 return mColumnIterator;
699 }
700
701 static auto asArrowField()
702 {
703 return std::make_shared<arrow::Field>(inherited_t::mLabel, soa::asArrowDataType<type>());
704 }
705
709};
710
713template <typename F, typename INHERIT>
715 using inherited_t = INHERIT;
716
717 static constexpr const char* const& columnLabel() { return INHERIT::mLabel; }
718};
719
720template <typename INHERIT>
722 using inherited_t = INHERIT;
723 static constexpr const uint32_t hash = 0;
724
725 static constexpr const char* const& columnLabel() { return INHERIT::mLabel; }
726};
727
728template <typename INHERIT>
730 using inherited_t = INHERIT;
731 static constexpr const uint32_t hash = 0;
732
733 static constexpr const char* const& columnLabel() { return INHERIT::mLabel; }
734};
735
736template <size_t M = 0>
737struct Marker : o2::soa::MarkerColumn<Marker<M>> {
738 using type = size_t;
740 constexpr inline static auto value = M;
741
742 Marker() = default;
743 Marker(Marker const&) = default;
744 Marker(Marker&&) = default;
745
746 Marker& operator=(Marker const&) = default;
747 Marker& operator=(Marker&&) = default;
748
749 Marker(arrow::ChunkedArray const*) {}
750 constexpr inline auto mark()
751 {
752 return value;
753 }
754
755 static constexpr const char* mLabel = "Marker";
756};
757
758template <int64_t START = 0, int64_t END = -1>
759struct Index : o2::soa::IndexColumn<Index<START, END>> {
761 constexpr inline static int64_t start = START;
762 constexpr inline static int64_t end = END;
763
764 Index() = default;
765 Index(Index const&) = default;
766 Index(Index&&) = default;
767
768 Index& operator=(Index const&) = default;
769 Index& operator=(Index&&) = default;
770
771 Index(arrow::ChunkedArray const*)
772 {
773 }
774
775 constexpr inline int64_t rangeStart()
776 {
777 return START;
778 }
779
780 constexpr inline int64_t rangeEnd()
781 {
782 return END;
783 }
784
785 [[nodiscard]] int64_t index() const
786 {
787 return index<0>();
788 }
789
790 [[nodiscard]] int64_t filteredIndex() const
791 {
792 return index<1>();
793 }
794
795 [[nodiscard]] int64_t globalIndex() const
796 {
797 return index<0>() + offsets<0>();
798 }
799
800 template <int N = 0>
801 [[nodiscard]] int64_t index() const
802 {
803 return *std::get<N>(rowIndices);
804 }
805
806 template <int N = 0>
807 [[nodiscard]] int64_t offsets() const
808 {
809 return *std::get<N>(rowOffsets);
810 }
811
812 void setIndices(std::tuple<int64_t const*, int64_t const*> indices)
813 {
815 }
816
817 void setOffsets(std::tuple<uint64_t const*> offsets)
818 {
820 }
821
822 static constexpr const char* mLabel = "Index";
823 using type = int64_t;
824
825 std::tuple<int64_t const*, int64_t const*> rowIndices;
828 std::tuple<uint64_t const*> rowOffsets;
829};
830
831template <typename C>
832concept is_indexing_column = requires(C& c) {
833 c.rowIndices;
834 c.rowOffsets;
835};
836
837template <typename C>
838concept is_dynamic_column = requires(C& c) {
839 c.boundIterators;
840};
841
842template <typename C>
843concept is_marker_column = requires { &C::mark; };
844
845template <typename T>
846using is_dynamic_t = std::conditional_t<is_dynamic_column<T>, std::true_type, std::false_type>;
847
848template <typename T>
850
851template <typename T>
852using is_indexing_t = std::conditional_t<is_indexing_column<T>, std::true_type, std::false_type>;
853
856 int64_t mRowIndex = 0;
858 uint64_t mOffset = 0;
859};
860
862 int64_t const index;
863};
864
866 // We use -1 in the IndexPolicyBase to indicate that the index is
867 // invalid. What will validate the index is the this->setCursor()
868 // which happens below which will properly setup the first index
869 // by remapping the filtered index 0 to whatever unfiltered index
870 // it belongs to.
871 FilteredIndexPolicy(std::span<int64_t const> selection, int64_t rows, uint64_t offset = 0)
872 : IndexPolicyBase{-1, offset},
873 mSelectedRows(selection),
874 mMaxSelection(selection.size()),
875 nRows{rows}
876 {
877 this->setCursor(0);
878 }
879
880 void resetSelection(std::span<int64_t const> selection)
881 {
882 mSelectedRows = selection;
883 mMaxSelection = selection.size();
884 this->setCursor(0);
885 }
886
892
893 [[nodiscard]] std::tuple<int64_t const*, int64_t const*>
895 {
896 return std::make_tuple(&mRowIndex, &mSelectionRow);
897 }
898
899 [[nodiscard]] std::tuple<uint64_t const*>
901 {
902 return std::make_tuple(&mOffset);
903 }
904
905 void limitRange(int64_t start, int64_t end)
906 {
907 this->setCursor(start);
908 if (end >= 0) {
909 mMaxSelection = std::min(end, mMaxSelection);
910 }
911 }
912
913 void setCursor(int64_t i)
914 {
915 mSelectionRow = i;
916 updateRow();
917 }
918
919 void moveByIndex(int64_t i)
920 {
921 mSelectionRow += i;
922 updateRow();
923 }
924
925 friend bool operator==(FilteredIndexPolicy const& lh, FilteredIndexPolicy const& rh)
926 {
927 return lh.mSelectionRow == rh.mSelectionRow;
928 }
929
930 bool operator==(RowViewSentinel const& sentinel) const
931 {
932 return O2_BUILTIN_UNLIKELY(mSelectionRow == sentinel.index);
933 }
934
939 {
940 this->mSelectionRow = this->mMaxSelection;
941 this->mRowIndex = -1;
942 }
943
944 [[nodiscard]] auto getSelectionRow() const
945 {
946 return mSelectionRow;
947 }
948
949 [[nodiscard]] auto size() const
950 {
951 return mMaxSelection;
952 }
953
954 [[nodiscard]] auto raw_size() const
955 {
956 return nRows;
957 }
958
959 private:
960 inline void updateRow()
961 {
962 this->mRowIndex = O2_BUILTIN_LIKELY(mSelectionRow < mMaxSelection) ? mSelectedRows[mSelectionRow] : -1;
963 }
964 std::span<int64_t const> mSelectedRows;
965 int64_t mSelectionRow = 0;
966 int64_t mMaxSelection = 0;
967 int64_t nRows = 0;
968};
969
977
981 DefaultIndexPolicy(int64_t nRows, uint64_t offset)
983 mMaxRow(nRows)
984 {
985 }
986
992
993 void limitRange(int64_t start, int64_t end)
994 {
995 this->setCursor(start);
996 if (end >= 0) {
997 mMaxRow = std::min(end, mMaxRow);
998 }
999 }
1000
1001 [[nodiscard]] std::tuple<int64_t const*, int64_t const*>
1003 {
1004 return std::make_tuple(&mRowIndex, &mRowIndex);
1005 }
1006
1007 [[nodiscard]] std::tuple<uint64_t const*>
1009 {
1010 return std::make_tuple(&mOffset);
1011 }
1012
1013 void setCursor(int64_t i)
1014 {
1015 this->mRowIndex = i;
1016 }
1017 void moveByIndex(int64_t i)
1018 {
1019 this->mRowIndex += i;
1020 }
1021
1023 {
1024 this->setCursor(mMaxRow);
1025 }
1026
1027 friend bool operator==(DefaultIndexPolicy const& lh, DefaultIndexPolicy const& rh)
1028 {
1029 return lh.mRowIndex == rh.mRowIndex;
1030 }
1031
1032 bool operator==(RowViewSentinel const& sentinel) const
1033 {
1034 return O2_BUILTIN_UNLIKELY(this->mRowIndex == sentinel.index);
1035 }
1036
1037 [[nodiscard]] auto size() const
1038 {
1039 return mMaxRow;
1040 }
1041
1042 int64_t mMaxRow = 0;
1043};
1044
1045// template <OriginEnc ORIGIN, typename... C>
1046// class Table;
1047
1048template <aod::is_aod_hash L, aod::is_aod_hash D, aod::is_origin_hash O, typename... T>
1049class Table;
1050
1051template <typename T>
1053
1056template <typename C>
1059 arrow::ChunkedArray* second;
1060};
1061
1062template <typename T, typename B>
1063concept can_bind = requires(T&& t) {
1064 { t.B::mColumnIterator };
1065};
1066
1067template <typename... C>
1069
1070template <typename D, typename O, typename IP, typename... C>
1071struct TableIterator : IP, C... {
1072 public:
1073 using self_t = TableIterator<D, O, IP, C...>;
1074 using policy_t = IP;
1079 using bindings_pack_t = decltype([]<typename... Cs>(framework::pack<Cs...>) -> framework::pack<typename Cs::binding_t...> {}(external_index_columns_t{})); // decltype(extractBindings(external_index_columns_t{}));
1080
1081 TableIterator(arrow::ChunkedArray* columnData[sizeof...(C)], IP&& policy)
1082 : IP{policy},
1083 C(columnData[framework::has_type_at_v<C>(all_columns{})])...
1084 {
1085 if (this->size() != 0) {
1086 bind();
1087 }
1088 }
1089
1090 TableIterator(arrow::ChunkedArray* columnData[sizeof...(C)], IP&& policy)
1091 requires(has_index<C...>)
1092 : IP{policy},
1093 C(columnData[framework::has_type_at_v<C>(all_columns{})])...
1094 {
1095 if (this->size() != 0) {
1096 bind();
1097 }
1098 // In case we have an index column might need to constrain the actual
1099 // number of rows in the view to the range provided by the index.
1100 // FIXME: we should really understand what happens to an index when we
1101 // have a RowViewFiltered.
1102 this->limitRange(this->rangeStart(), this->rangeEnd());
1103 }
1104
1105 TableIterator() = default;
1107 : IP{static_cast<IP const&>(other)},
1108 C(static_cast<C const&>(other))...
1109 {
1110 if (this->size() != 0) {
1111 bind();
1112 }
1113 }
1114
1116 {
1117 IP::operator=(static_cast<IP const&>(other));
1118 (void(static_cast<C&>(*this) = static_cast<C>(other)), ...);
1119 if (this->size() != 0) {
1120 bind();
1121 }
1122 return *this;
1123 }
1124
1126 requires std::same_as<IP, DefaultIndexPolicy>
1127 : IP{static_cast<IP const&>(other)},
1128 C(static_cast<C const&>(other))...
1129 {
1130 if (this->size() != 0) {
1131 bind();
1132 }
1133 }
1134
1136 {
1137 this->moveByIndex(1);
1138 return *this;
1139 }
1140
1142 {
1143 self_t copy = *this;
1144 this->operator++();
1145 return copy;
1146 }
1147
1149 {
1150 this->moveByIndex(-1);
1151 return *this;
1152 }
1153
1155 {
1156 self_t copy = *this;
1157 this->operator--();
1158 return copy;
1159 }
1160
1162 TableIterator operator+(int64_t inc) const
1163 {
1164 TableIterator copy = *this;
1165 copy.moveByIndex(inc);
1166 return copy;
1167 }
1168
1169 TableIterator operator-(int64_t dec) const
1170 {
1171 return operator+(-dec);
1172 }
1173
1175 {
1176 return *this;
1177 }
1178
1179 template <typename... CL, typename TA>
1181 {
1182 (CL::setCurrent(current), ...);
1183 }
1184
1185 template <typename CL>
1186 auto getCurrent() const
1187 {
1188 return CL::getCurrentRaw();
1189 }
1190
1191 template <typename... Cs>
1193 {
1194 return std::vector<o2::soa::Binding>{static_cast<Cs const&>(*this).getCurrentRaw()...};
1195 }
1196
1197 auto getIndexBindings() const
1198 {
1200 }
1201
1202 template <typename... TA>
1203 void bindExternalIndices(TA*... current)
1204 {
1206 }
1207
1208 template <typename... Cs>
1209 void doSetCurrentIndexRaw(framework::pack<Cs...> p, std::vector<o2::soa::Binding>&& ptrs)
1210 {
1211 (Cs::setCurrentRaw(ptrs[framework::has_type_at_v<Cs>(p)]), ...);
1212 }
1213
1214 template <typename... Cs, typename I>
1216 {
1218 b.bind(ptr);
1219 (Cs::setCurrentRaw(b), ...);
1220 }
1221
1222 void bindExternalIndicesRaw(std::vector<o2::soa::Binding>&& ptrs)
1223 {
1224 doSetCurrentIndexRaw(external_index_columns_t{}, std::forward<std::vector<o2::soa::Binding>>(ptrs));
1225 }
1226
1227 template <typename I>
1228 void bindInternalIndices(I const* table)
1229 {
1231 }
1232
1233 private:
1235 template <typename... PC>
1236 void doMoveToEnd(framework::pack<PC...>)
1237 {
1238 (PC::mColumnIterator.moveToEnd(), ...);
1239 }
1240
1243 void bind()
1244 {
1245 using namespace o2::soa;
1246 auto f = framework::overloaded{
1247 [this]<soa::is_persistent_column T>(T*) -> void { T::mColumnIterator.mCurrentPos = &this->mRowIndex; },
1248 [this]<soa::is_dynamic_column T>(T*) -> void { bindDynamicColumn<T>(typename T::bindings_t{}); },
1249 [this]<typename T>(T*) -> void {},
1250 };
1251 (f(static_cast<C*>(nullptr)), ...);
1252 if constexpr (has_index<C...>) {
1253 this->setIndices(this->getIndices());
1254 this->setOffsets(this->getOffsets());
1255 }
1256 }
1257
1258 template <typename DC, typename... B>
1259 auto bindDynamicColumn(framework::pack<B...>)
1260 {
1261 DC::boundIterators = std::make_tuple(getDynamicBinding<B>()...);
1262 }
1263
1264 // Sometimes dynamic columns are defined for tables in
1265 // the hope that it will be joined / extended with another one which provides
1266 // the full set of bindings. This is to avoid a compilation
1267 // error if constructor for the table or any other thing involving a missing
1268 // binding is preinstanciated.
1269 template <typename B>
1270 requires(can_bind<self_t, B>)
1271 decltype(auto) getDynamicBinding()
1272 {
1273 static_assert(std::same_as<decltype(&(static_cast<B*>(this)->mColumnIterator)), std::decay_t<decltype(B::mColumnIterator)>*>, "foo");
1274 return &(static_cast<B*>(this)->mColumnIterator);
1275 // return static_cast<std::decay_t<decltype(B::mColumnIterator)>*>(nullptr);
1276 }
1277
1278 template <typename B>
1279 decltype(auto) getDynamicBinding()
1280 {
1281 return static_cast<std::decay_t<decltype(B::mColumnIterator)>*>(nullptr);
1282 }
1283};
1284
1286 static std::shared_ptr<arrow::Table> joinTables(std::vector<std::shared_ptr<arrow::Table>>&& tables);
1287 static std::shared_ptr<arrow::Table> joinTables(std::vector<std::shared_ptr<arrow::Table>>&& tables, std::span<const char* const> labels);
1288 static std::shared_ptr<arrow::Table> joinTables(std::vector<std::shared_ptr<arrow::Table>>&& tables, std::span<const std::string> labels);
1289 static std::shared_ptr<arrow::Table> concatTables(std::vector<std::shared_ptr<arrow::Table>>&& tables);
1290};
1291
1293template <typename T>
1295
1296template <typename T>
1297concept with_originals = requires {
1298 T::originals.size();
1299};
1300
1301template <typename T>
1302concept with_sources = requires {
1303 T::sources.size();
1304};
1305
1306template <typename T>
1307concept with_ccdb_urls = requires {
1308 T::ccdb_urls.size();
1309};
1310
1311template <typename T>
1312concept with_base_table = requires {
1313 typename aod::MetadataTrait<o2::aod::Hash<T::ref.desc_hash>>::metadata::base_table_t;
1314};
1315
1316template <typename T>
1317concept with_expression_pack = requires {
1318 typename T::expression_pack_t{};
1319};
1320
1321template <typename T>
1322concept with_index_pack = requires {
1323 typename T::index_pack_t{};
1324};
1325
1326template <size_t N1, std::array<TableRef, N1> os1, size_t N2, std::array<TableRef, N2> os2>
1327consteval bool is_compatible()
1328{
1329 return []<size_t... Is>(std::index_sequence<Is...>) {
1330 return ([]<size_t... Ks>(std::index_sequence<Ks...>) {
1331 constexpr auto h = os1[Is].desc_hash;
1332 using H = o2::aod::Hash<h>;
1333 return (((h == os2[Ks].desc_hash) || is_ng_index_equivalent_v<H, o2::aod::Hash<os2[Ks].desc_hash>>) || ...);
1334 }(std::make_index_sequence<N2>()) ||
1335 ...);
1336 }(std::make_index_sequence<N1>());
1337}
1338
1339template <with_originals T, with_originals B>
1341{
1342 return is_compatible<T::originals.size(), T::originals, B::originals.size(), B::originals>();
1343}
1344
1345template <typename T, typename B>
1346using is_binding_compatible = std::conditional_t<is_binding_compatible_v<T, typename B::binding_t>(), std::true_type, std::false_type>;
1347
1348template <typename L, typename D, typename O, typename Key, typename H, typename... Ts>
1349struct IndexTable;
1350
1351template <typename T>
1353
1354template <soa::is_table T>
1355static constexpr std::string getLabelForTable()
1356{
1357 return std::string{aod::label<std::decay_t<T>::originals[0]>()};
1358}
1359
1360template <soa::is_table T>
1362static constexpr std::string getLabelFromType()
1363{
1364 return getLabelForTable<T>();
1365}
1366
1367template <soa::is_iterator T>
1368static constexpr std::string getLabelFromType()
1369{
1370 return getLabelForTable<typename std::decay_t<T>::parent_t>();
1371}
1372
1373template <soa::is_index_table T>
1374static constexpr std::string getLabelFromType()
1375{
1376 return getLabelForTable<typename std::decay_t<T>::first_t>();
1377}
1378template <soa::with_base_table T>
1379static constexpr std::string getLabelFromType()
1380{
1381 return getLabelForTable<typename aod::MetadataTrait<o2::aod::Hash<T::ref.desc_hash>>::metadata::base_table_t>();
1382}
1383
1384template <typename... C>
1385static constexpr auto hasColumnForKey(framework::pack<C...>, std::string const& key)
1386{
1387 auto caseInsensitiveCompare = [](const std::string_view& str1, const std::string& str2) {
1388 return std::ranges::equal(
1389 str1, str2,
1390 [](char c1, char c2) {
1391 return std::tolower(static_cast<unsigned char>(c1)) ==
1392 std::tolower(static_cast<unsigned char>(c2));
1393 });
1394 };
1395 return (caseInsensitiveCompare(C::inherited_t::mLabel, key) || ...);
1396}
1397
1398template <TableRef ref>
1399static constexpr std::pair<bool, std::string> hasKey(std::string const& key)
1400{
1401 return {hasColumnForKey(typename aod::MetadataTrait<o2::aod::Hash<ref.desc_hash>>::metadata::columns{}, key), aod::label<ref>()};
1402}
1403
1404template <TableRef ref>
1405static constexpr std::pair<bool, framework::ConcreteDataMatcher> hasKeyM(std::string const& key)
1406{
1407 return {hasColumnForKey(typename aod::MetadataTrait<o2::aod::Hash<ref.desc_hash>>::metadata::columns{}, key), aod::matcher<ref>()};
1408}
1409
1410template <typename... C>
1411static constexpr auto haveKey(framework::pack<C...>, std::string const& key)
1412{
1413 return std::vector{hasKey<C>(key)...};
1414}
1415
1416void notFoundColumn(const char* label, const char* key);
1417void missingOptionalPreslice(const char* label, const char* key);
1418
1419template <with_originals T, bool OPT = false>
1420static constexpr std::string getLabelFromTypeForKey(std::string const& key)
1421{
1422 if constexpr (T::originals.size() == 1) {
1423 auto locate = hasKey<T::originals[0]>(key);
1424 if (locate.first) {
1425 return locate.second;
1426 }
1427 } else {
1428 auto locate = [&]<size_t... Is>(std::index_sequence<Is...>) {
1429 return std::vector{hasKey<T::originals[Is]>(key)...};
1430 }(std::make_index_sequence<T::originals.size()>{});
1431 auto it = std::find_if(locate.begin(), locate.end(), [](auto const& x) { return x.first; });
1432 if (it != locate.end()) {
1433 return it->second;
1434 }
1435 }
1436 if constexpr (!OPT) {
1437 notFoundColumn(getLabelFromType<std::decay_t<T>>().data(), key.data());
1438 } else {
1439 return "[MISSING]";
1440 }
1442}
1443
1444template <with_originals T, bool OPT = false>
1445static constexpr framework::ConcreteDataMatcher getMatcherFromTypeForKey(std::string const& key)
1446{
1447 if constexpr (T::originals.size() == 1) {
1448 auto locate = hasKeyM<T::originals[0]>(key);
1449 if (locate.first) {
1450 return locate.second;
1451 }
1452 } else {
1453 auto locate = [&]<size_t... Is>(std::index_sequence<Is...>) {
1454 return std::vector{hasKeyM<T::originals[Is]>(key)...};
1455 }(std::make_index_sequence<T::originals.size()>{});
1456 auto it = std::find_if(locate.begin(), locate.end(), [](auto const& x) { return x.first; });
1457 if (it != locate.end()) {
1458 return it->second;
1459 }
1460 }
1461 if constexpr (!OPT) {
1462 notFoundColumn(getLabelFromType<std::decay_t<T>>().data(), key.data());
1463 } else {
1465 }
1467}
1468
1469template <typename B, typename... C>
1470consteval static bool hasIndexTo(framework::pack<C...>&&)
1471{
1472 return (o2::soa::is_binding_compatible_v<B, typename C::binding_t>() || ...);
1473}
1474
1475template <typename B, typename... C>
1476consteval static bool hasSortedIndexTo(framework::pack<C...>&&)
1477{
1478 return ((C::sorted && o2::soa::is_binding_compatible_v<B, typename C::binding_t>()) || ...);
1479}
1480
1481template <typename B, typename Z>
1482consteval static bool relatedByIndex()
1483{
1484 return hasIndexTo<B>(typename Z::table_t::external_index_columns_t{});
1485}
1486
1487template <typename B, typename Z>
1488consteval static bool relatedBySortedIndex()
1489{
1490 return hasSortedIndexTo<B>(typename Z::table_t::external_index_columns_t{});
1491}
1492} // namespace o2::soa
1493
1494namespace o2::framework
1495{
1496
1498 const std::string binding;
1500
1501 bool isMissing() const;
1502 Entry const& getBindingKey() const;
1503};
1504
1506 void updateSliceInfo(SliceInfoPtr&& si);
1507
1509 std::shared_ptr<arrow::Table> getSliceFor(int value, std::shared_ptr<arrow::Table> const& input, uint64_t& offset) const;
1510};
1511
1514
1516 std::span<const int64_t> getSliceFor(int value) const;
1517};
1518
1519template <typename T>
1520concept is_preslice_policy = std::derived_from<T, PreslicePolicyBase>;
1521
1522template <typename T, is_preslice_policy Policy, bool OPT = false>
1523struct PresliceBase : public Policy {
1524 constexpr static bool optional = OPT;
1525 using target_t = T;
1526 using policy_t = Policy;
1527 const std::string binding;
1528
1530 : Policy{PreslicePolicyBase{{o2::soa::getLabelFromTypeForKey<T, OPT>(std::string{index_.name})}, Entry(o2::soa::getLabelFromTypeForKey<T, OPT>(std::string{index_.name}), o2::soa::getMatcherFromTypeForKey<T, OPT>(std::string{index_.name}), std::string{index_.name})}, {}}
1531 {
1532 }
1533
1534 std::shared_ptr<arrow::Table> getSliceFor(int value, std::shared_ptr<arrow::Table> const& input, uint64_t& offset) const
1535 {
1536 if constexpr (OPT) {
1537 if (Policy::isMissing()) {
1538 return nullptr;
1539 }
1540 }
1541 return Policy::getSliceFor(value, input, offset);
1542 }
1543
1544 std::span<const int64_t> getSliceFor(int value) const
1545 {
1546 if constexpr (OPT) {
1547 if (Policy::isMissing()) {
1548 return {};
1549 }
1550 }
1551 return Policy::getSliceFor(value);
1552 }
1553};
1554
1555template <typename T>
1557template <typename T>
1559template <typename T>
1561template <typename T>
1563
1564template <typename T>
1565concept is_preslice = std::derived_from<T, PreslicePolicyBase>&&
1566 requires(T)
1567{
1568 T::optional;
1569};
1570
1584};
1585
1586template <typename T>
1587concept is_preslice_group = std::derived_from<T, PresliceGroup>;
1588
1589} // namespace o2::framework
1590
1591namespace o2::soa
1592{
1593template <soa::is_table T>
1594class FilteredBase;
1595template <typename T>
1596class Filtered;
1597
1598template <typename T>
1599concept has_filtered_policy = not_void<typename T::policy_t> && std::same_as<typename T::policy_t, soa::FilteredIndexPolicy>;
1600
1601template <typename T>
1603
1604template <typename T>
1606
1607// FIXME: compatbility declaration to be removed
1608template <typename T>
1610
1611template <typename T>
1613
1614template <typename T>
1616
1618template <typename... Is>
1619static consteval auto extractBindings(framework::pack<Is...>)
1620{
1621 return framework::pack<typename Is::binding_t...>{};
1622}
1623
1625
1626template <typename T, typename C, typename Policy, bool OPT>
1627 requires std::same_as<Policy, framework::PreslicePolicySorted> && (o2::soa::is_binding_compatible_v<C, T>())
1628auto doSliceBy(T const* table, o2::framework::PresliceBase<C, Policy, OPT> const& container, int value)
1629{
1630 if constexpr (OPT) {
1631 if (container.isMissing()) {
1632 missingOptionalPreslice(getLabelFromType<std::decay_t<T>>().data(), container.bindingKey.key.c_str());
1633 }
1634 }
1635 uint64_t offset = 0;
1636 auto out = container.getSliceFor(value, table->asArrowTable(), offset);
1637 auto t = typename T::self_t({out}, offset);
1638 if (t.tableSize() != 0) {
1639 table->copyIndexBindings(t);
1640 t.bindInternalIndicesTo(table);
1641 }
1642 return t;
1643}
1644
1645template <soa::is_filtered_table T>
1646auto doSliceByHelper(T const* table, std::span<const int64_t> const& selection)
1647{
1648 auto t = soa::Filtered<typename T::base_t>({table->asArrowTable()}, selection);
1649 if (t.tableSize() != 0) {
1650 table->copyIndexBindings(t);
1651 t.bindInternalIndicesTo(table);
1652 t.intersectWithSelection(table->getSelectedRows()); // intersect filters
1653 }
1654 return t;
1655}
1656
1657template <soa::is_table T>
1658 requires(!soa::is_filtered_table<T>)
1659auto doSliceByHelper(T const* table, std::span<const int64_t> const& selection)
1660{
1661 auto t = soa::Filtered<T>({table->asArrowTable()}, selection);
1662 if (t.tableSize() != 0) {
1663 table->copyIndexBindings(t);
1664 t.bindInternalIndicesTo(table);
1665 }
1666 return t;
1667}
1668
1669template <typename T, typename C, typename Policy, bool OPT>
1670 requires std::same_as<Policy, framework::PreslicePolicyGeneral> && (o2::soa::is_binding_compatible_v<C, T>())
1671auto doSliceBy(T const* table, o2::framework::PresliceBase<C, Policy, OPT> const& container, int value)
1672{
1673 if constexpr (OPT) {
1674 if (container.isMissing()) {
1675 missingOptionalPreslice(getLabelFromType<std::decay_t<T>>().data(), container.bindingKey.key.c_str());
1676 }
1677 }
1678 auto selection = container.getSliceFor(value);
1679 return doSliceByHelper(table, selection);
1680}
1681
1682SelectionVector sliceSelection(std::span<int64_t const> const& mSelectedRows, int64_t nrows, uint64_t offset);
1683
1684template <soa::is_filtered_table T>
1685auto prepareFilteredSlice(T const* table, std::shared_ptr<arrow::Table> slice, uint64_t offset)
1686{
1687 if (offset >= static_cast<uint64_t>(table->tableSize())) {
1688 Filtered<typename T::base_t> fresult{{{slice}}, SelectionVector{}, 0};
1689 if (fresult.tableSize() != 0) {
1690 table->copyIndexBindings(fresult);
1691 }
1692 return fresult;
1693 }
1694 auto slicedSelection = sliceSelection(table->getSelectedRows(), slice->num_rows(), offset);
1695 Filtered<typename T::base_t> fresult{{{slice}}, std::move(slicedSelection), offset};
1696 if (fresult.tableSize() != 0) {
1697 table->copyIndexBindings(fresult);
1698 }
1699 return fresult;
1700}
1701
1702template <soa::is_filtered_table T, typename C, bool OPT>
1703 requires(o2::soa::is_binding_compatible_v<C, T>())
1705{
1706 if constexpr (OPT) {
1707 if (container.isMissing()) {
1708 missingOptionalPreslice(getLabelFromType<T>().data(), container.bindingKey.key.c_str());
1709 }
1710 }
1711 uint64_t offset = 0;
1712 auto slice = container.getSliceFor(value, table->asArrowTable(), offset);
1713 return prepareFilteredSlice(table, slice, offset);
1714}
1715
1716template <soa::is_table T>
1718{
1719 auto localCache = cache.ptr->getCacheFor({"", o2::soa::getMatcherFromTypeForKey<T>(node.name), node.name});
1720 auto [offset, count] = localCache.getSliceFor(value);
1721 auto t = typename T::self_t({table->asArrowTable()->Slice(static_cast<uint64_t>(offset), count)}, static_cast<uint64_t>(offset));
1722 if (t.tableSize() != 0) {
1723 table->copyIndexBindings(t);
1724 }
1725 return t;
1726}
1727
1728template <soa::is_filtered_table T>
1730{
1731 auto localCache = cache.ptr->getCacheFor({"", o2::soa::getMatcherFromTypeForKey<T>(node.name), node.name});
1732 auto [offset, count] = localCache.getSliceFor(value);
1733 auto slice = table->asArrowTable()->Slice(static_cast<uint64_t>(offset), count);
1734 return prepareFilteredSlice(table, slice, offset);
1735}
1736
1737template <soa::is_table T>
1739{
1740 auto localCache = cache.ptr->getCacheUnsortedFor({"", o2::soa::getMatcherFromTypeForKey<T>(node.name), node.name});
1741 if constexpr (soa::is_filtered_table<T>) {
1742 auto t = typename T::self_t({table->asArrowTable()}, localCache.getSliceFor(value));
1743 if (t.tableSize() != 0) {
1744 t.intersectWithSelection(table->getSelectedRows());
1745 table->copyIndexBindings(t);
1746 }
1747 return t;
1748 } else {
1749 auto t = Filtered<T>({table->asArrowTable()}, localCache.getSliceFor(value));
1750 if (t.tableSize() != 0) {
1751 table->copyIndexBindings(t);
1752 }
1753 return t;
1754 }
1755}
1756
1757template <with_originals T>
1759{
1760 return Filtered<T>({t.asArrowTable()}, selectionToVector(framework::expressions::createSelection(t.asArrowTable(), f)));
1761}
1762
1763arrow::ChunkedArray* getIndexFromLabel(arrow::Table* table, std::string_view label);
1764
1765template <typename D, typename O, typename IP, typename... C>
1766consteval auto base_iter(framework::pack<C...>&&) -> TableIterator<D, O, IP, C...>
1767{
1768}
1769
1770template <TableRef ref, typename... Ts>
1771 requires((sizeof...(Ts) > 0) && (soa::is_column<Ts> && ...))
1772consteval auto getColumns()
1773{
1774 return framework::pack<Ts...>{};
1775}
1776
1777template <TableRef ref, typename... Ts>
1778 requires((sizeof...(Ts) > 0) && !(soa::is_column<Ts> || ...) && (ref.origin_hash == "CONC"_h))
1779consteval auto getColumns()
1780{
1781 return framework::full_intersected_pack_t<typename Ts::columns_t...>{};
1782}
1783
1784template <TableRef ref, typename... Ts>
1785 requires((sizeof...(Ts) > 0) && !(soa::is_column<Ts> || ...) && (ref.origin_hash != "CONC"_h))
1786consteval auto getColumns()
1787{
1788 return framework::concatenated_pack_unique_t<typename Ts::columns_t...>{};
1789}
1790
1791template <TableRef ref, typename... Ts>
1792 requires(sizeof...(Ts) == 0 && soa::has_metadata<aod::MetadataTrait<o2::aod::Hash<ref.desc_hash>>>)
1793consteval auto getColumns()
1794{
1795 return typename aod::MetadataTrait<o2::aod::Hash<ref.desc_hash>>::metadata::columns{};
1796}
1797
1798template <TableRef ref, typename... Ts>
1799 requires((sizeof...(Ts) == 0) || (o2::soa::is_column<Ts> && ...))
1800consteval auto computeOriginals()
1801{
1802 return std::array<TableRef, 1>{ref};
1803}
1804
1805template <TableRef ref, typename... Ts>
1806 requires((sizeof...(Ts) > 0) && (!o2::soa::is_column<Ts> || ...))
1807consteval auto computeOriginals()
1808{
1809 return o2::soa::mergeOriginals<Ts...>();
1810}
1811
1814template <aod::is_aod_hash L, aod::is_aod_hash D, aod::is_origin_hash O, typename... Ts>
1816{
1817 public:
1818 static constexpr const auto ref = TableRef{L::hash, D::hash, O::hash, o2::aod::version(D::str)};
1819 using self_t = Table<L, D, O, Ts...>;
1821
1822 static constexpr const auto originals = computeOriginals<ref, Ts...>();
1823 static constexpr const auto originalLabels = []<size_t N, std::array<TableRef, N> refs, size_t... Is>(std::index_sequence<Is...>) { return std::array<const char*, N>{o2::aod::label<refs[Is]>()...}; }.template operator()<originals.size(), originals>(std::make_index_sequence<originals.size()>());
1824
1825 template <size_t N, std::array<TableRef, N> bindings>
1826 requires(ref.origin_hash == "CONC"_h)
1827 static consteval auto isIndexTargetOf()
1828 {
1829 return false;
1830 }
1831
1832 template <size_t N, std::array<TableRef, N> bindings>
1833 requires(ref.origin_hash == "JOIN"_h)
1834 static consteval auto isIndexTargetOf()
1835 {
1836 return std::find_if(self_t::originals.begin(), self_t::originals.end(),
1837 [](TableRef const& r) {
1838 return std::find(bindings.begin(), bindings.end(), r) != bindings.end();
1839 }) != self_t::originals.end();
1840 }
1841
1842 template <size_t N, std::array<TableRef, N> bindings>
1843 requires(!(ref.origin_hash == "CONC"_h || ref.origin_hash == "JOIN"_h))
1844 static consteval auto isIndexTargetOf()
1845 {
1846 return std::find(bindings.begin(), bindings.end(), self_t::ref) != bindings.end();
1847 }
1848
1849 template <TableRef r>
1850 static consteval bool hasOriginal()
1851 {
1852 return std::find_if(originals.begin(), originals.end(), [](TableRef const& o) { return o.desc_hash == r.desc_hash; }) != originals.end();
1853 }
1854
1855 using columns_t = decltype(getColumns<ref, Ts...>());
1856
1859
1862 template <typename IP>
1863 using base_iterator = decltype(base_iter<D, O, IP>(columns_t{}));
1864
1865 template <typename IP, typename Parent, typename... T>
1867 using columns_t = typename Parent::columns_t;
1868 using external_index_columns_t = typename Parent::external_index_columns_t;
1870 // static constexpr const std::array<TableRef, sizeof...(T)> originals{T::ref...};
1871 static constexpr auto originals = Parent::originals;
1872 using policy_t = IP;
1873 using parent_t = Parent;
1874
1876
1877 TableIteratorBase(arrow::ChunkedArray* columnData[framework::pack_size(columns_t{})], IP&& policy)
1878 : base_iterator<IP>(columnData, std::forward<decltype(policy)>(policy))
1879 {
1880 }
1881
1882 template <typename P, typename... Os>
1884 requires(P::ref.desc_hash == Parent::ref.desc_hash)
1885 {
1886 static_cast<base_iterator<IP>&>(*this) = static_cast<base_iterator<IP>>(other);
1887 return *this;
1888 }
1889
1890 template <typename P>
1892 {
1893 static_cast<base_iterator<IP>&>(*this) = static_cast<base_iterator<IP>>(other);
1894 return *this;
1895 }
1896
1897 template <typename P>
1899 requires std::same_as<IP, DefaultIndexPolicy>
1900 {
1901 static_cast<base_iterator<IP>&>(*this) = static_cast<base_iterator<FilteredIndexPolicy>>(other);
1902 return *this;
1903 }
1904
1905 template <typename P, typename O1, typename... Os>
1907 requires(P::ref.desc_hash == Parent::ref.desc_hash)
1908 {
1909 *this = other;
1910 }
1911
1912 template <typename P, typename O1, typename... Os>
1914 requires(P::ref.desc_hash == Parent::ref.desc_hash)
1915 {
1916 *this = other;
1917 }
1918
1919 template <typename P>
1924
1925 template <typename P>
1927 {
1928 *this = other;
1929 }
1930
1931 template <typename P>
1933 requires std::same_as<IP, DefaultIndexPolicy>
1934 {
1935 *this = other;
1936 }
1937
1939 {
1940 this->mRowIndex = other.index;
1941 return *this;
1942 }
1943 template <typename P>
1945 {
1946 this->mRowIndex = other.mRowIndex;
1947 }
1948
1949 template <typename P, typename... Os>
1951 requires std::same_as<typename P::table_t, typename Parent::table_t>
1952 {
1953 this->mRowIndex = other.mRowIndex;
1954 }
1955
1956 template <typename TI>
1957 auto getId() const
1958 {
1959 using decayed = std::decay_t<TI>;
1960 if constexpr (framework::has_type<decayed>(bindings_pack_t{})) { // index to another table
1961 constexpr auto idx = framework::has_type_at_v<decayed>(bindings_pack_t{});
1963 } else if constexpr (std::same_as<decayed, Parent>) { // self index
1964 return this->globalIndex();
1965 } else if constexpr (is_indexing_column<decayed>) { // soa::Index<>
1966 return this->globalIndex();
1967 } else {
1968 return static_cast<int32_t>(-1);
1969 }
1970 }
1971
1972 template <typename CD, typename... CDArgs>
1973 auto getDynamicColumn() const
1974 {
1975 using decayed = std::decay_t<CD>;
1976 static_assert(is_dynamic_t<decayed>(), "Requested column is not a dynamic column");
1977 return static_cast<decayed>(*this).template getDynamicValue<CDArgs...>();
1978 }
1979
1980 template <typename B, typename CC>
1981 auto getValue() const
1982 {
1983 using COL = std::decay_t<CC>;
1984 static_assert(is_dynamic_t<COL>() || soa::is_persistent_column<COL>, "Should be persistent or dynamic column with no argument that has a return type convertable to float");
1985 return static_cast<B>(static_cast<COL>(*this).get());
1986 }
1987
1988 template <typename B, typename... CCs>
1989 std::array<B, sizeof...(CCs)> getValues() const
1990 {
1991 static_assert(std::same_as<B, float> || std::same_as<B, double>, "The common return type should be float or double");
1992 return {getValue<B, CCs>()...};
1993 }
1994
1995 using IP::size;
1996
1997 using base_iterator<IP>::operator++;
1998
2000 TableIteratorBase operator+(int64_t inc) const
2001 {
2002 TableIteratorBase copy = *this;
2003 copy.moveByIndex(inc);
2004 return copy;
2005 }
2006
2007 TableIteratorBase operator-(int64_t dec) const
2008 {
2009 return operator+(-dec);
2010 }
2011
2013 {
2014 return *this;
2015 }
2016 };
2017
2018 template <typename IP, typename Parent, typename... T>
2020
2021 template <typename IP, typename Parent>
2022 static consteval auto full_iter()
2023 {
2024 if constexpr (sizeof...(Ts) == 0) {
2026 } else {
2027 if constexpr ((o2::soa::is_column<Ts> && ...)) {
2029 } else {
2030 return iterator_template<IP, Parent, Ts...>{};
2031 }
2032 }
2033 }
2034
2035 template <typename IP, typename Parent>
2036 using iterator_template_o = decltype(full_iter<IP, Parent>());
2037
2040
2044
2045 static constexpr auto hashes()
2046 {
2047 return []<typename... C>(framework::pack<C...>) { return std::set{{C::hash...}}; }(columns_t{});
2048 }
2049
2050 Table(std::shared_ptr<arrow::Table> table, uint64_t offset = 0)
2051 : mTable(table),
2052 mEnd{table->num_rows()},
2053 mOffset(offset)
2054 {
2055 if (mTable->num_rows() == 0) {
2056 for (size_t ci = 0; ci < framework::pack_size(columns_t{}); ++ci) {
2057 mColumnChunks[ci] = nullptr;
2058 }
2059 mBegin = mEnd;
2060 } else {
2061 auto lookups = [this]<typename... C>(framework::pack<C...>) -> std::array<arrow::ChunkedArray*, framework::pack_size(columns_t{})> { return {lookupColumn<C>()...}; }(columns_t{});
2062 for (size_t ci = 0; ci < framework::pack_size(columns_t{}); ++ci) {
2063 mColumnChunks[ci] = lookups[ci];
2064 }
2065 mBegin = unfiltered_iterator{mColumnChunks, {table->num_rows(), offset}};
2066 mBegin.bindInternalIndices(this);
2067 }
2068 }
2069
2070 Table(std::vector<std::shared_ptr<arrow::Table>>&& tables, uint64_t offset = 0)
2071 requires(ref.origin_hash != "CONC"_h)
2072 : Table(ArrowHelpers::joinTables(std::move(tables), std::span{originalLabels}), offset)
2073 {
2074 }
2075
2076 Table(std::vector<std::shared_ptr<arrow::Table>>&& tables, uint64_t offset = 0)
2077 requires(ref.origin_hash == "CONC"_h)
2078 : Table(ArrowHelpers::concatTables(std::move(tables)), offset)
2079 {
2080 }
2081
2082 template <typename Key>
2083 inline arrow::ChunkedArray* getIndexToKey()
2084 {
2085 constexpr auto map = []<typename... Cs>(framework::pack<Cs...>) {
2086 return std::array<bool, sizeof...(Cs)>{[]() {
2087 if constexpr (requires { Cs::index_targets.size(); }) {
2088 return Key::template isIndexTargetOf<Cs::index_targets.size(), Cs::index_targets>();
2089 } else {
2090 return false;
2091 }
2092 }()...};
2094 constexpr auto pos = std::find(map.begin(), map.end(), true);
2095 if constexpr (pos != map.end()) {
2096 return mColumnChunks[std::distance(map.begin(), pos)];
2097 } else {
2098 static_assert(framework::always_static_assert_v<Key>, "This table does not have an index to given Key");
2099 }
2100 }
2101
2103 {
2104 return mBegin;
2105 }
2106
2107 auto const& cached_begin() const
2108 {
2109 return mBegin;
2110 }
2111
2113 {
2114 return unfiltered_iterator(mBegin);
2115 }
2116
2118 {
2119 return RowViewSentinel{mEnd};
2120 }
2121
2122 filtered_iterator filtered_begin(std::span<int64_t const> selection)
2123 {
2124 // Note that the FilteredIndexPolicy will never outlive the selection which
2125 // is held by the table, so we are safe passing the bare pointer. If it does it
2126 // means that the iterator on a table is outliving the table itself, which is
2127 // a bad idea.
2128 return filtered_iterator(mColumnChunks, {selection, mTable->num_rows(), mOffset});
2129 }
2130
2131 iterator iteratorAt(uint64_t i) const
2132 {
2133 return rawIteratorAt(i);
2134 }
2135
2137 {
2138 auto it = mBegin;
2139 it.setCursor(i);
2140 return it;
2141 }
2142
2144 {
2145 return unfiltered_const_iterator(mBegin);
2146 }
2147
2148 [[nodiscard]] RowViewSentinel end() const
2149 {
2150 return RowViewSentinel{mEnd};
2151 }
2152
2154 [[nodiscard]] std::shared_ptr<arrow::Table> asArrowTable() const
2155 {
2156 return mTable;
2157 }
2159 auto offset() const
2160 {
2161 return mOffset;
2162 }
2164 [[nodiscard]] int64_t size() const
2165 {
2166 return mTable->num_rows();
2167 }
2168
2169 [[nodiscard]] int64_t tableSize() const
2170 {
2171 return size();
2172 }
2173
2176 template <typename... TA>
2177 void bindExternalIndices(TA*... current)
2178 {
2179 mBegin.bindExternalIndices(current...);
2180 }
2181
2182 template <typename I>
2184 {
2185 mBegin.bindInternalIndices(ptr);
2186 }
2187
2192
2193 template <typename... Cs>
2195 {
2196 (static_cast<Cs>(mBegin).setCurrentRaw(binding), ...);
2197 }
2198
2199 void bindExternalIndicesRaw(std::vector<o2::soa::Binding>&& ptrs)
2200 {
2201 mBegin.bindExternalIndicesRaw(std::forward<std::vector<o2::soa::Binding>>(ptrs));
2202 }
2203
2204 template <typename T, typename... Cs>
2206 {
2207 dest.bindExternalIndicesRaw(mBegin.getIndexBindings());
2208 }
2209
2210 template <typename T>
2211 void copyIndexBindings(T& dest) const
2212 {
2214 }
2215
2217 {
2218 auto t = o2::soa::select(*this, f);
2220 return t;
2221 }
2222
2224 {
2225 return doSliceByCached(this, node, value, cache);
2226 }
2227
2232
2233 template <typename T1, typename Policy, bool OPT>
2235 {
2236 return doSliceBy(this, container, value);
2237 }
2238
2239 auto rawSlice(uint64_t start, uint64_t end) const
2240 {
2241 return self_t{mTable->Slice(start, end - start + 1), start};
2242 }
2243
2244 auto emptySlice() const
2245 {
2246 return self_t{mTable->Slice(0, 0), 0};
2247 }
2248
2249 private:
2250 template <typename T>
2251 arrow::ChunkedArray* lookupColumn()
2252 {
2253 if constexpr (soa::is_persistent_column<T>) {
2254 auto label = T::columnLabel();
2255 return getIndexFromLabel(mTable.get(), label);
2256 } else {
2257 return nullptr;
2258 }
2259 }
2260 std::shared_ptr<arrow::Table> mTable = nullptr;
2261 uint64_t mOffset = 0;
2262 // Cached pointers to the ChunkedArray associated to a column
2263 arrow::ChunkedArray* mColumnChunks[framework::pack_size(columns_t{})];
2264 RowViewSentinel mEnd;
2265 iterator mBegin;
2266};
2267
2268template <uint32_t D, soa::is_column... C>
2270
2271void getterNotFound(const char* targetColumnLabel);
2272void emptyColumnLabel();
2273
2274namespace row_helpers
2275{
2276template <typename R, typename T, typename C>
2277R getColumnValue(const T& rowIterator)
2278{
2279 return static_cast<R>(static_cast<C>(rowIterator).get());
2280}
2281
2282namespace
2283{
2284template <typename R, typename T>
2285using ColumnGetterFunction = R (*)(const T&);
2286
2287template <typename T, typename R>
2289 // lambda is callable without additional free args
2290 framework::pack_size(typename T::bindings_t{}) == framework::pack_size(typename T::callable_t::args{}) &&
2291 requires(T t) {
2292 { t.get() } -> std::convertible_to<R>;
2293 };
2294
2295template <typename T, typename R>
2296concept persistent_with_common_getter = is_persistent_v<T> && requires(T t) {
2297 { t.get() } -> std::convertible_to<R>;
2298};
2299
2300template <typename R, typename T, persistent_with_common_getter<R> C>
2301ColumnGetterFunction<R, T> createGetterPtr(const std::string_view& targetColumnLabel)
2302{
2303 return targetColumnLabel == C::columnLabel() ? &getColumnValue<R, T, C> : nullptr;
2304}
2305
2306template <typename R, typename T, dynamic_with_common_getter<R> C>
2307ColumnGetterFunction<R, T> createGetterPtr(const std::string_view& targetColumnLabel)
2308{
2309 std::string_view columnLabel(C::columnLabel());
2310
2311 // allows user to use consistent formatting (with prefix) of all column labels
2312 // by default there isn't 'f' prefix for dynamic column labels
2313 if (targetColumnLabel.starts_with("f") && targetColumnLabel.substr(1) == columnLabel) {
2314 return &getColumnValue<R, T, C>;
2315 }
2316
2317 // check also exact match if user is aware of prefix missing
2318 if (targetColumnLabel == columnLabel) {
2319 return &getColumnValue<R, T, C>;
2320 }
2321
2322 return nullptr;
2323}
2324
2325template <typename R, typename T, typename... Cs>
2326ColumnGetterFunction<R, T> getColumnGetterByLabel(o2::framework::pack<Cs...>, const std::string_view& targetColumnLabel)
2327{
2328 ColumnGetterFunction<R, T> func;
2329
2330 (void)((func = createGetterPtr<R, T, Cs>(targetColumnLabel), func) || ...);
2331
2332 if (!func) {
2333 getterNotFound(targetColumnLabel.data());
2334 }
2335
2336 return func;
2337}
2338
2339template <typename T, typename R>
2340using with_common_getter_t = typename std::conditional<persistent_with_common_getter<T, R> || dynamic_with_common_getter<T, R>, std::true_type, std::false_type>::type;
2341} // namespace
2342
2343template <typename R, typename T>
2344ColumnGetterFunction<R, typename T::iterator> getColumnGetterByLabel(const std::string_view& targetColumnLabel)
2345{
2346 using TypesWithCommonGetter = o2::framework::selected_pack_multicondition<with_common_getter_t, framework::pack<R>, typename T::columns_t>;
2347
2348 if (targetColumnLabel.size() == 0) {
2350 }
2351
2352 return getColumnGetterByLabel<R, typename T::iterator>(TypesWithCommonGetter{}, targetColumnLabel);
2353}
2354} // namespace row_helpers
2355} // namespace o2::soa
2356
2357namespace o2::aod
2358{
2359// If you get an error about not satisfying is_origin_hash, you need to add
2360// an entry here.
2362O2ORIGIN("AOD1");
2363O2ORIGIN("AOD2");
2366O2ORIGIN("ATIM");
2367O2ORIGIN("JOIN");
2368O2HASH("JOIN/0");
2369O2ORIGIN("CONC");
2370O2HASH("CONC/0");
2371O2ORIGIN("TEST");
2372O2HASH("TEST/0");
2373} // namespace o2::aod
2374
2375namespace
2376{
2377template <typename T>
2378consteval static std::string_view namespace_prefix()
2379{
2380 constexpr auto name = o2::framework::type_name<T>();
2381 const auto pos = name.rfind(std::string_view{":"});
2382 return name.substr(0, pos + 1);
2383}
2384} // namespace
2385
2386#define DECLARE_EQUIVALENT_FOR_INDEX(_Base_, _Equiv_) \
2387 template <> \
2388 struct EquivalentIndexNG<o2::aod::Hash<_Base_::ref.desc_hash>, o2::aod::Hash<_Equiv_::ref.desc_hash>> { \
2389 constexpr static bool value = true; \
2390 }
2391
2392#define DECLARE_EQUIVALENT_FOR_INDEX_NG(_Base_, _Equiv_) \
2393 template <> \
2394 struct EquivalentIndexNG<o2::aod::Hash<_Base_ ""_h>, o2::aod::Hash<_Equiv_ ""_h>> { \
2395 constexpr static bool value = true; \
2396 }
2397
2398#define DECLARE_SOA_COLUMN_FULL(_Name_, _Getter_, _Type_, _Label_) \
2399 struct _Name_ : o2::soa::Column<_Type_, _Name_> { \
2400 static constexpr const char* mLabel = _Label_; \
2401 static constexpr const uint32_t hash = compile_time_hash(namespace_prefix<_Name_>(), std::string_view{#_Getter_}); \
2402 static_assert(!((*(mLabel + 1) == 'I' && *(mLabel + 2) == 'n' && *(mLabel + 3) == 'd' && *(mLabel + 4) == 'e' && *(mLabel + 5) == 'x')), "Index is not a valid column name"); \
2403 using base = o2::soa::Column<_Type_, _Name_>; \
2404 using type = _Type_; \
2405 using column_t = _Name_; \
2406 _Name_(arrow::ChunkedArray const* column) \
2407 : o2::soa::Column<_Type_, _Name_>(o2::soa::ColumnIterator<type>(column)) \
2408 { \
2409 } \
2410 \
2411 _Name_() = default; \
2412 _Name_(_Name_ const& other) = default; \
2413 _Name_& operator=(_Name_ const& other) = default; \
2414 \
2415 decltype(auto) _Getter_() const \
2416 { \
2417 return *mColumnIterator; \
2418 } \
2419 \
2420 decltype(auto) get() const \
2421 { \
2422 return _Getter_(); \
2423 } \
2424 }; \
2425 [[maybe_unused]] static constexpr o2::framework::expressions::BindingNode _Getter_ { _Label_, _Name_::hash, o2::framework::expressions::selectArrowType<_Type_>() }
2426
2427#define DECLARE_SOA_CCDB_COLUMN_FULL(_Name_, _Label_, _Getter_, _ConcreteType_, _CCDBQuery_) \
2428 struct _Name_ : o2::soa::Column<std::span<std::byte>, _Name_> { \
2429 static constexpr const char* mLabel = _Label_; \
2430 static constexpr const char* query = _CCDBQuery_; \
2431 static constexpr const uint32_t hash = crc32(namespace_prefix<_Name_>(), std::string_view{#_Getter_}); \
2432 using base = o2::soa::Column<std::span<std::byte>, _Name_>; \
2433 using type = std::span<std::byte>; \
2434 using column_t = _Name_; \
2435 _Name_(arrow::ChunkedArray const* column) \
2436 : o2::soa::Column<std::span<std::byte>, _Name_>(o2::soa::ColumnIterator<std::span<std::byte>>(column)) \
2437 { \
2438 } \
2439 \
2440 _Name_() = default; \
2441 _Name_(_Name_ const& other) = default; \
2442 _Name_& operator=(_Name_ const& other) = default; \
2443 \
2444 decltype(auto) _Getter_() const \
2445 { \
2446 static std::byte* payload = nullptr; \
2447 static _ConcreteType_* deserialised = nullptr; \
2448 static TClass* c = TClass::GetClass(#_ConcreteType_); \
2449 auto span = *mColumnIterator; \
2450 if (payload != (std::byte*)span.data()) { \
2451 payload = (std::byte*)span.data(); \
2452 delete deserialised; \
2453 TBufferFile f(TBufferFile::EMode::kRead, span.size(), (char*)span.data(), kFALSE); \
2454 deserialised = (_ConcreteType_*)soa::extractCCDBPayload((char*)payload, span.size(), c, "ccdb_object"); \
2455 } \
2456 return *deserialised; \
2457 } \
2458 \
2459 decltype(auto) \
2460 get() const \
2461 { \
2462 return _Getter_(); \
2463 } \
2464 };
2465
2466#define DECLARE_SOA_CCDB_COLUMN(_Name_, _Getter_, _ConcreteType_, _CCDBQuery_) \
2467 DECLARE_SOA_CCDB_COLUMN_FULL(_Name_, "f" #_Name_, _Getter_, _ConcreteType_, _CCDBQuery_)
2468
2469#define DECLARE_SOA_COLUMN(_Name_, _Getter_, _Type_) \
2470 DECLARE_SOA_COLUMN_FULL(_Name_, _Getter_, _Type_, "f" #_Name_)
2471
2474#define MAKEINT(_Size_) uint##_Size_##_t
2475
2476#define DECLARE_SOA_BITMAP_COLUMN_FULL(_Name_, _Getter_, _Size_, _Label_) \
2477 struct _Name_ : o2::soa::Column<MAKEINT(_Size_), _Name_> { \
2478 static constexpr const char* mLabel = _Label_; \
2479 static constexpr const uint32_t hash = compile_time_hash(namespace_prefix<_Name_>(), std::string_view{#_Getter_}); \
2480 static_assert(!((*(mLabel + 1) == 'I' && *(mLabel + 2) == 'n' && *(mLabel + 3) == 'd' && *(mLabel + 4) == 'e' && *(mLabel + 5) == 'x')), "Index is not a valid column name"); \
2481 using base = o2::soa::Column<MAKEINT(_Size_), _Name_>; \
2482 using type = MAKEINT(_Size_); \
2483 _Name_(arrow::ChunkedArray const* column) \
2484 : o2::soa::Column<type, _Name_>(o2::soa::ColumnIterator<type>(column)) \
2485 { \
2486 } \
2487 \
2488 _Name_() = default; \
2489 _Name_(_Name_ const& other) = default; \
2490 _Name_& operator=(_Name_ const& other) = default; \
2491 \
2492 decltype(auto) _Getter_##_raw() const \
2493 { \
2494 return *mColumnIterator; \
2495 } \
2496 \
2497 bool _Getter_##_bit(int bit) const \
2498 { \
2499 return (*mColumnIterator & (static_cast<type>(1) << bit)) >> bit; \
2500 } \
2501 }; \
2502 [[maybe_unused]] static constexpr o2::framework::expressions::BindingNode _Getter_ { _Label_, _Name_::hash, o2::framework::expressions::selectArrowType<MAKEINT(_Size_)>() }
2503
2504#define DECLARE_SOA_BITMAP_COLUMN(_Name_, _Getter_, _Size_) \
2505 DECLARE_SOA_BITMAP_COLUMN_FULL(_Name_, _Getter_, _Size_, "f" #_Name_)
2506
2509#define DECLARE_SOA_EXPRESSION_COLUMN_FULL(_Name_, _Getter_, _Type_, _Label_, _Expression_) \
2510 struct _Name_ : o2::soa::Column<_Type_, _Name_> { \
2511 static constexpr const char* mLabel = _Label_; \
2512 static constexpr const uint32_t hash = compile_time_hash(namespace_prefix<_Name_>(), std::string_view{#_Getter_}); \
2513 using base = o2::soa::Column<_Type_, _Name_>; \
2514 using type = _Type_; \
2515 using column_t = _Name_; \
2516 using spawnable_t = std::true_type; \
2517 _Name_(arrow::ChunkedArray const* column) \
2518 : o2::soa::Column<_Type_, _Name_>(o2::soa::ColumnIterator<type>(column)) \
2519 { \
2520 } \
2521 \
2522 _Name_() = default; \
2523 _Name_(_Name_ const& other) = default; \
2524 _Name_& operator=(_Name_ const& other) = default; \
2525 \
2526 decltype(auto) _Getter_() const \
2527 { \
2528 return *mColumnIterator; \
2529 } \
2530 \
2531 decltype(auto) get() const \
2532 { \
2533 return _Getter_(); \
2534 } \
2535 \
2536 static o2::framework::expressions::Projector Projector() \
2537 { \
2538 return _Expression_; \
2539 } \
2540 }; \
2541 [[maybe_unused]] static constexpr o2::framework::expressions::BindingNode _Getter_ { _Label_, _Name_::hash, o2::framework::expressions::selectArrowType<_Type_>() }
2542
2543#define DECLARE_SOA_EXPRESSION_COLUMN(_Name_, _Getter_, _Type_, _Expression_) \
2544 DECLARE_SOA_EXPRESSION_COLUMN_FULL(_Name_, _Getter_, _Type_, "f" #_Name_, _Expression_);
2545
2548#define DECLARE_SOA_CONFIGURABLE_EXPRESSION_COLUMN(_Name_, _Getter_, _Type_, _Label_) \
2549 struct _Name_ : o2::soa::Column<_Type_, _Name_> { \
2550 static constexpr const char* mLabel = _Label_; \
2551 static constexpr const uint32_t hash = compile_time_hash(namespace_prefix<_Name_>(), std::string_view{#_Getter_}); \
2552 static constexpr const int32_t mHash = _Label_ ""_h; \
2553 using base = o2::soa::Column<_Type_, _Name_>; \
2554 using type = _Type_; \
2555 using column_t = _Name_; \
2556 using spawnable_t = std::true_type; \
2557 _Name_(arrow::ChunkedArray const* column) \
2558 : o2::soa::Column<_Type_, _Name_>(o2::soa::ColumnIterator<type>(column)) \
2559 { \
2560 } \
2561 \
2562 _Name_() = default; \
2563 _Name_(_Name_ const& other) = default; \
2564 _Name_& operator=(_Name_ const& other) = default; \
2565 \
2566 decltype(auto) _Getter_() const \
2567 { \
2568 return *mColumnIterator; \
2569 } \
2570 \
2571 decltype(auto) get() const \
2572 { \
2573 return _Getter_(); \
2574 } \
2575 }; \
2576 [[maybe_unused]] static constexpr o2::framework::expressions::BindingNode _Getter_ { _Label_, _Name_::hash, o2::framework::expressions::selectArrowType<_Type_>() }
2577
2596
2598
2599template <o2::soa::is_table T>
2600consteval auto getIndexTargets()
2601{
2602 return T::originals;
2603}
2604
2605#define DECLARE_SOA_SLICE_INDEX_COLUMN_FULL_CUSTOM(_Name_, _Getter_, _Type_, _Table_, _Label_, _Suffix_) \
2606 struct _Name_##IdSlice : o2::soa::Column<_Type_[2], _Name_##IdSlice> { \
2607 static_assert(std::is_integral_v<_Type_>, "Index type must be integral"); \
2608 static_assert((*_Suffix_ == '\0') || (*_Suffix_ == '_'), "Suffix has to begin with _"); \
2609 static constexpr const char* mLabel = "fIndexSlice" _Label_ _Suffix_; \
2610 static constexpr const uint32_t hash = 0; \
2611 using base = o2::soa::Column<_Type_[2], _Name_##IdSlice>; \
2612 using type = _Type_[2]; \
2613 using column_t = _Name_##IdSlice; \
2614 using binding_t = _Table_; \
2615 static constexpr auto index_targets = getIndexTargets<_Table_>(); \
2616 _Name_##IdSlice(arrow::ChunkedArray const* column) \
2617 : o2::soa::Column<_Type_[2], _Name_##IdSlice>(o2::soa::ColumnIterator<type>(column)) \
2618 { \
2619 } \
2620 \
2621 _Name_##IdSlice() = default; \
2622 _Name_##IdSlice(_Name_##IdSlice const& other) = default; \
2623 _Name_##IdSlice& operator=(_Name_##IdSlice const& other) = default; \
2624 std::array<_Type_, 2> inline getIds() const \
2625 { \
2626 return _Getter_##Ids(); \
2627 } \
2628 \
2629 bool has_##_Getter_() const \
2630 { \
2631 auto a = *mColumnIterator; \
2632 return a[0] >= 0 && a[1] >= 0; \
2633 } \
2634 \
2635 std::array<_Type_, 2> _Getter_##Ids() const \
2636 { \
2637 auto a = *mColumnIterator; \
2638 return std::array{a[0], a[1]}; \
2639 } \
2640 \
2641 template <typename T> \
2642 auto _Getter_##_as() const \
2643 { \
2644 if (O2_BUILTIN_UNLIKELY(mBinding.ptr == nullptr)) { \
2645 o2::soa::notBoundTable(#_Table_); \
2646 } \
2647 auto t = mBinding.get<T>(); \
2648 if (O2_BUILTIN_UNLIKELY(t == nullptr)) { \
2649 o2::soa::dereferenceWithWrongType(#_Getter_, #_Table_); \
2650 } \
2651 if (O2_BUILTIN_UNLIKELY(!has_##_Getter_())) { \
2652 return t->emptySlice(); \
2653 } \
2654 auto a = *mColumnIterator; \
2655 auto r = t->rawSlice(a[0], a[1]); \
2656 t->copyIndexBindings(r); \
2657 r.bindInternalIndicesTo(t); \
2658 return r; \
2659 } \
2660 \
2661 auto _Getter_() const \
2662 { \
2663 return _Getter_##_as<binding_t>(); \
2664 } \
2665 \
2666 template <typename T> \
2667 bool setCurrent(T const* current) \
2668 { \
2669 if constexpr (o2::soa::is_binding_compatible_v<T, binding_t>()) { \
2670 assert(current != nullptr); \
2671 this->mBinding.bind(current); \
2672 return true; \
2673 } \
2674 return false; \
2675 } \
2676 \
2677 bool setCurrentRaw(o2::soa::Binding current) \
2678 { \
2679 this->mBinding = current; \
2680 return true; \
2681 } \
2682 binding_t const* getCurrent() const { return mBinding.get<binding_t>(); } \
2683 o2::soa::Binding getCurrentRaw() const { return mBinding; } \
2684 o2::soa::Binding mBinding; \
2685 };
2686
2687#define DECLARE_SOA_SLICE_INDEX_COLUMN_FULL(_Name_, _Getter_, _Type_, _Table_, _Suffix_) DECLARE_SOA_SLICE_INDEX_COLUMN_FULL_CUSTOM(_Name_, _Getter_, _Type_, _Table_, #_Table_, _Suffix_)
2688#define DECLARE_SOA_SLICE_INDEX_COLUMN(_Name_, _Getter_) DECLARE_SOA_SLICE_INDEX_COLUMN_FULL(_Name_, _Getter_, int32_t, _Name_##s, "")
2689#define DECLARE_SOA_SLICE_INDEX_COLUMN_CUSTOM(_Name_, _Getter_, _Label_) DECLARE_SOA_SLICE_INDEX_COLUMN_FULL_CUSTOM(_Name_, _Getter_, int32_t, _Name_##s, _Label_, "")
2690
2692#define DECLARE_SOA_ARRAY_INDEX_COLUMN_FULL_CUSTOM(_Name_, _Getter_, _Type_, _Table_, _Label_, _Suffix_) \
2693 struct _Name_##Ids : o2::soa::Column<std::vector<_Type_>, _Name_##Ids> { \
2694 static_assert(std::is_integral_v<_Type_>, "Index type must be integral"); \
2695 static_assert((*_Suffix_ == '\0') || (*_Suffix_ == '_'), "Suffix has to begin with _"); \
2696 static constexpr const char* mLabel = "fIndexArray" _Label_ _Suffix_; \
2697 static constexpr const uint32_t hash = 0; \
2698 using base = o2::soa::Column<std::vector<_Type_>, _Name_##Ids>; \
2699 using type = std::vector<_Type_>; \
2700 using column_t = _Name_##Ids; \
2701 using binding_t = _Table_; \
2702 static constexpr auto index_targets = getIndexTargets<_Table_>(); \
2703 _Name_##Ids(arrow::ChunkedArray const* column) \
2704 : o2::soa::Column<std::vector<_Type_>, _Name_##Ids>(o2::soa::ColumnIterator<type>(column)) \
2705 { \
2706 } \
2707 \
2708 _Name_##Ids() = default; \
2709 _Name_##Ids(_Name_##Ids const& other) = default; \
2710 _Name_##Ids& operator=(_Name_##Ids const& other) = default; \
2711 \
2712 gsl::span<const _Type_> inline getIds() const \
2713 { \
2714 return _Getter_##Ids(); \
2715 } \
2716 \
2717 gsl::span<const _Type_> _Getter_##Ids() const \
2718 { \
2719 return *mColumnIterator; \
2720 } \
2721 \
2722 bool has_##_Getter_() const \
2723 { \
2724 return !(*mColumnIterator).empty(); \
2725 } \
2726 \
2727 template <typename T> \
2728 auto _Getter_##_as() const \
2729 { \
2730 if (O2_BUILTIN_UNLIKELY(mBinding.ptr == nullptr)) { \
2731 o2::soa::notBoundTable(#_Table_); \
2732 } \
2733 auto t = mBinding.get<T>(); \
2734 if (O2_BUILTIN_UNLIKELY(t == nullptr)) { \
2735 o2::soa::dereferenceWithWrongType(#_Getter_, #_Table_); \
2736 } \
2737 return getIterators<T>(); \
2738 } \
2739 \
2740 template <typename T> \
2741 auto filtered_##_Getter_##_as() const \
2742 { \
2743 if (O2_BUILTIN_UNLIKELY(mBinding.ptr == nullptr)) { \
2744 o2::soa::notBoundTable(#_Table_); \
2745 } \
2746 auto t = mBinding.get<T>(); \
2747 if (O2_BUILTIN_UNLIKELY(t == nullptr)) { \
2748 o2::soa::dereferenceWithWrongType(#_Getter_, #_Table_); \
2749 } \
2750 return getFilteredIterators<T>(); \
2751 } \
2752 \
2753 template <typename T> \
2754 auto getIterators() const \
2755 { \
2756 auto result = std::vector<typename T::unfiltered_iterator>(); \
2757 for (auto& i : *mColumnIterator) { \
2758 result.push_back(mBinding.get<T>()->rawIteratorAt(i)); \
2759 } \
2760 return result; \
2761 } \
2762 \
2763 template <typename T> \
2764 std::vector<typename T::iterator> getFilteredIterators() const \
2765 { \
2766 if constexpr (o2::soa::is_filtered_table<T>) { \
2767 auto result = std::vector<typename T::iterator>(); \
2768 for (auto const& i : *mColumnIterator) { \
2769 auto pos = mBinding.get<T>()->isInSelectedRows(i); \
2770 if (pos > 0) { \
2771 result.emplace_back(mBinding.get<T>()->iteratorAt(pos)); \
2772 } \
2773 } \
2774 return result; \
2775 } else { \
2776 static_assert(o2::framework::always_static_assert_v<T>, "T is not a Filtered type"); \
2777 } \
2778 return {}; \
2779 } \
2780 \
2781 auto _Getter_() const \
2782 { \
2783 return _Getter_##_as<binding_t>(); \
2784 } \
2785 \
2786 template <typename T> \
2787 auto _Getter_##_first_as() const \
2788 { \
2789 if (O2_BUILTIN_UNLIKELY(mBinding.ptr == nullptr)) { \
2790 o2::soa::notBoundTable(#_Table_); \
2791 } \
2792 auto t = mBinding.get<T>(); \
2793 if (O2_BUILTIN_UNLIKELY(t == nullptr)) { \
2794 o2::soa::dereferenceWithWrongType(#_Getter_, #_Table_); \
2795 } \
2796 return t->rawIteratorAt((*mColumnIterator)[0]); \
2797 } \
2798 \
2799 template <typename T> \
2800 auto _Getter_##_last_as() const \
2801 { \
2802 if (O2_BUILTIN_UNLIKELY(mBinding.ptr == nullptr)) { \
2803 o2::soa::notBoundTable(#_Table_); \
2804 } \
2805 auto t = mBinding.get<T>(); \
2806 if (O2_BUILTIN_UNLIKELY(t == nullptr)) { \
2807 o2::soa::dereferenceWithWrongType(#_Getter_, #_Table_); \
2808 } \
2809 return t->rawIteratorAt((*mColumnIterator).back()); \
2810 } \
2811 \
2812 auto _Getter_first() const \
2813 { \
2814 return _Getter_##_first_as<binding_t>(); \
2815 } \
2816 \
2817 auto _Getter_last() const \
2818 { \
2819 return _Getter_##_last_as<binding_t>(); \
2820 } \
2821 \
2822 template <typename T> \
2823 bool setCurrent(T const* current) \
2824 { \
2825 if constexpr (o2::soa::is_binding_compatible_v<T, binding_t>()) { \
2826 assert(current != nullptr); \
2827 this->mBinding.bind(current); \
2828 return true; \
2829 } \
2830 return false; \
2831 } \
2832 \
2833 bool setCurrentRaw(o2::soa::Binding current) \
2834 { \
2835 this->mBinding = current; \
2836 return true; \
2837 } \
2838 binding_t const* getCurrent() const { return mBinding.get<binding_t>(); } \
2839 o2::soa::Binding getCurrentRaw() const { return mBinding; } \
2840 o2::soa::Binding mBinding; \
2841 };
2842
2843#define DECLARE_SOA_ARRAY_INDEX_COLUMN_FULL(_Name_, _Getter_, _Type_, _Table_, _Suffix_) DECLARE_SOA_ARRAY_INDEX_COLUMN_FULL_CUSTOM(_Name_, _Getter_, _Type_, _Table_, #_Table_, _Suffix_)
2844#define DECLARE_SOA_ARRAY_INDEX_COLUMN(_Name_, _Getter_) DECLARE_SOA_ARRAY_INDEX_COLUMN_FULL(_Name_, _Getter_, int32_t, _Name_##s, "")
2845#define DECLARE_SOA_ARRAY_INDEX_COLUMN_CUSTOM(_Name_, _Getter_, _Label_) DECLARE_SOA_ARRAY_INDEX_COLUMN_FULL_CUSTOM(_Name_, _Getter_, int32_t, _Name_##s, _Label_, "")
2846
2848#define DECLARE_SOA_INDEX_COLUMN_FULL_CUSTOM(_Name_, _Getter_, _Type_, _Table_, _Label_, _Suffix_) \
2849 struct _Name_##Id : o2::soa::Column<_Type_, _Name_##Id> { \
2850 static_assert(std::is_integral_v<_Type_>, "Index type must be integral"); \
2851 static_assert((*_Suffix_ == '\0') || (*_Suffix_ == '_'), "Suffix has to begin with _"); \
2852 static constexpr const char* mLabel = "fIndex" _Label_ _Suffix_; \
2853 static constexpr const uint32_t hash = compile_time_hash(namespace_prefix<_Name_##Id>(), std::string_view{#_Getter_ "Id"}); \
2854 using base = o2::soa::Column<_Type_, _Name_##Id>; \
2855 using type = _Type_; \
2856 using column_t = _Name_##Id; \
2857 using binding_t = _Table_; \
2858 static constexpr auto index_targets = getIndexTargets<_Table_>(); \
2859 _Name_##Id(arrow::ChunkedArray const* column) \
2860 : o2::soa::Column<_Type_, _Name_##Id>(o2::soa::ColumnIterator<type>(column)) \
2861 { \
2862 } \
2863 \
2864 _Name_##Id() = default; \
2865 _Name_##Id(_Name_##Id const& other) = default; \
2866 _Name_##Id& operator=(_Name_##Id const& other) = default; \
2867 type inline getId() const \
2868 { \
2869 return _Getter_##Id(); \
2870 } \
2871 \
2872 type _Getter_##Id() const \
2873 { \
2874 return *mColumnIterator; \
2875 } \
2876 \
2877 bool has_##_Getter_() const \
2878 { \
2879 return *mColumnIterator >= 0; \
2880 } \
2881 \
2882 template <typename T> \
2883 auto _Getter_##_as() const \
2884 { \
2885 if (O2_BUILTIN_UNLIKELY(mBinding.ptr == nullptr)) { \
2886 o2::soa::notBoundTable(#_Table_); \
2887 } \
2888 if (O2_BUILTIN_UNLIKELY(!has_##_Getter_())) { \
2889 o2::soa::accessingInvalidIndexFor(#_Getter_); \
2890 } \
2891 auto t = mBinding.get<T>(); \
2892 if (O2_BUILTIN_UNLIKELY(t == nullptr)) { \
2893 o2::soa::dereferenceWithWrongType(#_Getter_, #_Table_); \
2894 } \
2895 return t->rawIteratorAt(*mColumnIterator); \
2896 } \
2897 \
2898 auto _Getter_() const \
2899 { \
2900 return _Getter_##_as<binding_t>(); \
2901 } \
2902 \
2903 template <typename T> \
2904 bool setCurrent(T* current) \
2905 { \
2906 if constexpr (o2::soa::is_binding_compatible_v<T, binding_t>()) { \
2907 assert(current != nullptr); \
2908 this->mBinding.bind(current); \
2909 return true; \
2910 } \
2911 return false; \
2912 } \
2913 \
2914 bool setCurrentRaw(o2::soa::Binding current) \
2915 { \
2916 this->mBinding = current; \
2917 return true; \
2918 } \
2919 binding_t const* getCurrent() const { return mBinding.get<binding_t>(); } \
2920 o2::soa::Binding getCurrentRaw() const { return mBinding; } \
2921 o2::soa::Binding mBinding; \
2922 }; \
2923 [[maybe_unused]] static constexpr o2::framework::expressions::BindingNode _Getter_##Id { "fIndex" _Label_ _Suffix_, _Name_##Id::hash, o2::framework::expressions::selectArrowType<_Type_>() }
2924
2925#define DECLARE_SOA_INDEX_COLUMN_FULL(_Name_, _Getter_, _Type_, _Table_, _Suffix_) DECLARE_SOA_INDEX_COLUMN_FULL_CUSTOM(_Name_, _Getter_, _Type_, _Table_, #_Table_, _Suffix_)
2926#define DECLARE_SOA_INDEX_COLUMN(_Name_, _Getter_) DECLARE_SOA_INDEX_COLUMN_FULL(_Name_, _Getter_, int32_t, _Name_##s, "")
2927#define DECLARE_SOA_INDEX_COLUMN_CUSTOM(_Name_, _Getter_, _Label_) DECLARE_SOA_INDEX_COLUMN_FULL_CUSTOM(_Name_, _Getter_, int32_t, _Name_##s, _Label_, "")
2928
2930#define DECLARE_SOA_SELF_INDEX_COLUMN_COMPLETE(_Name_, _Getter_, _Type_, _Label_, _IndexTarget_) \
2931 struct _Name_##Id : o2::soa::Column<_Type_, _Name_##Id> { \
2932 static_assert(std::is_integral_v<_Type_>, "Index type must be integral"); \
2933 static constexpr const char* mLabel = "fIndex" _Label_; \
2934 static constexpr const uint32_t hash = compile_time_hash(namespace_prefix<_Name_##Id>(), std::string_view{#_Getter_ "Id"}); \
2935 using base = o2::soa::Column<_Type_, _Name_##Id>; \
2936 using type = _Type_; \
2937 using column_t = _Name_##Id; \
2938 using self_index_t = std::true_type; \
2939 using compatible_signature = std::conditional<aod::is_aod_hash<_IndexTarget_>, _IndexTarget_, void>; \
2940 _Name_##Id(arrow::ChunkedArray const* column) \
2941 : o2::soa::Column<_Type_, _Name_##Id>(o2::soa::ColumnIterator<type>(column)) \
2942 { \
2943 } \
2944 \
2945 _Name_##Id() = default; \
2946 _Name_##Id(_Name_##Id const& other) = default; \
2947 _Name_##Id& operator=(_Name_##Id const& other) = default; \
2948 type inline getId() const \
2949 { \
2950 return _Getter_##Id(); \
2951 } \
2952 \
2953 type _Getter_##Id() const \
2954 { \
2955 return *mColumnIterator; \
2956 } \
2957 \
2958 bool has_##_Getter_() const \
2959 { \
2960 return *mColumnIterator >= 0; \
2961 } \
2962 \
2963 template <typename T> \
2964 auto _Getter_##_as() const \
2965 { \
2966 if (O2_BUILTIN_UNLIKELY(!has_##_Getter_())) { \
2967 o2::soa::accessingInvalidIndexFor(#_Getter_); \
2968 } \
2969 auto t = mBinding.get<T>(); \
2970 if (O2_BUILTIN_UNLIKELY(t == nullptr)) { \
2971 o2::soa::dereferenceWithWrongType(#_Getter_, "self"); \
2972 } \
2973 return t->rawIteratorAt(*mColumnIterator); \
2974 } \
2975 \
2976 bool setCurrentRaw(o2::soa::Binding current) \
2977 { \
2978 this->mBinding = current; \
2979 return true; \
2980 } \
2981 o2::soa::Binding getCurrentRaw() const { return mBinding; } \
2982 o2::soa::Binding mBinding; \
2983 }; \
2984 [[maybe_unused]] static constexpr o2::framework::expressions::BindingNode _Getter_##Id { "fIndex" _Label_, _Name_##Id::hash, o2::framework::expressions::selectArrowType<_Type_>() }
2985
2986#define DECLARE_SOA_SELF_INDEX_COLUMN_FULL(_Name_, _Getter_, _Type_, _Label_) DECLARE_SOA_SELF_INDEX_COLUMN_COMPLETE(_Name_, _Getter_, _Type_, _Label_, void)
2987#define DECLARE_SOA_SELF_INDEX_COLUMN(_Name_, _Getter_) DECLARE_SOA_SELF_INDEX_COLUMN_FULL(_Name_, _Getter_, int32_t, #_Name_)
2989#define DECLARE_SOA_SELF_SLICE_INDEX_COLUMN_COMPLETE(_Name_, _Getter_, _Type_, _Label_, _IndexTarget_) \
2990 struct _Name_##IdSlice : o2::soa::Column<_Type_[2], _Name_##IdSlice> { \
2991 static_assert(std::is_integral_v<_Type_>, "Index type must be integral"); \
2992 static constexpr const char* mLabel = "fIndexSlice" _Label_; \
2993 static constexpr const uint32_t hash = 0; \
2994 using base = o2::soa::Column<_Type_[2], _Name_##IdSlice>; \
2995 using type = _Type_[2]; \
2996 using column_t = _Name_##IdSlice; \
2997 using self_index_t = std::true_type; \
2998 using compatible_signature = std::conditional<aod::is_aod_hash<_IndexTarget_>, _IndexTarget_, void>; \
2999 _Name_##IdSlice(arrow::ChunkedArray const* column) \
3000 : o2::soa::Column<_Type_[2], _Name_##IdSlice>(o2::soa::ColumnIterator<type>(column)) \
3001 { \
3002 } \
3003 \
3004 _Name_##IdSlice() = default; \
3005 _Name_##IdSlice(_Name_##IdSlice const& other) = default; \
3006 _Name_##IdSlice& operator=(_Name_##IdSlice const& other) = default; \
3007 std::array<_Type_, 2> inline getIds() const \
3008 { \
3009 return _Getter_##Ids(); \
3010 } \
3011 \
3012 bool has_##_Getter_() const \
3013 { \
3014 auto a = *mColumnIterator; \
3015 return a[0] >= 0 && a[1] >= 0; \
3016 } \
3017 \
3018 std::array<_Type_, 2> _Getter_##Ids() const \
3019 { \
3020 auto a = *mColumnIterator; \
3021 return std::array{a[0], a[1]}; \
3022 } \
3023 \
3024 template <typename T> \
3025 auto _Getter_##_as() const \
3026 { \
3027 auto t = mBinding.get<T>(); \
3028 if (O2_BUILTIN_UNLIKELY(t == nullptr)) { \
3029 o2::soa::dereferenceWithWrongType(#_Getter_, "self"); \
3030 } \
3031 if (O2_BUILTIN_UNLIKELY(!has_##_Getter_())) { \
3032 return t->emptySlice(); \
3033 } \
3034 auto a = *mColumnIterator; \
3035 auto r = t->rawSlice(a[0], a[1]); \
3036 t->copyIndexBindings(r); \
3037 r.bindInternalIndicesTo(t); \
3038 return r; \
3039 } \
3040 \
3041 bool setCurrentRaw(o2::soa::Binding current) \
3042 { \
3043 this->mBinding = current; \
3044 return true; \
3045 } \
3046 o2::soa::Binding getCurrentRaw() const { return mBinding; } \
3047 o2::soa::Binding mBinding; \
3048 };
3049
3050#define DECLARE_SOA_SELF_SLICE_INDEX_COLUMN_FULL(_Name_, _Getter_, _Type_, _Label_) DECLARE_SOA_SELF_SLICE_INDEX_COLUMN_COMPLETE(_Name_, _Getter_, _Type_, _Label_, void)
3051#define DECLARE_SOA_SELF_SLICE_INDEX_COLUMN(_Name_, _Getter_) DECLARE_SOA_SELF_SLICE_INDEX_COLUMN_FULL(_Name_, _Getter_, int32_t, "_" #_Name_)
3053#define DECLARE_SOA_SELF_ARRAY_INDEX_COLUMN_COMPLETE(_Name_, _Getter_, _Type_, _Label_, _IndexTarget_) \
3054 struct _Name_##Ids : o2::soa::Column<std::vector<_Type_>, _Name_##Ids> { \
3055 static_assert(std::is_integral_v<_Type_>, "Index type must be integral"); \
3056 static constexpr const char* mLabel = "fIndexArray" _Label_; \
3057 static constexpr const uint32_t hash = 0; \
3058 using base = o2::soa::Column<std::vector<_Type_>, _Name_##Ids>; \
3059 using type = std::vector<_Type_>; \
3060 using column_t = _Name_##Ids; \
3061 using self_index_t = std::true_type; \
3062 using compatible_signature = std::conditional<aod::is_aod_hash<_IndexTarget_>, _IndexTarget_, void>; \
3063 _Name_##Ids(arrow::ChunkedArray const* column) \
3064 : o2::soa::Column<std::vector<_Type_>, _Name_##Ids>(o2::soa::ColumnIterator<type>(column)) \
3065 { \
3066 } \
3067 \
3068 _Name_##Ids() = default; \
3069 _Name_##Ids(_Name_##Ids const& other) = default; \
3070 _Name_##Ids& operator=(_Name_##Ids const& other) = default; \
3071 gsl::span<const _Type_> inline getIds() const \
3072 { \
3073 return _Getter_##Ids(); \
3074 } \
3075 \
3076 gsl::span<const _Type_> _Getter_##Ids() const \
3077 { \
3078 return *mColumnIterator; \
3079 } \
3080 \
3081 bool has_##_Getter_() const \
3082 { \
3083 return !(*mColumnIterator).empty(); \
3084 } \
3085 \
3086 template <typename T> \
3087 auto _Getter_##_as() const \
3088 { \
3089 auto t = mBinding.get<T>(); \
3090 if (O2_BUILTIN_UNLIKELY(t == nullptr)) { \
3091 o2::soa::dereferenceWithWrongType(#_Getter_, "self"); \
3092 } \
3093 return getIterators<T>(); \
3094 } \
3095 \
3096 template <typename T> \
3097 auto getIterators() const \
3098 { \
3099 auto result = std::vector<typename T::unfiltered_iterator>(); \
3100 for (auto& i : *mColumnIterator) { \
3101 result.push_back(mBinding.get<T>()->rawIteratorAt(i)); \
3102 } \
3103 return result; \
3104 } \
3105 \
3106 template <typename T> \
3107 auto _Getter_##_first_as() const \
3108 { \
3109 return mBinding.get<T>()->rawIteratorAt((*mColumnIterator)[0]); \
3110 } \
3111 \
3112 template <typename T> \
3113 auto _Getter_##_last_as() const \
3114 { \
3115 return mBinding.get<T>()->rawIteratorAt((*mColumnIterator).back()); \
3116 } \
3117 \
3118 bool setCurrentRaw(o2::soa::Binding current) \
3119 { \
3120 this->mBinding = current; \
3121 return true; \
3122 } \
3123 o2::soa::Binding getCurrentRaw() const { return mBinding; } \
3124 o2::soa::Binding mBinding; \
3125 };
3126
3127#define DECLARE_SOA_SELF_ARRAY_INDEX_COLUMN_FULL(_Name_, _Getter_, _Type_, _Label_) DECLARE_SOA_SELF_ARRAY_INDEX_COLUMN_COMPLETE(_Name_, _Getter_, _Type_, _Label_, void)
3128#define DECLARE_SOA_SELF_ARRAY_INDEX_COLUMN(_Name_, _Getter_) DECLARE_SOA_SELF_ARRAY_INDEX_COLUMN_FULL(_Name_, _Getter_, int32_t, "_" #_Name_)
3129
3158#define DECLARE_SOA_DYNAMIC_COLUMN(_Name_, _Getter_, ...) \
3159 struct _Name_##Callback { \
3160 static inline constexpr auto getLambda() { return __VA_ARGS__; } \
3161 }; \
3162 \
3163 struct _Name_##Helper { \
3164 using callable_t = decltype(o2::framework::FunctionMetadata(std::declval<decltype(_Name_##Callback::getLambda())>())); \
3165 using return_type = typename callable_t::return_type; \
3166 }; \
3167 template <typename... Bindings> \
3168 struct _Name_ : o2::soa::DynamicColumn<typename _Name_##Helper::callable_t::type, _Name_<Bindings...>> { \
3169 using base = o2::soa::DynamicColumn<typename _Name_##Helper::callable_t::type, _Name_<Bindings...>>; \
3170 using helper = _Name_##Helper; \
3171 using callback_holder_t = _Name_##Callback; \
3172 using callable_t = helper::callable_t; \
3173 using callback_t = callable_t::type; \
3174 static constexpr const uint32_t hash = 0; \
3175 \
3176 _Name_(arrow::ChunkedArray const*) \
3177 { \
3178 } \
3179 _Name_() = default; \
3180 _Name_(_Name_ const& other) = default; \
3181 _Name_& operator=(_Name_ const& other) = default; \
3182 static constexpr const char* mLabel = #_Name_; \
3183 using type = typename callable_t::return_type; \
3184 \
3185 template <typename... FreeArgs> \
3186 type _Getter_(FreeArgs... freeArgs) const \
3187 { \
3188 return boundGetter(std::make_index_sequence<std::tuple_size_v<decltype(boundIterators)>>{}, freeArgs...); \
3189 } \
3190 template <typename... FreeArgs> \
3191 type getDynamicValue(FreeArgs... freeArgs) const \
3192 { \
3193 return boundGetter(std::make_index_sequence<std::tuple_size_v<decltype(boundIterators)>>{}, freeArgs...); \
3194 } \
3195 \
3196 type get() const \
3197 { \
3198 return _Getter_(); \
3199 } \
3200 \
3201 template <size_t... Is, typename... FreeArgs> \
3202 type boundGetter(std::integer_sequence<size_t, Is...>&&, FreeArgs... freeArgs) const \
3203 { \
3204 return __VA_ARGS__((**std::get<Is>(boundIterators))..., freeArgs...); \
3205 } \
3206 \
3207 using bindings_t = typename o2::framework::pack<Bindings...>; \
3208 std::tuple<o2::soa::ColumnIterator<typename Bindings::type> const*...> boundIterators; \
3209 }
3210
3211#define DECLARE_SOA_TABLE_METADATA(_Name_, _Desc_, _Version_, ...) \
3212 using _Name_##Metadata = TableMetadata<Hash<_Desc_ "/" #_Version_ ""_h>, __VA_ARGS__>;
3213
3214#define DECLARE_SOA_TABLE_METADATA_TRAIT(_Name_, _Desc_, _Version_) \
3215 template <> \
3216 struct MetadataTrait<Hash<_Desc_ "/" #_Version_ ""_h>> { \
3217 using metadata = _Name_##Metadata; \
3218 };
3219
3220#define DECLARE_SOA_TABLE_FULL_VERSIONED_(_Name_, _Label_, _Origin_, _Desc_, _Version_) \
3221 O2HASH(_Desc_ "/" #_Version_); \
3222 template <typename O> \
3223 using _Name_##From = o2::soa::Table<Hash<_Label_ ""_h>, Hash<_Desc_ "/" #_Version_ ""_h>, O>; \
3224 using _Name_ = _Name_##From<Hash<_Origin_ ""_h>>; \
3225 template <> \
3226 struct MetadataTrait<Hash<_Desc_ "/" #_Version_ ""_h>> { \
3227 using metadata = _Name_##Metadata; \
3228 };
3229
3230#define DECLARE_SOA_STAGE(_Name_, _Origin_, _Desc_, _Version_) \
3231 template <typename O> \
3232 using _Name_##From = o2::soa::Table<Hash<#_Name_ ""_h>, Hash<_Desc_ "/" #_Version_ ""_h>, O>; \
3233 using _Name_ = _Name_##From<Hash<_Origin_ ""_h>>;
3234
3235#define DECLARE_SOA_TABLE_FULL_VERSIONED(_Name_, _Label_, _Origin_, _Desc_, _Version_, ...) \
3236 DECLARE_SOA_TABLE_METADATA(_Name_, _Desc_, _Version_, __VA_ARGS__); \
3237 DECLARE_SOA_TABLE_FULL_VERSIONED_(_Name_, _Label_, _Origin_, _Desc_, _Version_);
3238
3239#define DECLARE_SOA_TABLE_FULL(_Name_, _Label_, _Origin_, _Desc_, ...) \
3240 O2HASH(_Label_); \
3241 DECLARE_SOA_TABLE_METADATA(_Name_, _Desc_, 0, __VA_ARGS__); \
3242 DECLARE_SOA_TABLE_FULL_VERSIONED_(_Name_, _Label_, _Origin_, _Desc_, 0)
3243
3244#define DECLARE_SOA_TABLE(_Name_, _Origin_, _Desc_, ...) \
3245 DECLARE_SOA_TABLE_FULL(_Name_, #_Name_, _Origin_, _Desc_, __VA_ARGS__)
3246
3247#define DECLARE_SOA_TABLE_VERSIONED(_Name_, _Origin_, _Desc_, _Version_, ...) \
3248 O2HASH(#_Name_); \
3249 DECLARE_SOA_TABLE_METADATA(_Name_, _Desc_, _Version_, __VA_ARGS__); \
3250 DECLARE_SOA_TABLE_FULL_VERSIONED_(_Name_, #_Name_, _Origin_, _Desc_, _Version_)
3251
3252#define DECLARE_SOA_TABLE_STAGED_VERSIONED(_BaseName_, _Desc_, _Version_, ...) \
3253 O2HASH(_Desc_ "/" #_Version_); \
3254 O2HASH(#_BaseName_); \
3255 O2HASH("Stored" #_BaseName_); \
3256 DECLARE_SOA_TABLE_METADATA(_BaseName_, _Desc_, _Version_, __VA_ARGS__); \
3257 using Stored##_BaseName_##Metadata = _BaseName_##Metadata; \
3258 DECLARE_SOA_TABLE_METADATA_TRAIT(_BaseName_, _Desc_, _Version_); \
3259 DECLARE_SOA_STAGE(_BaseName_, "AOD", _Desc_, _Version_); \
3260 DECLARE_SOA_STAGE(Stored##_BaseName_, "AOD1", _Desc_, _Version_);
3261
3262#define DECLARE_SOA_TABLE_STAGED(_BaseName_, _Desc_, ...) \
3263 DECLARE_SOA_TABLE_STAGED_VERSIONED(_BaseName_, _Desc_, 0, __VA_ARGS__);
3264
3265#define DECLARE_SOA_EXTENDED_TABLE_FULL(_Name_, _Label_, _OriginalTable_, _Origin_, _Desc_, _Version_, ...) \
3266 O2HASH(_Desc_ "/" #_Version_); \
3267 template <typename O> \
3268 using _Name_##ExtensionFrom = soa::Table<o2::aod::Hash<_Label_ ""_h>, o2::aod::Hash<_Desc_ "/" #_Version_ ""_h>, O>; \
3269 using _Name_##Extension = _Name_##ExtensionFrom<o2::aod::Hash<_Origin_ ""_h>>; \
3270 template <typename O = o2::aod::Hash<_Origin_ ""_h>> \
3271 struct _Name_##ExtensionMetadataFrom : TableMetadata<o2::aod::Hash<_Desc_ "/" #_Version_ ""_h>, __VA_ARGS__> { \
3272 using base_table_t = _OriginalTable_; \
3273 using extension_table_t = _Name_##ExtensionFrom<O>; \
3274 using expression_pack_t = framework::pack<__VA_ARGS__>; \
3275 static constexpr auto sources = _OriginalTable_::originals; \
3276 }; \
3277 using _Name_##ExtensionMetadata = _Name_##ExtensionMetadataFrom<o2::aod::Hash<_Origin_ ""_h>>; \
3278 template <> \
3279 struct MetadataTrait<o2::aod::Hash<_Desc_ "/" #_Version_ ""_h>> { \
3280 using metadata = _Name_##ExtensionMetadata; \
3281 }; \
3282 template <typename O> \
3283 using _Name_##From = o2::soa::JoinFull<o2::aod::Hash<_Desc_ "/" #_Version_ ""_h>, _OriginalTable_, _Name_##ExtensionFrom<O>>; \
3284 using _Name_ = _Name_##From<o2::aod::Hash<_Origin_ ""_h>>;
3285
3286#define DECLARE_SOA_EXTENDED_TABLE(_Name_, _Table_, _Description_, _Version_, ...) \
3287 O2HASH(#_Name_ "Extension"); \
3288 DECLARE_SOA_EXTENDED_TABLE_FULL(_Name_, #_Name_ "Extension", _Table_, "DYN", _Description_, _Version_, __VA_ARGS__)
3289
3290#define DECLARE_SOA_EXTENDED_TABLE_USER(_Name_, _Table_, _Description_, ...) \
3291 O2HASH(#_Name_ "Extension"); \
3292 DECLARE_SOA_EXTENDED_TABLE_FULL(_Name_, #_Name_ "Extension", _Table_, "AOD", "EX" _Description_, 0, __VA_ARGS__)
3293
3294#define DECLARE_SOA_CONFIGURABLE_EXTENDED_TABLE_FULL(_Name_, _Label_, _OriginalTable_, _Origin_, _Desc_, _Version_, ...) \
3295 O2HASH(_Desc_ "/" #_Version_); \
3296 template <typename O> \
3297 using _Name_##CfgExtensionFrom = soa::Table<o2::aod::Hash<_Label_ ""_h>, o2::aod::Hash<_Desc_ "/" #_Version_ ""_h>, O>; \
3298 using _Name_##CfgExtension = _Name_##CfgExtensionFrom<o2::aod::Hash<_Origin_ ""_h>>; \
3299 template <typename O = o2::aod::Hash<_Origin_ ""_h>> \
3300 struct _Name_##CfgExtensionMetadataFrom : TableMetadata<o2::aod::Hash<_Desc_ "/" #_Version_ ""_h>, __VA_ARGS__> { \
3301 using base_table_t = _OriginalTable_; \
3302 using extension_table_t = _Name_##CfgExtensionFrom<O>; \
3303 using placeholders_pack_t = framework::pack<__VA_ARGS__>; \
3304 using configurable_t = std::true_type; \
3305 static constexpr auto sources = _OriginalTable_::originals; \
3306 }; \
3307 using _Name_##CfgExtensionMetadata = _Name_##CfgExtensionMetadataFrom<o2::aod::Hash<_Origin_ ""_h>>; \
3308 template <> \
3309 struct MetadataTrait<o2::aod::Hash<_Desc_ "/" #_Version_ ""_h>> { \
3310 using metadata = _Name_##CfgExtensionMetadata; \
3311 }; \
3312 template <typename O> \
3313 using _Name_##From = o2::soa::JoinFull<o2::aod::Hash<_Desc_ "/" #_Version_ ""_h>, _OriginalTable_, _Name_##CfgExtensionFrom<O>>; \
3314 using _Name_ = _Name_##From<o2::aod::Hash<_Origin_ ""_h>>;
3315
3316#define DECLARE_SOA_CONFIGURABLE_EXTENDED_TABLE(_Name_, _Table_, _Description_, ...) \
3317 O2HASH(#_Name_ "CfgExtension"); \
3318 DECLARE_SOA_CONFIGURABLE_EXTENDED_TABLE_FULL(_Name_, #_Name_ "CfgExtension", _Table_, "AOD", "EX" _Description_, 0, __VA_ARGS__)
3319
3320#define DECLARE_SOA_INDEX_TABLE_FULL(_Name_, _Key_, _Origin_, _Version_, _Desc_, _Exclusive_, ...) \
3321 O2HASH(#_Name_); \
3322 O2HASH(_Desc_ "/" #_Version_); \
3323 template <typename O = o2::aod::Hash<_Origin_ ""_h>> \
3324 struct _Name_##MetadataFrom : o2::aod::TableMetadata<o2::aod::Hash<_Desc_ "/" #_Version_ ""_h>, soa::Index<>, __VA_ARGS__> { \
3325 static constexpr bool exclusive = _Exclusive_; \
3326 using Key = _Key_; \
3327 using index_pack_t = framework::pack<__VA_ARGS__>; \
3328 static constexpr const auto sources = []<typename... Cs>(framework::pack<Cs...>) { \
3329 constexpr auto a = o2::soa::mergeOriginals<typename Cs::binding_t...>(); \
3330 return o2::aod::filterForKey<a.size(), a, Key>(); \
3331 }(framework::pack<__VA_ARGS__>{}); \
3332 static_assert(sources.size() - Key::originals.size() + 1 == framework::pack_size(index_pack_t{}), "One of the referred tables does not have index to Key"); \
3333 }; \
3334 using _Name_##Metadata = _Name_##MetadataFrom<o2::aod::Hash<_Origin_ ""_h>>; \
3335 \
3336 template <typename O = o2::aod::Hash<_Origin_ ""_h>> \
3337 using _Name_##From = o2::soa::IndexTable<o2::aod::Hash<#_Name_ ""_h>, o2::aod::Hash<_Desc_ "/" #_Version_ ""_h>, O, _Key_, __VA_ARGS__>; \
3338 using _Name_ = _Name_##From<o2::aod::Hash<_Origin_ ""_h>>; \
3339 \
3340 template <> \
3341 struct MetadataTrait<o2::aod::Hash<_Desc_ "/" #_Version_ ""_h>> { \
3342 using metadata = _Name_##Metadata; \
3343 };
3344
3345// Declare were each row is associated to a timestamp column of an _TimestampSource_
3346// table.
3347//
3348// The columns of this table have to be CCDB_COLUMNS so that for each timestamp, we get a row
3349// which points to the specified CCDB objectes described by those columns.
3350#define DECLARE_SOA_TIMESTAMPED_TABLE_FULL(_Name_, _Label_, _TimestampSource_, _TimestampColumn_, _Origin_, _Version_, _Desc_, ...) \
3351 O2HASH(_Desc_ "/" #_Version_); \
3352 template <typename O> \
3353 using _Name_##TimestampFrom = soa::Table<o2::aod::Hash<_Label_ ""_h>, o2::aod::Hash<_Desc_ "/" #_Version_ ""_h>, O>; \
3354 using _Name_##Timestamp = _Name_##TimestampFrom<o2::aod::Hash<_Origin_ ""_h>>; \
3355 template <typename O = o2::aod::Hash<_Origin_ ""_h>> \
3356 struct _Name_##TimestampMetadataFrom : TableMetadata<o2::aod::Hash<_Desc_ "/" #_Version_ ""_h>, __VA_ARGS__> { \
3357 using base_table_t = _TimestampSource_; \
3358 using extension_table_t = _Name_##TimestampFrom<O>; \
3359 static constexpr const auto ccdb_urls = []<typename... Cs>(framework::pack<Cs...>) { \
3360 return std::array<std::string_view, sizeof...(Cs)>{Cs::query...}; \
3361 }(framework::pack<__VA_ARGS__>{}); \
3362 static constexpr const auto ccdb_bindings = []<typename... Cs>(framework::pack<Cs...>) { \
3363 return std::array<std::string_view, sizeof...(Cs)>{Cs::mLabel...}; \
3364 }(framework::pack<__VA_ARGS__>{}); \
3365 static constexpr auto sources = _TimestampSource_::originals; \
3366 static constexpr auto timestamp_column_label = _TimestampColumn_::mLabel; \
3367 /*static constexpr auto timestampColumn = _TimestampColumn_;*/ \
3368 }; \
3369 using _Name_##TimestampMetadata = _Name_##TimestampMetadataFrom<o2::aod::Hash<_Origin_ ""_h>>; \
3370 template <> \
3371 struct MetadataTrait<o2::aod::Hash<_Desc_ "/" #_Version_ ""_h>> { \
3372 using metadata = _Name_##TimestampMetadata; \
3373 }; \
3374 template <typename O> \
3375 using _Name_##From = o2::soa::JoinFull<o2::aod::Hash<_Desc_ "/" #_Version_ ""_h>, _TimestampSource_, _Name_##TimestampFrom<O>>; \
3376 using _Name_ = _Name_##From<o2::aod::Hash<_Origin_ ""_h>>;
3377
3378#define DECLARE_SOA_TIMESTAMPED_TABLE(_Name_, _TimestampSource_, _TimestampColumn_, _Version_, _Desc_, ...) \
3379 O2HASH(#_Name_ "Timestamped"); \
3380 DECLARE_SOA_TIMESTAMPED_TABLE_FULL(_Name_, #_Name_ "Timestamped", _TimestampSource_, _TimestampColumn_, "ATIM", _Version_, _Desc_, __VA_ARGS__)
3381
3382#define DECLARE_SOA_INDEX_TABLE(_Name_, _Key_, _Description_, ...) \
3383 DECLARE_SOA_INDEX_TABLE_FULL(_Name_, _Key_, "IDX", 0, _Description_, false, __VA_ARGS__)
3384
3385#define DECLARE_SOA_INDEX_TABLE_EXCLUSIVE(_Name_, _Key_, _Description_, ...) \
3386 DECLARE_SOA_INDEX_TABLE_FULL(_Name_, _Key_, "IDX", 0, _Description_, true, __VA_ARGS__)
3387
3388#define DECLARE_SOA_INDEX_TABLE_USER(_Name_, _Key_, _Description_, ...) \
3389 DECLARE_SOA_INDEX_TABLE_FULL(_Name_, _Key_, "AOD", 0, _Description_, false, __VA_ARGS__)
3390
3391#define DECLARE_SOA_INDEX_TABLE_EXCLUSIVE_USER(_Name_, _Key_, _Description_, ...) \
3392 DECLARE_SOA_INDEX_TABLE_FULL(_Name_, _Key_, "AOD", 0, _Description_, true, __VA_ARGS__)
3393
3394namespace o2::soa
3395{
3396template <typename D, typename... Ts>
3397struct JoinFull : Table<o2::aod::Hash<"JOIN"_h>, D, o2::aod::Hash<"JOIN"_h>, Ts...> {
3398 using base = Table<o2::aod::Hash<"JOIN"_h>, D, o2::aod::Hash<"JOIN"_h>, Ts...>;
3399
3400 JoinFull(std::shared_ptr<arrow::Table>&& table, uint64_t offset = 0)
3401 : base{std::move(table), offset}
3402 {
3403 if (this->tableSize() != 0) {
3405 }
3406 }
3407 JoinFull(std::vector<std::shared_ptr<arrow::Table>>&& tables, uint64_t offset = 0)
3408 : base{ArrowHelpers::joinTables(std::move(tables), std::span{base::originalLabels}), offset}
3409 {
3410 if (this->tableSize() != 0) {
3412 }
3413 }
3416
3417 using self_t = JoinFull<D, Ts...>;
3418 using table_t = base;
3419 static constexpr const auto originals = base::originals;
3420 static constexpr const auto originalLabels = base::originalLabels;
3423 using iterator = table_t::template iterator_template<DefaultIndexPolicy, self_t, Ts...>;
3429
3431 {
3432 return iterator{this->cached_begin()};
3433 }
3434
3436 {
3437 return const_iterator{this->cached_begin()};
3438 }
3439
3441 {
3442 return doSliceByCached(this, node, value, cache);
3443 }
3444
3449
3450 template <typename T1, typename Policy, bool OPT>
3452 {
3453 return doSliceBy(this, container, value);
3454 }
3455
3456 iterator rawIteratorAt(uint64_t i) const
3457 {
3458 auto it = iterator{this->cached_begin()};
3459 it.setCursor(i);
3460 return it;
3461 }
3462
3463 iterator iteratorAt(uint64_t i) const
3464 {
3465 return rawIteratorAt(i);
3466 }
3467
3468 auto rawSlice(uint64_t start, uint64_t end) const
3469 {
3470 return self_t{{this->asArrowTable()->Slice(start, end - start + 1)}, start};
3471 }
3472
3473 auto emptySlice() const
3474 {
3475 return self_t{{this->asArrowTable()->Slice(0, 0)}, 0};
3476 }
3477
3478 template <typename T>
3479 static consteval bool contains()
3480 {
3481 return std::find_if(originals.begin(), originals.end(), [](TableRef const& ref) { return ref.desc_hash == T::ref.desc_hash; }) != originals.end();
3482 }
3483};
3484
3485template <typename... Ts>
3486using Join = JoinFull<o2::aod::Hash<"JOIN/0"_h>, Ts...>;
3487
3488template <typename... Ts>
3489constexpr auto join(Ts const&... t)
3490{
3491 return Join<Ts...>(ArrowHelpers::joinTables({t.asArrowTable()...}, std::span{Join<Ts...>::base::originalLabels}));
3492}
3493
3494template <typename T>
3496
3497template <typename T>
3498constexpr bool is_soa_join_v = is_join<T>;
3499
3500template <typename... Ts>
3501struct Concat : Table<o2::aod::Hash<"CONC"_h>, o2::aod::Hash<"CONC/0"_h>, o2::aod::Hash<"CONC"_h>, Ts...> {
3502 using base = Table<o2::aod::Hash<"CONC"_h>, o2::aod::Hash<"CONC/0"_h>, o2::aod::Hash<"CONC"_h>, Ts...>;
3503 using self_t = Concat<Ts...>;
3504 Concat(std::vector<std::shared_ptr<arrow::Table>>&& tables, uint64_t offset = 0)
3505 : base{ArrowHelpers::concatTables(std::move(tables)), offset}
3506 {
3508 }
3509 Concat(Ts const&... t, uint64_t offset = 0)
3510 : base{ArrowHelpers::concatTables({t.asArrowTable()...}), offset}
3511 {
3512 bindInternalIndicesTo(this);
3513 }
3514
3515 using base::originals;
3516
3517 using base::bindExternalIndices;
3518 using base::bindInternalIndicesTo;
3519
3520 using table_t = base;
3523
3524 using iterator = table_t::template iterator_template<DefaultIndexPolicy, self_t, Ts...>;
3530};
3531
3532template <typename... Ts>
3533constexpr auto concat(Ts const&... t)
3534{
3535 return Concat<Ts...>{t...};
3536}
3537
3538template <soa::is_table T>
3539class FilteredBase : public T
3540{
3541 public:
3543 using table_t = typename T::table_t;
3544 using T::originals;
3545 using columns_t = typename T::columns_t;
3546 using persistent_columns_t = typename T::persistent_columns_t;
3547 using external_index_columns_t = typename T::external_index_columns_t;
3548
3549 using iterator = T::template iterator_template_o<FilteredIndexPolicy, self_t>;
3550 using unfiltered_iterator = T::template iterator_template_o<DefaultIndexPolicy, self_t>;
3552
3553 FilteredBase(std::vector<std::shared_ptr<arrow::Table>>&& tables, gandiva::Selection const& selection, uint64_t offset = 0)
3554 : T{std::move(tables), offset},
3555 mSelectedRows{getSpan(selection)}
3556 {
3557 if (this->tableSize() != 0) {
3558 mFilteredBegin = table_t::filtered_begin(mSelectedRows);
3559 }
3560 resetRanges();
3561 mFilteredBegin.bindInternalIndices(this);
3562 }
3563
3564 FilteredBase(std::vector<std::shared_ptr<arrow::Table>>&& tables, SelectionVector&& selection, uint64_t offset = 0)
3565 : T{std::move(tables), offset},
3566 mSelectedRowsCache{std::move(selection)},
3567 mCached{true}
3568 {
3569 mSelectedRows = std::span{mSelectedRowsCache};
3570 if (this->tableSize() != 0) {
3571 mFilteredBegin = table_t::filtered_begin(mSelectedRows);
3572 }
3573 resetRanges();
3574 mFilteredBegin.bindInternalIndices(this);
3575 }
3576
3577 FilteredBase(std::vector<std::shared_ptr<arrow::Table>>&& tables, std::span<int64_t const> const& selection, uint64_t offset = 0)
3578 : T{std::move(tables), offset},
3579 mSelectedRows{selection}
3580 {
3581 if (this->tableSize() != 0) {
3582 mFilteredBegin = table_t::filtered_begin(mSelectedRows);
3583 }
3584 resetRanges();
3585 mFilteredBegin.bindInternalIndices(this);
3586 }
3587
3589 {
3590 return iterator(mFilteredBegin);
3591 }
3592
3594 {
3595 return const_iterator(mFilteredBegin);
3596 }
3597
3599 {
3600 auto it = unfiltered_iterator{mFilteredBegin};
3601 it.setCursor(i);
3602 return it;
3603 }
3604
3605 [[nodiscard]] RowViewSentinel end() const
3606 {
3607 return RowViewSentinel{*mFilteredEnd};
3608 }
3609
3611 {
3612 return mFilteredBegin;
3613 }
3614
3615 auto const& cached_begin() const
3616 {
3617 return mFilteredBegin;
3618 }
3619
3620 iterator iteratorAt(uint64_t i) const
3621 {
3622 return mFilteredBegin + i;
3623 }
3624
3625 [[nodiscard]] int64_t size() const
3626 {
3627 return mSelectedRows.size();
3628 }
3629
3630 [[nodiscard]] int64_t tableSize() const
3631 {
3632 return table_t::asArrowTable()->num_rows();
3633 }
3634
3635 auto const& getSelectedRows() const
3636 {
3637 return mSelectedRows;
3638 }
3639
3640 auto rawSlice(uint64_t start, uint64_t end) const
3641 {
3642 SelectionVector newSelection;
3643 newSelection.resize(static_cast<int64_t>(end - start + 1));
3644 std::iota(newSelection.begin(), newSelection.end(), start);
3645 return self_t{{this->asArrowTable()}, std::move(newSelection), 0};
3646 }
3647
3648 auto emptySlice() const
3649 {
3650 return self_t{{this->asArrowTable()}, SelectionVector{}, 0};
3651 }
3652
3653 static inline auto getSpan(gandiva::Selection const& sel)
3654 {
3655 if (sel == nullptr) {
3656 return std::span<int64_t const>{};
3657 }
3658 auto array = std::static_pointer_cast<arrow::Int64Array>(sel->ToArray());
3659 auto start = array->raw_values();
3660 auto stop = start + array->length();
3661 return std::span{start, stop};
3662 }
3663
3666 template <typename... TA>
3667 void bindExternalIndices(TA*... current)
3668 {
3669 table_t::bindExternalIndices(current...);
3670 mFilteredBegin.bindExternalIndices(current...);
3671 }
3672
3673 void bindExternalIndicesRaw(std::vector<o2::soa::Binding>&& ptrs)
3674 {
3675 mFilteredBegin.bindExternalIndicesRaw(std::forward<std::vector<o2::soa::Binding>>(ptrs));
3676 }
3677
3678 template <typename I>
3680 {
3681 mFilteredBegin.bindInternalIndices(ptr);
3682 }
3683
3684 template <typename T1, typename... Cs>
3686 {
3687 dest.bindExternalIndicesRaw(mFilteredBegin.getIndexBindings());
3688 }
3689
3690 template <typename T1>
3691 void copyIndexBindings(T1& dest) const
3692 {
3693 doCopyIndexBindings(external_index_columns_t{}, dest);
3694 }
3695
3696 template <typename T1>
3697 auto rawSliceBy(o2::framework::Preslice<T1> const& container, int value) const
3698 {
3699 return (table_t)this->sliceBy(container, value);
3700 }
3701
3703 {
3704 return doFilteredSliceByCached(this, node, value, cache);
3705 }
3706
3711
3712 template <typename T1, bool OPT>
3714 {
3715 return doFilteredSliceBy(this, container, value);
3716 }
3717
3718 template <typename T1, bool OPT>
3720 {
3721 return doSliceBy(this, container, value);
3722 }
3723
3725 {
3726 auto t = o2::soa::select(*this, f);
3727 copyIndexBindings(t);
3728 return t;
3729 }
3730
3731 int isInSelectedRows(int i) const
3732 {
3733 auto locate = std::find(mSelectedRows.begin(), mSelectedRows.end(), i);
3734 if (locate == mSelectedRows.end()) {
3735 return -1;
3736 }
3737 return static_cast<int>(std::distance(mSelectedRows.begin(), locate));
3738 }
3739
3740 void sumWithSelection(SelectionVector const& selection)
3741 {
3742 mCached = true;
3743 SelectionVector rowsUnion;
3744 std::set_union(mSelectedRows.begin(), mSelectedRows.end(), selection.begin(), selection.end(), std::back_inserter(rowsUnion));
3745 mSelectedRowsCache.clear();
3746 mSelectedRowsCache = rowsUnion;
3747 resetRanges();
3748 }
3749
3751 {
3752 mCached = true;
3753 SelectionVector intersection;
3754 std::set_intersection(mSelectedRows.begin(), mSelectedRows.end(), selection.begin(), selection.end(), std::back_inserter(intersection));
3755 mSelectedRowsCache.clear();
3756 mSelectedRowsCache = intersection;
3757 resetRanges();
3758 }
3759
3760 void sumWithSelection(std::span<int64_t const> const& selection)
3761 {
3762 mCached = true;
3763 SelectionVector rowsUnion;
3764 std::set_union(mSelectedRows.begin(), mSelectedRows.end(), selection.begin(), selection.end(), std::back_inserter(rowsUnion));
3765 mSelectedRowsCache.clear();
3766 mSelectedRowsCache = rowsUnion;
3767 resetRanges();
3768 }
3769
3770 void intersectWithSelection(std::span<int64_t const> const& selection)
3771 {
3772 mCached = true;
3773 SelectionVector intersection;
3774 std::set_intersection(mSelectedRows.begin(), mSelectedRows.end(), selection.begin(), selection.end(), std::back_inserter(intersection));
3775 mSelectedRowsCache.clear();
3776 mSelectedRowsCache = intersection;
3777 resetRanges();
3778 }
3779
3780 bool isCached() const
3781 {
3782 return mCached;
3783 }
3784
3785 private:
3786 void resetRanges()
3787 {
3788 if (mCached) {
3789 mSelectedRows = std::span{mSelectedRowsCache};
3790 }
3791 mFilteredEnd.reset(new RowViewSentinel{static_cast<int64_t>(mSelectedRows.size())});
3792 if (tableSize() == 0) {
3793 mFilteredBegin = *mFilteredEnd;
3794 } else {
3795 mFilteredBegin.resetSelection(mSelectedRows);
3796 }
3797 }
3798
3799 std::span<int64_t const> mSelectedRows;
3800 SelectionVector mSelectedRowsCache;
3801 bool mCached = false;
3802 iterator mFilteredBegin;
3803 std::shared_ptr<RowViewSentinel> mFilteredEnd;
3804};
3805
3806template <typename T>
3807class Filtered : public FilteredBase<T>
3808{
3809 public:
3810 using base_t = T;
3812 using table_t = typename T::table_t;
3813 using columns_t = typename T::columns_t;
3814
3815 using iterator = T::template iterator_template_o<FilteredIndexPolicy, self_t>;
3816 using unfiltered_iterator = T::template iterator_template_o<DefaultIndexPolicy, self_t>;
3818
3820 {
3821 return iterator(this->cached_begin());
3822 }
3823
3825 {
3826 return const_iterator(this->cached_begin());
3827 }
3828
3829 Filtered(std::vector<std::shared_ptr<arrow::Table>>&& tables, gandiva::Selection const& selection, uint64_t offset = 0)
3830 : FilteredBase<T>(std::move(tables), selection, offset) {}
3831
3832 Filtered(std::vector<std::shared_ptr<arrow::Table>>&& tables, SelectionVector&& selection, uint64_t offset = 0)
3833 : FilteredBase<T>(std::move(tables), std::forward<SelectionVector>(selection), offset) {}
3834
3835 Filtered(std::vector<std::shared_ptr<arrow::Table>>&& tables, std::span<int64_t const> const& selection, uint64_t offset = 0)
3836 : FilteredBase<T>(std::move(tables), selection, offset) {}
3837
3839 {
3840 Filtered<T> copy(*this);
3841 copy.sumWithSelection(selection);
3842 return copy;
3843 }
3844
3845 Filtered<T> operator+(std::span<int64_t const> const& selection)
3846 {
3847 Filtered<T> copy(*this);
3848 copy.sumWithSelection(selection);
3849 return copy;
3850 }
3851
3853 {
3854 return operator+(other.getSelectedRows());
3855 }
3856
3858 {
3859 this->sumWithSelection(selection);
3860 return *this;
3861 }
3862
3863 Filtered<T> operator+=(std::span<int64_t const> const& selection)
3864 {
3865 this->sumWithSelection(selection);
3866 return *this;
3867 }
3868
3870 {
3871 return operator+=(other.getSelectedRows());
3872 }
3873
3875 {
3876 Filtered<T> copy(*this);
3877 copy.intersectWithSelection(selection);
3878 return copy;
3879 }
3880
3881 Filtered<T> operator*(std::span<int64_t const> const& selection)
3882 {
3883 Filtered<T> copy(*this);
3884 copy.intersectWithSelection(selection);
3885 return copy;
3886 }
3887
3889 {
3890 return operator*(other.getSelectedRows());
3891 }
3892
3894 {
3895 this->intersectWithSelection(selection);
3896 return *this;
3897 }
3898
3899 Filtered<T> operator*=(std::span<int64_t const> const& selection)
3900 {
3901 this->intersectWithSelection(selection);
3902 return *this;
3903 }
3904
3906 {
3907 return operator*=(other.getSelectedRows());
3908 }
3909
3911 {
3912 auto it = unfiltered_iterator{this->cached_begin()};
3913 it.setCursor(i);
3914 return it;
3915 }
3916
3917 using FilteredBase<T>::getSelectedRows;
3918
3919 auto rawSlice(uint64_t start, uint64_t end) const
3920 {
3921 SelectionVector newSelection;
3922 newSelection.resize(static_cast<int64_t>(end - start + 1));
3923 std::iota(newSelection.begin(), newSelection.end(), start);
3924 return self_t{{this->asArrowTable()}, std::move(newSelection), 0};
3925 }
3926
3927 auto emptySlice() const
3928 {
3929 return self_t{{this->asArrowTable()}, SelectionVector{}, 0};
3930 }
3931
3932 template <typename T1>
3933 auto rawSliceBy(o2::framework::Preslice<T1> const& container, int value) const
3934 {
3935 return (table_t)this->sliceBy(container, value);
3936 }
3937
3939 {
3940 return doFilteredSliceByCached(this, node, value, cache);
3941 }
3942
3947
3948 template <typename T1, bool OPT>
3950 {
3951 return doFilteredSliceBy(this, container, value);
3952 }
3953
3954 template <typename T1, bool OPT>
3956 {
3957 return doSliceBy(this, container, value);
3958 }
3959
3961 {
3962 auto t = o2::soa::select(*this, f);
3963 copyIndexBindings(t);
3964 return t;
3965 }
3966};
3967
3968template <typename T>
3969class Filtered<Filtered<T>> : public FilteredBase<typename T::table_t>
3970{
3971 public:
3973 using base_t = T;
3975 using columns_t = typename T::columns_t;
3976
3977 using iterator = typename T::template iterator_template_o<FilteredIndexPolicy, self_t>;
3978 using unfiltered_iterator = typename T::template iterator_template_o<DefaultIndexPolicy, self_t>;
3980
3982 {
3983 return iterator(this->cached_begin());
3984 }
3985
3987 {
3988 return const_iterator(this->cached_begin());
3989 }
3990
3991 Filtered(std::vector<Filtered<T>>&& tables, gandiva::Selection const& selection, uint64_t offset = 0)
3992 : FilteredBase<typename T::table_t>(std::move(extractTablesFromFiltered(tables)), selection, offset)
3993 {
3994 for (auto& table : tables) {
3995 *this *= table;
3996 }
3997 }
3998
3999 Filtered(std::vector<Filtered<T>>&& tables, SelectionVector&& selection, uint64_t offset = 0)
4000 : FilteredBase<typename T::table_t>(std::move(extractTablesFromFiltered(tables)), std::forward<SelectionVector>(selection), offset)
4001 {
4002 for (auto& table : tables) {
4003 *this *= table;
4004 }
4005 }
4006
4007 Filtered(std::vector<Filtered<T>>&& tables, std::span<int64_t const> const& selection, uint64_t offset = 0)
4008 : FilteredBase<typename T::table_t>(std::move(extractTablesFromFiltered(tables)), selection, offset)
4009 {
4010 for (auto& table : tables) {
4011 *this *= table;
4012 }
4013 }
4014
4016 {
4017 Filtered<Filtered<T>> copy(*this);
4018 copy.sumWithSelection(selection);
4019 return copy;
4020 }
4021
4022 Filtered<Filtered<T>> operator+(std::span<int64_t const> const& selection)
4023 {
4024 Filtered<Filtered<T>> copy(*this);
4025 copy.sumWithSelection(selection);
4026 return copy;
4027 }
4028
4030 {
4031 return operator+(other.getSelectedRows());
4032 }
4033
4035 {
4036 this->sumWithSelection(selection);
4037 return *this;
4038 }
4039
4040 Filtered<Filtered<T>> operator+=(std::span<int64_t const> const& selection)
4041 {
4042 this->sumWithSelection(selection);
4043 return *this;
4044 }
4045
4047 {
4048 return operator+=(other.getSelectedRows());
4049 }
4050
4052 {
4053 Filtered<Filtered<T>> copy(*this);
4054 copy.intersectionWithSelection(selection);
4055 return copy;
4056 }
4057
4058 Filtered<Filtered<T>> operator*(std::span<int64_t const> const& selection)
4059 {
4060 Filtered<Filtered<T>> copy(*this);
4061 copy.intersectionWithSelection(selection);
4062 return copy;
4063 }
4064
4066 {
4067 return operator*(other.getSelectedRows());
4068 }
4069
4071 {
4072 this->intersectWithSelection(selection);
4073 return *this;
4074 }
4075
4076 Filtered<Filtered<T>> operator*=(std::span<int64_t const> const& selection)
4077 {
4078 this->intersectWithSelection(selection);
4079 return *this;
4080 }
4081
4083 {
4084 return operator*=(other.getSelectedRows());
4085 }
4086
4088 {
4089 auto it = unfiltered_iterator{this->cached_begin()};
4090 it.setCursor(i);
4091 return it;
4092 }
4093
4094 auto rawSlice(uint64_t start, uint64_t end) const
4095 {
4096 SelectionVector newSelection;
4097 newSelection.resize(static_cast<int64_t>(end - start + 1));
4098 std::iota(newSelection.begin(), newSelection.end(), start);
4099 return self_t{{this->asArrowTable()}, std::move(newSelection), 0};
4100 }
4101
4102 auto emptySlice() const
4103 {
4104 return self_t{{this->asArrowTable()}, SelectionVector{}, 0};
4105 }
4106
4108 {
4109 return doFilteredSliceByCached(this, node, value, cache);
4110 }
4111
4116
4117 template <typename T1, bool OPT>
4119 {
4120 return doFilteredSliceBy(this, container, value);
4121 }
4122
4123 template <typename T1, bool OPT>
4125 {
4126 return doSliceBy(this, container, value);
4127 }
4128
4129 private:
4130 std::vector<std::shared_ptr<arrow::Table>> extractTablesFromFiltered(std::vector<Filtered<T>>& tables)
4131 {
4132 std::vector<std::shared_ptr<arrow::Table>> outTables;
4133 for (auto& table : tables) {
4134 outTables.push_back(table.asArrowTable());
4135 }
4136 return outTables;
4137 }
4138};
4139
4145template <typename L, typename D, typename O, typename Key, typename H, typename... Ts>
4146struct IndexTable : Table<L, D, O> {
4147 using self_t = IndexTable<L, D, O, Key, H, Ts...>;
4152 using first_t = typename H::binding_t;
4153 using rest_t = framework::pack<typename Ts::binding_t...>;
4154
4155 IndexTable(std::shared_ptr<arrow::Table> table, uint64_t offset = 0)
4156 : base_t{table, offset}
4157 {
4158 }
4159
4160 IndexTable(std::vector<std::shared_ptr<arrow::Table>> tables, uint64_t offset = 0)
4161 : base_t{tables[0], offset}
4162 {
4163 }
4164
4165 IndexTable(IndexTable const&) = default;
4167 IndexTable& operator=(IndexTable const&) = default;
4169
4174};
4175
4176template <typename T, bool APPLY>
4177struct SmallGroupsBase : public Filtered<T> {
4178 static constexpr bool applyFilters = APPLY;
4179 SmallGroupsBase(std::vector<std::shared_ptr<arrow::Table>>&& tables, gandiva::Selection const& selection, uint64_t offset = 0)
4180 : Filtered<T>(std::move(tables), selection, offset) {}
4181
4182 SmallGroupsBase(std::vector<std::shared_ptr<arrow::Table>>&& tables, SelectionVector&& selection, uint64_t offset = 0)
4183 : Filtered<T>(std::move(tables), std::forward<SelectionVector>(selection), offset) {}
4184
4185 SmallGroupsBase(std::vector<std::shared_ptr<arrow::Table>>&& tables, std::span<int64_t const> const& selection, uint64_t offset = 0)
4186 : Filtered<T>(std::move(tables), selection, offset) {}
4187};
4188
4189template <typename T>
4191
4192template <typename T>
4194
4195template <typename T>
4196concept is_smallgroups = requires {
4197 []<typename B, bool A>(SmallGroupsBase<B, A>*) {}(std::declval<T*>());
4198};
4199} // namespace o2::soa
4200
4201#endif // O2_FRAMEWORK_ASOA_H_
header::DataDescription description
std::vector< std::string > labels
std::string binding
#define O2HASH(_Str_)
Pre-declare Hash specialization for a generic string.
Definition ASoA.h:294
#define O2ORIGIN(_Str_)
Pre-declare Hash specialization for an origin string.
Definition ASoA.h:302
consteval auto getIndexTargets()
SLICE.
Definition ASoA.h:2600
o2::monitoring::tags::Key Key
#define O2_BUILTIN_UNREACHABLE
#define O2_BUILTIN_LIKELY(x)
#define O2_BUILTIN_UNLIKELY(x)
Hit operator+(const Hit &lhs, const Hit &rhs)
Definition Hit.cxx:46
uint32_t hash
std::unique_ptr< expressions::Node > node
int32_t i
std::string columnLabel
uint16_t pos
Definition RawData.h:3
uint32_t res
Definition RawData.h:0
uint32_t c
Definition RawData.h:2
uint32_t version
Definition RawData.h:8
TBranch * ptr
void merge(Options const &options)
StringRef key
Definition A.h:16
Definition B.h:16
Class for time synchronization of RawReader instances.
int64_t const * mCurrentPos
Definition ASoA.h:621
ColumnIterator(arrow::ChunkedArray const *column)
Definition ASoA.h:514
ColumnIterator(ColumnIterator< T, ChunkingPolicy > const &)=default
void moveToEnd()
Move the iterator to the end of the column.
Definition ASoA.h:572
ColumnIterator< T > & moveToPos()
Definition ASoA.h:614
auto operator*() const
Definition ASoA.h:588
ColumnIterator< T, ChunkingPolicy > & operator=(ColumnIterator< T, ChunkingPolicy > const &)=default
unwrap_t< T > const * mCurrent
Definition ASoA.h:620
unwrap_t< T > const * mLast
Definition ASoA.h:622
ColumnIterator(ColumnIterator< T, ChunkingPolicy > &&)=default
void prevChunk() const
Definition ASoA.h:547
arrow::ChunkedArray const * mColumn
Definition ASoA.h:623
auto operator*() const
Definition ASoA.h:581
ColumnIterator< T, ChunkingPolicy > & operator=(ColumnIterator< T, ChunkingPolicy > &&)=default
void moveToChunk(int chunk)
Definition ASoA.h:558
void nextChunk() const
Move the iterator to the next chunk.
Definition ASoA.h:536
bool isCached() const
Definition ASoA.h:3780
auto sliceByCachedUnsorted(framework::expressions::BindingNode const &node, int value, o2::framework::SliceCache &cache) const
Definition ASoA.h:3707
int64_t tableSize() const
Definition ASoA.h:3630
FilteredBase(std::vector< std::shared_ptr< arrow::Table > > &&tables, gandiva::Selection const &selection, uint64_t offset=0)
Definition ASoA.h:3553
auto & cached_begin()
Definition ASoA.h:3610
typename T::external_index_columns_t external_index_columns_t
Definition ASoA.h:3547
auto select(framework::expressions::Filter const &f) const
Definition ASoA.h:3724
static auto getSpan(gandiva::Selection const &sel)
Definition ASoA.h:3653
int64_t size() const
Definition ASoA.h:3625
T::template iterator_template_o< FilteredIndexPolicy, self_t > iterator
Definition ASoA.h:3549
auto rawSliceBy(o2::framework::Preslice< T1 > const &container, int value) const
Definition ASoA.h:3697
T::template iterator_template_o< DefaultIndexPolicy, self_t > unfiltered_iterator
Definition ASoA.h:3550
void copyIndexBindings(T1 &dest) const
Definition ASoA.h:3691
auto const & getSelectedRows() const
Definition ASoA.h:3635
void sumWithSelection(std::span< int64_t const > const &selection)
Definition ASoA.h:3760
void intersectWithSelection(std::span< int64_t const > const &selection)
Definition ASoA.h:3770
typename T::columns_t columns_t
Definition ASoA.h:3545
auto emptySlice() const
Definition ASoA.h:3648
void bindExternalIndices(TA *... current)
Definition ASoA.h:3667
void sumWithSelection(SelectionVector const &selection)
Definition ASoA.h:3740
void bindInternalIndicesTo(I const *ptr)
Definition ASoA.h:3679
void intersectWithSelection(SelectionVector const &selection)
Definition ASoA.h:3750
auto sliceBy(o2::framework::PresliceBase< T1, framework::PreslicePolicyGeneral, OPT > const &container, int value) const
Definition ASoA.h:3719
FilteredBase(std::vector< std::shared_ptr< arrow::Table > > &&tables, std::span< int64_t const > const &selection, uint64_t offset=0)
Definition ASoA.h:3577
auto rawSlice(uint64_t start, uint64_t end) const
Definition ASoA.h:3640
auto sliceBy(o2::framework::PresliceBase< T1, framework::PreslicePolicySorted, OPT > const &container, int value) const
Definition ASoA.h:3713
iterator iteratorAt(uint64_t i) const
Definition ASoA.h:3620
iterator const_iterator
Definition ASoA.h:3551
typename T::table_t table_t
Definition ASoA.h:3543
typename T::persistent_columns_t persistent_columns_t
Definition ASoA.h:3546
RowViewSentinel end() const
Definition ASoA.h:3605
FilteredBase(std::vector< std::shared_ptr< arrow::Table > > &&tables, SelectionVector &&selection, uint64_t offset=0)
Definition ASoA.h:3564
void bindExternalIndicesRaw(std::vector< o2::soa::Binding > &&ptrs)
Definition ASoA.h:3673
const_iterator begin() const
Definition ASoA.h:3593
unfiltered_iterator rawIteratorAt(uint64_t i) const
Definition ASoA.h:3598
int isInSelectedRows(int i) const
Definition ASoA.h:3731
auto sliceByCached(framework::expressions::BindingNode const &node, int value, o2::framework::SliceCache &cache) const
Definition ASoA.h:3702
void doCopyIndexBindings(framework::pack< Cs... >, T1 &dest) const
Definition ASoA.h:3685
iterator begin()
Definition ASoA.h:3588
auto const & cached_begin() const
Definition ASoA.h:3615
auto sliceBy(o2::framework::PresliceBase< T1, framework::PreslicePolicySorted, OPT > const &container, int value) const
Definition ASoA.h:4118
Filtered< Filtered< T > > operator*(std::span< int64_t const > const &selection)
Definition ASoA.h:4058
typename FilteredBase< typename T::table_t >::table_t table_t
Definition ASoA.h:3974
typename T::template iterator_template_o< DefaultIndexPolicy, self_t > unfiltered_iterator
Definition ASoA.h:3978
Filtered< Filtered< T > > operator+(SelectionVector const &selection)
Definition ASoA.h:4015
auto sliceBy(o2::framework::PresliceBase< T1, framework::PreslicePolicyGeneral, OPT > const &container, int value) const
Definition ASoA.h:4124
Filtered< Filtered< T > > operator+=(std::span< int64_t const > const &selection)
Definition ASoA.h:4040
typename T::template iterator_template_o< FilteredIndexPolicy, self_t > iterator
Definition ASoA.h:3977
typename T::columns_t columns_t
Definition ASoA.h:3975
const_iterator begin() const
Definition ASoA.h:3986
Filtered(std::vector< Filtered< T > > &&tables, std::span< int64_t const > const &selection, uint64_t offset=0)
Definition ASoA.h:4007
Filtered< Filtered< T > > operator+(std::span< int64_t const > const &selection)
Definition ASoA.h:4022
Filtered(std::vector< Filtered< T > > &&tables, SelectionVector &&selection, uint64_t offset=0)
Definition ASoA.h:3999
unfiltered_iterator rawIteratorAt(uint64_t i) const
Definition ASoA.h:4087
Filtered< Filtered< T > > operator*=(std::span< int64_t const > const &selection)
Definition ASoA.h:4076
Filtered< Filtered< T > > operator+=(Filtered< T > const &other)
Definition ASoA.h:4046
Filtered< Filtered< T > > operator+=(SelectionVector const &selection)
Definition ASoA.h:4034
Filtered< Filtered< T > > operator*=(SelectionVector const &selection)
Definition ASoA.h:4070
auto rawSlice(uint64_t start, uint64_t end) const
Definition ASoA.h:4094
Filtered< Filtered< T > > operator+(Filtered< T > const &other)
Definition ASoA.h:4029
Filtered(std::vector< Filtered< T > > &&tables, gandiva::Selection const &selection, uint64_t offset=0)
Definition ASoA.h:3991
Filtered< Filtered< T > > operator*=(Filtered< T > const &other)
Definition ASoA.h:4082
auto sliceByCached(framework::expressions::BindingNode const &node, int value, o2::framework::SliceCache &cache) const
Definition ASoA.h:4107
Filtered< Filtered< T > > operator*(Filtered< T > const &other)
Definition ASoA.h:4065
Filtered< Filtered< T > > operator*(SelectionVector const &selection)
Definition ASoA.h:4051
auto sliceByCachedUnsorted(framework::expressions::BindingNode const &node, int value, o2::framework::SliceCache &cache) const
Definition ASoA.h:4112
Filtered< T > operator*(std::span< int64_t const > const &selection)
Definition ASoA.h:3881
Filtered< T > operator+=(Filtered< T > const &other)
Definition ASoA.h:3869
auto sliceBy(o2::framework::PresliceBase< T1, framework::PreslicePolicyGeneral, OPT > const &container, int value) const
Definition ASoA.h:3955
Filtered(std::vector< std::shared_ptr< arrow::Table > > &&tables, SelectionVector &&selection, uint64_t offset=0)
Definition ASoA.h:3832
iterator const_iterator
Definition ASoA.h:3817
Filtered< T > operator+(std::span< int64_t const > const &selection)
Definition ASoA.h:3845
iterator begin()
Definition ASoA.h:3819
auto sliceByCachedUnsorted(framework::expressions::BindingNode const &node, int value, o2::framework::SliceCache &cache) const
Definition ASoA.h:3943
Filtered< T > operator+(Filtered< T > const &other)
Definition ASoA.h:3852
Filtered< T > operator*=(SelectionVector const &selection)
Definition ASoA.h:3893
Filtered(std::vector< std::shared_ptr< arrow::Table > > &&tables, std::span< int64_t const > const &selection, uint64_t offset=0)
Definition ASoA.h:3835
auto emptySlice() const
Definition ASoA.h:3927
const_iterator begin() const
Definition ASoA.h:3824
T::template iterator_template_o< FilteredIndexPolicy, self_t > iterator
Definition ASoA.h:3815
auto sliceByCached(framework::expressions::BindingNode const &node, int value, o2::framework::SliceCache &cache) const
Definition ASoA.h:3938
auto select(framework::expressions::Filter const &f) const
Definition ASoA.h:3960
Filtered< T > operator+(SelectionVector const &selection)
Definition ASoA.h:3838
T::template iterator_template_o< DefaultIndexPolicy, self_t > unfiltered_iterator
Definition ASoA.h:3816
unfiltered_iterator rawIteratorAt(uint64_t i) const
Definition ASoA.h:3910
Filtered< T > operator*(SelectionVector const &selection)
Definition ASoA.h:3874
Filtered< T > operator*=(Filtered< T > const &other)
Definition ASoA.h:3905
Filtered< T > operator*(Filtered< T > const &other)
Definition ASoA.h:3888
auto rawSliceBy(o2::framework::Preslice< T1 > const &container, int value) const
Definition ASoA.h:3933
Filtered< T > operator+=(SelectionVector const &selection)
Definition ASoA.h:3857
auto rawSlice(uint64_t start, uint64_t end) const
Definition ASoA.h:3919
Filtered(std::vector< std::shared_ptr< arrow::Table > > &&tables, gandiva::Selection const &selection, uint64_t offset=0)
Definition ASoA.h:3829
auto sliceBy(o2::framework::PresliceBase< T1, framework::PreslicePolicySorted, OPT > const &container, int value) const
Definition ASoA.h:3949
Filtered< T > operator*=(std::span< int64_t const > const &selection)
Definition ASoA.h:3899
Filtered< T > operator+=(std::span< int64_t const > const &selection)
Definition ASoA.h:3863
typename T::table_t table_t
Definition ASoA.h:3812
typename T::columns_t columns_t
Definition ASoA.h:3813
decltype([]< typename... C >(framework::pack< C... > &&) -> framework::selected_pack< soa::is_self_index_t, C... > {}(columns_t{})) internal_index_columns_t
Definition ASoA.h:1861
void bindInternalIndicesExplicit(o2::soa::Binding binding)
Definition ASoA.h:2188
auto & cached_begin()
Definition ASoA.h:2102
iterator iteratorAt(uint64_t i) const
Definition ASoA.h:2131
decltype([]< typename... C >(framework::pack< C... > &&) -> framework::selected_pack< soa::is_persistent_column_t, C... > {}(columns_t{})) persistent_columns_t
Definition ASoA.h:1857
static constexpr const auto ref
Definition ASoA.h:1818
auto offset() const
Return offset.
Definition ASoA.h:2159
static consteval bool hasOriginal()
Definition ASoA.h:1850
unfiltered_iterator begin()
Definition ASoA.h:2112
int64_t tableSize() const
Definition ASoA.h:2169
auto rawSlice(uint64_t start, uint64_t end) const
Definition ASoA.h:2239
void bindExternalIndices(TA *... current)
Definition ASoA.h:2177
auto select(framework::expressions::Filter const &f) const
Definition ASoA.h:2216
unfiltered_iterator unfiltered_const_iterator
Definition ASoA.h:2043
static consteval auto full_iter()
Definition ASoA.h:2022
auto const & cached_begin() const
Definition ASoA.h:2107
auto emptySlice() const
Definition ASoA.h:2244
auto sliceByCachedUnsorted(framework::expressions::BindingNode const &node, int value, o2::framework::SliceCache &cache) const
Definition ASoA.h:2228
void bindExternalIndicesRaw(std::vector< o2::soa::Binding > &&ptrs)
Definition ASoA.h:2199
auto sliceBy(o2::framework::PresliceBase< T1, Policy, OPT > const &container, int value) const
Definition ASoA.h:2234
static constexpr auto hashes()
Definition ASoA.h:2045
iterator unfiltered_iterator
Definition ASoA.h:2041
std::shared_ptr< arrow::Table > asArrowTable() const
Return a type erased arrow table backing store for / the type safe table.
Definition ASoA.h:2154
filtered_iterator filtered_begin(std::span< int64_t const > selection)
Definition ASoA.h:2122
void doCopyIndexBindings(framework::pack< Cs... >, T &dest) const
Definition ASoA.h:2205
int64_t size() const
Size of the table, in rows.
Definition ASoA.h:2164
Table(std::vector< std::shared_ptr< arrow::Table > > &&tables, uint64_t offset=0)
Definition ASoA.h:2076
decltype(getColumns< ref, Ts... >()) columns_t
Definition ASoA.h:1855
arrow::ChunkedArray * getIndexToKey()
Definition ASoA.h:2083
RowViewSentinel end()
Definition ASoA.h:2117
decltype([]< typename... C >(framework::pack< C... >) -> framework::pack< typename C::type... > {}(persistent_columns_t{})) column_types
Definition ASoA.h:1858
static consteval auto isIndexTargetOf()
Definition ASoA.h:1827
iterator_template_o< FilteredIndexPolicy, table_t > filtered_iterator
Definition ASoA.h:2039
unfiltered_const_iterator begin() const
Definition ASoA.h:2143
void copyIndexBindings(T &dest) const
Definition ASoA.h:2211
static constexpr const auto originalLabels
Definition ASoA.h:1823
Table(std::vector< std::shared_ptr< arrow::Table > > &&tables, uint64_t offset=0)
Definition ASoA.h:2070
Table< L, D, O, Ts... > self_t
Definition ASoA.h:1819
static consteval auto isIndexTargetOf()
Definition ASoA.h:1834
decltype(full_iter< IP, Parent >()) iterator_template_o
Definition ASoA.h:2036
void doBindInternalIndicesExplicit(framework::pack< Cs... >, o2::soa::Binding binding)
Definition ASoA.h:2194
static constexpr const auto originals
Definition ASoA.h:1822
decltype([]< typename... C >(framework::pack< C... > &&) -> framework::selected_pack< soa::is_external_index_t, C... > {}(columns_t{})) external_index_columns_t
Definition ASoA.h:1860
Table(std::shared_ptr< arrow::Table > table, uint64_t offset=0)
Definition ASoA.h:2050
RowViewSentinel end() const
Definition ASoA.h:2148
auto sliceByCached(framework::expressions::BindingNode const &node, int value, o2::framework::SliceCache &cache) const
Definition ASoA.h:2223
void bindInternalIndicesTo(I const *ptr)
Definition ASoA.h:2183
unfiltered_iterator rawIteratorAt(uint64_t i) const
Definition ASoA.h:2136
iterator_template_o< DefaultIndexPolicy, table_t > iterator
Definition ASoA.h:2038
hash identification concepts
Definition ASoA.h:387
Helper to check if a type T is an iterator.
Definition ASoA.h:1294
column identification concepts
Definition ASoA.h:195
GLint GLenum GLint x
Definition glcorearb.h:403
GLenum func
Definition glcorearb.h:778
GLint GLsizei count
Definition glcorearb.h:399
GLsizeiptr size
Definition glcorearb.h:659
GLuint GLsizei const GLuint const GLintptr * offsets
Definition glcorearb.h:2595
GLuint GLuint end
Definition glcorearb.h:469
GLenum array
Definition glcorearb.h:4274
GLuint index
Definition glcorearb.h:781
GLuint const GLchar * name
Definition glcorearb.h:781
GLdouble f
Definition glcorearb.h:310
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLsizei const GLfloat * value
Definition glcorearb.h:819
GLenum target
Definition glcorearb.h:1641
GLint GLint GLsizei GLint GLenum GLenum type
Definition glcorearb.h:275
GLboolean * data
Definition glcorearb.h:298
GLintptr offset
Definition glcorearb.h:660
GLuint GLsizei GLsizei * length
Definition glcorearb.h:790
GLuint GLsizei const GLchar * label
Definition glcorearb.h:2519
GLsizei GLenum const void * indices
Definition glcorearb.h:400
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
GLboolean r
Definition glcorearb.h:1233
GLuint start
Definition glcorearb.h:469
GLenum GLenum GLsizei len
Definition glcorearb.h:4232
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233
GLint ref
Definition glcorearb.h:291
std::shared_ptr< gandiva::SelectionVector > Selection
Definition Expressions.h:46
consteval const char * origin_str()
Definition ASoA.h:362
consteval const char * signature()
Definition ASoA.h:374
constexpr framework::ConcreteDataMatcher matcher()
Definition ASoA.h:380
consteval auto filterForKey()
Filter TableRef array for compatibility with Key table.
Definition ASoA.h:282
consteval const char * label()
Definition ASoA.h:356
consteval header::DataOrigin origin()
Definition ASoA.h:368
gandiva::Selection createSelection(std::shared_ptr< arrow::Table > const &table, Filter const &expression)
Function for creating gandiva selection from our internal filter tree.
Defining PrimaryVertex explicitly as messageable.
std::decay_t< decltype(select_pack< Condition >(pack<>{}, Pack{}, CondPack{}))> selected_pack_multicondition
Definition Pack.h:181
std::decay_t< decltype(prune_voids_pack(pack<>{}, with_condition_pack< Condition, Types... >{}))> selected_pack
Definition Pack.h:179
decltype(intersected_pack(Ps{}...)) full_intersected_pack_t
Definition Pack.h:283
typename pack_element< I, T >::type pack_element_t
Definition Pack.h:56
consteval size_t has_type_at_v(pack< Ts... >)
Definition Pack.h:228
constexpr std::size_t pack_size(pack< Ts... > const &)
template function to determine number of types in a pack
Definition Pack.h:28
decltype(concatenate_pack_unique(Ps{}...)) concatenated_pack_unique_t
Definition Pack.h:319
std::string strToUpper(std::string &&str)
Definition ASoA.cxx:275
typename pack_element< 0, T >::type pack_head_t
Definition Pack.h:59
std::string cutString(std::string &&str)
Definition ASoA.cxx:266
std::vector< std::vector< int64_t > > ListVector
Descriptor< gSizeDataDescriptionString > DataDescription
Definition DataHeader.h:551
R getColumnValue(const T &rowIterator)
Definition ASoA.h:2277
ColumnGetterFunction< R, typename T::iterator > getColumnGetterByLabel(const std::string_view &targetColumnLabel)
Definition ASoA.h:2344
void * extractCCDBPayload(char *payload, size_t size, TClass const *cl, const char *what)
Definition ASoA.cxx:206
consteval auto computeOriginals()
Definition ASoA.h:1800
auto createFieldsFromColumns(framework::pack< C... >)
Definition ASoA.h:58
SelectionVector selectionToVector(gandiva::Selection const &sel)
Definition ASoA.cxx:48
constexpr bool is_persistent_v
Definition ASoA.h:198
constexpr bool is_ng_index_equivalent_v
Definition ASoA.h:466
consteval auto remove_if(L l)
Definition ASoA.h:136
constexpr auto join(Ts const &... t)
Definition ASoA.h:3489
auto doSliceBy(T const *table, o2::framework::PresliceBase< C, Policy, OPT > const &container, int value)
Definition ASoA.h:1628
void notBoundTable(const char *tableName)
Definition ASoA.cxx:191
SelectionVector sliceSelection(std::span< int64_t const > const &mSelectedRows, int64_t nrows, uint64_t offset)
Definition ASoA.cxx:58
auto doFilteredSliceBy(T const *table, o2::framework::PresliceBase< C, framework::PreslicePolicySorted, OPT > const &container, int value)
Definition ASoA.h:1704
constexpr auto concat(Ts const &... t)
Definition ASoA.h:3533
consteval auto intersectOriginals()
Definition ASoA.h:171
consteval auto getColumns()
Definition ASoA.h:1772
std::vector< int64_t > SelectionVector
Definition ASoA.h:429
std::conditional_t< is_binding_compatible_v< T, typename B::binding_t >(), std::true_type, std::false_type > is_binding_compatible
Definition ASoA.h:1346
consteval auto mergeOriginals()
Definition ASoA.h:154
constexpr bool is_soa_filtered_v
Definition ASoA.h:1609
typename std::conditional_t< is_index_column< C >, std::true_type, std::false_type > is_external_index_t
Definition ASoA.h:213
void missingFilterDeclaration(int hash, int ai)
Definition ASoA.cxx:33
auto doSliceByCachedUnsorted(T const *table, framework::expressions::BindingNode const &node, int value, o2::framework::SliceCache &cache)
Definition ASoA.h:1738
auto doSliceByCached(T const *table, framework::expressions::BindingNode const &node, int value, o2::framework::SliceCache &cache)
Definition ASoA.h:1717
void accessingInvalidIndexFor(const char *getter)
Definition ASoA.cxx:25
auto select(T const &t, framework::expressions::Filter const &f)
Definition ASoA.h:1758
consteval auto base_iter(framework::pack< C... > &&) -> TableIterator< D, O, IP, C... >
Definition ASoA.h:1766
constexpr bool is_index_equivalent_v
Definition ASoA.h:463
constexpr bool is_soa_join_v
Definition ASoA.h:3498
void dereferenceWithWrongType(const char *getter, const char *target)
Definition ASoA.cxx:29
std::conditional_t< is_indexing_column< T >, std::true_type, std::false_type > is_indexing_t
Definition ASoA.h:852
consteval bool is_binding_compatible_v()
Definition ASoA.h:1340
auto prepareFilteredSlice(T const *table, std::shared_ptr< arrow::Table > slice, uint64_t offset)
Definition ASoA.h:1685
void emptyColumnLabel()
Definition ASoA.cxx:43
typename unwrap< T >::type unwrap_t
Definition ASoA.h:498
void getterNotFound(const char *targetColumnLabel)
Definition ASoA.cxx:38
auto doFilteredSliceByCached(T const *table, framework::expressions::BindingNode const &node, int value, o2::framework::SliceCache &cache)
Definition ASoA.h:1729
void missingOptionalPreslice(const char *label, const char *key)
Definition ASoA.cxx:201
auto doSliceByHelper(T const *table, std::span< const int64_t > const &selection)
Definition ASoA.h:1646
consteval bool is_compatible()
Definition ASoA.h:1327
arrow::ChunkedArray * getIndexFromLabel(arrow::Table *table, std::string_view label)
Definition ASoA.cxx:170
consteval auto merge()
Helpers to manipulate TableRef arrays.
Definition ASoA.h:113
consteval auto merge_if(L l)
Definition ASoA.h:124
std::conditional_t< is_persistent_column< C >, std::true_type, std::false_type > is_persistent_column_t
Definition ASoA.h:201
typename arrow_array_for< T >::type arrow_array_for_t
Definition ArrowTypes.h:118
void notFoundColumn(const char *label, const char *key)
Definition ASoA.cxx:196
std::conditional_t< is_dynamic_column< T >, std::true_type, std::false_type > is_dynamic_t
Definition ASoA.h:846
typename std::conditional_t< is_self_index_column< C >, std::true_type, std::false_type > is_self_index_t
Definition ASoA.h:216
@ C
Definition Defs.h:36
Defining DataPointCompositeObject explicitly as copiable.
FIXME: do not use data model tables.
Definition list.h:40
static constexpr uint32_t hash
Definition ASoA.h:276
static constexpr char const *const str
Definition ASoA.h:277
Base type for table metadata.
Definition ASoA.h:237
static consteval int getIndexPosToKey()
Definition ASoA.h:256
framework::selected_pack< soa::is_self_index_t, Cs... > internal_index_columns_t
Definition ASoA.h:241
framework::selected_pack< soa::is_persistent_column_t, Cs... > persistent_columns_t
Definition ASoA.h:239
static std::shared_ptr< arrow::Schema > getSchema()
Definition ASoA.h:261
framework::selected_pack< soa::is_external_index_t, Cs... > external_index_columns_t
Definition ASoA.h:240
static consteval std::array< bool, sizeof...(PCs)> getMap(framework::pack< PCs... >)
Definition ASoA.h:244
SliceInfoUnsortedPtr getCacheUnsortedFor(Entry const &bindingKey) const
SliceInfoPtr getCacheFor(Entry const &bindingKey) const
std::shared_ptr< arrow::Table > getSliceFor(int value, std::shared_ptr< arrow::Table > const &input, uint64_t &offset) const
Definition ASoA.h:1534
static constexpr bool optional
Definition ASoA.h:1524
PresliceBase(expressions::BindingNode index_)
Definition ASoA.h:1529
std::span< const int64_t > getSliceFor(int value) const
Definition ASoA.h:1544
const std::string binding
Definition ASoA.h:1527
const std::string binding
Definition ASoA.h:1498
Entry const & getBindingKey() const
Definition ASoA.cxx:286
SliceInfoUnsortedPtr sliceInfo
Definition ASoA.h:1515
std::span< const int64_t > getSliceFor(int value) const
Definition ASoA.cxx:309
void updateSliceInfo(SliceInfoUnsortedPtr &&si)
Definition ASoA.cxx:296
void updateSliceInfo(SliceInfoPtr &&si)
Definition ASoA.cxx:291
std::shared_ptr< arrow::Table > getSliceFor(int value, std::shared_ptr< arrow::Table > const &input, uint64_t &offset) const
Definition ASoA.cxx:301
ArrowTableSlicingCache * ptr
Definition SliceCache.h:22
std::pair< int64_t, int64_t > getSliceFor(int value) const
An expression tree node corresponding to a column binding.
A struct, containing the root of the expression tree.
From https://en.cppreference.com/w/cpp/utility/variant/visit.
static std::shared_ptr< arrow::Table > joinTables(std::vector< std::shared_ptr< arrow::Table > > &&tables)
Definition ASoA.cxx:72
static std::shared_ptr< arrow::Table > concatTables(std::vector< std::shared_ptr< arrow::Table > > &&tables)
Definition ASoA.cxx:132
Type-checking index column binding.
Definition ASoA.h:406
std::span< TableRef const > refs
Definition ASoA.h:409
size_t hash
Definition ASoA.h:408
void const * ptr
Definition ASoA.h:407
void bind(T const *table)
Definition ASoA.h:412
T const * get() const
Definition ASoA.h:420
static constexpr bool chunked
Definition ASoA.h:472
arrow::ChunkedArray * second
Definition ASoA.h:1059
Column(ColumnIterator< T > const &it)
Definition ASoA.h:682
Column()=default
static constexpr const char *const & columnLabel()
Definition ASoA.h:695
ColumnIterator< T > const & getIterator() const
Definition ASoA.h:696
Column & operator=(Column const &)=default
INHERIT inherited_t
Definition ASoA.h:681
Column(Column &&)=default
static auto asArrowField()
Definition ASoA.h:701
Column & operator=(Column &&)=default
Column(Column const &)=default
ColumnIterator< T > mColumnIterator
Definition ASoA.h:708
table_t::template iterator_template< DefaultIndexPolicy, self_t, Ts... > iterator
Definition ASoA.h:3524
Concat(Ts const &... t, uint64_t offset=0)
Definition ASoA.h:3509
typename table_t::persistent_columns_t persistent_columns_t
Definition ASoA.h:3522
typename table_t::columns_t columns_t
Definition ASoA.h:3521
iterator const_iterator
Definition ASoA.h:3525
const_iterator unfiltered_const_iterator
Definition ASoA.h:3527
iterator unfiltered_iterator
Definition ASoA.h:3526
table_t::template iterator_template< FilteredIndexPolicy, self_t, Ts... > filtered_iterator
Definition ASoA.h:3528
Concat(std::vector< std::shared_ptr< arrow::Table > > &&tables, uint64_t offset=0)
Definition ASoA.h:3504
filtered_iterator filtered_const_iterator
Definition ASoA.h:3529
DefaultIndexPolicy(int64_t nRows, uint64_t offset)
Definition ASoA.h:981
friend bool operator==(DefaultIndexPolicy const &lh, DefaultIndexPolicy const &rh)
Definition ASoA.h:1027
bool operator==(RowViewSentinel const &sentinel) const
Definition ASoA.h:1032
DefaultIndexPolicy(FilteredIndexPolicy const &other)
Definition ASoA.h:987
std::tuple< uint64_t const * > getOffsets() const
Definition ASoA.h:1008
DefaultIndexPolicy & operator=(DefaultIndexPolicy &&)=default
void setCursor(int64_t i)
Definition ASoA.h:1013
void limitRange(int64_t start, int64_t end)
Definition ASoA.h:993
DefaultIndexPolicy(DefaultIndexPolicy &&)=default
DefaultIndexPolicy(DefaultIndexPolicy const &)=default
DefaultIndexPolicy & operator=(DefaultIndexPolicy const &)=default
std::tuple< int64_t const *, int64_t const * > getIndices() const
Definition ASoA.h:1002
DefaultIndexPolicy()=default
Needed to be able to copy the policy.
void moveByIndex(int64_t i)
Definition ASoA.h:1017
static constexpr const char *const & columnLabel()
Definition ASoA.h:717
INHERIT inherited_t
Definition ASoA.h:715
FilteredIndexPolicy & operator=(FilteredIndexPolicy &&)=default
std::tuple< int64_t const *, int64_t const * > getIndices() const
Definition ASoA.h:894
FilteredIndexPolicy & operator=(FilteredIndexPolicy const &)=default
auto getSelectionRow() const
Definition ASoA.h:944
FilteredIndexPolicy(std::span< int64_t const > selection, int64_t rows, uint64_t offset=0)
Definition ASoA.h:871
friend bool operator==(FilteredIndexPolicy const &lh, FilteredIndexPolicy const &rh)
Definition ASoA.h:925
void resetSelection(std::span< int64_t const > selection)
Definition ASoA.h:880
void setCursor(int64_t i)
Definition ASoA.h:913
FilteredIndexPolicy(FilteredIndexPolicy const &)=default
auto raw_size() const
Definition ASoA.h:954
bool operator==(RowViewSentinel const &sentinel) const
Definition ASoA.h:930
std::tuple< uint64_t const * > getOffsets() const
Definition ASoA.h:900
void limitRange(int64_t start, int64_t end)
Definition ASoA.h:905
FilteredIndexPolicy(FilteredIndexPolicy &&)=default
void moveByIndex(int64_t i)
Definition ASoA.h:919
static constexpr bool chunked
Definition ASoA.h:478
static constexpr const char *const & columnLabel()
Definition ASoA.h:725
INHERIT inherited_t
Definition ASoA.h:722
static constexpr const uint32_t hash
Definition ASoA.h:723
uint64_t mOffset
Offset within a larger table.
Definition ASoA.h:858
int64_t mRowIndex
Position inside the current table.
Definition ASoA.h:856
IndexTable(std::vector< std::shared_ptr< arrow::Table > > tables, uint64_t offset=0)
Definition ASoA.h:4160
IndexTable(std::shared_ptr< arrow::Table > table, uint64_t offset=0)
Definition ASoA.h:4155
typename base_t::template iterator_template_o< DefaultIndexPolicy, self_t > iterator
Definition ASoA.h:4170
filtered_iterator const_filtered_iterator
Definition ASoA.h:4173
IndexTable(IndexTable &&)=default
IndexTable & operator=(IndexTable const &)=default
iterator const_iterator
Definition ASoA.h:4171
IndexTable & operator=(IndexTable &&)=default
typename H::binding_t first_t
Definition ASoA.h:4152
typename base_t::template iterator_template_o< FilteredIndexPolicy, self_t > filtered_iterator
Definition ASoA.h:4172
IndexTable(IndexTable const &)=default
int64_t type
Definition ASoA.h:823
Index(Index const &)=default
void setIndices(std::tuple< int64_t const *, int64_t const * > indices)
Definition ASoA.h:812
Index & operator=(Index &&)=default
int64_t index() const
Definition ASoA.h:785
Index()=default
Index(arrow::ChunkedArray const *)
Definition ASoA.h:771
int64_t filteredIndex() const
Definition ASoA.h:790
constexpr int64_t rangeEnd()
Definition ASoA.h:780
constexpr int64_t rangeStart()
Definition ASoA.h:775
Index(Index &&)=default
Index & operator=(Index const &)=default
int64_t index() const
Definition ASoA.h:801
int64_t globalIndex() const
Definition ASoA.h:795
std::tuple< int64_t const *, int64_t const * > rowIndices
Definition ASoA.h:825
int64_t offsets() const
Definition ASoA.h:807
void setOffsets(std::tuple< uint64_t const * > offsets)
Definition ASoA.h:817
static constexpr const char * mLabel
Definition ASoA.h:822
std::tuple< uint64_t const * > rowOffsets
Definition ASoA.h:828
iterator begin()
Definition ASoA.h:3430
iterator unfiltered_iterator
Definition ASoA.h:3425
auto sliceBy(o2::framework::PresliceBase< T1, Policy, OPT > const &container, int value) const
Definition ASoA.h:3451
auto rawSlice(uint64_t start, uint64_t end) const
Definition ASoA.h:3468
auto sliceByCachedUnsorted(framework::expressions::BindingNode const &node, int value, o2::framework::SliceCache &cache) const
Definition ASoA.h:3445
JoinFull(std::vector< std::shared_ptr< arrow::Table > > &&tables, uint64_t offset=0)
Definition ASoA.h:3407
static constexpr const auto originalLabels
Definition ASoA.h:3420
const_iterator unfiltered_const_iterator
Definition ASoA.h:3426
filtered_iterator filtered_const_iterator
Definition ASoA.h:3428
static consteval bool contains()
Definition ASoA.h:3479
iterator iteratorAt(uint64_t i) const
Definition ASoA.h:3463
typename table_t::columns_t columns_t
Definition ASoA.h:3421
table_t::template iterator_template< DefaultIndexPolicy, self_t, Ts... > iterator
Definition ASoA.h:3423
table_t::template iterator_template< FilteredIndexPolicy, self_t, Ts... > filtered_iterator
Definition ASoA.h:3427
static constexpr const auto originals
Definition ASoA.h:3419
JoinFull< D, Ts... > self_t
Definition ASoA.h:3417
const_iterator begin() const
Definition ASoA.h:3435
typename table_t::persistent_columns_t persistent_columns_t
Definition ASoA.h:3422
iterator const_iterator
Definition ASoA.h:3424
iterator rawIteratorAt(uint64_t i) const
Definition ASoA.h:3456
Table< o2::aod::Hash<"JOIN"_h >, D, o2::aod::Hash<"JOIN"_h >, Ts... > base
Definition ASoA.h:3398
JoinFull(std::shared_ptr< arrow::Table > &&table, uint64_t offset=0)
Definition ASoA.h:3400
auto emptySlice() const
Definition ASoA.h:3473
auto sliceByCached(framework::expressions::BindingNode const &node, int value, o2::framework::SliceCache &cache) const
Definition ASoA.h:3440
static constexpr const uint32_t hash
Definition ASoA.h:731
static constexpr const char *const & columnLabel()
Definition ASoA.h:733
INHERIT inherited_t
Definition ASoA.h:730
constexpr auto mark()
Definition ASoA.h:750
Marker & operator=(Marker const &)=default
size_t type
Definition ASoA.h:738
static constexpr auto value
Definition ASoA.h:740
static constexpr const char * mLabel
Definition ASoA.h:755
Marker(arrow::ChunkedArray const *)
Definition ASoA.h:749
Marker()=default
Marker(Marker const &)=default
Marker & operator=(Marker &&)=default
Marker(Marker &&)=default
int64_t const index
Definition ASoA.h:862
SmallGroupsBase(std::vector< std::shared_ptr< arrow::Table > > &&tables, SelectionVector &&selection, uint64_t offset=0)
Definition ASoA.h:4182
SmallGroupsBase(std::vector< std::shared_ptr< arrow::Table > > &&tables, std::span< int64_t const > const &selection, uint64_t offset=0)
Definition ASoA.h:4185
SmallGroupsBase(std::vector< std::shared_ptr< arrow::Table > > &&tables, gandiva::Selection const &selection, uint64_t offset=0)
Definition ASoA.h:4179
framework::selected_pack< soa::is_persistent_column_t, C... > persistent_columns_t
Definition ASoA.h:1076
void doSetCurrentIndexRaw(framework::pack< Cs... > p, std::vector< o2::soa::Binding > &&ptrs)
Definition ASoA.h:1209
void bindInternalIndices(I const *table)
Definition ASoA.h:1228
TableIterator(TableIterator< D, O, FilteredIndexPolicy, C... > const &other)
Definition ASoA.h:1125
TableIterator(self_t const &other)
Definition ASoA.h:1106
TableIterator operator-(int64_t dec) const
Definition ASoA.h:1169
TableIterator(arrow::ChunkedArray *columnData[sizeof...(C)], IP &&policy)
Definition ASoA.h:1090
TableIterator & operator=(TableIterator other)
Definition ASoA.h:1115
TableIterator & operator++()
Definition ASoA.h:1135
void doSetCurrentInternal(framework::pack< Cs... >, I const *ptr)
Definition ASoA.h:1215
auto getIndexBindingsImpl(framework::pack< Cs... >) const
Definition ASoA.h:1192
TableIterator operator--(int)
Definition ASoA.h:1154
void bindExternalIndicesRaw(std::vector< o2::soa::Binding > &&ptrs)
Definition ASoA.h:1222
TableIterator(arrow::ChunkedArray *columnData[sizeof...(C)], IP &&policy)
Definition ASoA.h:1081
decltype([]< typename... Cs >(framework::pack< Cs... >) -> framework::pack< typename Cs::binding_t... > {}(external_index_columns_t{})) bindings_pack_t
Definition ASoA.h:1079
void bindExternalIndices(TA *... current)
Definition ASoA.h:1203
auto getCurrent() const
Definition ASoA.h:1186
TableIterator & operator--()
Definition ASoA.h:1148
framework::selected_pack< soa::is_external_index_t, C... > external_index_columns_t
Definition ASoA.h:1077
TableIterator const & operator*() const
Definition ASoA.h:1174
TableIterator operator++(int)
Definition ASoA.h:1141
framework::selected_pack< soa::is_self_index_t, C... > internal_index_columns_t
Definition ASoA.h:1078
auto getIndexBindings() const
Definition ASoA.h:1197
void doSetCurrentIndex(framework::pack< CL... >, TA *current)
Definition ASoA.h:1180
TableIterator operator+(int64_t inc) const
Allow incrementing by more than one the iterator.
Definition ASoA.h:1162
Generic identifier for a table type.
Definition ASoA.h:67
constexpr TableRef & operator=(TableRef const &)=default
consteval TableRef()
Definition ASoA.h:68
uint32_t label_hash
Definition ASoA.h:82
constexpr bool descriptionCompatible(uint32_t _desc_hash) const noexcept
Definition ASoA.h:100
constexpr bool operator==(TableRef const &other) const noexcept
Definition ASoA.h:87
constexpr TableRef(TableRef &&)=default
uint32_t version
Definition ASoA.h:85
constexpr TableRef(TableRef const &)=default
consteval TableRef(uint32_t _label, uint32_t _desc, uint32_t _origin, uint32_t _version)
Definition ASoA.h:75
constexpr bool descriptionCompatible(TableRef const &other) const noexcept
Definition ASoA.h:95
uint32_t desc_hash
Definition ASoA.h:83
uint32_t origin_hash
Definition ASoA.h:84
constexpr TableRef & operator=(TableRef &&)=default
TableIteratorBase const & operator*() const
Definition ASoA.h:2012
TableIteratorBase(TableIteratorBase< IP, P, T... > const &other)
Definition ASoA.h:1920
typename Parent::columns_t columns_t
Definition ASoA.h:1867
TableIteratorBase(TableIteratorBase< IP, P, O1, Os... > const &other)
Definition ASoA.h:1906
typename Parent::external_index_columns_t external_index_columns_t
Definition ASoA.h:1868
TableIteratorBase operator-(int64_t dec) const
Definition ASoA.h:2007
void matchTo(TableIteratorBase< IP, P, T... > const &other)
Definition ASoA.h:1944
void matchTo(TableIteratorBase< IP, P, Os... > const &other)
Definition ASoA.h:1950
TableIteratorBase(TableIteratorBase< FilteredIndexPolicy, P, T... > other)
Definition ASoA.h:1932
std::array< B, sizeof...(CCs)> getValues() const
Definition ASoA.h:1989
static constexpr auto originals
Definition ASoA.h:1871
TableIteratorBase(TableIteratorBase< IP, P, T... > &&other) noexcept
Definition ASoA.h:1926
decltype([]< typename... C >(framework::pack< C... >) -> framework::pack< typename C::binding_t... > {}(external_index_columns_t{})) bindings_pack_t
Definition ASoA.h:1869
TableIteratorBase & operator=(TableIteratorBase< IP, P, Os... > other)
Definition ASoA.h:1883
TableIteratorBase(TableIteratorBase< IP, P, O1, Os... > &&other) noexcept
Definition ASoA.h:1913
TableIteratorBase & operator=(RowViewSentinel const &other)
Definition ASoA.h:1938
TableIteratorBase(arrow::ChunkedArray *columnData[framework::pack_size(columns_t{})], IP &&policy)
Definition ASoA.h:1877
TableIteratorBase & operator=(TableIteratorBase< IP, P, T... > other)
Definition ASoA.h:1891
TableIteratorBase operator+(int64_t inc) const
Allow incrementing by more than one the iterator.
Definition ASoA.h:2000
TableIteratorBase & operator=(TableIteratorBase< FilteredIndexPolicy, P, T... > other)
Definition ASoA.h:1898
unwrapper
Definition ASoA.h:483
VectorOfTObjectPtrs other
std::vector< ReadoutWindowData > rows
const std::string str