From 631ae2dba7a09e348ac10dc9f524bdd3e4f639cb Mon Sep 17 00:00:00 2001 From: Maja Kabus Date: Wed, 29 Jun 2022 11:22:54 +0200 Subject: [PATCH 1/6] Improve tests for persistent and index columns --- Framework/Core/include/Framework/ASoA.h | 43 +++++++++++++++++++------ 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/Framework/Core/include/Framework/ASoA.h b/Framework/Core/include/Framework/ASoA.h index 9030cf5fe7eec..542c6a88fb3db 100644 --- a/Framework/Core/include/Framework/ASoA.h +++ b/Framework/Core/include/Framework/ASoA.h @@ -541,8 +541,26 @@ struct Index : o2::soa::IndexColumn> { template using is_dynamic_t = framework::is_specialization; +// template +// using is_persistent_t = typename std::decay_t::persistent::type; + +namespace persistent_type_helper +{ +// This checks both for the existence of the ::persistent member in the class T as well as the value returned stored in it. +// Hack: a pointer to any field of type int inside persistent. Both true_type and false_type do not have any int field, but anyways we pass nullptr. +// The compiler picks the version with exact number of arguments when only it can, i.e., when T::persistent is defined. +template +typename T::persistent test(int T::persistent::*); + +template +std::false_type test(...); +} // namespace persistent_type_helper + template -using is_persistent_t = typename std::decay_t::persistent::type; +using is_persistent_t = decltype(persistent_type_helper::test(nullptr)); + +template +using is_persistent_v = typename is_persistent_t::value; template using is_external_index_t = typename std::conditional, std::true_type, std::false_type>::type; @@ -1112,10 +1130,12 @@ class Table auto getId() const { using decayed = std::decay_t; - if constexpr (framework::has_type_v) { + if constexpr (framework::has_type_v) { // 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::is_same_v) { + } else if constexpr (std::is_same_v) { // self index + return this->globalIndex(); + } else if constexpr (is_index_t::value && decayed::mLabel == "Index") { // soa::Index<> return this->globalIndex(); } else { return static_cast(-1); @@ -1505,14 +1525,14 @@ namespace row_helpers template std::array getArrowColumns(arrow::Table* table, framework::pack) { - static_assert(std::conjunction_v, "BinningPolicy: only persistent columns accepted (not dynamic and not index ones"); + static_assert(std::conjunction_v, "Arrow columns: only persistent columns accepted (not dynamic and not index ones"); return std::array{o2::soa::getIndexFromLabel(table, Cs::columnLabel())...}; } template std::array, sizeof...(Cs)> getChunks(arrow::Table* table, framework::pack, uint64_t ci) { - static_assert(std::conjunction_v, "BinningPolicy: only persistent columns accepted (not dynamic and not index ones"); + static_assert(std::conjunction_v, "Arrow chunks: only persistent columns accepted (not dynamic and not index ones"); return std::array, sizeof...(Cs)>{o2::soa::getIndexFromLabel(table, Cs::columnLabel())->chunk(ci)...}; } @@ -1541,11 +1561,16 @@ typename C::type getSingleRowData(arrow::Table* table, T& rowIterator, uint64_t { using decayed = std::decay_t; if constexpr (decayed::persistent::value) { - return getSingleRowPersistentData(table, ci, ai); + auto val = getSingleRowPersistentData(table, ci, ai); + return val; } else if constexpr (o2::soa::is_dynamic_t()) { - return getSingleRowDynamicData(rowIterator, globalIndex); - } else if constexpr (o2::soa::is_index_column_v) { - return getSingleRowIndexData(rowIterator, globalIndex); + auto val = getSingleRowDynamicData(rowIterator, globalIndex); + return val; + } else if constexpr (o2::soa::is_index_t::value) { + auto val = getSingleRowIndexData(rowIterator, globalIndex); + return val; + } else { + static_assert(!sizeof(decayed*), "Unrecognized column kind"); // A trick to delay static_assert until we actually instantiate this branch } } From 47c5d624229aa54596ef228740b8143dc2200ea4 Mon Sep 17 00:00:00 2001 From: Maja Kabus Date: Wed, 29 Jun 2022 11:29:27 +0200 Subject: [PATCH 2/6] Refactor binning policy to accept lambdas --- Framework/Core/include/Framework/ASoA.h | 2 +- .../Core/include/Framework/ASoAHelpers.h | 11 +- .../Core/include/Framework/BinningPolicy.h | 308 ++++++++++++------ Framework/Core/test/benchmark_EventMixing.cxx | 4 +- Framework/Core/test/test_ASoAHelpers.cxx | 16 +- 5 files changed, 218 insertions(+), 123 deletions(-) diff --git a/Framework/Core/include/Framework/ASoA.h b/Framework/Core/include/Framework/ASoA.h index 542c6a88fb3db..b4308f3334b17 100644 --- a/Framework/Core/include/Framework/ASoA.h +++ b/Framework/Core/include/Framework/ASoA.h @@ -1575,7 +1575,7 @@ typename C::type getSingleRowData(arrow::Table* table, T& rowIterator, uint64_t } template -std::tuple getRowData(arrow::Table* table, T rowIterator, uint64_t ci, uint64_t ai, uint64_t globalIndex) +std::tuple getRowData(arrow::Table* table, T rowIterator, framework::pack, uint64_t ci, uint64_t ai, uint64_t globalIndex) { return std::make_tuple(getSingleRowData(table, rowIterator, ci, ai, globalIndex)...); } diff --git a/Framework/Core/include/Framework/ASoAHelpers.h b/Framework/Core/include/Framework/ASoAHelpers.h index 19b1cd1408865..01ddaf1989246 100644 --- a/Framework/Core/include/Framework/ASoAHelpers.h +++ b/Framework/Core/include/Framework/ASoAHelpers.h @@ -72,8 +72,8 @@ inline bool diffCategory(BinningIndex const& a, BinningIndex const& b) return a.bin >= b.bin; } -template