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