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, std::span<const char* const> labels);
1287 static std::shared_ptr<arrow::Table> joinTables(std::vector<std::shared_ptr<arrow::Table>>&& tables, std::span<const std::string> labels);
1288 static std::shared_ptr<arrow::Table> concatTables(std::vector<std::shared_ptr<arrow::Table>>&& tables);
1289};
1290
1292template <typename T>
1294
1295template <typename T>
1296concept with_originals = requires {
1297 T::originals.size();
1298};
1299
1300template <typename T>
1301concept with_sources = requires {
1302 T::sources.size();
1303};
1304
1305template <typename T>
1306concept with_ccdb_urls = requires {
1307 T::ccdb_urls.size();
1308};
1309
1310template <typename T>
1311concept with_base_table = requires {
1312 typename aod::MetadataTrait<o2::aod::Hash<T::ref.desc_hash>>::metadata::base_table_t;
1313};
1314
1315template <typename T>
1316concept with_expression_pack = requires {
1317 typename T::expression_pack_t{};
1318};
1319
1320template <typename T>
1321concept with_index_pack = requires {
1322 typename T::index_pack_t{};
1323};
1324
1325template <size_t N1, std::array<TableRef, N1> os1, size_t N2, std::array<TableRef, N2> os2>
1326consteval bool is_compatible()
1327{
1328 return []<size_t... Is>(std::index_sequence<Is...>) {
1329 return ([]<size_t... Ks>(std::index_sequence<Ks...>) {
1330 constexpr auto h = os1[Is].desc_hash;
1331 using H = o2::aod::Hash<h>;
1332 return (((h == os2[Ks].desc_hash) || is_ng_index_equivalent_v<H, o2::aod::Hash<os2[Ks].desc_hash>>) || ...);
1333 }(std::make_index_sequence<N2>()) ||
1334 ...);
1335 }(std::make_index_sequence<N1>());
1336}
1337
1338template <with_originals T, with_originals B>
1340{
1341 return is_compatible<T::originals.size(), T::originals, B::originals.size(), B::originals>();
1342}
1343
1344template <typename T, typename B>
1345using is_binding_compatible = std::conditional_t<is_binding_compatible_v<T, typename B::binding_t>(), std::true_type, std::false_type>;
1346
1347template <typename L, typename D, typename O, typename Key, typename H, typename... Ts>
1348struct IndexTable;
1349
1350template <typename T>
1352
1353template <soa::is_table T>
1354static constexpr std::string getLabelForTable()
1355{
1356 return std::string{aod::label<std::decay_t<T>::originals[0]>()};
1357}
1358
1359template <soa::is_table T>
1361static constexpr std::string getLabelFromType()
1362{
1363 return getLabelForTable<T>();
1364}
1365
1366template <soa::is_iterator T>
1367static constexpr std::string getLabelFromType()
1368{
1369 return getLabelForTable<typename std::decay_t<T>::parent_t>();
1370}
1371
1372template <soa::is_index_table T>
1373static constexpr std::string getLabelFromType()
1374{
1375 return getLabelForTable<typename std::decay_t<T>::first_t>();
1376}
1377template <soa::with_base_table T>
1378static constexpr std::string getLabelFromType()
1379{
1380 return getLabelForTable<typename aod::MetadataTrait<o2::aod::Hash<T::ref.desc_hash>>::metadata::base_table_t>();
1381}
1382
1383template <typename... C>
1384static constexpr auto hasColumnForKey(framework::pack<C...>, std::string const& key)
1385{
1386 auto caseInsensitiveCompare = [](const std::string_view& str1, const std::string& str2) {
1387 return std::ranges::equal(
1388 str1, str2,
1389 [](char c1, char c2) {
1390 return std::tolower(static_cast<unsigned char>(c1)) ==
1391 std::tolower(static_cast<unsigned char>(c2));
1392 });
1393 };
1394 return (caseInsensitiveCompare(C::inherited_t::mLabel, key) || ...);
1395}
1396
1397template <TableRef ref>
1398static constexpr std::pair<bool, std::string> hasKey(std::string const& key)
1399{
1400 return {hasColumnForKey(typename aod::MetadataTrait<o2::aod::Hash<ref.desc_hash>>::metadata::columns{}, key), aod::label<ref>()};
1401}
1402
1403template <TableRef ref>
1404static constexpr std::pair<bool, framework::ConcreteDataMatcher> hasKeyM(std::string const& key)
1405{
1406 return {hasColumnForKey(typename aod::MetadataTrait<o2::aod::Hash<ref.desc_hash>>::metadata::columns{}, key), aod::matcher<ref>()};
1407}
1408
1409template <typename... C>
1410static constexpr auto haveKey(framework::pack<C...>, std::string const& key)
1411{
1412 return std::vector{hasKey<C>(key)...};
1413}
1414
1415void notFoundColumn(const char* label, const char* key);
1416void missingOptionalPreslice(const char* label, const char* key);
1417
1418template <with_originals T, bool OPT = false>
1419static constexpr std::string getLabelFromTypeForKey(std::string const& key)
1420{
1421 if constexpr (T::originals.size() == 1) {
1422 auto locate = hasKey<T::originals[0]>(key);
1423 if (locate.first) {
1424 return locate.second;
1425 }
1426 } else {
1427 auto locate = [&]<size_t... Is>(std::index_sequence<Is...>) {
1428 return std::vector{hasKey<T::originals[Is]>(key)...};
1429 }(std::make_index_sequence<T::originals.size()>{});
1430 auto it = std::find_if(locate.begin(), locate.end(), [](auto const& x) { return x.first; });
1431 if (it != locate.end()) {
1432 return it->second;
1433 }
1434 }
1435 if constexpr (!OPT) {
1436 notFoundColumn(getLabelFromType<std::decay_t<T>>().data(), key.data());
1437 } else {
1438 return "[MISSING]";
1439 }
1441}
1442
1443template <with_originals T, bool OPT = false>
1444static constexpr framework::ConcreteDataMatcher getMatcherFromTypeForKey(std::string const& key)
1445{
1446 if constexpr (T::originals.size() == 1) {
1447 auto locate = hasKeyM<T::originals[0]>(key);
1448 if (locate.first) {
1449 return locate.second;
1450 }
1451 } else {
1452 auto locate = [&]<size_t... Is>(std::index_sequence<Is...>) {
1453 return std::vector{hasKeyM<T::originals[Is]>(key)...};
1454 }(std::make_index_sequence<T::originals.size()>{});
1455 auto it = std::find_if(locate.begin(), locate.end(), [](auto const& x) { return x.first; });
1456 if (it != locate.end()) {
1457 return it->second;
1458 }
1459 }
1460 if constexpr (!OPT) {
1461 notFoundColumn(getLabelFromType<std::decay_t<T>>().data(), key.data());
1462 } else {
1464 }
1466}
1467
1468template <typename B, typename... C>
1469consteval static bool hasIndexTo(framework::pack<C...>&&)
1470{
1471 return (o2::soa::is_binding_compatible_v<B, typename C::binding_t>() || ...);
1472}
1473
1474template <typename B, typename... C>
1475consteval static bool hasSortedIndexTo(framework::pack<C...>&&)
1476{
1477 return ((C::sorted && o2::soa::is_binding_compatible_v<B, typename C::binding_t>()) || ...);
1478}
1479
1480template <typename B, typename Z>
1481consteval static bool relatedByIndex()
1482{
1483 return hasIndexTo<B>(typename Z::table_t::external_index_columns_t{});
1484}
1485
1486template <typename B, typename Z>
1487consteval static bool relatedBySortedIndex()
1488{
1489 return hasSortedIndexTo<B>(typename Z::table_t::external_index_columns_t{});
1490}
1491} // namespace o2::soa
1492
1493namespace o2::framework
1494{
1495
1497 const std::string binding;
1499
1500 bool isMissing() const;
1501 Entry const& getBindingKey() const;
1502};
1503
1505 void updateSliceInfo(SliceInfoPtr&& si);
1506
1508 std::shared_ptr<arrow::Table> getSliceFor(int value, std::shared_ptr<arrow::Table> const& input, uint64_t& offset) const;
1509};
1510
1513
1515 std::span<const int64_t> getSliceFor(int value) const;
1516};
1517
1518template <typename T>
1519concept is_preslice_policy = std::derived_from<T, PreslicePolicyBase>;
1520
1521template <typename T, is_preslice_policy Policy, bool OPT = false>
1522struct PresliceBase : public Policy {
1523 constexpr static bool optional = OPT;
1524 using target_t = T;
1525 using policy_t = Policy;
1526 const std::string binding;
1527
1529 : 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})}, {}}
1530 {
1531 }
1532
1533 std::shared_ptr<arrow::Table> getSliceFor(int value, std::shared_ptr<arrow::Table> const& input, uint64_t& offset) const
1534 {
1535 if constexpr (OPT) {
1536 if (Policy::isMissing()) {
1537 return nullptr;
1538 }
1539 }
1540 return Policy::getSliceFor(value, input, offset);
1541 }
1542
1543 std::span<const int64_t> getSliceFor(int value) const
1544 {
1545 if constexpr (OPT) {
1546 if (Policy::isMissing()) {
1547 return {};
1548 }
1549 }
1550 return Policy::getSliceFor(value);
1551 }
1552};
1553
1554template <typename T>
1556template <typename T>
1558template <typename T>
1560template <typename T>
1562
1563template <typename T>
1564concept is_preslice = std::derived_from<T, PreslicePolicyBase>&&
1565 requires(T)
1566{
1567 T::optional;
1568};
1569
1583};
1584
1585template <typename T>
1586concept is_preslice_group = std::derived_from<T, PresliceGroup>;
1587
1588} // namespace o2::framework
1589
1590namespace o2::soa
1591{
1592template <soa::is_table T>
1593class FilteredBase;
1594template <typename T>
1595class Filtered;
1596
1597template <typename T>
1598concept has_filtered_policy = not_void<typename T::policy_t> && std::same_as<typename T::policy_t, soa::FilteredIndexPolicy>;
1599
1600template <typename T>
1602
1603template <typename T>
1605
1606// FIXME: compatbility declaration to be removed
1607template <typename T>
1609
1610template <typename T>
1612
1613template <typename T>
1615
1617template <typename... Is>
1618static consteval auto extractBindings(framework::pack<Is...>)
1619{
1620 return framework::pack<typename Is::binding_t...>{};
1621}
1622
1624
1625template <typename T, typename C, typename Policy, bool OPT>
1626 requires std::same_as<Policy, framework::PreslicePolicySorted> && (o2::soa::is_binding_compatible_v<C, T>())
1627auto doSliceBy(T const* table, o2::framework::PresliceBase<C, Policy, OPT> const& container, int value)
1628{
1629 if constexpr (OPT) {
1630 if (container.isMissing()) {
1631 missingOptionalPreslice(getLabelFromType<std::decay_t<T>>().data(), container.bindingKey.key.c_str());
1632 }
1633 }
1634 uint64_t offset = 0;
1635 auto out = container.getSliceFor(value, table->asArrowTable(), offset);
1636 auto t = typename T::self_t({out}, offset);
1637 if (t.tableSize() != 0) {
1638 table->copyIndexBindings(t);
1639 t.bindInternalIndicesTo(table);
1640 }
1641 return t;
1642}
1643
1644template <soa::is_filtered_table T>
1645auto doSliceByHelper(T const* table, std::span<const int64_t> const& selection)
1646{
1647 auto t = soa::Filtered<typename T::base_t>({table->asArrowTable()}, selection);
1648 if (t.tableSize() != 0) {
1649 table->copyIndexBindings(t);
1650 t.bindInternalIndicesTo(table);
1651 t.intersectWithSelection(table->getSelectedRows()); // intersect filters
1652 }
1653 return t;
1654}
1655
1656template <soa::is_table T>
1657 requires(!soa::is_filtered_table<T>)
1658auto doSliceByHelper(T const* table, std::span<const int64_t> const& selection)
1659{
1660 auto t = soa::Filtered<T>({table->asArrowTable()}, selection);
1661 if (t.tableSize() != 0) {
1662 table->copyIndexBindings(t);
1663 t.bindInternalIndicesTo(table);
1664 }
1665 return t;
1666}
1667
1668template <typename T, typename C, typename Policy, bool OPT>
1669 requires std::same_as<Policy, framework::PreslicePolicyGeneral> && (o2::soa::is_binding_compatible_v<C, T>())
1670auto doSliceBy(T const* table, o2::framework::PresliceBase<C, Policy, OPT> const& container, int value)
1671{
1672 if constexpr (OPT) {
1673 if (container.isMissing()) {
1674 missingOptionalPreslice(getLabelFromType<std::decay_t<T>>().data(), container.bindingKey.key.c_str());
1675 }
1676 }
1677 auto selection = container.getSliceFor(value);
1678 return doSliceByHelper(table, selection);
1679}
1680
1681SelectionVector sliceSelection(std::span<int64_t const> const& mSelectedRows, int64_t nrows, uint64_t offset);
1682
1683template <soa::is_filtered_table T>
1684auto prepareFilteredSlice(T const* table, std::shared_ptr<arrow::Table> slice, uint64_t offset)
1685{
1686 if (offset >= static_cast<uint64_t>(table->tableSize())) {
1687 Filtered<typename T::base_t> fresult{{{slice}}, SelectionVector{}, 0};
1688 if (fresult.tableSize() != 0) {
1689 table->copyIndexBindings(fresult);
1690 }
1691 return fresult;
1692 }
1693 auto slicedSelection = sliceSelection(table->getSelectedRows(), slice->num_rows(), offset);
1694 Filtered<typename T::base_t> fresult{{{slice}}, std::move(slicedSelection), offset};
1695 if (fresult.tableSize() != 0) {
1696 table->copyIndexBindings(fresult);
1697 }
1698 return fresult;
1699}
1700
1701template <soa::is_filtered_table T, typename C, bool OPT>
1702 requires(o2::soa::is_binding_compatible_v<C, T>())
1704{
1705 if constexpr (OPT) {
1706 if (container.isMissing()) {
1707 missingOptionalPreslice(getLabelFromType<T>().data(), container.bindingKey.key.c_str());
1708 }
1709 }
1710 uint64_t offset = 0;
1711 auto slice = container.getSliceFor(value, table->asArrowTable(), offset);
1712 return prepareFilteredSlice(table, slice, offset);
1713}
1714
1715template <soa::is_table T>
1717{
1718 auto localCache = cache.ptr->getCacheFor({"", o2::soa::getMatcherFromTypeForKey<T>(node.name), node.name});
1719 auto [offset, count] = localCache.getSliceFor(value);
1720 auto t = typename T::self_t({table->asArrowTable()->Slice(static_cast<uint64_t>(offset), count)}, static_cast<uint64_t>(offset));
1721 if (t.tableSize() != 0) {
1722 table->copyIndexBindings(t);
1723 }
1724 return t;
1725}
1726
1727template <soa::is_filtered_table T>
1729{
1730 auto localCache = cache.ptr->getCacheFor({"", o2::soa::getMatcherFromTypeForKey<T>(node.name), node.name});
1731 auto [offset, count] = localCache.getSliceFor(value);
1732 auto slice = table->asArrowTable()->Slice(static_cast<uint64_t>(offset), count);
1733 return prepareFilteredSlice(table, slice, offset);
1734}
1735
1736template <soa::is_table T>
1738{
1739 auto localCache = cache.ptr->getCacheUnsortedFor({"", o2::soa::getMatcherFromTypeForKey<T>(node.name), node.name});
1740 if constexpr (soa::is_filtered_table<T>) {
1741 auto t = typename T::self_t({table->asArrowTable()}, localCache.getSliceFor(value));
1742 if (t.tableSize() != 0) {
1743 t.intersectWithSelection(table->getSelectedRows());
1744 table->copyIndexBindings(t);
1745 }
1746 return t;
1747 } else {
1748 auto t = Filtered<T>({table->asArrowTable()}, localCache.getSliceFor(value));
1749 if (t.tableSize() != 0) {
1750 table->copyIndexBindings(t);
1751 }
1752 return t;
1753 }
1754}
1755
1756template <with_originals T>
1758{
1759 return Filtered<T>({t.asArrowTable()}, selectionToVector(framework::expressions::createSelection(t.asArrowTable(), f)));
1760}
1761
1762arrow::ChunkedArray* getIndexFromLabel(arrow::Table* table, std::string_view label);
1763
1764template <typename D, typename O, typename IP, typename... C>
1765consteval auto base_iter(framework::pack<C...>&&) -> TableIterator<D, O, IP, C...>
1766{
1767}
1768
1769template <TableRef ref, typename... Ts>
1770 requires((sizeof...(Ts) > 0) && (soa::is_column<Ts> && ...))
1771consteval auto getColumns()
1772{
1773 return framework::pack<Ts...>{};
1774}
1775
1776template <TableRef ref, typename... Ts>
1777 requires((sizeof...(Ts) > 0) && !(soa::is_column<Ts> || ...) && (ref.origin_hash == "CONC"_h))
1778consteval auto getColumns()
1779{
1780 return framework::full_intersected_pack_t<typename Ts::columns_t...>{};
1781}
1782
1783template <TableRef ref, typename... Ts>
1784 requires((sizeof...(Ts) > 0) && !(soa::is_column<Ts> || ...) && (ref.origin_hash != "CONC"_h))
1785consteval auto getColumns()
1786{
1787 return framework::concatenated_pack_unique_t<typename Ts::columns_t...>{};
1788}
1789
1790template <TableRef ref, typename... Ts>
1791 requires(sizeof...(Ts) == 0 && soa::has_metadata<aod::MetadataTrait<o2::aod::Hash<ref.desc_hash>>>)
1792consteval auto getColumns()
1793{
1794 return typename aod::MetadataTrait<o2::aod::Hash<ref.desc_hash>>::metadata::columns{};
1795}
1796
1797template <TableRef ref, typename... Ts>
1798 requires((sizeof...(Ts) == 0) || (o2::soa::is_column<Ts> && ...))
1799consteval auto computeOriginals()
1800{
1801 return std::array<TableRef, 1>{ref};
1802}
1803
1804template <TableRef ref, typename... Ts>
1805 requires((sizeof...(Ts) > 0) && (!o2::soa::is_column<Ts> || ...))
1806consteval auto computeOriginals()
1807{
1808 return o2::soa::mergeOriginals<Ts...>();
1809}
1810
1813template <aod::is_aod_hash L, aod::is_aod_hash D, aod::is_origin_hash O, typename... Ts>
1815{
1816 public:
1817 static constexpr const auto ref = TableRef{L::hash, D::hash, O::hash, o2::aod::version(D::str)};
1818 using self_t = Table<L, D, O, Ts...>;
1820
1821 static constexpr const auto originals = computeOriginals<ref, Ts...>();
1822 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()>());
1823
1824 template <size_t N, std::array<TableRef, N> bindings>
1825 requires(ref.origin_hash == "CONC"_h)
1826 static consteval auto isIndexTargetOf()
1827 {
1828 return false;
1829 }
1830
1831 template <size_t N, std::array<TableRef, N> bindings>
1832 requires(ref.origin_hash == "JOIN"_h)
1833 static consteval auto isIndexTargetOf()
1834 {
1835 return std::find_if(self_t::originals.begin(), self_t::originals.end(),
1836 [](TableRef const& r) {
1837 return std::find(bindings.begin(), bindings.end(), r) != bindings.end();
1838 }) != self_t::originals.end();
1839 }
1840
1841 template <size_t N, std::array<TableRef, N> bindings>
1842 requires(!(ref.origin_hash == "CONC"_h || ref.origin_hash == "JOIN"_h))
1843 static consteval auto isIndexTargetOf()
1844 {
1845 return std::find(bindings.begin(), bindings.end(), self_t::ref) != bindings.end();
1846 }
1847
1848 template <TableRef r>
1849 static consteval bool hasOriginal()
1850 {
1851 return std::find_if(originals.begin(), originals.end(), [](TableRef const& o) { return o.desc_hash == r.desc_hash; }) != originals.end();
1852 }
1853
1854 using columns_t = decltype(getColumns<ref, Ts...>());
1855
1858
1861 template <typename IP>
1862 using base_iterator = decltype(base_iter<D, O, IP>(columns_t{}));
1863
1864 template <typename IP, typename Parent, typename... T>
1866 using columns_t = typename Parent::columns_t;
1867 using external_index_columns_t = typename Parent::external_index_columns_t;
1869 // static constexpr const std::array<TableRef, sizeof...(T)> originals{T::ref...};
1870 static constexpr auto originals = Parent::originals;
1871 using policy_t = IP;
1872 using parent_t = Parent;
1873
1875
1876 TableIteratorBase(arrow::ChunkedArray* columnData[framework::pack_size(columns_t{})], IP&& policy)
1877 : base_iterator<IP>(columnData, std::forward<decltype(policy)>(policy))
1878 {
1879 }
1880
1881 template <typename P, typename... Os>
1883 requires(P::ref.desc_hash == Parent::ref.desc_hash)
1884 {
1885 static_cast<base_iterator<IP>&>(*this) = static_cast<base_iterator<IP>>(other);
1886 return *this;
1887 }
1888
1889 template <typename P>
1891 {
1892 static_cast<base_iterator<IP>&>(*this) = static_cast<base_iterator<IP>>(other);
1893 return *this;
1894 }
1895
1896 template <typename P>
1898 requires std::same_as<IP, DefaultIndexPolicy>
1899 {
1900 static_cast<base_iterator<IP>&>(*this) = static_cast<base_iterator<FilteredIndexPolicy>>(other);
1901 return *this;
1902 }
1903
1904 template <typename P, typename O1, typename... Os>
1906 requires(P::ref.desc_hash == Parent::ref.desc_hash)
1907 {
1908 *this = other;
1909 }
1910
1911 template <typename P, typename O1, typename... Os>
1913 requires(P::ref.desc_hash == Parent::ref.desc_hash)
1914 {
1915 *this = other;
1916 }
1917
1918 template <typename P>
1923
1924 template <typename P>
1926 {
1927 *this = other;
1928 }
1929
1930 template <typename P>
1932 requires std::same_as<IP, DefaultIndexPolicy>
1933 {
1934 *this = other;
1935 }
1936
1938 {
1939 this->mRowIndex = other.index;
1940 return *this;
1941 }
1942 template <typename P>
1944 {
1945 this->mRowIndex = other.mRowIndex;
1946 }
1947
1948 template <typename P, typename... Os>
1950 requires std::same_as<typename P::table_t, typename Parent::table_t>
1951 {
1952 this->mRowIndex = other.mRowIndex;
1953 }
1954
1955 template <typename TI>
1956 auto getId() const
1957 {
1958 using decayed = std::decay_t<TI>;
1959 if constexpr (framework::has_type<decayed>(bindings_pack_t{})) { // index to another table
1960 constexpr auto idx = framework::has_type_at_v<decayed>(bindings_pack_t{});
1962 } else if constexpr (std::same_as<decayed, Parent>) { // self index
1963 return this->globalIndex();
1964 } else if constexpr (is_indexing_column<decayed>) { // soa::Index<>
1965 return this->globalIndex();
1966 } else {
1967 return static_cast<int32_t>(-1);
1968 }
1969 }
1970
1971 template <typename CD, typename... CDArgs>
1972 auto getDynamicColumn() const
1973 {
1974 using decayed = std::decay_t<CD>;
1975 static_assert(is_dynamic_t<decayed>(), "Requested column is not a dynamic column");
1976 return static_cast<decayed>(*this).template getDynamicValue<CDArgs...>();
1977 }
1978
1979 template <typename B, typename CC>
1980 auto getValue() const
1981 {
1982 using COL = std::decay_t<CC>;
1983 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");
1984 return static_cast<B>(static_cast<COL>(*this).get());
1985 }
1986
1987 template <typename B, typename... CCs>
1988 std::array<B, sizeof...(CCs)> getValues() const
1989 {
1990 static_assert(std::same_as<B, float> || std::same_as<B, double>, "The common return type should be float or double");
1991 return {getValue<B, CCs>()...};
1992 }
1993
1994 using IP::size;
1995
1996 using base_iterator<IP>::operator++;
1997
1999 TableIteratorBase operator+(int64_t inc) const
2000 {
2001 TableIteratorBase copy = *this;
2002 copy.moveByIndex(inc);
2003 return copy;
2004 }
2005
2006 TableIteratorBase operator-(int64_t dec) const
2007 {
2008 return operator+(-dec);
2009 }
2010
2012 {
2013 return *this;
2014 }
2015 };
2016
2017 template <typename IP, typename Parent, typename... T>
2019
2020 template <typename IP, typename Parent>
2021 static consteval auto full_iter()
2022 {
2023 if constexpr (sizeof...(Ts) == 0) {
2025 } else {
2026 if constexpr ((o2::soa::is_column<Ts> && ...)) {
2028 } else {
2029 return iterator_template<IP, Parent, Ts...>{};
2030 }
2031 }
2032 }
2033
2034 template <typename IP, typename Parent>
2035 using iterator_template_o = decltype(full_iter<IP, Parent>());
2036
2039
2043
2044 static constexpr auto hashes()
2045 {
2046 return []<typename... C>(framework::pack<C...>) { return std::set{{C::hash...}}; }(columns_t{});
2047 }
2048
2049 Table(std::shared_ptr<arrow::Table> table, uint64_t offset = 0)
2050 : mTable(table),
2051 mEnd{table->num_rows()},
2052 mOffset(offset)
2053 {
2054 if (mTable->num_rows() == 0) {
2055 for (size_t ci = 0; ci < framework::pack_size(columns_t{}); ++ci) {
2056 mColumnChunks[ci] = nullptr;
2057 }
2058 mBegin = mEnd;
2059 } else {
2060 auto lookups = [this]<typename... C>(framework::pack<C...>) -> std::array<arrow::ChunkedArray*, framework::pack_size(columns_t{})> { return {lookupColumn<C>()...}; }(columns_t{});
2061 for (size_t ci = 0; ci < framework::pack_size(columns_t{}); ++ci) {
2062 mColumnChunks[ci] = lookups[ci];
2063 }
2064 mBegin = unfiltered_iterator{mColumnChunks, {table->num_rows(), offset}};
2065 mBegin.bindInternalIndices(this);
2066 }
2067 }
2068
2069 Table(std::vector<std::shared_ptr<arrow::Table>>&& tables, uint64_t offset = 0)
2070 requires(ref.origin_hash != "CONC"_h)
2071 : Table(ArrowHelpers::joinTables(std::move(tables), std::span{originalLabels}), offset)
2072 {
2073 }
2074
2075 Table(std::vector<std::shared_ptr<arrow::Table>>&& tables, uint64_t offset = 0)
2076 requires(ref.origin_hash == "CONC"_h)
2077 : Table(ArrowHelpers::concatTables(std::move(tables)), offset)
2078 {
2079 }
2080
2081 template <typename Key>
2082 inline arrow::ChunkedArray* getIndexToKey()
2083 {
2084 constexpr auto map = []<typename... Cs>(framework::pack<Cs...>) {
2085 return std::array<bool, sizeof...(Cs)>{[]() {
2086 if constexpr (requires { Cs::index_targets.size(); }) {
2087 return Key::template isIndexTargetOf<Cs::index_targets.size(), Cs::index_targets>();
2088 } else {
2089 return false;
2090 }
2091 }()...};
2093 constexpr auto pos = std::find(map.begin(), map.end(), true);
2094 if constexpr (pos != map.end()) {
2095 return mColumnChunks[std::distance(map.begin(), pos)];
2096 } else {
2097 static_assert(framework::always_static_assert_v<Key>, "This table does not have an index to given Key");
2098 }
2099 }
2100
2102 {
2103 return mBegin;
2104 }
2105
2106 auto const& cached_begin() const
2107 {
2108 return mBegin;
2109 }
2110
2112 {
2113 return unfiltered_iterator(mBegin);
2114 }
2115
2117 {
2118 return RowViewSentinel{mEnd};
2119 }
2120
2121 filtered_iterator filtered_begin(std::span<int64_t const> selection)
2122 {
2123 // Note that the FilteredIndexPolicy will never outlive the selection which
2124 // is held by the table, so we are safe passing the bare pointer. If it does it
2125 // means that the iterator on a table is outliving the table itself, which is
2126 // a bad idea.
2127 return filtered_iterator(mColumnChunks, {selection, mTable->num_rows(), mOffset});
2128 }
2129
2130 iterator iteratorAt(uint64_t i) const
2131 {
2132 return rawIteratorAt(i);
2133 }
2134
2136 {
2137 auto it = mBegin;
2138 it.setCursor(i);
2139 return it;
2140 }
2141
2143 {
2144 return unfiltered_const_iterator(mBegin);
2145 }
2146
2147 [[nodiscard]] RowViewSentinel end() const
2148 {
2149 return RowViewSentinel{mEnd};
2150 }
2151
2153 [[nodiscard]] std::shared_ptr<arrow::Table> asArrowTable() const
2154 {
2155 return mTable;
2156 }
2158 auto offset() const
2159 {
2160 return mOffset;
2161 }
2163 [[nodiscard]] int64_t size() const
2164 {
2165 return mTable->num_rows();
2166 }
2167
2168 [[nodiscard]] int64_t tableSize() const
2169 {
2170 return size();
2171 }
2172
2175 template <typename... TA>
2176 void bindExternalIndices(TA*... current)
2177 {
2178 mBegin.bindExternalIndices(current...);
2179 }
2180
2181 template <typename I>
2183 {
2184 mBegin.bindInternalIndices(ptr);
2185 }
2186
2191
2192 template <typename... Cs>
2194 {
2195 (static_cast<Cs>(mBegin).setCurrentRaw(binding), ...);
2196 }
2197
2198 void bindExternalIndicesRaw(std::vector<o2::soa::Binding>&& ptrs)
2199 {
2200 mBegin.bindExternalIndicesRaw(std::forward<std::vector<o2::soa::Binding>>(ptrs));
2201 }
2202
2203 template <typename T, typename... Cs>
2205 {
2206 dest.bindExternalIndicesRaw(mBegin.getIndexBindings());
2207 }
2208
2209 template <typename T>
2210 void copyIndexBindings(T& dest) const
2211 {
2213 }
2214
2216 {
2217 auto t = o2::soa::select(*this, f);
2219 return t;
2220 }
2221
2223 {
2224 return doSliceByCached(this, node, value, cache);
2225 }
2226
2231
2232 template <typename T1, typename Policy, bool OPT>
2234 {
2235 return doSliceBy(this, container, value);
2236 }
2237
2238 auto rawSlice(uint64_t start, uint64_t end) const
2239 {
2240 return self_t{mTable->Slice(start, end - start + 1), start};
2241 }
2242
2243 auto emptySlice() const
2244 {
2245 return self_t{mTable->Slice(0, 0), 0};
2246 }
2247
2248 private:
2249 template <typename T>
2250 arrow::ChunkedArray* lookupColumn()
2251 {
2252 if constexpr (soa::is_persistent_column<T>) {
2253 auto label = T::columnLabel();
2254 return getIndexFromLabel(mTable.get(), label);
2255 } else {
2256 return nullptr;
2257 }
2258 }
2259 std::shared_ptr<arrow::Table> mTable = nullptr;
2260 uint64_t mOffset = 0;
2261 // Cached pointers to the ChunkedArray associated to a column
2262 arrow::ChunkedArray* mColumnChunks[framework::pack_size(columns_t{})];
2263 RowViewSentinel mEnd;
2264 iterator mBegin;
2265};
2266
2267template <uint32_t D, soa::is_column... C>
2269
2270void getterNotFound(const char* targetColumnLabel);
2271void emptyColumnLabel();
2272
2273namespace row_helpers
2274{
2275template <typename R, typename T, typename C>
2276R getColumnValue(const T& rowIterator)
2277{
2278 return static_cast<R>(static_cast<C>(rowIterator).get());
2279}
2280
2281namespace
2282{
2283template <typename R, typename T>
2284using ColumnGetterFunction = R (*)(const T&);
2285
2286template <typename T, typename R>
2288 // lambda is callable without additional free args
2289 framework::pack_size(typename T::bindings_t{}) == framework::pack_size(typename T::callable_t::args{}) &&
2290 requires(T t) {
2291 { t.get() } -> std::convertible_to<R>;
2292 };
2293
2294template <typename T, typename R>
2295concept persistent_with_common_getter = is_persistent_v<T> && requires(T t) {
2296 { t.get() } -> std::convertible_to<R>;
2297};
2298
2299template <typename R, typename T, persistent_with_common_getter<R> C>
2300ColumnGetterFunction<R, T> createGetterPtr(const std::string_view& targetColumnLabel)
2301{
2302 return targetColumnLabel == C::columnLabel() ? &getColumnValue<R, T, C> : nullptr;
2303}
2304
2305template <typename R, typename T, dynamic_with_common_getter<R> C>
2306ColumnGetterFunction<R, T> createGetterPtr(const std::string_view& targetColumnLabel)
2307{
2308 std::string_view columnLabel(C::columnLabel());
2309
2310 // allows user to use consistent formatting (with prefix) of all column labels
2311 // by default there isn't 'f' prefix for dynamic column labels
2312 if (targetColumnLabel.starts_with("f") && targetColumnLabel.substr(1) == columnLabel) {
2313 return &getColumnValue<R, T, C>;
2314 }
2315
2316 // check also exact match if user is aware of prefix missing
2317 if (targetColumnLabel == columnLabel) {
2318 return &getColumnValue<R, T, C>;
2319 }
2320
2321 return nullptr;
2322}
2323
2324template <typename R, typename T, typename... Cs>
2325ColumnGetterFunction<R, T> getColumnGetterByLabel(o2::framework::pack<Cs...>, const std::string_view& targetColumnLabel)
2326{
2327 ColumnGetterFunction<R, T> func;
2328
2329 (void)((func = createGetterPtr<R, T, Cs>(targetColumnLabel), func) || ...);
2330
2331 if (!func) {
2332 getterNotFound(targetColumnLabel.data());
2333 }
2334
2335 return func;
2336}
2337
2338template <typename T, typename R>
2339using 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;
2340} // namespace
2341
2342template <typename R, typename T>
2343ColumnGetterFunction<R, typename T::iterator> getColumnGetterByLabel(const std::string_view& targetColumnLabel)
2344{
2345 using TypesWithCommonGetter = o2::framework::selected_pack_multicondition<with_common_getter_t, framework::pack<R>, typename T::columns_t>;
2346
2347 if (targetColumnLabel.size() == 0) {
2349 }
2350
2351 return getColumnGetterByLabel<R, typename T::iterator>(TypesWithCommonGetter{}, targetColumnLabel);
2352}
2353} // namespace row_helpers
2354} // namespace o2::soa
2355
2356namespace o2::aod
2357{
2358// If you get an error about not satisfying is_origin_hash, you need to add
2359// an entry here.
2361O2ORIGIN("AOD1");
2362O2ORIGIN("AOD2");
2365O2ORIGIN("ATIM");
2366O2ORIGIN("JOIN");
2367O2HASH("JOIN/0");
2368O2ORIGIN("CONC");
2369O2HASH("CONC/0");
2370O2ORIGIN("TEST");
2371O2HASH("TEST/0");
2372} // namespace o2::aod
2373
2374namespace
2375{
2376template <typename T>
2377consteval static std::string_view namespace_prefix()
2378{
2379 constexpr auto name = o2::framework::type_name<T>();
2380 const auto pos = name.rfind(std::string_view{":"});
2381 return name.substr(0, pos + 1);
2382}
2383} // namespace
2384
2385#define DECLARE_EQUIVALENT_FOR_INDEX(_Base_, _Equiv_) \
2386 template <> \
2387 struct EquivalentIndexNG<o2::aod::Hash<_Base_::ref.desc_hash>, o2::aod::Hash<_Equiv_::ref.desc_hash>> { \
2388 constexpr static bool value = true; \
2389 }
2390
2391#define DECLARE_EQUIVALENT_FOR_INDEX_NG(_Base_, _Equiv_) \
2392 template <> \
2393 struct EquivalentIndexNG<o2::aod::Hash<_Base_ ""_h>, o2::aod::Hash<_Equiv_ ""_h>> { \
2394 constexpr static bool value = true; \
2395 }
2396
2397#define DECLARE_SOA_COLUMN_FULL(_Name_, _Getter_, _Type_, _Label_) \
2398 struct _Name_ : o2::soa::Column<_Type_, _Name_> { \
2399 static constexpr const char* mLabel = _Label_; \
2400 static constexpr const uint32_t hash = compile_time_hash(namespace_prefix<_Name_>(), std::string_view{#_Getter_}); \
2401 static_assert(!((*(mLabel + 1) == 'I' && *(mLabel + 2) == 'n' && *(mLabel + 3) == 'd' && *(mLabel + 4) == 'e' && *(mLabel + 5) == 'x')), "Index is not a valid column name"); \
2402 using base = o2::soa::Column<_Type_, _Name_>; \
2403 using type = _Type_; \
2404 using column_t = _Name_; \
2405 _Name_(arrow::ChunkedArray const* column) \
2406 : o2::soa::Column<_Type_, _Name_>(o2::soa::ColumnIterator<type>(column)) \
2407 { \
2408 } \
2409 \
2410 _Name_() = default; \
2411 _Name_(_Name_ const& other) = default; \
2412 _Name_& operator=(_Name_ const& other) = default; \
2413 \
2414 decltype(auto) _Getter_() const \
2415 { \
2416 return *mColumnIterator; \
2417 } \
2418 \
2419 decltype(auto) get() const \
2420 { \
2421 return _Getter_(); \
2422 } \
2423 }; \
2424 [[maybe_unused]] static constexpr o2::framework::expressions::BindingNode _Getter_ { _Label_, _Name_::hash, o2::framework::expressions::selectArrowType<_Type_>() }
2425
2426#define DECLARE_SOA_CCDB_COLUMN_FULL(_Name_, _Label_, _Getter_, _ConcreteType_, _CCDBQuery_) \
2427 struct _Name_ : o2::soa::Column<std::span<std::byte>, _Name_> { \
2428 static constexpr const char* mLabel = _Label_; \
2429 static constexpr const char* query = _CCDBQuery_; \
2430 static constexpr const uint32_t hash = crc32(namespace_prefix<_Name_>(), std::string_view{#_Getter_}); \
2431 using base = o2::soa::Column<std::span<std::byte>, _Name_>; \
2432 using type = std::span<std::byte>; \
2433 using column_t = _Name_; \
2434 _Name_(arrow::ChunkedArray const* column) \
2435 : o2::soa::Column<std::span<std::byte>, _Name_>(o2::soa::ColumnIterator<std::span<std::byte>>(column)) \
2436 { \
2437 } \
2438 \
2439 _Name_() = default; \
2440 _Name_(_Name_ const& other) = default; \
2441 _Name_& operator=(_Name_ const& other) = default; \
2442 \
2443 decltype(auto) _Getter_() const \
2444 { \
2445 static std::byte* payload = nullptr; \
2446 static _ConcreteType_* deserialised = nullptr; \
2447 static TClass* c = TClass::GetClass(#_ConcreteType_); \
2448 auto span = *mColumnIterator; \
2449 if (payload != (std::byte*)span.data()) { \
2450 payload = (std::byte*)span.data(); \
2451 delete deserialised; \
2452 TBufferFile f(TBufferFile::EMode::kRead, span.size(), (char*)span.data(), kFALSE); \
2453 deserialised = (_ConcreteType_*)soa::extractCCDBPayload((char*)payload, span.size(), c, "ccdb_object"); \
2454 } \
2455 return *deserialised; \
2456 } \
2457 \
2458 decltype(auto) \
2459 get() const \
2460 { \
2461 return _Getter_(); \
2462 } \
2463 };
2464
2465#define DECLARE_SOA_CCDB_COLUMN(_Name_, _Getter_, _ConcreteType_, _CCDBQuery_) \
2466 DECLARE_SOA_CCDB_COLUMN_FULL(_Name_, "f" #_Name_, _Getter_, _ConcreteType_, _CCDBQuery_)
2467
2468#define DECLARE_SOA_COLUMN(_Name_, _Getter_, _Type_) \
2469 DECLARE_SOA_COLUMN_FULL(_Name_, _Getter_, _Type_, "f" #_Name_)
2470
2473#define MAKEINT(_Size_) uint##_Size_##_t
2474
2475#define DECLARE_SOA_BITMAP_COLUMN_FULL(_Name_, _Getter_, _Size_, _Label_) \
2476 struct _Name_ : o2::soa::Column<MAKEINT(_Size_), _Name_> { \
2477 static constexpr const char* mLabel = _Label_; \
2478 static constexpr const uint32_t hash = compile_time_hash(namespace_prefix<_Name_>(), std::string_view{#_Getter_}); \
2479 static_assert(!((*(mLabel + 1) == 'I' && *(mLabel + 2) == 'n' && *(mLabel + 3) == 'd' && *(mLabel + 4) == 'e' && *(mLabel + 5) == 'x')), "Index is not a valid column name"); \
2480 using base = o2::soa::Column<MAKEINT(_Size_), _Name_>; \
2481 using type = MAKEINT(_Size_); \
2482 _Name_(arrow::ChunkedArray const* column) \
2483 : o2::soa::Column<type, _Name_>(o2::soa::ColumnIterator<type>(column)) \
2484 { \
2485 } \
2486 \
2487 _Name_() = default; \
2488 _Name_(_Name_ const& other) = default; \
2489 _Name_& operator=(_Name_ const& other) = default; \
2490 \
2491 decltype(auto) _Getter_##_raw() const \
2492 { \
2493 return *mColumnIterator; \
2494 } \
2495 \
2496 bool _Getter_##_bit(int bit) const \
2497 { \
2498 return (*mColumnIterator & (static_cast<type>(1) << bit)) >> bit; \
2499 } \
2500 }; \
2501 [[maybe_unused]] static constexpr o2::framework::expressions::BindingNode _Getter_ { _Label_, _Name_::hash, o2::framework::expressions::selectArrowType<MAKEINT(_Size_)>() }
2502
2503#define DECLARE_SOA_BITMAP_COLUMN(_Name_, _Getter_, _Size_) \
2504 DECLARE_SOA_BITMAP_COLUMN_FULL(_Name_, _Getter_, _Size_, "f" #_Name_)
2505
2508#define DECLARE_SOA_EXPRESSION_COLUMN_FULL(_Name_, _Getter_, _Type_, _Label_, _Expression_) \
2509 struct _Name_ : o2::soa::Column<_Type_, _Name_> { \
2510 static constexpr const char* mLabel = _Label_; \
2511 static constexpr const uint32_t hash = compile_time_hash(namespace_prefix<_Name_>(), std::string_view{#_Getter_}); \
2512 using base = o2::soa::Column<_Type_, _Name_>; \
2513 using type = _Type_; \
2514 using column_t = _Name_; \
2515 using spawnable_t = std::true_type; \
2516 _Name_(arrow::ChunkedArray const* column) \
2517 : o2::soa::Column<_Type_, _Name_>(o2::soa::ColumnIterator<type>(column)) \
2518 { \
2519 } \
2520 \
2521 _Name_() = default; \
2522 _Name_(_Name_ const& other) = default; \
2523 _Name_& operator=(_Name_ const& other) = default; \
2524 \
2525 decltype(auto) _Getter_() const \
2526 { \
2527 return *mColumnIterator; \
2528 } \
2529 \
2530 decltype(auto) get() const \
2531 { \
2532 return _Getter_(); \
2533 } \
2534 \
2535 static o2::framework::expressions::Projector Projector() \
2536 { \
2537 return _Expression_; \
2538 } \
2539 }; \
2540 [[maybe_unused]] static constexpr o2::framework::expressions::BindingNode _Getter_ { _Label_, _Name_::hash, o2::framework::expressions::selectArrowType<_Type_>() }
2541
2542#define DECLARE_SOA_EXPRESSION_COLUMN(_Name_, _Getter_, _Type_, _Expression_) \
2543 DECLARE_SOA_EXPRESSION_COLUMN_FULL(_Name_, _Getter_, _Type_, "f" #_Name_, _Expression_);
2544
2547#define DECLARE_SOA_CONFIGURABLE_EXPRESSION_COLUMN(_Name_, _Getter_, _Type_, _Label_) \
2548 struct _Name_ : o2::soa::Column<_Type_, _Name_> { \
2549 static constexpr const char* mLabel = _Label_; \
2550 static constexpr const uint32_t hash = compile_time_hash(namespace_prefix<_Name_>(), std::string_view{#_Getter_}); \
2551 static constexpr const int32_t mHash = _Label_ ""_h; \
2552 using base = o2::soa::Column<_Type_, _Name_>; \
2553 using type = _Type_; \
2554 using column_t = _Name_; \
2555 using spawnable_t = std::true_type; \
2556 _Name_(arrow::ChunkedArray const* column) \
2557 : o2::soa::Column<_Type_, _Name_>(o2::soa::ColumnIterator<type>(column)) \
2558 { \
2559 } \
2560 \
2561 _Name_() = default; \
2562 _Name_(_Name_ const& other) = default; \
2563 _Name_& operator=(_Name_ const& other) = default; \
2564 \
2565 decltype(auto) _Getter_() const \
2566 { \
2567 return *mColumnIterator; \
2568 } \
2569 \
2570 decltype(auto) get() const \
2571 { \
2572 return _Getter_(); \
2573 } \
2574 }; \
2575 [[maybe_unused]] static constexpr o2::framework::expressions::BindingNode _Getter_ { _Label_, _Name_::hash, o2::framework::expressions::selectArrowType<_Type_>() }
2576
2595
2597
2598template <o2::soa::is_table T>
2599consteval auto getIndexTargets()
2600{
2601 return T::originals;
2602}
2603
2604#define DECLARE_SOA_SLICE_INDEX_COLUMN_FULL_CUSTOM(_Name_, _Getter_, _Type_, _Table_, _Label_, _Suffix_) \
2605 struct _Name_##IdSlice : o2::soa::Column<_Type_[2], _Name_##IdSlice> { \
2606 static_assert(std::is_integral_v<_Type_>, "Index type must be integral"); \
2607 static_assert((*_Suffix_ == '\0') || (*_Suffix_ == '_'), "Suffix has to begin with _"); \
2608 static constexpr const char* mLabel = "fIndexSlice" _Label_ _Suffix_; \
2609 static constexpr const uint32_t hash = 0; \
2610 using base = o2::soa::Column<_Type_[2], _Name_##IdSlice>; \
2611 using type = _Type_[2]; \
2612 using column_t = _Name_##IdSlice; \
2613 using binding_t = _Table_; \
2614 static constexpr auto index_targets = getIndexTargets<_Table_>(); \
2615 _Name_##IdSlice(arrow::ChunkedArray const* column) \
2616 : o2::soa::Column<_Type_[2], _Name_##IdSlice>(o2::soa::ColumnIterator<type>(column)) \
2617 { \
2618 } \
2619 \
2620 _Name_##IdSlice() = default; \
2621 _Name_##IdSlice(_Name_##IdSlice const& other) = default; \
2622 _Name_##IdSlice& operator=(_Name_##IdSlice const& other) = default; \
2623 std::array<_Type_, 2> inline getIds() const \
2624 { \
2625 return _Getter_##Ids(); \
2626 } \
2627 \
2628 bool has_##_Getter_() const \
2629 { \
2630 auto a = *mColumnIterator; \
2631 return a[0] >= 0 && a[1] >= 0; \
2632 } \
2633 \
2634 std::array<_Type_, 2> _Getter_##Ids() const \
2635 { \
2636 auto a = *mColumnIterator; \
2637 return std::array{a[0], a[1]}; \
2638 } \
2639 \
2640 template <typename T> \
2641 auto _Getter_##_as() const \
2642 { \
2643 if (O2_BUILTIN_UNLIKELY(mBinding.ptr == nullptr)) { \
2644 o2::soa::notBoundTable(#_Table_); \
2645 } \
2646 auto t = mBinding.get<T>(); \
2647 if (O2_BUILTIN_UNLIKELY(t == nullptr)) { \
2648 o2::soa::dereferenceWithWrongType(#_Getter_, #_Table_); \
2649 } \
2650 if (O2_BUILTIN_UNLIKELY(!has_##_Getter_())) { \
2651 return t->emptySlice(); \
2652 } \
2653 auto a = *mColumnIterator; \
2654 auto r = t->rawSlice(a[0], a[1]); \
2655 t->copyIndexBindings(r); \
2656 r.bindInternalIndicesTo(t); \
2657 return r; \
2658 } \
2659 \
2660 auto _Getter_() const \
2661 { \
2662 return _Getter_##_as<binding_t>(); \
2663 } \
2664 \
2665 template <typename T> \
2666 bool setCurrent(T const* current) \
2667 { \
2668 if constexpr (o2::soa::is_binding_compatible_v<T, binding_t>()) { \
2669 assert(current != nullptr); \
2670 this->mBinding.bind(current); \
2671 return true; \
2672 } \
2673 return false; \
2674 } \
2675 \
2676 bool setCurrentRaw(o2::soa::Binding current) \
2677 { \
2678 this->mBinding = current; \
2679 return true; \
2680 } \
2681 binding_t const* getCurrent() const { return mBinding.get<binding_t>(); } \
2682 o2::soa::Binding getCurrentRaw() const { return mBinding; } \
2683 o2::soa::Binding mBinding; \
2684 };
2685
2686#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_)
2687#define DECLARE_SOA_SLICE_INDEX_COLUMN(_Name_, _Getter_) DECLARE_SOA_SLICE_INDEX_COLUMN_FULL(_Name_, _Getter_, int32_t, _Name_##s, "")
2688#define DECLARE_SOA_SLICE_INDEX_COLUMN_CUSTOM(_Name_, _Getter_, _Label_) DECLARE_SOA_SLICE_INDEX_COLUMN_FULL_CUSTOM(_Name_, _Getter_, int32_t, _Name_##s, _Label_, "")
2689
2691#define DECLARE_SOA_ARRAY_INDEX_COLUMN_FULL_CUSTOM(_Name_, _Getter_, _Type_, _Table_, _Label_, _Suffix_) \
2692 struct _Name_##Ids : o2::soa::Column<std::vector<_Type_>, _Name_##Ids> { \
2693 static_assert(std::is_integral_v<_Type_>, "Index type must be integral"); \
2694 static_assert((*_Suffix_ == '\0') || (*_Suffix_ == '_'), "Suffix has to begin with _"); \
2695 static constexpr const char* mLabel = "fIndexArray" _Label_ _Suffix_; \
2696 static constexpr const uint32_t hash = 0; \
2697 using base = o2::soa::Column<std::vector<_Type_>, _Name_##Ids>; \
2698 using type = std::vector<_Type_>; \
2699 using column_t = _Name_##Ids; \
2700 using binding_t = _Table_; \
2701 static constexpr auto index_targets = getIndexTargets<_Table_>(); \
2702 _Name_##Ids(arrow::ChunkedArray const* column) \
2703 : o2::soa::Column<std::vector<_Type_>, _Name_##Ids>(o2::soa::ColumnIterator<type>(column)) \
2704 { \
2705 } \
2706 \
2707 _Name_##Ids() = default; \
2708 _Name_##Ids(_Name_##Ids const& other) = default; \
2709 _Name_##Ids& operator=(_Name_##Ids const& other) = default; \
2710 \
2711 gsl::span<const _Type_> inline getIds() const \
2712 { \
2713 return _Getter_##Ids(); \
2714 } \
2715 \
2716 gsl::span<const _Type_> _Getter_##Ids() const \
2717 { \
2718 return *mColumnIterator; \
2719 } \
2720 \
2721 bool has_##_Getter_() const \
2722 { \
2723 return !(*mColumnIterator).empty(); \
2724 } \
2725 \
2726 template <typename T> \
2727 auto _Getter_##_as() const \
2728 { \
2729 if (O2_BUILTIN_UNLIKELY(mBinding.ptr == nullptr)) { \
2730 o2::soa::notBoundTable(#_Table_); \
2731 } \
2732 auto t = mBinding.get<T>(); \
2733 if (O2_BUILTIN_UNLIKELY(t == nullptr)) { \
2734 o2::soa::dereferenceWithWrongType(#_Getter_, #_Table_); \
2735 } \
2736 return getIterators<T>(); \
2737 } \
2738 \
2739 template <typename T> \
2740 auto filtered_##_Getter_##_as() const \
2741 { \
2742 if (O2_BUILTIN_UNLIKELY(mBinding.ptr == nullptr)) { \
2743 o2::soa::notBoundTable(#_Table_); \
2744 } \
2745 auto t = mBinding.get<T>(); \
2746 if (O2_BUILTIN_UNLIKELY(t == nullptr)) { \
2747 o2::soa::dereferenceWithWrongType(#_Getter_, #_Table_); \
2748 } \
2749 return getFilteredIterators<T>(); \
2750 } \
2751 \
2752 template <typename T> \
2753 auto getIterators() const \
2754 { \
2755 auto result = std::vector<typename T::unfiltered_iterator>(); \
2756 for (auto& i : *mColumnIterator) { \
2757 result.push_back(mBinding.get<T>()->rawIteratorAt(i)); \
2758 } \
2759 return result; \
2760 } \
2761 \
2762 template <typename T> \
2763 std::vector<typename T::iterator> getFilteredIterators() const \
2764 { \
2765 if constexpr (o2::soa::is_filtered_table<T>) { \
2766 auto result = std::vector<typename T::iterator>(); \
2767 for (auto const& i : *mColumnIterator) { \
2768 auto pos = mBinding.get<T>()->isInSelectedRows(i); \
2769 if (pos > 0) { \
2770 result.emplace_back(mBinding.get<T>()->iteratorAt(pos)); \
2771 } \
2772 } \
2773 return result; \
2774 } else { \
2775 static_assert(o2::framework::always_static_assert_v<T>, "T is not a Filtered type"); \
2776 } \
2777 return {}; \
2778 } \
2779 \
2780 auto _Getter_() const \
2781 { \
2782 return _Getter_##_as<binding_t>(); \
2783 } \
2784 \
2785 template <typename T> \
2786 auto _Getter_##_first_as() const \
2787 { \
2788 if (O2_BUILTIN_UNLIKELY(mBinding.ptr == nullptr)) { \
2789 o2::soa::notBoundTable(#_Table_); \
2790 } \
2791 auto t = mBinding.get<T>(); \
2792 if (O2_BUILTIN_UNLIKELY(t == nullptr)) { \
2793 o2::soa::dereferenceWithWrongType(#_Getter_, #_Table_); \
2794 } \
2795 return t->rawIteratorAt((*mColumnIterator)[0]); \
2796 } \
2797 \
2798 template <typename T> \
2799 auto _Getter_##_last_as() const \
2800 { \
2801 if (O2_BUILTIN_UNLIKELY(mBinding.ptr == nullptr)) { \
2802 o2::soa::notBoundTable(#_Table_); \
2803 } \
2804 auto t = mBinding.get<T>(); \
2805 if (O2_BUILTIN_UNLIKELY(t == nullptr)) { \
2806 o2::soa::dereferenceWithWrongType(#_Getter_, #_Table_); \
2807 } \
2808 return t->rawIteratorAt((*mColumnIterator).back()); \
2809 } \
2810 \
2811 auto _Getter_first() const \
2812 { \
2813 return _Getter_##_first_as<binding_t>(); \
2814 } \
2815 \
2816 auto _Getter_last() const \
2817 { \
2818 return _Getter_##_last_as<binding_t>(); \
2819 } \
2820 \
2821 template <typename T> \
2822 bool setCurrent(T const* current) \
2823 { \
2824 if constexpr (o2::soa::is_binding_compatible_v<T, binding_t>()) { \
2825 assert(current != nullptr); \
2826 this->mBinding.bind(current); \
2827 return true; \
2828 } \
2829 return false; \
2830 } \
2831 \
2832 bool setCurrentRaw(o2::soa::Binding current) \
2833 { \
2834 this->mBinding = current; \
2835 return true; \
2836 } \
2837 binding_t const* getCurrent() const { return mBinding.get<binding_t>(); } \
2838 o2::soa::Binding getCurrentRaw() const { return mBinding; } \
2839 o2::soa::Binding mBinding; \
2840 };
2841
2842#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_)
2843#define DECLARE_SOA_ARRAY_INDEX_COLUMN(_Name_, _Getter_) DECLARE_SOA_ARRAY_INDEX_COLUMN_FULL(_Name_, _Getter_, int32_t, _Name_##s, "")
2844#define DECLARE_SOA_ARRAY_INDEX_COLUMN_CUSTOM(_Name_, _Getter_, _Label_) DECLARE_SOA_ARRAY_INDEX_COLUMN_FULL_CUSTOM(_Name_, _Getter_, int32_t, _Name_##s, _Label_, "")
2845
2847#define DECLARE_SOA_INDEX_COLUMN_FULL_CUSTOM(_Name_, _Getter_, _Type_, _Table_, _Label_, _Suffix_) \
2848 struct _Name_##Id : o2::soa::Column<_Type_, _Name_##Id> { \
2849 static_assert(std::is_integral_v<_Type_>, "Index type must be integral"); \
2850 static_assert((*_Suffix_ == '\0') || (*_Suffix_ == '_'), "Suffix has to begin with _"); \
2851 static constexpr const char* mLabel = "fIndex" _Label_ _Suffix_; \
2852 static constexpr const uint32_t hash = compile_time_hash(namespace_prefix<_Name_##Id>(), std::string_view{#_Getter_ "Id"}); \
2853 using base = o2::soa::Column<_Type_, _Name_##Id>; \
2854 using type = _Type_; \
2855 using column_t = _Name_##Id; \
2856 using binding_t = _Table_; \
2857 static constexpr auto index_targets = getIndexTargets<_Table_>(); \
2858 _Name_##Id(arrow::ChunkedArray const* column) \
2859 : o2::soa::Column<_Type_, _Name_##Id>(o2::soa::ColumnIterator<type>(column)) \
2860 { \
2861 } \
2862 \
2863 _Name_##Id() = default; \
2864 _Name_##Id(_Name_##Id const& other) = default; \
2865 _Name_##Id& operator=(_Name_##Id const& other) = default; \
2866 type inline getId() const \
2867 { \
2868 return _Getter_##Id(); \
2869 } \
2870 \
2871 type _Getter_##Id() const \
2872 { \
2873 return *mColumnIterator; \
2874 } \
2875 \
2876 bool has_##_Getter_() const \
2877 { \
2878 return *mColumnIterator >= 0; \
2879 } \
2880 \
2881 template <typename T> \
2882 auto _Getter_##_as() const \
2883 { \
2884 if (O2_BUILTIN_UNLIKELY(mBinding.ptr == nullptr)) { \
2885 o2::soa::notBoundTable(#_Table_); \
2886 } \
2887 if (O2_BUILTIN_UNLIKELY(!has_##_Getter_())) { \
2888 o2::soa::accessingInvalidIndexFor(#_Getter_); \
2889 } \
2890 auto t = mBinding.get<T>(); \
2891 if (O2_BUILTIN_UNLIKELY(t == nullptr)) { \
2892 o2::soa::dereferenceWithWrongType(#_Getter_, #_Table_); \
2893 } \
2894 return t->rawIteratorAt(*mColumnIterator); \
2895 } \
2896 \
2897 auto _Getter_() const \
2898 { \
2899 return _Getter_##_as<binding_t>(); \
2900 } \
2901 \
2902 template <typename T> \
2903 bool setCurrent(T* current) \
2904 { \
2905 if constexpr (o2::soa::is_binding_compatible_v<T, binding_t>()) { \
2906 assert(current != nullptr); \
2907 this->mBinding.bind(current); \
2908 return true; \
2909 } \
2910 return false; \
2911 } \
2912 \
2913 bool setCurrentRaw(o2::soa::Binding current) \
2914 { \
2915 this->mBinding = current; \
2916 return true; \
2917 } \
2918 binding_t const* getCurrent() const { return mBinding.get<binding_t>(); } \
2919 o2::soa::Binding getCurrentRaw() const { return mBinding; } \
2920 o2::soa::Binding mBinding; \
2921 }; \
2922 [[maybe_unused]] static constexpr o2::framework::expressions::BindingNode _Getter_##Id { "fIndex" _Label_ _Suffix_, _Name_##Id::hash, o2::framework::expressions::selectArrowType<_Type_>() }
2923
2924#define DECLARE_SOA_INDEX_COLUMN_FULL(_Name_, _Getter_, _Type_, _Table_, _Suffix_) DECLARE_SOA_INDEX_COLUMN_FULL_CUSTOM(_Name_, _Getter_, _Type_, _Table_, #_Table_, _Suffix_)
2925#define DECLARE_SOA_INDEX_COLUMN(_Name_, _Getter_) DECLARE_SOA_INDEX_COLUMN_FULL(_Name_, _Getter_, int32_t, _Name_##s, "")
2926#define DECLARE_SOA_INDEX_COLUMN_CUSTOM(_Name_, _Getter_, _Label_) DECLARE_SOA_INDEX_COLUMN_FULL_CUSTOM(_Name_, _Getter_, int32_t, _Name_##s, _Label_, "")
2927
2929#define DECLARE_SOA_SELF_INDEX_COLUMN_COMPLETE(_Name_, _Getter_, _Type_, _Label_, _IndexTarget_) \
2930 struct _Name_##Id : o2::soa::Column<_Type_, _Name_##Id> { \
2931 static_assert(std::is_integral_v<_Type_>, "Index type must be integral"); \
2932 static constexpr const char* mLabel = "fIndex" _Label_; \
2933 static constexpr const uint32_t hash = compile_time_hash(namespace_prefix<_Name_##Id>(), std::string_view{#_Getter_ "Id"}); \
2934 using base = o2::soa::Column<_Type_, _Name_##Id>; \
2935 using type = _Type_; \
2936 using column_t = _Name_##Id; \
2937 using self_index_t = std::true_type; \
2938 using compatible_signature = std::conditional<aod::is_aod_hash<_IndexTarget_>, _IndexTarget_, void>; \
2939 _Name_##Id(arrow::ChunkedArray const* column) \
2940 : o2::soa::Column<_Type_, _Name_##Id>(o2::soa::ColumnIterator<type>(column)) \
2941 { \
2942 } \
2943 \
2944 _Name_##Id() = default; \
2945 _Name_##Id(_Name_##Id const& other) = default; \
2946 _Name_##Id& operator=(_Name_##Id const& other) = default; \
2947 type inline getId() const \
2948 { \
2949 return _Getter_##Id(); \
2950 } \
2951 \
2952 type _Getter_##Id() const \
2953 { \
2954 return *mColumnIterator; \
2955 } \
2956 \
2957 bool has_##_Getter_() const \
2958 { \
2959 return *mColumnIterator >= 0; \
2960 } \
2961 \
2962 template <typename T> \
2963 auto _Getter_##_as() const \
2964 { \
2965 if (O2_BUILTIN_UNLIKELY(!has_##_Getter_())) { \
2966 o2::soa::accessingInvalidIndexFor(#_Getter_); \
2967 } \
2968 auto t = mBinding.get<T>(); \
2969 if (O2_BUILTIN_UNLIKELY(t == nullptr)) { \
2970 o2::soa::dereferenceWithWrongType(#_Getter_, "self"); \
2971 } \
2972 return t->rawIteratorAt(*mColumnIterator); \
2973 } \
2974 \
2975 bool setCurrentRaw(o2::soa::Binding current) \
2976 { \
2977 this->mBinding = current; \
2978 return true; \
2979 } \
2980 o2::soa::Binding getCurrentRaw() const { return mBinding; } \
2981 o2::soa::Binding mBinding; \
2982 }; \
2983 [[maybe_unused]] static constexpr o2::framework::expressions::BindingNode _Getter_##Id { "fIndex" _Label_, _Name_##Id::hash, o2::framework::expressions::selectArrowType<_Type_>() }
2984
2985#define DECLARE_SOA_SELF_INDEX_COLUMN_FULL(_Name_, _Getter_, _Type_, _Label_) DECLARE_SOA_SELF_INDEX_COLUMN_COMPLETE(_Name_, _Getter_, _Type_, _Label_, void)
2986#define DECLARE_SOA_SELF_INDEX_COLUMN(_Name_, _Getter_) DECLARE_SOA_SELF_INDEX_COLUMN_FULL(_Name_, _Getter_, int32_t, #_Name_)
2988#define DECLARE_SOA_SELF_SLICE_INDEX_COLUMN_COMPLETE(_Name_, _Getter_, _Type_, _Label_, _IndexTarget_) \
2989 struct _Name_##IdSlice : o2::soa::Column<_Type_[2], _Name_##IdSlice> { \
2990 static_assert(std::is_integral_v<_Type_>, "Index type must be integral"); \
2991 static constexpr const char* mLabel = "fIndexSlice" _Label_; \
2992 static constexpr const uint32_t hash = 0; \
2993 using base = o2::soa::Column<_Type_[2], _Name_##IdSlice>; \
2994 using type = _Type_[2]; \
2995 using column_t = _Name_##IdSlice; \
2996 using self_index_t = std::true_type; \
2997 using compatible_signature = std::conditional<aod::is_aod_hash<_IndexTarget_>, _IndexTarget_, void>; \
2998 _Name_##IdSlice(arrow::ChunkedArray const* column) \
2999 : o2::soa::Column<_Type_[2], _Name_##IdSlice>(o2::soa::ColumnIterator<type>(column)) \
3000 { \
3001 } \
3002 \
3003 _Name_##IdSlice() = default; \
3004 _Name_##IdSlice(_Name_##IdSlice const& other) = default; \
3005 _Name_##IdSlice& operator=(_Name_##IdSlice const& other) = default; \
3006 std::array<_Type_, 2> inline getIds() const \
3007 { \
3008 return _Getter_##Ids(); \
3009 } \
3010 \
3011 bool has_##_Getter_() const \
3012 { \
3013 auto a = *mColumnIterator; \
3014 return a[0] >= 0 && a[1] >= 0; \
3015 } \
3016 \
3017 std::array<_Type_, 2> _Getter_##Ids() const \
3018 { \
3019 auto a = *mColumnIterator; \
3020 return std::array{a[0], a[1]}; \
3021 } \
3022 \
3023 template <typename T> \
3024 auto _Getter_##_as() const \
3025 { \
3026 auto t = mBinding.get<T>(); \
3027 if (O2_BUILTIN_UNLIKELY(t == nullptr)) { \
3028 o2::soa::dereferenceWithWrongType(#_Getter_, "self"); \
3029 } \
3030 if (O2_BUILTIN_UNLIKELY(!has_##_Getter_())) { \
3031 return t->emptySlice(); \
3032 } \
3033 auto a = *mColumnIterator; \
3034 auto r = t->rawSlice(a[0], a[1]); \
3035 t->copyIndexBindings(r); \
3036 r.bindInternalIndicesTo(t); \
3037 return r; \
3038 } \
3039 \
3040 bool setCurrentRaw(o2::soa::Binding current) \
3041 { \
3042 this->mBinding = current; \
3043 return true; \
3044 } \
3045 o2::soa::Binding getCurrentRaw() const { return mBinding; } \
3046 o2::soa::Binding mBinding; \
3047 };
3048
3049#define DECLARE_SOA_SELF_SLICE_INDEX_COLUMN_FULL(_Name_, _Getter_, _Type_, _Label_) DECLARE_SOA_SELF_SLICE_INDEX_COLUMN_COMPLETE(_Name_, _Getter_, _Type_, _Label_, void)
3050#define DECLARE_SOA_SELF_SLICE_INDEX_COLUMN(_Name_, _Getter_) DECLARE_SOA_SELF_SLICE_INDEX_COLUMN_FULL(_Name_, _Getter_, int32_t, "_" #_Name_)
3052#define DECLARE_SOA_SELF_ARRAY_INDEX_COLUMN_COMPLETE(_Name_, _Getter_, _Type_, _Label_, _IndexTarget_) \
3053 struct _Name_##Ids : o2::soa::Column<std::vector<_Type_>, _Name_##Ids> { \
3054 static_assert(std::is_integral_v<_Type_>, "Index type must be integral"); \
3055 static constexpr const char* mLabel = "fIndexArray" _Label_; \
3056 static constexpr const uint32_t hash = 0; \
3057 using base = o2::soa::Column<std::vector<_Type_>, _Name_##Ids>; \
3058 using type = std::vector<_Type_>; \
3059 using column_t = _Name_##Ids; \
3060 using self_index_t = std::true_type; \
3061 using compatible_signature = std::conditional<aod::is_aod_hash<_IndexTarget_>, _IndexTarget_, void>; \
3062 _Name_##Ids(arrow::ChunkedArray const* column) \
3063 : o2::soa::Column<std::vector<_Type_>, _Name_##Ids>(o2::soa::ColumnIterator<type>(column)) \
3064 { \
3065 } \
3066 \
3067 _Name_##Ids() = default; \
3068 _Name_##Ids(_Name_##Ids const& other) = default; \
3069 _Name_##Ids& operator=(_Name_##Ids const& other) = default; \
3070 gsl::span<const _Type_> inline getIds() const \
3071 { \
3072 return _Getter_##Ids(); \
3073 } \
3074 \
3075 gsl::span<const _Type_> _Getter_##Ids() const \
3076 { \
3077 return *mColumnIterator; \
3078 } \
3079 \
3080 bool has_##_Getter_() const \
3081 { \
3082 return !(*mColumnIterator).empty(); \
3083 } \
3084 \
3085 template <typename T> \
3086 auto _Getter_##_as() const \
3087 { \
3088 auto t = mBinding.get<T>(); \
3089 if (O2_BUILTIN_UNLIKELY(t == nullptr)) { \
3090 o2::soa::dereferenceWithWrongType(#_Getter_, "self"); \
3091 } \
3092 return getIterators<T>(); \
3093 } \
3094 \
3095 template <typename T> \
3096 auto getIterators() const \
3097 { \
3098 auto result = std::vector<typename T::unfiltered_iterator>(); \
3099 for (auto& i : *mColumnIterator) { \
3100 result.push_back(mBinding.get<T>()->rawIteratorAt(i)); \
3101 } \
3102 return result; \
3103 } \
3104 \
3105 template <typename T> \
3106 auto _Getter_##_first_as() const \
3107 { \
3108 return mBinding.get<T>()->rawIteratorAt((*mColumnIterator)[0]); \
3109 } \
3110 \
3111 template <typename T> \
3112 auto _Getter_##_last_as() const \
3113 { \
3114 return mBinding.get<T>()->rawIteratorAt((*mColumnIterator).back()); \
3115 } \
3116 \
3117 bool setCurrentRaw(o2::soa::Binding current) \
3118 { \
3119 this->mBinding = current; \
3120 return true; \
3121 } \
3122 o2::soa::Binding getCurrentRaw() const { return mBinding; } \
3123 o2::soa::Binding mBinding; \
3124 };
3125
3126#define DECLARE_SOA_SELF_ARRAY_INDEX_COLUMN_FULL(_Name_, _Getter_, _Type_, _Label_) DECLARE_SOA_SELF_ARRAY_INDEX_COLUMN_COMPLETE(_Name_, _Getter_, _Type_, _Label_, void)
3127#define DECLARE_SOA_SELF_ARRAY_INDEX_COLUMN(_Name_, _Getter_) DECLARE_SOA_SELF_ARRAY_INDEX_COLUMN_FULL(_Name_, _Getter_, int32_t, "_" #_Name_)
3128
3157#define DECLARE_SOA_DYNAMIC_COLUMN(_Name_, _Getter_, ...) \
3158 struct _Name_##Callback { \
3159 static inline constexpr auto getLambda() { return __VA_ARGS__; } \
3160 }; \
3161 \
3162 struct _Name_##Helper { \
3163 using callable_t = decltype(o2::framework::FunctionMetadata(std::declval<decltype(_Name_##Callback::getLambda())>())); \
3164 using return_type = typename callable_t::return_type; \
3165 }; \
3166 template <typename... Bindings> \
3167 struct _Name_ : o2::soa::DynamicColumn<typename _Name_##Helper::callable_t::type, _Name_<Bindings...>> { \
3168 using base = o2::soa::DynamicColumn<typename _Name_##Helper::callable_t::type, _Name_<Bindings...>>; \
3169 using helper = _Name_##Helper; \
3170 using callback_holder_t = _Name_##Callback; \
3171 using callable_t = helper::callable_t; \
3172 using callback_t = callable_t::type; \
3173 static constexpr const uint32_t hash = 0; \
3174 \
3175 _Name_(arrow::ChunkedArray const*) \
3176 { \
3177 } \
3178 _Name_() = default; \
3179 _Name_(_Name_ const& other) = default; \
3180 _Name_& operator=(_Name_ const& other) = default; \
3181 static constexpr const char* mLabel = #_Name_; \
3182 using type = typename callable_t::return_type; \
3183 \
3184 template <typename... FreeArgs> \
3185 type _Getter_(FreeArgs... freeArgs) const \
3186 { \
3187 return boundGetter(std::make_index_sequence<std::tuple_size_v<decltype(boundIterators)>>{}, freeArgs...); \
3188 } \
3189 template <typename... FreeArgs> \
3190 type getDynamicValue(FreeArgs... freeArgs) const \
3191 { \
3192 return boundGetter(std::make_index_sequence<std::tuple_size_v<decltype(boundIterators)>>{}, freeArgs...); \
3193 } \
3194 \
3195 type get() const \
3196 { \
3197 return _Getter_(); \
3198 } \
3199 \
3200 template <size_t... Is, typename... FreeArgs> \
3201 type boundGetter(std::integer_sequence<size_t, Is...>&&, FreeArgs... freeArgs) const \
3202 { \
3203 return __VA_ARGS__((**std::get<Is>(boundIterators))..., freeArgs...); \
3204 } \
3205 \
3206 using bindings_t = typename o2::framework::pack<Bindings...>; \
3207 std::tuple<o2::soa::ColumnIterator<typename Bindings::type> const*...> boundIterators; \
3208 }
3209
3210#define DECLARE_SOA_TABLE_METADATA(_Name_, _Desc_, _Version_, ...) \
3211 using _Name_##Metadata = TableMetadata<Hash<_Desc_ "/" #_Version_ ""_h>, __VA_ARGS__>;
3212
3213#define DECLARE_SOA_TABLE_METADATA_TRAIT(_Name_, _Desc_, _Version_) \
3214 template <> \
3215 struct MetadataTrait<Hash<_Desc_ "/" #_Version_ ""_h>> { \
3216 using metadata = _Name_##Metadata; \
3217 };
3218
3219#define DECLARE_SOA_TABLE_FULL_VERSIONED_(_Name_, _Label_, _Origin_, _Desc_, _Version_) \
3220 O2HASH(_Desc_ "/" #_Version_); \
3221 template <typename O> \
3222 using _Name_##From = o2::soa::Table<Hash<_Label_ ""_h>, Hash<_Desc_ "/" #_Version_ ""_h>, O>; \
3223 using _Name_ = _Name_##From<Hash<_Origin_ ""_h>>; \
3224 template <> \
3225 struct MetadataTrait<Hash<_Desc_ "/" #_Version_ ""_h>> { \
3226 using metadata = _Name_##Metadata; \
3227 };
3228
3229#define DECLARE_SOA_STAGE(_Name_, _Origin_, _Desc_, _Version_) \
3230 template <typename O> \
3231 using _Name_##From = o2::soa::Table<Hash<#_Name_ ""_h>, Hash<_Desc_ "/" #_Version_ ""_h>, O>; \
3232 using _Name_ = _Name_##From<Hash<_Origin_ ""_h>>;
3233
3234#define DECLARE_SOA_TABLE_FULL_VERSIONED(_Name_, _Label_, _Origin_, _Desc_, _Version_, ...) \
3235 DECLARE_SOA_TABLE_METADATA(_Name_, _Desc_, _Version_, __VA_ARGS__); \
3236 DECLARE_SOA_TABLE_FULL_VERSIONED_(_Name_, _Label_, _Origin_, _Desc_, _Version_);
3237
3238#define DECLARE_SOA_TABLE_FULL(_Name_, _Label_, _Origin_, _Desc_, ...) \
3239 O2HASH(_Label_); \
3240 DECLARE_SOA_TABLE_METADATA(_Name_, _Desc_, 0, __VA_ARGS__); \
3241 DECLARE_SOA_TABLE_FULL_VERSIONED_(_Name_, _Label_, _Origin_, _Desc_, 0)
3242
3243#define DECLARE_SOA_TABLE(_Name_, _Origin_, _Desc_, ...) \
3244 DECLARE_SOA_TABLE_FULL(_Name_, #_Name_, _Origin_, _Desc_, __VA_ARGS__)
3245
3246#define DECLARE_SOA_TABLE_VERSIONED(_Name_, _Origin_, _Desc_, _Version_, ...) \
3247 O2HASH(#_Name_); \
3248 DECLARE_SOA_TABLE_METADATA(_Name_, _Desc_, _Version_, __VA_ARGS__); \
3249 DECLARE_SOA_TABLE_FULL_VERSIONED_(_Name_, #_Name_, _Origin_, _Desc_, _Version_)
3250
3251#define DECLARE_SOA_TABLE_STAGED_VERSIONED(_BaseName_, _Desc_, _Version_, ...) \
3252 O2HASH(_Desc_ "/" #_Version_); \
3253 O2HASH(#_BaseName_); \
3254 O2HASH("Stored" #_BaseName_); \
3255 DECLARE_SOA_TABLE_METADATA(_BaseName_, _Desc_, _Version_, __VA_ARGS__); \
3256 using Stored##_BaseName_##Metadata = _BaseName_##Metadata; \
3257 DECLARE_SOA_TABLE_METADATA_TRAIT(_BaseName_, _Desc_, _Version_); \
3258 DECLARE_SOA_STAGE(_BaseName_, "AOD", _Desc_, _Version_); \
3259 DECLARE_SOA_STAGE(Stored##_BaseName_, "AOD1", _Desc_, _Version_);
3260
3261#define DECLARE_SOA_TABLE_STAGED(_BaseName_, _Desc_, ...) \
3262 DECLARE_SOA_TABLE_STAGED_VERSIONED(_BaseName_, _Desc_, 0, __VA_ARGS__);
3263
3264#define DECLARE_SOA_EXTENDED_TABLE_FULL(_Name_, _Label_, _OriginalTable_, _Origin_, _Desc_, _Version_, ...) \
3265 O2HASH(_Desc_ "/" #_Version_); \
3266 template <typename O> \
3267 using _Name_##ExtensionFrom = soa::Table<o2::aod::Hash<_Label_ ""_h>, o2::aod::Hash<_Desc_ "/" #_Version_ ""_h>, O>; \
3268 using _Name_##Extension = _Name_##ExtensionFrom<o2::aod::Hash<_Origin_ ""_h>>; \
3269 template <typename O = o2::aod::Hash<_Origin_ ""_h>> \
3270 struct _Name_##ExtensionMetadataFrom : TableMetadata<o2::aod::Hash<_Desc_ "/" #_Version_ ""_h>, __VA_ARGS__> { \
3271 using base_table_t = _OriginalTable_; \
3272 using extension_table_t = _Name_##ExtensionFrom<O>; \
3273 using expression_pack_t = framework::pack<__VA_ARGS__>; \
3274 static constexpr auto sources = _OriginalTable_::originals; \
3275 }; \
3276 using _Name_##ExtensionMetadata = _Name_##ExtensionMetadataFrom<o2::aod::Hash<_Origin_ ""_h>>; \
3277 template <> \
3278 struct MetadataTrait<o2::aod::Hash<_Desc_ "/" #_Version_ ""_h>> { \
3279 using metadata = _Name_##ExtensionMetadata; \
3280 }; \
3281 template <typename O> \
3282 using _Name_##From = o2::soa::JoinFull<o2::aod::Hash<_Desc_ "/" #_Version_ ""_h>, _OriginalTable_, _Name_##ExtensionFrom<O>>; \
3283 using _Name_ = _Name_##From<o2::aod::Hash<_Origin_ ""_h>>;
3284
3285#define DECLARE_SOA_EXTENDED_TABLE(_Name_, _Table_, _Description_, _Version_, ...) \
3286 O2HASH(#_Name_ "Extension"); \
3287 DECLARE_SOA_EXTENDED_TABLE_FULL(_Name_, #_Name_ "Extension", _Table_, "DYN", _Description_, _Version_, __VA_ARGS__)
3288
3289#define DECLARE_SOA_EXTENDED_TABLE_USER(_Name_, _Table_, _Description_, ...) \
3290 O2HASH(#_Name_ "Extension"); \
3291 DECLARE_SOA_EXTENDED_TABLE_FULL(_Name_, #_Name_ "Extension", _Table_, "AOD", "EX" _Description_, 0, __VA_ARGS__)
3292
3293#define DECLARE_SOA_CONFIGURABLE_EXTENDED_TABLE_FULL(_Name_, _Label_, _OriginalTable_, _Origin_, _Desc_, _Version_, ...) \
3294 O2HASH(_Desc_ "/" #_Version_); \
3295 template <typename O> \
3296 using _Name_##CfgExtensionFrom = soa::Table<o2::aod::Hash<_Label_ ""_h>, o2::aod::Hash<_Desc_ "/" #_Version_ ""_h>, O>; \
3297 using _Name_##CfgExtension = _Name_##CfgExtensionFrom<o2::aod::Hash<_Origin_ ""_h>>; \
3298 template <typename O = o2::aod::Hash<_Origin_ ""_h>> \
3299 struct _Name_##CfgExtensionMetadataFrom : TableMetadata<o2::aod::Hash<_Desc_ "/" #_Version_ ""_h>, __VA_ARGS__> { \
3300 using base_table_t = _OriginalTable_; \
3301 using extension_table_t = _Name_##CfgExtensionFrom<O>; \
3302 using placeholders_pack_t = framework::pack<__VA_ARGS__>; \
3303 using configurable_t = std::true_type; \
3304 static constexpr auto sources = _OriginalTable_::originals; \
3305 }; \
3306 using _Name_##CfgExtensionMetadata = _Name_##CfgExtensionMetadataFrom<o2::aod::Hash<_Origin_ ""_h>>; \
3307 template <> \
3308 struct MetadataTrait<o2::aod::Hash<_Desc_ "/" #_Version_ ""_h>> { \
3309 using metadata = _Name_##CfgExtensionMetadata; \
3310 }; \
3311 template <typename O> \
3312 using _Name_##From = o2::soa::JoinFull<o2::aod::Hash<_Desc_ "/" #_Version_ ""_h>, _OriginalTable_, _Name_##CfgExtensionFrom<O>>; \
3313 using _Name_ = _Name_##From<o2::aod::Hash<_Origin_ ""_h>>;
3314
3315#define DECLARE_SOA_CONFIGURABLE_EXTENDED_TABLE(_Name_, _Table_, _Description_, ...) \
3316 O2HASH(#_Name_ "CfgExtension"); \
3317 DECLARE_SOA_CONFIGURABLE_EXTENDED_TABLE_FULL(_Name_, #_Name_ "CfgExtension", _Table_, "AOD", "EX" _Description_, 0, __VA_ARGS__)
3318
3319#define DECLARE_SOA_INDEX_TABLE_FULL(_Name_, _Key_, _Origin_, _Version_, _Desc_, _Exclusive_, ...) \
3320 O2HASH(#_Name_); \
3321 O2HASH(_Desc_ "/" #_Version_); \
3322 template <typename O = o2::aod::Hash<_Origin_ ""_h>> \
3323 struct _Name_##MetadataFrom : o2::aod::TableMetadata<o2::aod::Hash<_Desc_ "/" #_Version_ ""_h>, soa::Index<>, __VA_ARGS__> { \
3324 static constexpr bool exclusive = _Exclusive_; \
3325 using Key = _Key_; \
3326 using index_pack_t = framework::pack<__VA_ARGS__>; \
3327 static constexpr const auto sources = []<typename... Cs>(framework::pack<Cs...>) { \
3328 constexpr auto a = o2::soa::mergeOriginals<typename Cs::binding_t...>(); \
3329 return o2::aod::filterForKey<a.size(), a, Key>(); \
3330 }(framework::pack<__VA_ARGS__>{}); \
3331 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"); \
3332 }; \
3333 using _Name_##Metadata = _Name_##MetadataFrom<o2::aod::Hash<_Origin_ ""_h>>; \
3334 \
3335 template <typename O = o2::aod::Hash<_Origin_ ""_h>> \
3336 using _Name_##From = o2::soa::IndexTable<o2::aod::Hash<#_Name_ ""_h>, o2::aod::Hash<_Desc_ "/" #_Version_ ""_h>, O, _Key_, __VA_ARGS__>; \
3337 using _Name_ = _Name_##From<o2::aod::Hash<_Origin_ ""_h>>; \
3338 \
3339 template <> \
3340 struct MetadataTrait<o2::aod::Hash<_Desc_ "/" #_Version_ ""_h>> { \
3341 using metadata = _Name_##Metadata; \
3342 };
3343
3344// Declare were each row is associated to a timestamp column of an _TimestampSource_
3345// table.
3346//
3347// The columns of this table have to be CCDB_COLUMNS so that for each timestamp, we get a row
3348// which points to the specified CCDB objectes described by those columns.
3349#define DECLARE_SOA_TIMESTAMPED_TABLE_FULL(_Name_, _Label_, _TimestampSource_, _TimestampColumn_, _Origin_, _Version_, _Desc_, ...) \
3350 O2HASH(_Desc_ "/" #_Version_); \
3351 template <typename O> \
3352 using _Name_##TimestampFrom = soa::Table<o2::aod::Hash<_Label_ ""_h>, o2::aod::Hash<_Desc_ "/" #_Version_ ""_h>, O>; \
3353 using _Name_##Timestamp = _Name_##TimestampFrom<o2::aod::Hash<_Origin_ ""_h>>; \
3354 template <typename O = o2::aod::Hash<_Origin_ ""_h>> \
3355 struct _Name_##TimestampMetadataFrom : TableMetadata<o2::aod::Hash<_Desc_ "/" #_Version_ ""_h>, __VA_ARGS__> { \
3356 using base_table_t = _TimestampSource_; \
3357 using extension_table_t = _Name_##TimestampFrom<O>; \
3358 static constexpr const auto ccdb_urls = []<typename... Cs>(framework::pack<Cs...>) { \
3359 return std::array<std::string_view, sizeof...(Cs)>{Cs::query...}; \
3360 }(framework::pack<__VA_ARGS__>{}); \
3361 static constexpr const auto ccdb_bindings = []<typename... Cs>(framework::pack<Cs...>) { \
3362 return std::array<std::string_view, sizeof...(Cs)>{Cs::mLabel...}; \
3363 }(framework::pack<__VA_ARGS__>{}); \
3364 static constexpr auto sources = _TimestampSource_::originals; \
3365 static constexpr auto timestamp_column_label = _TimestampColumn_::mLabel; \
3366 /*static constexpr auto timestampColumn = _TimestampColumn_;*/ \
3367 }; \
3368 using _Name_##TimestampMetadata = _Name_##TimestampMetadataFrom<o2::aod::Hash<_Origin_ ""_h>>; \
3369 template <> \
3370 struct MetadataTrait<o2::aod::Hash<_Desc_ "/" #_Version_ ""_h>> { \
3371 using metadata = _Name_##TimestampMetadata; \
3372 }; \
3373 template <typename O> \
3374 using _Name_##From = o2::soa::JoinFull<o2::aod::Hash<_Desc_ "/" #_Version_ ""_h>, _TimestampSource_, _Name_##TimestampFrom<O>>; \
3375 using _Name_ = _Name_##From<o2::aod::Hash<_Origin_ ""_h>>;
3376
3377#define DECLARE_SOA_TIMESTAMPED_TABLE(_Name_, _TimestampSource_, _TimestampColumn_, _Version_, _Desc_, ...) \
3378 O2HASH(#_Name_ "Timestamped"); \
3379 DECLARE_SOA_TIMESTAMPED_TABLE_FULL(_Name_, #_Name_ "Timestamped", _TimestampSource_, _TimestampColumn_, "ATIM", _Version_, _Desc_, __VA_ARGS__)
3380
3381#define DECLARE_SOA_INDEX_TABLE(_Name_, _Key_, _Description_, ...) \
3382 DECLARE_SOA_INDEX_TABLE_FULL(_Name_, _Key_, "IDX", 0, _Description_, false, __VA_ARGS__)
3383
3384#define DECLARE_SOA_INDEX_TABLE_EXCLUSIVE(_Name_, _Key_, _Description_, ...) \
3385 DECLARE_SOA_INDEX_TABLE_FULL(_Name_, _Key_, "IDX", 0, _Description_, true, __VA_ARGS__)
3386
3387#define DECLARE_SOA_INDEX_TABLE_USER(_Name_, _Key_, _Description_, ...) \
3388 DECLARE_SOA_INDEX_TABLE_FULL(_Name_, _Key_, "AOD", 0, _Description_, false, __VA_ARGS__)
3389
3390#define DECLARE_SOA_INDEX_TABLE_EXCLUSIVE_USER(_Name_, _Key_, _Description_, ...) \
3391 DECLARE_SOA_INDEX_TABLE_FULL(_Name_, _Key_, "AOD", 0, _Description_, true, __VA_ARGS__)
3392
3393namespace o2::soa
3394{
3395template <typename D, typename... Ts>
3396struct JoinFull : Table<o2::aod::Hash<"JOIN"_h>, D, o2::aod::Hash<"JOIN"_h>, Ts...> {
3397 using base = Table<o2::aod::Hash<"JOIN"_h>, D, o2::aod::Hash<"JOIN"_h>, Ts...>;
3398
3399 JoinFull(std::shared_ptr<arrow::Table>&& table, uint64_t offset = 0)
3400 : base{std::move(table), offset}
3401 {
3402 if (this->tableSize() != 0) {
3404 }
3405 }
3406 JoinFull(std::vector<std::shared_ptr<arrow::Table>>&& tables, uint64_t offset = 0)
3407 : base{ArrowHelpers::joinTables(std::move(tables), std::span{base::originalLabels}), offset}
3408 {
3409 if (this->tableSize() != 0) {
3411 }
3412 }
3415
3416 using self_t = JoinFull<D, Ts...>;
3417 using table_t = base;
3418 static constexpr const auto originals = base::originals;
3419 static constexpr const auto originalLabels = base::originalLabels;
3422 using iterator = table_t::template iterator_template<DefaultIndexPolicy, self_t, Ts...>;
3428
3430 {
3431 return iterator{this->cached_begin()};
3432 }
3433
3435 {
3436 return const_iterator{this->cached_begin()};
3437 }
3438
3440 {
3441 return doSliceByCached(this, node, value, cache);
3442 }
3443
3448
3449 template <typename T1, typename Policy, bool OPT>
3451 {
3452 return doSliceBy(this, container, value);
3453 }
3454
3455 iterator rawIteratorAt(uint64_t i) const
3456 {
3457 auto it = iterator{this->cached_begin()};
3458 it.setCursor(i);
3459 return it;
3460 }
3461
3462 iterator iteratorAt(uint64_t i) const
3463 {
3464 return rawIteratorAt(i);
3465 }
3466
3467 auto rawSlice(uint64_t start, uint64_t end) const
3468 {
3469 return self_t{{this->asArrowTable()->Slice(start, end - start + 1)}, start};
3470 }
3471
3472 auto emptySlice() const
3473 {
3474 return self_t{{this->asArrowTable()->Slice(0, 0)}, 0};
3475 }
3476
3477 template <typename T>
3478 static consteval bool contains()
3479 {
3480 return std::find_if(originals.begin(), originals.end(), [](TableRef const& ref) { return ref.desc_hash == T::ref.desc_hash; }) != originals.end();
3481 }
3482};
3483
3484template <typename... Ts>
3485using Join = JoinFull<o2::aod::Hash<"JOIN/0"_h>, Ts...>;
3486
3487template <typename... Ts>
3488constexpr auto join(Ts const&... t)
3489{
3490 return Join<Ts...>(ArrowHelpers::joinTables({t.asArrowTable()...}, std::span{Join<Ts...>::base::originalLabels}));
3491}
3492
3493template <typename T>
3495
3496template <typename T>
3497constexpr bool is_soa_join_v = is_join<T>;
3498
3499template <typename... Ts>
3500struct Concat : Table<o2::aod::Hash<"CONC"_h>, o2::aod::Hash<"CONC/0"_h>, o2::aod::Hash<"CONC"_h>, Ts...> {
3501 using base = Table<o2::aod::Hash<"CONC"_h>, o2::aod::Hash<"CONC/0"_h>, o2::aod::Hash<"CONC"_h>, Ts...>;
3502 using self_t = Concat<Ts...>;
3503 Concat(std::vector<std::shared_ptr<arrow::Table>>&& tables, uint64_t offset = 0)
3504 : base{ArrowHelpers::concatTables(std::move(tables)), offset}
3505 {
3507 }
3508 Concat(Ts const&... t, uint64_t offset = 0)
3509 : base{ArrowHelpers::concatTables({t.asArrowTable()...}), offset}
3510 {
3511 bindInternalIndicesTo(this);
3512 }
3513
3514 using base::originals;
3515
3516 using base::bindExternalIndices;
3517 using base::bindInternalIndicesTo;
3518
3519 using table_t = base;
3522
3523 using iterator = table_t::template iterator_template<DefaultIndexPolicy, self_t, Ts...>;
3529};
3530
3531template <typename... Ts>
3532constexpr auto concat(Ts const&... t)
3533{
3534 return Concat<Ts...>{t...};
3535}
3536
3537template <soa::is_table T>
3538class FilteredBase : public T
3539{
3540 public:
3542 using table_t = typename T::table_t;
3543 using T::originals;
3544 using columns_t = typename T::columns_t;
3545 using persistent_columns_t = typename T::persistent_columns_t;
3546 using external_index_columns_t = typename T::external_index_columns_t;
3547
3548 using iterator = T::template iterator_template_o<FilteredIndexPolicy, self_t>;
3549 using unfiltered_iterator = T::template iterator_template_o<DefaultIndexPolicy, self_t>;
3551
3552 FilteredBase(std::vector<std::shared_ptr<arrow::Table>>&& tables, gandiva::Selection const& selection, uint64_t offset = 0)
3553 : T{std::move(tables), offset},
3554 mSelectedRows{getSpan(selection)}
3555 {
3556 if (this->tableSize() != 0) {
3557 mFilteredBegin = table_t::filtered_begin(mSelectedRows);
3558 }
3559 resetRanges();
3560 mFilteredBegin.bindInternalIndices(this);
3561 }
3562
3563 FilteredBase(std::vector<std::shared_ptr<arrow::Table>>&& tables, SelectionVector&& selection, uint64_t offset = 0)
3564 : T{std::move(tables), offset},
3565 mSelectedRowsCache{std::move(selection)},
3566 mCached{true}
3567 {
3568 mSelectedRows = std::span{mSelectedRowsCache};
3569 if (this->tableSize() != 0) {
3570 mFilteredBegin = table_t::filtered_begin(mSelectedRows);
3571 }
3572 resetRanges();
3573 mFilteredBegin.bindInternalIndices(this);
3574 }
3575
3576 FilteredBase(std::vector<std::shared_ptr<arrow::Table>>&& tables, std::span<int64_t const> const& selection, uint64_t offset = 0)
3577 : T{std::move(tables), offset},
3578 mSelectedRows{selection}
3579 {
3580 if (this->tableSize() != 0) {
3581 mFilteredBegin = table_t::filtered_begin(mSelectedRows);
3582 }
3583 resetRanges();
3584 mFilteredBegin.bindInternalIndices(this);
3585 }
3586
3588 {
3589 return iterator(mFilteredBegin);
3590 }
3591
3593 {
3594 return const_iterator(mFilteredBegin);
3595 }
3596
3598 {
3599 auto it = unfiltered_iterator{mFilteredBegin};
3600 it.setCursor(i);
3601 return it;
3602 }
3603
3604 [[nodiscard]] RowViewSentinel end() const
3605 {
3606 return RowViewSentinel{*mFilteredEnd};
3607 }
3608
3610 {
3611 return mFilteredBegin;
3612 }
3613
3614 auto const& cached_begin() const
3615 {
3616 return mFilteredBegin;
3617 }
3618
3619 iterator iteratorAt(uint64_t i) const
3620 {
3621 return mFilteredBegin + i;
3622 }
3623
3624 [[nodiscard]] int64_t size() const
3625 {
3626 return mSelectedRows.size();
3627 }
3628
3629 [[nodiscard]] int64_t tableSize() const
3630 {
3631 return table_t::asArrowTable()->num_rows();
3632 }
3633
3634 auto const& getSelectedRows() const
3635 {
3636 return mSelectedRows;
3637 }
3638
3639 auto rawSlice(uint64_t start, uint64_t end) const
3640 {
3641 SelectionVector newSelection;
3642 newSelection.resize(static_cast<int64_t>(end - start + 1));
3643 std::iota(newSelection.begin(), newSelection.end(), start);
3644 return self_t{{this->asArrowTable()}, std::move(newSelection), 0};
3645 }
3646
3647 auto emptySlice() const
3648 {
3649 return self_t{{this->asArrowTable()}, SelectionVector{}, 0};
3650 }
3651
3652 static inline auto getSpan(gandiva::Selection const& sel)
3653 {
3654 if (sel == nullptr) {
3655 return std::span<int64_t const>{};
3656 }
3657 auto array = std::static_pointer_cast<arrow::Int64Array>(sel->ToArray());
3658 auto start = array->raw_values();
3659 auto stop = start + array->length();
3660 return std::span{start, stop};
3661 }
3662
3665 template <typename... TA>
3666 void bindExternalIndices(TA*... current)
3667 {
3668 table_t::bindExternalIndices(current...);
3669 mFilteredBegin.bindExternalIndices(current...);
3670 }
3671
3672 void bindExternalIndicesRaw(std::vector<o2::soa::Binding>&& ptrs)
3673 {
3674 mFilteredBegin.bindExternalIndicesRaw(std::forward<std::vector<o2::soa::Binding>>(ptrs));
3675 }
3676
3677 template <typename I>
3679 {
3680 mFilteredBegin.bindInternalIndices(ptr);
3681 }
3682
3683 template <typename T1, typename... Cs>
3685 {
3686 dest.bindExternalIndicesRaw(mFilteredBegin.getIndexBindings());
3687 }
3688
3689 template <typename T1>
3690 void copyIndexBindings(T1& dest) const
3691 {
3692 doCopyIndexBindings(external_index_columns_t{}, dest);
3693 }
3694
3695 template <typename T1>
3696 auto rawSliceBy(o2::framework::Preslice<T1> const& container, int value) const
3697 {
3698 return (table_t)this->sliceBy(container, value);
3699 }
3700
3702 {
3703 return doFilteredSliceByCached(this, node, value, cache);
3704 }
3705
3710
3711 template <typename T1, bool OPT>
3713 {
3714 return doFilteredSliceBy(this, container, value);
3715 }
3716
3717 template <typename T1, bool OPT>
3719 {
3720 return doSliceBy(this, container, value);
3721 }
3722
3724 {
3725 auto t = o2::soa::select(*this, f);
3726 copyIndexBindings(t);
3727 return t;
3728 }
3729
3730 int isInSelectedRows(int i) const
3731 {
3732 auto locate = std::find(mSelectedRows.begin(), mSelectedRows.end(), i);
3733 if (locate == mSelectedRows.end()) {
3734 return -1;
3735 }
3736 return static_cast<int>(std::distance(mSelectedRows.begin(), locate));
3737 }
3738
3739 void sumWithSelection(SelectionVector const& selection)
3740 {
3741 mCached = true;
3742 SelectionVector rowsUnion;
3743 std::set_union(mSelectedRows.begin(), mSelectedRows.end(), selection.begin(), selection.end(), std::back_inserter(rowsUnion));
3744 mSelectedRowsCache.clear();
3745 mSelectedRowsCache = rowsUnion;
3746 resetRanges();
3747 }
3748
3750 {
3751 mCached = true;
3752 SelectionVector intersection;
3753 std::set_intersection(mSelectedRows.begin(), mSelectedRows.end(), selection.begin(), selection.end(), std::back_inserter(intersection));
3754 mSelectedRowsCache.clear();
3755 mSelectedRowsCache = intersection;
3756 resetRanges();
3757 }
3758
3759 void sumWithSelection(std::span<int64_t const> const& selection)
3760 {
3761 mCached = true;
3762 SelectionVector rowsUnion;
3763 std::set_union(mSelectedRows.begin(), mSelectedRows.end(), selection.begin(), selection.end(), std::back_inserter(rowsUnion));
3764 mSelectedRowsCache.clear();
3765 mSelectedRowsCache = rowsUnion;
3766 resetRanges();
3767 }
3768
3769 void intersectWithSelection(std::span<int64_t const> const& selection)
3770 {
3771 mCached = true;
3772 SelectionVector intersection;
3773 std::set_intersection(mSelectedRows.begin(), mSelectedRows.end(), selection.begin(), selection.end(), std::back_inserter(intersection));
3774 mSelectedRowsCache.clear();
3775 mSelectedRowsCache = intersection;
3776 resetRanges();
3777 }
3778
3779 bool isCached() const
3780 {
3781 return mCached;
3782 }
3783
3784 private:
3785 void resetRanges()
3786 {
3787 if (mCached) {
3788 mSelectedRows = std::span{mSelectedRowsCache};
3789 }
3790 mFilteredEnd.reset(new RowViewSentinel{static_cast<int64_t>(mSelectedRows.size())});
3791 if (tableSize() == 0) {
3792 mFilteredBegin = *mFilteredEnd;
3793 } else {
3794 mFilteredBegin.resetSelection(mSelectedRows);
3795 }
3796 }
3797
3798 std::span<int64_t const> mSelectedRows;
3799 SelectionVector mSelectedRowsCache;
3800 bool mCached = false;
3801 iterator mFilteredBegin;
3802 std::shared_ptr<RowViewSentinel> mFilteredEnd;
3803};
3804
3805template <typename T>
3806class Filtered : public FilteredBase<T>
3807{
3808 public:
3809 using base_t = T;
3811 using table_t = typename T::table_t;
3812 using columns_t = typename T::columns_t;
3813
3814 using iterator = T::template iterator_template_o<FilteredIndexPolicy, self_t>;
3815 using unfiltered_iterator = T::template iterator_template_o<DefaultIndexPolicy, self_t>;
3817
3819 {
3820 return iterator(this->cached_begin());
3821 }
3822
3824 {
3825 return const_iterator(this->cached_begin());
3826 }
3827
3828 Filtered(std::vector<std::shared_ptr<arrow::Table>>&& tables, gandiva::Selection const& selection, uint64_t offset = 0)
3829 : FilteredBase<T>(std::move(tables), selection, offset) {}
3830
3831 Filtered(std::vector<std::shared_ptr<arrow::Table>>&& tables, SelectionVector&& selection, uint64_t offset = 0)
3832 : FilteredBase<T>(std::move(tables), std::forward<SelectionVector>(selection), offset) {}
3833
3834 Filtered(std::vector<std::shared_ptr<arrow::Table>>&& tables, std::span<int64_t const> const& selection, uint64_t offset = 0)
3835 : FilteredBase<T>(std::move(tables), selection, offset) {}
3836
3838 {
3839 Filtered<T> copy(*this);
3840 copy.sumWithSelection(selection);
3841 return copy;
3842 }
3843
3844 Filtered<T> operator+(std::span<int64_t const> const& selection)
3845 {
3846 Filtered<T> copy(*this);
3847 copy.sumWithSelection(selection);
3848 return copy;
3849 }
3850
3852 {
3853 return operator+(other.getSelectedRows());
3854 }
3855
3857 {
3858 this->sumWithSelection(selection);
3859 return *this;
3860 }
3861
3862 Filtered<T> operator+=(std::span<int64_t const> const& selection)
3863 {
3864 this->sumWithSelection(selection);
3865 return *this;
3866 }
3867
3869 {
3870 return operator+=(other.getSelectedRows());
3871 }
3872
3874 {
3875 Filtered<T> copy(*this);
3876 copy.intersectWithSelection(selection);
3877 return copy;
3878 }
3879
3880 Filtered<T> operator*(std::span<int64_t const> const& selection)
3881 {
3882 Filtered<T> copy(*this);
3883 copy.intersectWithSelection(selection);
3884 return copy;
3885 }
3886
3888 {
3889 return operator*(other.getSelectedRows());
3890 }
3891
3893 {
3894 this->intersectWithSelection(selection);
3895 return *this;
3896 }
3897
3898 Filtered<T> operator*=(std::span<int64_t const> const& selection)
3899 {
3900 this->intersectWithSelection(selection);
3901 return *this;
3902 }
3903
3905 {
3906 return operator*=(other.getSelectedRows());
3907 }
3908
3910 {
3911 auto it = unfiltered_iterator{this->cached_begin()};
3912 it.setCursor(i);
3913 return it;
3914 }
3915
3916 using FilteredBase<T>::getSelectedRows;
3917
3918 auto rawSlice(uint64_t start, uint64_t end) const
3919 {
3920 SelectionVector newSelection;
3921 newSelection.resize(static_cast<int64_t>(end - start + 1));
3922 std::iota(newSelection.begin(), newSelection.end(), start);
3923 return self_t{{this->asArrowTable()}, std::move(newSelection), 0};
3924 }
3925
3926 auto emptySlice() const
3927 {
3928 return self_t{{this->asArrowTable()}, SelectionVector{}, 0};
3929 }
3930
3931 template <typename T1>
3932 auto rawSliceBy(o2::framework::Preslice<T1> const& container, int value) const
3933 {
3934 return (table_t)this->sliceBy(container, value);
3935 }
3936
3938 {
3939 return doFilteredSliceByCached(this, node, value, cache);
3940 }
3941
3946
3947 template <typename T1, bool OPT>
3949 {
3950 return doFilteredSliceBy(this, container, value);
3951 }
3952
3953 template <typename T1, bool OPT>
3955 {
3956 return doSliceBy(this, container, value);
3957 }
3958
3960 {
3961 auto t = o2::soa::select(*this, f);
3962 copyIndexBindings(t);
3963 return t;
3964 }
3965};
3966
3967template <typename T>
3968class Filtered<Filtered<T>> : public FilteredBase<typename T::table_t>
3969{
3970 public:
3972 using base_t = T;
3974 using columns_t = typename T::columns_t;
3975
3976 using iterator = typename T::template iterator_template_o<FilteredIndexPolicy, self_t>;
3977 using unfiltered_iterator = typename T::template iterator_template_o<DefaultIndexPolicy, self_t>;
3979
3981 {
3982 return iterator(this->cached_begin());
3983 }
3984
3986 {
3987 return const_iterator(this->cached_begin());
3988 }
3989
3990 Filtered(std::vector<Filtered<T>>&& tables, gandiva::Selection const& selection, uint64_t offset = 0)
3991 : FilteredBase<typename T::table_t>(std::move(extractTablesFromFiltered(tables)), selection, offset)
3992 {
3993 for (auto& table : tables) {
3994 *this *= table;
3995 }
3996 }
3997
3998 Filtered(std::vector<Filtered<T>>&& tables, SelectionVector&& selection, uint64_t offset = 0)
3999 : FilteredBase<typename T::table_t>(std::move(extractTablesFromFiltered(tables)), std::forward<SelectionVector>(selection), offset)
4000 {
4001 for (auto& table : tables) {
4002 *this *= table;
4003 }
4004 }
4005
4006 Filtered(std::vector<Filtered<T>>&& tables, std::span<int64_t const> const& selection, uint64_t offset = 0)
4007 : FilteredBase<typename T::table_t>(std::move(extractTablesFromFiltered(tables)), selection, offset)
4008 {
4009 for (auto& table : tables) {
4010 *this *= table;
4011 }
4012 }
4013
4015 {
4016 Filtered<Filtered<T>> copy(*this);
4017 copy.sumWithSelection(selection);
4018 return copy;
4019 }
4020
4021 Filtered<Filtered<T>> operator+(std::span<int64_t const> const& selection)
4022 {
4023 Filtered<Filtered<T>> copy(*this);
4024 copy.sumWithSelection(selection);
4025 return copy;
4026 }
4027
4029 {
4030 return operator+(other.getSelectedRows());
4031 }
4032
4034 {
4035 this->sumWithSelection(selection);
4036 return *this;
4037 }
4038
4039 Filtered<Filtered<T>> operator+=(std::span<int64_t const> const& selection)
4040 {
4041 this->sumWithSelection(selection);
4042 return *this;
4043 }
4044
4046 {
4047 return operator+=(other.getSelectedRows());
4048 }
4049
4051 {
4052 Filtered<Filtered<T>> copy(*this);
4053 copy.intersectionWithSelection(selection);
4054 return copy;
4055 }
4056
4057 Filtered<Filtered<T>> operator*(std::span<int64_t const> const& selection)
4058 {
4059 Filtered<Filtered<T>> copy(*this);
4060 copy.intersectionWithSelection(selection);
4061 return copy;
4062 }
4063
4065 {
4066 return operator*(other.getSelectedRows());
4067 }
4068
4070 {
4071 this->intersectWithSelection(selection);
4072 return *this;
4073 }
4074
4075 Filtered<Filtered<T>> operator*=(std::span<int64_t const> const& selection)
4076 {
4077 this->intersectWithSelection(selection);
4078 return *this;
4079 }
4080
4082 {
4083 return operator*=(other.getSelectedRows());
4084 }
4085
4087 {
4088 auto it = unfiltered_iterator{this->cached_begin()};
4089 it.setCursor(i);
4090 return it;
4091 }
4092
4093 auto rawSlice(uint64_t start, uint64_t end) const
4094 {
4095 SelectionVector newSelection;
4096 newSelection.resize(static_cast<int64_t>(end - start + 1));
4097 std::iota(newSelection.begin(), newSelection.end(), start);
4098 return self_t{{this->asArrowTable()}, std::move(newSelection), 0};
4099 }
4100
4101 auto emptySlice() const
4102 {
4103 return self_t{{this->asArrowTable()}, SelectionVector{}, 0};
4104 }
4105
4107 {
4108 return doFilteredSliceByCached(this, node, value, cache);
4109 }
4110
4115
4116 template <typename T1, bool OPT>
4118 {
4119 return doFilteredSliceBy(this, container, value);
4120 }
4121
4122 template <typename T1, bool OPT>
4124 {
4125 return doSliceBy(this, container, value);
4126 }
4127
4128 private:
4129 std::vector<std::shared_ptr<arrow::Table>> extractTablesFromFiltered(std::vector<Filtered<T>>& tables)
4130 {
4131 std::vector<std::shared_ptr<arrow::Table>> outTables;
4132 for (auto& table : tables) {
4133 outTables.push_back(table.asArrowTable());
4134 }
4135 return outTables;
4136 }
4137};
4138
4144template <typename L, typename D, typename O, typename Key, typename H, typename... Ts>
4145struct IndexTable : Table<L, D, O> {
4146 using self_t = IndexTable<L, D, O, Key, H, Ts...>;
4151 using first_t = typename H::binding_t;
4152 using rest_t = framework::pack<typename Ts::binding_t...>;
4153
4154 IndexTable(std::shared_ptr<arrow::Table> table, uint64_t offset = 0)
4155 : base_t{table, offset}
4156 {
4157 }
4158
4159 IndexTable(std::vector<std::shared_ptr<arrow::Table>> tables, uint64_t offset = 0)
4160 : base_t{tables[0], offset}
4161 {
4162 }
4163
4164 IndexTable(IndexTable const&) = default;
4166 IndexTable& operator=(IndexTable const&) = default;
4168
4173};
4174
4175template <typename T, bool APPLY>
4176struct SmallGroupsBase : public Filtered<T> {
4177 static constexpr bool applyFilters = APPLY;
4178 SmallGroupsBase(std::vector<std::shared_ptr<arrow::Table>>&& tables, gandiva::Selection const& selection, uint64_t offset = 0)
4179 : Filtered<T>(std::move(tables), selection, offset) {}
4180
4181 SmallGroupsBase(std::vector<std::shared_ptr<arrow::Table>>&& tables, SelectionVector&& selection, uint64_t offset = 0)
4182 : Filtered<T>(std::move(tables), std::forward<SelectionVector>(selection), offset) {}
4183
4184 SmallGroupsBase(std::vector<std::shared_ptr<arrow::Table>>&& tables, std::span<int64_t const> const& selection, uint64_t offset = 0)
4185 : Filtered<T>(std::move(tables), selection, offset) {}
4186};
4187
4188template <typename T>
4190
4191template <typename T>
4193
4194template <typename T>
4195concept is_smallgroups = requires {
4196 []<typename B, bool A>(SmallGroupsBase<B, A>*) {}(std::declval<T*>());
4197};
4198} // namespace o2::soa
4199
4200#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:2599
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:3779
auto sliceByCachedUnsorted(framework::expressions::BindingNode const &node, int value, o2::framework::SliceCache &cache) const
Definition ASoA.h:3706
int64_t tableSize() const
Definition ASoA.h:3629
FilteredBase(std::vector< std::shared_ptr< arrow::Table > > &&tables, gandiva::Selection const &selection, uint64_t offset=0)
Definition ASoA.h:3552
auto & cached_begin()
Definition ASoA.h:3609
typename T::external_index_columns_t external_index_columns_t
Definition ASoA.h:3546
auto select(framework::expressions::Filter const &f) const
Definition ASoA.h:3723
static auto getSpan(gandiva::Selection const &sel)
Definition ASoA.h:3652
int64_t size() const
Definition ASoA.h:3624
T::template iterator_template_o< FilteredIndexPolicy, self_t > iterator
Definition ASoA.h:3548
auto rawSliceBy(o2::framework::Preslice< T1 > const &container, int value) const
Definition ASoA.h:3696
T::template iterator_template_o< DefaultIndexPolicy, self_t > unfiltered_iterator
Definition ASoA.h:3549
void copyIndexBindings(T1 &dest) const
Definition ASoA.h:3690
auto const & getSelectedRows() const
Definition ASoA.h:3634
void sumWithSelection(std::span< int64_t const > const &selection)
Definition ASoA.h:3759
void intersectWithSelection(std::span< int64_t const > const &selection)
Definition ASoA.h:3769
typename T::columns_t columns_t
Definition ASoA.h:3544
auto emptySlice() const
Definition ASoA.h:3647
void bindExternalIndices(TA *... current)
Definition ASoA.h:3666
void sumWithSelection(SelectionVector const &selection)
Definition ASoA.h:3739
void bindInternalIndicesTo(I const *ptr)
Definition ASoA.h:3678
void intersectWithSelection(SelectionVector const &selection)
Definition ASoA.h:3749
auto sliceBy(o2::framework::PresliceBase< T1, framework::PreslicePolicyGeneral, OPT > const &container, int value) const
Definition ASoA.h:3718
FilteredBase(std::vector< std::shared_ptr< arrow::Table > > &&tables, std::span< int64_t const > const &selection, uint64_t offset=0)
Definition ASoA.h:3576
auto rawSlice(uint64_t start, uint64_t end) const
Definition ASoA.h:3639
auto sliceBy(o2::framework::PresliceBase< T1, framework::PreslicePolicySorted, OPT > const &container, int value) const
Definition ASoA.h:3712
iterator iteratorAt(uint64_t i) const
Definition ASoA.h:3619
iterator const_iterator
Definition ASoA.h:3550
typename T::table_t table_t
Definition ASoA.h:3542
typename T::persistent_columns_t persistent_columns_t
Definition ASoA.h:3545
RowViewSentinel end() const
Definition ASoA.h:3604
FilteredBase(std::vector< std::shared_ptr< arrow::Table > > &&tables, SelectionVector &&selection, uint64_t offset=0)
Definition ASoA.h:3563
void bindExternalIndicesRaw(std::vector< o2::soa::Binding > &&ptrs)
Definition ASoA.h:3672
const_iterator begin() const
Definition ASoA.h:3592
unfiltered_iterator rawIteratorAt(uint64_t i) const
Definition ASoA.h:3597
int isInSelectedRows(int i) const
Definition ASoA.h:3730
auto sliceByCached(framework::expressions::BindingNode const &node, int value, o2::framework::SliceCache &cache) const
Definition ASoA.h:3701
void doCopyIndexBindings(framework::pack< Cs... >, T1 &dest) const
Definition ASoA.h:3684
iterator begin()
Definition ASoA.h:3587
auto const & cached_begin() const
Definition ASoA.h:3614
auto sliceBy(o2::framework::PresliceBase< T1, framework::PreslicePolicySorted, OPT > const &container, int value) const
Definition ASoA.h:4117
Filtered< Filtered< T > > operator*(std::span< int64_t const > const &selection)
Definition ASoA.h:4057
typename FilteredBase< typename T::table_t >::table_t table_t
Definition ASoA.h:3973
typename T::template iterator_template_o< DefaultIndexPolicy, self_t > unfiltered_iterator
Definition ASoA.h:3977
Filtered< Filtered< T > > operator+(SelectionVector const &selection)
Definition ASoA.h:4014
auto sliceBy(o2::framework::PresliceBase< T1, framework::PreslicePolicyGeneral, OPT > const &container, int value) const
Definition ASoA.h:4123
Filtered< Filtered< T > > operator+=(std::span< int64_t const > const &selection)
Definition ASoA.h:4039
typename T::template iterator_template_o< FilteredIndexPolicy, self_t > iterator
Definition ASoA.h:3976
typename T::columns_t columns_t
Definition ASoA.h:3974
const_iterator begin() const
Definition ASoA.h:3985
Filtered(std::vector< Filtered< T > > &&tables, std::span< int64_t const > const &selection, uint64_t offset=0)
Definition ASoA.h:4006
Filtered< Filtered< T > > operator+(std::span< int64_t const > const &selection)
Definition ASoA.h:4021
Filtered(std::vector< Filtered< T > > &&tables, SelectionVector &&selection, uint64_t offset=0)
Definition ASoA.h:3998
unfiltered_iterator rawIteratorAt(uint64_t i) const
Definition ASoA.h:4086
Filtered< Filtered< T > > operator*=(std::span< int64_t const > const &selection)
Definition ASoA.h:4075
Filtered< Filtered< T > > operator+=(Filtered< T > const &other)
Definition ASoA.h:4045
Filtered< Filtered< T > > operator+=(SelectionVector const &selection)
Definition ASoA.h:4033
Filtered< Filtered< T > > operator*=(SelectionVector const &selection)
Definition ASoA.h:4069
auto rawSlice(uint64_t start, uint64_t end) const
Definition ASoA.h:4093
Filtered< Filtered< T > > operator+(Filtered< T > const &other)
Definition ASoA.h:4028
Filtered(std::vector< Filtered< T > > &&tables, gandiva::Selection const &selection, uint64_t offset=0)
Definition ASoA.h:3990
Filtered< Filtered< T > > operator*=(Filtered< T > const &other)
Definition ASoA.h:4081
auto sliceByCached(framework::expressions::BindingNode const &node, int value, o2::framework::SliceCache &cache) const
Definition ASoA.h:4106
Filtered< Filtered< T > > operator*(Filtered< T > const &other)
Definition ASoA.h:4064
Filtered< Filtered< T > > operator*(SelectionVector const &selection)
Definition ASoA.h:4050
auto sliceByCachedUnsorted(framework::expressions::BindingNode const &node, int value, o2::framework::SliceCache &cache) const
Definition ASoA.h:4111
Filtered< T > operator*(std::span< int64_t const > const &selection)
Definition ASoA.h:3880
Filtered< T > operator+=(Filtered< T > const &other)
Definition ASoA.h:3868
auto sliceBy(o2::framework::PresliceBase< T1, framework::PreslicePolicyGeneral, OPT > const &container, int value) const
Definition ASoA.h:3954
Filtered(std::vector< std::shared_ptr< arrow::Table > > &&tables, SelectionVector &&selection, uint64_t offset=0)
Definition ASoA.h:3831
iterator const_iterator
Definition ASoA.h:3816
Filtered< T > operator+(std::span< int64_t const > const &selection)
Definition ASoA.h:3844
iterator begin()
Definition ASoA.h:3818
auto sliceByCachedUnsorted(framework::expressions::BindingNode const &node, int value, o2::framework::SliceCache &cache) const
Definition ASoA.h:3942
Filtered< T > operator+(Filtered< T > const &other)
Definition ASoA.h:3851
Filtered< T > operator*=(SelectionVector const &selection)
Definition ASoA.h:3892
Filtered(std::vector< std::shared_ptr< arrow::Table > > &&tables, std::span< int64_t const > const &selection, uint64_t offset=0)
Definition ASoA.h:3834
auto emptySlice() const
Definition ASoA.h:3926
const_iterator begin() const
Definition ASoA.h:3823
T::template iterator_template_o< FilteredIndexPolicy, self_t > iterator
Definition ASoA.h:3814
auto sliceByCached(framework::expressions::BindingNode const &node, int value, o2::framework::SliceCache &cache) const
Definition ASoA.h:3937
auto select(framework::expressions::Filter const &f) const
Definition ASoA.h:3959
Filtered< T > operator+(SelectionVector const &selection)
Definition ASoA.h:3837
T::template iterator_template_o< DefaultIndexPolicy, self_t > unfiltered_iterator
Definition ASoA.h:3815
unfiltered_iterator rawIteratorAt(uint64_t i) const
Definition ASoA.h:3909
Filtered< T > operator*(SelectionVector const &selection)
Definition ASoA.h:3873
Filtered< T > operator*=(Filtered< T > const &other)
Definition ASoA.h:3904
Filtered< T > operator*(Filtered< T > const &other)
Definition ASoA.h:3887
auto rawSliceBy(o2::framework::Preslice< T1 > const &container, int value) const
Definition ASoA.h:3932
Filtered< T > operator+=(SelectionVector const &selection)
Definition ASoA.h:3856
auto rawSlice(uint64_t start, uint64_t end) const
Definition ASoA.h:3918
Filtered(std::vector< std::shared_ptr< arrow::Table > > &&tables, gandiva::Selection const &selection, uint64_t offset=0)
Definition ASoA.h:3828
auto sliceBy(o2::framework::PresliceBase< T1, framework::PreslicePolicySorted, OPT > const &container, int value) const
Definition ASoA.h:3948
Filtered< T > operator*=(std::span< int64_t const > const &selection)
Definition ASoA.h:3898
Filtered< T > operator+=(std::span< int64_t const > const &selection)
Definition ASoA.h:3862
typename T::table_t table_t
Definition ASoA.h:3811
typename T::columns_t columns_t
Definition ASoA.h:3812
decltype([]< typename... C >(framework::pack< C... > &&) -> framework::selected_pack< soa::is_self_index_t, C... > {}(columns_t{})) internal_index_columns_t
Definition ASoA.h:1860
void bindInternalIndicesExplicit(o2::soa::Binding binding)
Definition ASoA.h:2187
auto & cached_begin()
Definition ASoA.h:2101
iterator iteratorAt(uint64_t i) const
Definition ASoA.h:2130
decltype([]< typename... C >(framework::pack< C... > &&) -> framework::selected_pack< soa::is_persistent_column_t, C... > {}(columns_t{})) persistent_columns_t
Definition ASoA.h:1856
static constexpr const auto ref
Definition ASoA.h:1817
auto offset() const
Return offset.
Definition ASoA.h:2158
static consteval bool hasOriginal()
Definition ASoA.h:1849
unfiltered_iterator begin()
Definition ASoA.h:2111
int64_t tableSize() const
Definition ASoA.h:2168
auto rawSlice(uint64_t start, uint64_t end) const
Definition ASoA.h:2238
void bindExternalIndices(TA *... current)
Definition ASoA.h:2176
auto select(framework::expressions::Filter const &f) const
Definition ASoA.h:2215
unfiltered_iterator unfiltered_const_iterator
Definition ASoA.h:2042
static consteval auto full_iter()
Definition ASoA.h:2021
auto const & cached_begin() const
Definition ASoA.h:2106
auto emptySlice() const
Definition ASoA.h:2243
auto sliceByCachedUnsorted(framework::expressions::BindingNode const &node, int value, o2::framework::SliceCache &cache) const
Definition ASoA.h:2227
void bindExternalIndicesRaw(std::vector< o2::soa::Binding > &&ptrs)
Definition ASoA.h:2198
auto sliceBy(o2::framework::PresliceBase< T1, Policy, OPT > const &container, int value) const
Definition ASoA.h:2233
static constexpr auto hashes()
Definition ASoA.h:2044
iterator unfiltered_iterator
Definition ASoA.h:2040
std::shared_ptr< arrow::Table > asArrowTable() const
Return a type erased arrow table backing store for / the type safe table.
Definition ASoA.h:2153
filtered_iterator filtered_begin(std::span< int64_t const > selection)
Definition ASoA.h:2121
void doCopyIndexBindings(framework::pack< Cs... >, T &dest) const
Definition ASoA.h:2204
int64_t size() const
Size of the table, in rows.
Definition ASoA.h:2163
Table(std::vector< std::shared_ptr< arrow::Table > > &&tables, uint64_t offset=0)
Definition ASoA.h:2075
decltype(getColumns< ref, Ts... >()) columns_t
Definition ASoA.h:1854
arrow::ChunkedArray * getIndexToKey()
Definition ASoA.h:2082
RowViewSentinel end()
Definition ASoA.h:2116
decltype([]< typename... C >(framework::pack< C... >) -> framework::pack< typename C::type... > {}(persistent_columns_t{})) column_types
Definition ASoA.h:1857
static consteval auto isIndexTargetOf()
Definition ASoA.h:1826
iterator_template_o< FilteredIndexPolicy, table_t > filtered_iterator
Definition ASoA.h:2038
unfiltered_const_iterator begin() const
Definition ASoA.h:2142
void copyIndexBindings(T &dest) const
Definition ASoA.h:2210
static constexpr const auto originalLabels
Definition ASoA.h:1822
Table(std::vector< std::shared_ptr< arrow::Table > > &&tables, uint64_t offset=0)
Definition ASoA.h:2069
Table< L, D, O, Ts... > self_t
Definition ASoA.h:1818
static consteval auto isIndexTargetOf()
Definition ASoA.h:1833
decltype(full_iter< IP, Parent >()) iterator_template_o
Definition ASoA.h:2035
void doBindInternalIndicesExplicit(framework::pack< Cs... >, o2::soa::Binding binding)
Definition ASoA.h:2193
static constexpr const auto originals
Definition ASoA.h:1821
decltype([]< typename... C >(framework::pack< C... > &&) -> framework::selected_pack< soa::is_external_index_t, C... > {}(columns_t{})) external_index_columns_t
Definition ASoA.h:1859
Table(std::shared_ptr< arrow::Table > table, uint64_t offset=0)
Definition ASoA.h:2049
RowViewSentinel end() const
Definition ASoA.h:2147
auto sliceByCached(framework::expressions::BindingNode const &node, int value, o2::framework::SliceCache &cache) const
Definition ASoA.h:2222
void bindInternalIndicesTo(I const *ptr)
Definition ASoA.h:2182
unfiltered_iterator rawIteratorAt(uint64_t i) const
Definition ASoA.h:2135
iterator_template_o< DefaultIndexPolicy, table_t > iterator
Definition ASoA.h:2037
hash identification concepts
Definition ASoA.h:387
Helper to check if a type T is an iterator.
Definition ASoA.h:1293
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:277
typename pack_element< 0, T >::type pack_head_t
Definition Pack.h:59
std::string cutString(std::string &&str)
Definition ASoA.cxx:268
std::vector< std::vector< int64_t > > ListVector
Descriptor< gSizeDataDescriptionString > DataDescription
Definition DataHeader.h:551
R getColumnValue(const T &rowIterator)
Definition ASoA.h:2276
ColumnGetterFunction< R, typename T::iterator > getColumnGetterByLabel(const std::string_view &targetColumnLabel)
Definition ASoA.h:2343
void * extractCCDBPayload(char *payload, size_t size, TClass const *cl, const char *what)
Definition ASoA.cxx:208
consteval auto computeOriginals()
Definition ASoA.h:1799
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:3488
auto doSliceBy(T const *table, o2::framework::PresliceBase< C, Policy, OPT > const &container, int value)
Definition ASoA.h:1627
void notBoundTable(const char *tableName)
Definition ASoA.cxx:193
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:1703
constexpr auto concat(Ts const &... t)
Definition ASoA.h:3532
consteval auto intersectOriginals()
Definition ASoA.h:171
consteval auto getColumns()
Definition ASoA.h:1771
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:1345
consteval auto mergeOriginals()
Definition ASoA.h:154
constexpr bool is_soa_filtered_v
Definition ASoA.h:1608
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:1737
auto doSliceByCached(T const *table, framework::expressions::BindingNode const &node, int value, o2::framework::SliceCache &cache)
Definition ASoA.h:1716
void accessingInvalidIndexFor(const char *getter)
Definition ASoA.cxx:25
auto select(T const &t, framework::expressions::Filter const &f)
Definition ASoA.h:1757
consteval auto base_iter(framework::pack< C... > &&) -> TableIterator< D, O, IP, C... >
Definition ASoA.h:1765
constexpr bool is_index_equivalent_v
Definition ASoA.h:463
constexpr bool is_soa_join_v
Definition ASoA.h:3497
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:1339
auto prepareFilteredSlice(T const *table, std::shared_ptr< arrow::Table > slice, uint64_t offset)
Definition ASoA.h:1684
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:1728
void missingOptionalPreslice(const char *label, const char *key)
Definition ASoA.cxx:203
auto doSliceByHelper(T const *table, std::span< const int64_t > const &selection)
Definition ASoA.h:1645
consteval bool is_compatible()
Definition ASoA.h:1326
arrow::ChunkedArray * getIndexFromLabel(arrow::Table *table, std::string_view label)
Definition ASoA.cxx:172
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:198
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:1533
static constexpr bool optional
Definition ASoA.h:1523
PresliceBase(expressions::BindingNode index_)
Definition ASoA.h:1528
std::span< const int64_t > getSliceFor(int value) const
Definition ASoA.h:1543
const std::string binding
Definition ASoA.h:1526
const std::string binding
Definition ASoA.h:1497
Entry const & getBindingKey() const
Definition ASoA.cxx:288
SliceInfoUnsortedPtr sliceInfo
Definition ASoA.h:1514
std::span< const int64_t > getSliceFor(int value) const
Definition ASoA.cxx:311
void updateSliceInfo(SliceInfoUnsortedPtr &&si)
Definition ASoA.cxx:298
void updateSliceInfo(SliceInfoPtr &&si)
Definition ASoA.cxx:293
std::shared_ptr< arrow::Table > getSliceFor(int value, std::shared_ptr< arrow::Table > const &input, uint64_t &offset) const
Definition ASoA.cxx:303
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, std::span< const char *const > labels)
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:3523
Concat(Ts const &... t, uint64_t offset=0)
Definition ASoA.h:3508
typename table_t::persistent_columns_t persistent_columns_t
Definition ASoA.h:3521
typename table_t::columns_t columns_t
Definition ASoA.h:3520
iterator const_iterator
Definition ASoA.h:3524
const_iterator unfiltered_const_iterator
Definition ASoA.h:3526
iterator unfiltered_iterator
Definition ASoA.h:3525
table_t::template iterator_template< FilteredIndexPolicy, self_t, Ts... > filtered_iterator
Definition ASoA.h:3527
Concat(std::vector< std::shared_ptr< arrow::Table > > &&tables, uint64_t offset=0)
Definition ASoA.h:3503
filtered_iterator filtered_const_iterator
Definition ASoA.h:3528
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:4159
IndexTable(std::shared_ptr< arrow::Table > table, uint64_t offset=0)
Definition ASoA.h:4154
typename base_t::template iterator_template_o< DefaultIndexPolicy, self_t > iterator
Definition ASoA.h:4169
filtered_iterator const_filtered_iterator
Definition ASoA.h:4172
IndexTable(IndexTable &&)=default
IndexTable & operator=(IndexTable const &)=default
iterator const_iterator
Definition ASoA.h:4170
IndexTable & operator=(IndexTable &&)=default
typename H::binding_t first_t
Definition ASoA.h:4151
typename base_t::template iterator_template_o< FilteredIndexPolicy, self_t > filtered_iterator
Definition ASoA.h:4171
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:3429
iterator unfiltered_iterator
Definition ASoA.h:3424
auto sliceBy(o2::framework::PresliceBase< T1, Policy, OPT > const &container, int value) const
Definition ASoA.h:3450
auto rawSlice(uint64_t start, uint64_t end) const
Definition ASoA.h:3467
auto sliceByCachedUnsorted(framework::expressions::BindingNode const &node, int value, o2::framework::SliceCache &cache) const
Definition ASoA.h:3444
JoinFull(std::vector< std::shared_ptr< arrow::Table > > &&tables, uint64_t offset=0)
Definition ASoA.h:3406
static constexpr const auto originalLabels
Definition ASoA.h:3419
const_iterator unfiltered_const_iterator
Definition ASoA.h:3425
filtered_iterator filtered_const_iterator
Definition ASoA.h:3427
static consteval bool contains()
Definition ASoA.h:3478
iterator iteratorAt(uint64_t i) const
Definition ASoA.h:3462
typename table_t::columns_t columns_t
Definition ASoA.h:3420
table_t::template iterator_template< DefaultIndexPolicy, self_t, Ts... > iterator
Definition ASoA.h:3422
table_t::template iterator_template< FilteredIndexPolicy, self_t, Ts... > filtered_iterator
Definition ASoA.h:3426
static constexpr const auto originals
Definition ASoA.h:3418
JoinFull< D, Ts... > self_t
Definition ASoA.h:3416
const_iterator begin() const
Definition ASoA.h:3434
typename table_t::persistent_columns_t persistent_columns_t
Definition ASoA.h:3421
iterator const_iterator
Definition ASoA.h:3423
iterator rawIteratorAt(uint64_t i) const
Definition ASoA.h:3455
Table< o2::aod::Hash<"JOIN"_h >, D, o2::aod::Hash<"JOIN"_h >, Ts... > base
Definition ASoA.h:3397
JoinFull(std::shared_ptr< arrow::Table > &&table, uint64_t offset=0)
Definition ASoA.h:3399
auto emptySlice() const
Definition ASoA.h:3472
auto sliceByCached(framework::expressions::BindingNode const &node, int value, o2::framework::SliceCache &cache) const
Definition ASoA.h:3439
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:4181
SmallGroupsBase(std::vector< std::shared_ptr< arrow::Table > > &&tables, std::span< int64_t const > const &selection, uint64_t offset=0)
Definition ASoA.h:4184
SmallGroupsBase(std::vector< std::shared_ptr< arrow::Table > > &&tables, gandiva::Selection const &selection, uint64_t offset=0)
Definition ASoA.h:4178
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:2011
TableIteratorBase(TableIteratorBase< IP, P, T... > const &other)
Definition ASoA.h:1919
typename Parent::columns_t columns_t
Definition ASoA.h:1866
TableIteratorBase(TableIteratorBase< IP, P, O1, Os... > const &other)
Definition ASoA.h:1905
typename Parent::external_index_columns_t external_index_columns_t
Definition ASoA.h:1867
TableIteratorBase operator-(int64_t dec) const
Definition ASoA.h:2006
void matchTo(TableIteratorBase< IP, P, T... > const &other)
Definition ASoA.h:1943
void matchTo(TableIteratorBase< IP, P, Os... > const &other)
Definition ASoA.h:1949
TableIteratorBase(TableIteratorBase< FilteredIndexPolicy, P, T... > other)
Definition ASoA.h:1931
std::array< B, sizeof...(CCs)> getValues() const
Definition ASoA.h:1988
static constexpr auto originals
Definition ASoA.h:1870
TableIteratorBase(TableIteratorBase< IP, P, T... > &&other) noexcept
Definition ASoA.h:1925
decltype([]< typename... C >(framework::pack< C... >) -> framework::pack< typename C::binding_t... > {}(external_index_columns_t{})) bindings_pack_t
Definition ASoA.h:1868
TableIteratorBase & operator=(TableIteratorBase< IP, P, Os... > other)
Definition ASoA.h:1882
TableIteratorBase(TableIteratorBase< IP, P, O1, Os... > &&other) noexcept
Definition ASoA.h:1912
TableIteratorBase & operator=(RowViewSentinel const &other)
Definition ASoA.h:1937
TableIteratorBase(arrow::ChunkedArray *columnData[framework::pack_size(columns_t{})], IP &&policy)
Definition ASoA.h:1876
TableIteratorBase & operator=(TableIteratorBase< IP, P, T... > other)
Definition ASoA.h:1890
TableIteratorBase operator+(int64_t inc) const
Allow incrementing by more than one the iterator.
Definition ASoA.h:1999
TableIteratorBase & operator=(TableIteratorBase< FilteredIndexPolicy, P, T... > other)
Definition ASoA.h:1897
unwrapper
Definition ASoA.h:483
VectorOfTObjectPtrs other
std::vector< ReadoutWindowData > rows
const std::string str