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