From ed0a5681d3227752a881e9d1892ac0ff88048ba8 Mon Sep 17 00:00:00 2001 From: Maja Kabus Date: Wed, 29 Jun 2022 13:39:56 +0200 Subject: [PATCH 1/2] Improve tests for persistent and index columns --- Framework/Core/include/Framework/ASoA.h | 40 +++++++++++++++++++------ 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/Framework/Core/include/Framework/ASoA.h b/Framework/Core/include/Framework/ASoA.h index 9030cf5fe7eec..f358186617b03 100644 --- a/Framework/Core/include/Framework/ASoA.h +++ b/Framework/Core/include/Framework/ASoA.h @@ -541,8 +541,23 @@ struct Index : o2::soa::IndexColumn> { template using is_dynamic_t = framework::is_specialization; +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 +1127,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 +1522,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 +1558,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 933be9b943d8f7ec448f84369371fbbc953ec2f9 Mon Sep 17 00:00:00 2001 From: Maja Kabus Date: Wed, 6 Jul 2022 18:00:11 +0200 Subject: [PATCH 2/2] Remove leftover lines --- Framework/Core/include/Framework/ASoA.h | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Framework/Core/include/Framework/ASoA.h b/Framework/Core/include/Framework/ASoA.h index f358186617b03..1cf56bcaaacf4 100644 --- a/Framework/Core/include/Framework/ASoA.h +++ b/Framework/Core/include/Framework/ASoA.h @@ -1558,14 +1558,11 @@ typename C::type getSingleRowData(arrow::Table* table, T& rowIterator, uint64_t { using decayed = std::decay_t; if constexpr (decayed::persistent::value) { - auto val = getSingleRowPersistentData(table, ci, ai); - return val; + return getSingleRowPersistentData(table, ci, ai); } else if constexpr (o2::soa::is_dynamic_t()) { - auto val = getSingleRowDynamicData(rowIterator, globalIndex); - return val; + return getSingleRowDynamicData(rowIterator, globalIndex); } else if constexpr (o2::soa::is_index_t::value) { - auto val = getSingleRowIndexData(rowIterator, globalIndex); - return val; + return getSingleRowIndexData(rowIterator, globalIndex); } else { static_assert(!sizeof(decayed*), "Unrecognized column kind"); // A trick to delay static_assert until we actually instantiate this branch }