diff --git a/Framework/Core/include/Framework/ASoA.h b/Framework/Core/include/Framework/ASoA.h index 8af872a64176d..fd61ac741ee5c 100644 --- a/Framework/Core/include/Framework/ASoA.h +++ b/Framework/Core/include/Framework/ASoA.h @@ -208,8 +208,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) @@ -806,9 +804,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; @@ -1031,6 +1026,17 @@ 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 struct TableIterator : IP, C... { public: @@ -1038,9 +1044,9 @@ 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{})); + using bindings_pack_t = decltype([](framework::pack) { + return framework::pack())...>{}; + }(all_columns{})); TableIterator(arrow::ChunkedArray* columnData[sizeof...(C)], IP&& policy) : IP{policy}, @@ -1133,7 +1139,7 @@ struct TableIterator : IP, C... { template void doSetCurrentIndex(framework::pack, TA* current) { - (CL::setCurrent(current), ...); + (doSetCurrentIndexImpl(current), ...); } template @@ -1145,24 +1151,26 @@ struct TableIterator : IP, C... { template auto getIndexBindingsImpl(framework::pack) const { - return std::vector{static_cast(*this).getCurrentRaw()...}; + std::vector result; + (doGetIndexBindingImpl(result), ...); + return result; } auto getIndexBindings() const { - return getIndexBindingsImpl(external_index_columns_t{}); + return getIndexBindingsImpl(all_columns{}); } template void bindExternalIndices(TA*... current) { - (doSetCurrentIndex(external_index_columns_t{}, current), ...); + (doSetCurrentIndex(all_columns{}, current), ...); } template - void doSetCurrentIndexRaw(framework::pack p, std::vector&& ptrs) + void doSetCurrentIndexRaw(framework::pack p, std::vector&& bindings) { - (Cs::setCurrentRaw(ptrs[framework::has_type_at_v(p)]), ...); + (doSetCurrentIndexRawImpl(bindings[framework::has_type_at_v(p)]), ...); } template @@ -1170,21 +1178,93 @@ struct TableIterator : IP, C... { { o2::soa::Binding b; b.bind(ptr); - (Cs::setCurrentRaw(b), ...); + (doSetCurrentInternalImpl(b), ...); } - void bindExternalIndicesRaw(std::vector&& ptrs) + void bindExternalIndicesRaw(std::vector&& bindings) { - doSetCurrentIndexRaw(external_index_columns_t{}, std::forward>(ptrs)); + doSetCurrentIndexRaw(all_columns{}, std::forward>(bindings)); } template void bindInternalIndices(I const* table) { - doSetCurrentInternal(internal_index_columns_t{}, table); + doSetCurrentInternal(all_columns{}, table); } private: + /// Overloaded helpers for index manipulations + template + requires(!soa::is_self_index_column) + void doSetCurrentIndexImpl(TA* current) + { + CL::setCurrent(current); + } + + 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() + { + } + /// Helper to move at the end of columns which actually have an iterator. template void doMoveToEnd(framework::pack) @@ -1197,12 +1277,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()); @@ -1362,28 +1437,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 @@ -1726,16 +1829,13 @@ 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{})); + using bindings_pack_t = typename base_iterator::bindings_pack_t; // static constexpr const std::array originals{T::ref...}; static constexpr auto originals = Parent::originals; using policy_t = IP; @@ -1828,7 +1928,7 @@ class Table 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(); + 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<> @@ -1838,20 +1938,17 @@ class Table } } - template + 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 @@ -2056,13 +2153,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) @@ -2079,7 +2188,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 @@ -3298,7 +3407,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; @@ -3444,7 +3552,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/Configurable.h b/Framework/Core/include/Framework/Configurable.h index 88e50cf3c7c26..930c37e700105 100644 --- a/Framework/Core/include/Framework/Configurable.h +++ b/Framework/Core/include/Framework/Configurable.h @@ -83,6 +83,9 @@ struct Configurable : IP { template using MutableConfigurable = Configurable>; +template +concept is_configurable = requires(T& t) { &T::operator typename T::type; }; + using ConfigurableAxis = Configurable, ConfigParamKind::kAxisSpec, ConfigurablePolicyConst, ConfigParamKind::kAxisSpec>>; template @@ -97,7 +100,7 @@ struct ProcessConfigurable : Configurable { }; template -concept is_process_configurable = base_of_template; +concept is_process_configurable = is_configurable && requires(T& t) { t.process; }; #define PROCESS_SWITCH(_Class_, _Name_, _Help_, _Default_) \ decltype(ProcessConfigurable{&_Class_ ::_Name_, #_Name_, _Default_, _Help_}) do##_Name_ = ProcessConfigurable{&_Class_ ::_Name_, #_Name_, _Default_, _Help_}; diff --git a/Framework/Core/include/Framework/GroupedCombinations.h b/Framework/Core/include/Framework/GroupedCombinations.h index 21d8384e3aa6e..c212ae7eaeabe 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()};