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