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