diff --git a/Framework/Core/include/Framework/ASoA.h b/Framework/Core/include/Framework/ASoA.h index f21decd0d5c45..e7fc8fddd5a9d 100644 --- a/Framework/Core/include/Framework/ASoA.h +++ b/Framework/Core/include/Framework/ASoA.h @@ -213,8 +213,6 @@ template struct TableMetadata { using columns = framework::pack; using persistent_columns_t = framework::selected_pack; - using external_index_columns_t = framework::selected_pack; - using internal_index_columns_t = framework::selected_pack; template static consteval std::array getMap(framework::pack) @@ -811,9 +809,6 @@ concept is_dynamic_column = requires(C& c) { template concept is_marker_column = requires { &C::mark; }; -template -using is_dynamic_t = std::conditional_t, std::true_type, std::false_type>; - template concept is_column = is_persistent_column || is_dynamic_column || is_indexing_column || is_marker_column; @@ -1036,6 +1031,23 @@ concept can_bind = requires(T&& t) { template concept has_index = (is_indexing_column || ...); +template + requires(!is_self_index_column) +consteval auto getBinding() -> typename C::binding_t +{ +} + +template +consteval auto getBinding() -> void +{ +} + +template +consteval auto inBindings(framework::pack) +{ + return framework::has_type_at_v(framework::pack())...>{}); +} + template struct TableIterator : IP, C... { public: @@ -1043,13 +1055,10 @@ struct TableIterator : IP, C... { using policy_t = IP; using all_columns = framework::pack; using persistent_columns_t = framework::selected_pack; - using external_index_columns_t = framework::selected_pack; - using internal_index_columns_t = framework::selected_pack; - using bindings_pack_t = decltype([](framework::pack) -> framework::pack {}(external_index_columns_t{})); // decltype(extractBindings(external_index_columns_t{})); TableIterator(arrow::ChunkedArray* columnData[sizeof...(C)], IP&& policy) : IP{policy}, - C(columnData[framework::has_type_at_v(all_columns{})])... + C(columnData[framework::has_type_at_v(framework::pack{})])... { bind(); } @@ -1057,7 +1066,7 @@ struct TableIterator : IP, C... { TableIterator(arrow::ChunkedArray* columnData[sizeof...(C)], IP&& policy) requires(has_index) : IP{policy}, - C(columnData[framework::has_type_at_v(all_columns{})])... + C(columnData[framework::has_type_at_v(framework::pack{})])... { bind(); // In case we have an index column might need to constrain the actual @@ -1135,61 +1144,114 @@ struct TableIterator : IP, C... { return *this; } - template - void doSetCurrentIndex(framework::pack, TA* current) - { - (CL::setCurrent(current), ...); - } - template auto getCurrent() const { return CL::getCurrentRaw(); } - template - auto getIndexBindingsImpl(framework::pack) const - { - return std::vector{static_cast(*this).getCurrentRaw()...}; - } - auto getIndexBindings() const { - return getIndexBindingsImpl(external_index_columns_t{}); + std::vector result; + (doGetIndexBindingImpl(result), ...); + return result; } template void bindExternalIndices(TA*... current) { - (doSetCurrentIndex(external_index_columns_t{}, current), ...); + ([this](framework::pack, TT* t) { + (doSetCurrentIndexImpl(t), ...); + }(framework::pack{}, current), + ...); } - template - void doSetCurrentIndexRaw(framework::pack p, std::vector&& ptrs) + void bindExternalIndicesRaw(std::vector&& bindings) { - (Cs::setCurrentRaw(ptrs[framework::has_type_at_v(p)]), ...); + (doSetCurrentIndexRawImpl(bindings[framework::has_type_at_v(framework::pack{})]), ...); } - template - void doSetCurrentInternal(framework::pack, I const* ptr) + template + void bindInternalIndices(I const* table) { o2::soa::Binding b; - b.bind(ptr); - (Cs::setCurrentRaw(b), ...); + b.bind(table); + (doSetCurrentInternalImpl(b), ...); } - void bindExternalIndicesRaw(std::vector&& ptrs) + private: + /// Overloaded helpers for index manipulations + template + requires(!soa::is_self_index_column) + void doSetCurrentIndexImpl(TA* current) { - doSetCurrentIndexRaw(external_index_columns_t{}, std::forward>(ptrs)); + CL::setCurrent(current); } - template - void bindInternalIndices(I const* table) + template + requires(!soa::is_index_column) + void doSetCurrentIndexImpl(TA*) + { + } + + template + requires(!soa::is_self_index_column) + auto doGetIndexBindingImpl(std::vector& bindings) const + { + bindings.emplace_back(CL::getCurrentRaw()); + } + + template + requires(!soa::is_index_column) + auto doGetIndexBindingImpl(std::vector& bindings) const + { + bindings.emplace_back(); + } + + template + requires(!soa::is_self_index_column) + void doSetCurrentIndexRawImpl(o2::soa::Binding const& b) + { + CL::setCurrentRaw(b); + } + + template + requires(!soa::is_index_column) + void doSetCurrentIndexRawImpl(o2::soa::Binding const&) + { + } + + template + void doSetCurrentInternalImpl(o2::soa::Binding const& b) + { + CL::setCurrentRaw(b); + } + + template + requires(!soa::is_self_index_column) + void doSetCurrentInternalImpl(o2::soa::Binding const&) + { + } + + /// Overloaded helpers for column binding + template + void doBind() + { + CL::mColumnIterator.mCurrentPos = &this->mRowIndex; + } + + template + void doBind() + { + bindDynamicColumn(typename CL::bindings_t{}); + } + + template + requires(!soa::is_persistent_column && !soa::is_dynamic_column) + void doBind() { - doSetCurrentInternal(internal_index_columns_t{}, table); } - private: /// Helper to move at the end of columns which actually have an iterator. template void doMoveToEnd(framework::pack) @@ -1202,12 +1264,7 @@ struct TableIterator : IP, C... { void bind() { using namespace o2::soa; - auto f = framework::overloaded{ - [this](T*) -> void { T::mColumnIterator.mCurrentPos = &this->mRowIndex; }, - [this](T*) -> void { bindDynamicColumn(typename T::bindings_t{}); }, - [this](T*) -> void {}, - }; - (f(static_cast(nullptr)), ...); + (doBind(), ...); if constexpr (has_index) { this->setIndices(this->getIndices()); this->setOffsets(this->getOffsets()); @@ -1367,28 +1424,56 @@ static constexpr std::string getLabelFromTypeForKey(std::string const& key) O2_BUILTIN_UNREACHABLE(); } +template + requires(!soa::is_self_index_column) +consteval static bool hasIndexToImpl() +{ + return o2::soa::is_binding_compatible_v(); +} + +template + requires(!soa::is_index_column) +consteval static bool hasIndexToImpl() +{ + return false; +} + template consteval static bool hasIndexTo(framework::pack&&) { - return (o2::soa::is_binding_compatible_v() || ...); + return (hasIndexToImpl() || ...); +} + +template + requires(!soa::is_self_index_column) +consteval static bool hasSortedIndexToImpl() +{ + return CL::sorted && o2::soa::is_binding_compatible_v(); +} + +template + requires(!soa::is_index_column) +consteval static bool hasSortedIndexToImpl() +{ + return false; } template consteval static bool hasSortedIndexTo(framework::pack&&) { - return ((C::sorted && o2::soa::is_binding_compatible_v()) || ...); + return (hasSortedIndexToImpl() || ...); } template consteval static bool relatedByIndex() { - return hasIndexTo(typename Z::table_t::external_index_columns_t{}); + return hasIndexTo(typename Z::table_t::columns_t{}); } template consteval static bool relatedBySortedIndex() { - return hasSortedIndexTo(typename Z::table_t::external_index_columns_t{}); + return hasSortedIndexTo(typename Z::table_t::columns_t{}); } } // namespace o2::soa @@ -1716,17 +1801,12 @@ class Table using persistent_columns_t = decltype([](framework::pack&&) -> framework::selected_pack {}(columns_t{})); using column_types = decltype([](framework::pack) -> framework::pack {}(persistent_columns_t{})); - using external_index_columns_t = decltype([](framework::pack&&) -> framework::selected_pack {}(columns_t{})); - using internal_index_columns_t = decltype([](framework::pack&&) -> framework::selected_pack {}(columns_t{})); template using base_iterator = decltype(base_iter(columns_t{})); template struct TableIteratorBase : base_iterator { using columns_t = typename Parent::columns_t; - using external_index_columns_t = typename Parent::external_index_columns_t; - using bindings_pack_t = decltype([](framework::pack) -> framework::pack {}(external_index_columns_t{})); - // static constexpr const std::array originals{T::ref...}; static constexpr auto originals = Parent::originals; using policy_t = IP; using parent_t = Parent; @@ -1815,33 +1895,34 @@ class Table template auto getId() const { - using decayed = std::decay_t; - if constexpr (framework::has_type(bindings_pack_t{})) { // index to another table - constexpr auto idx = framework::has_type_at_v(bindings_pack_t{}); - return framework::pack_element_t::getId(); - } else if constexpr (std::same_as) { // self index - return this->globalIndex(); - } else if constexpr (is_indexing_column) { // soa::Index<> - return this->globalIndex(); - } else { - return static_cast(-1); - } + return static_cast(-1); } - template + template + requires(std::same_as, Parent> || is_indexing_column>) + auto getId() const + { + return this->globalIndex(); + } + + template + requires(inBindings>(typename Parent::all_columns{}) < framework::pack_size(typename Parent::all_columns{})) + auto getId() const + { + return inBindings>(typename Parent::all_columns{}); + } + + template auto getDynamicColumn() const { - using decayed = std::decay_t; - static_assert(is_dynamic_t(), "Requested column is not a dynamic column"); - return static_cast(*this).template getDynamicValue(); + return static_cast>(*this).template getDynamicValue(); } template + requires(is_dynamic_column || is_persistent_column) auto getValue() const { - using COL = std::decay_t; - static_assert(is_dynamic_t() || soa::is_persistent_column, "Should be persistent or dynamic column with no argument that has a return type convertable to float"); - return static_cast(static_cast(*this).get()); + return static_cast(static_cast>(*this).get()); } template @@ -2046,13 +2127,25 @@ class Table void bindInternalIndicesExplicit(o2::soa::Binding binding) { - doBindInternalIndicesExplicit(internal_index_columns_t{}, binding); + doBindInternalIndicesExplicit(columns_t{}, binding); + } + + template + void doBindInternalIndicesExplicitImpl(o2::soa::Binding binding) + { + static_cast(mBegin).setCurrentRaw(binding); + } + + template + requires(!soa::is_self_index_column) + void doBindInternalIndicesExplicitImpl(o2::soa::Binding) + { } template void doBindInternalIndicesExplicit(framework::pack, o2::soa::Binding binding) { - (static_cast(mBegin).setCurrentRaw(binding), ...); + (doBindInternalIndicesExplicitImpl(binding), ...); } void bindExternalIndicesRaw(std::vector&& ptrs) @@ -2069,7 +2162,7 @@ class Table template void copyIndexBindings(T& dest) const { - doCopyIndexBindings(external_index_columns_t{}, dest); + doCopyIndexBindings(columns_t{}, dest); } auto select(framework::expressions::Filter const& f) const @@ -3288,7 +3381,6 @@ class FilteredBase : public T using T::originals; using columns_t = typename T::columns_t; using persistent_columns_t = typename T::persistent_columns_t; - using external_index_columns_t = typename T::external_index_columns_t; using iterator = T::template iterator_template_o; using unfiltered_iterator = T::template iterator_template_o; @@ -3434,7 +3526,7 @@ class FilteredBase : public T template void copyIndexBindings(T1& dest) const { - doCopyIndexBindings(external_index_columns_t{}, dest); + doCopyIndexBindings(columns_t{}, dest); } template diff --git a/Framework/Core/include/Framework/GroupedCombinations.h b/Framework/Core/include/Framework/GroupedCombinations.h index bdbddee871baa..2f2293593a1cb 100644 --- a/Framework/Core/include/Framework/GroupedCombinations.h +++ b/Framework/Core/include/Framework/GroupedCombinations.h @@ -34,14 +34,34 @@ auto interleaveTuples(std::tuple& t1, std::tuple& t2) return interleaveTuplesImpl(t1, t2, std::index_sequence_for()); } +template + requires(!soa::is_self_index_column && o2::soa::is_binding_compatible_v, typename std::decay_t::binding_t>()) +consteval auto isIndexTo() +{ + return std::true_type{}; +} + +template + requires(!soa::is_self_index_column && !o2::soa::is_binding_compatible_v, typename std::decay_t::binding_t>()) +consteval auto isIndexTo() +{ + return std::false_type{}; +} + +template + requires(!soa::is_index_column) +consteval auto isIndexTo() +{ + return std::false_type{}; +} + template -using is_index_to_g_t = typename std::conditional(), std::true_type, std::false_type>::type; +using is_index_to_g_t = decltype(isIndexTo()); template expressions::BindingNode getMatchingIndexNode() { - using external_index_columns_pack = typename A::external_index_columns_t; - using selected_indices_t = selected_pack_multicondition, external_index_columns_pack>; + using selected_indices_t = selected_pack_multicondition, typename A::columns_t>; static_assert(pack_size(selected_indices_t{}) == 1, "No matching index column from associated to grouping"); using index_column_t = pack_head_t; return expressions::BindingNode{index_column_t::mLabel, o2::framework::TypeIdHelpers::uniqueId(), expressions::selectArrowType()};