From 2fad33c03c4ae2f80a505c58b491f2bf7630947b Mon Sep 17 00:00:00 2001 From: Anton Alkin Date: Fri, 11 Sep 2020 11:21:39 +0200 Subject: [PATCH 1/3] DPL Analysis: first draft for more generic index binding --- Analysis/Tutorials/src/associatedExample.cxx | 29 +++++++------------- Framework/Core/include/Framework/ASoA.h | 23 ++++++++++++---- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/Analysis/Tutorials/src/associatedExample.cxx b/Analysis/Tutorials/src/associatedExample.cxx index 424c9298b87bc..f29f43e53fa8d 100644 --- a/Analysis/Tutorials/src/associatedExample.cxx +++ b/Analysis/Tutorials/src/associatedExample.cxx @@ -15,15 +15,13 @@ namespace o2::aod { namespace etaphi { -DECLARE_SOA_COLUMN(Eta, etas, float); -DECLARE_SOA_COLUMN(Phi, phis, float); -DECLARE_SOA_COLUMN(Pt, pts, float); +DECLARE_SOA_COLUMN(AEta, etas, float); +DECLARE_SOA_COLUMN(APhi, phis, float); +DECLARE_SOA_COLUMN(APt, pts, float); } // namespace etaphi DECLARE_SOA_TABLE(EtaPhi, "AOD", "ETAPHI", - etaphi::Eta, etaphi::Phi); -DECLARE_SOA_TABLE(EtaPhiPt, "AOD", "ETAPHIPT", - etaphi::Eta, etaphi::Phi, etaphi::Pt); + etaphi::AEta, etaphi::APhi); namespace collision { @@ -43,16 +41,13 @@ using namespace o2::framework; // we need GCC 7.4+ for that struct ATask { Produces etaphi; - Produces etaphipt; void process(aod::Tracks const& tracks) { for (auto& track : tracks) { float phi = asin(track.snp()) + track.alpha() + static_cast(M_PI); float eta = log(tan(0.25f * static_cast(M_PI) - 0.5f * atan(track.tgl()))); - float pt = 1.f / track.signed1Pt(); etaphi(eta, phi); - etaphipt(eta, phi, pt); } } }; @@ -77,18 +72,15 @@ struct BTask { } }; -struct CTask { - void process(aod::Collision const& collision, soa::Concat const& concatenated) - { - LOGF(INFO, "ID: %d", collision.globalIndex()); - LOGF(INFO, "Tracks: %d", concatenated.size()); - } -}; - struct TTask { + using myCol = soa::Join; void process(soa::Join::iterator const& col, aod::Tracks const& tracks) { - LOGF(INFO, "ID: %d; %d == %d", col.globalIndex(), col.mult(), tracks.size()); + LOGF(INFO, "[direct] ID: %d; %d == %d", col.globalIndex(), col.mult(), tracks.size()); + if (tracks.size() > 0) { + auto track0 = tracks.begin(); + LOGF(INFO, "[index ] ID: %d; %d == %d", track0.collision_as().globalIndex(), track0.collision_as().mult(), tracks.size()); + } } }; @@ -97,7 +89,6 @@ WorkflowSpec defineDataProcessing(ConfigContext const&) return WorkflowSpec{ adaptAnalysisTask("produce-etaphi"), adaptAnalysisTask("consume-etaphi"), - adaptAnalysisTask("consume-etaphi-twice"), adaptAnalysisTask("produce-mult"), adaptAnalysisTask("consume-mult")}; } diff --git a/Framework/Core/include/Framework/ASoA.h b/Framework/Core/include/Framework/ASoA.h index 01073b2ed94df..996733098cb3f 100644 --- a/Framework/Core/include/Framework/ASoA.h +++ b/Framework/Core/include/Framework/ASoA.h @@ -1110,6 +1110,13 @@ using JoinBase = decltype(join(std::declval()...)); template using ConcatBase = decltype(concat(std::declval(), std::declval())); +template +constexpr auto is_binding_compatible_v() +{ + return framework::pack_size( + framework::intersected_pack_t{}) > 0; +} + } // namespace o2::soa #define DECLARE_SOA_STORE() \ @@ -1220,24 +1227,30 @@ using ConcatBase = decltype(concat(std::declval(), std::declval())); return *mColumnIterator >= 0; \ } \ \ - binding_t::iterator _Getter_() const \ + template \ + auto _Getter_##_as() const \ { \ assert(mBinding != nullptr); \ - return mBinding->begin() + *mColumnIterator; \ + return static_cast(mBinding)->begin() + *mColumnIterator; \ + } \ + \ + auto _Getter_() const \ + { \ + return _Getter_##_as(); \ } \ \ template \ bool setCurrent(T* current) \ { \ - if constexpr (std::is_same_v) { \ + if constexpr (soa::is_binding_compatible_v()) { \ assert(current != nullptr); \ this->mBinding = current; \ return true; \ } \ return false; \ } \ - binding_t* getCurrent() { return mBinding; } \ - binding_t* mBinding = nullptr; \ + binding_t* getCurrent() { return static_cast(mBinding); } \ + void* mBinding = nullptr; \ }; \ static const o2::framework::expressions::BindingNode _Getter_##Id { _Label_, \ o2::framework::expressions::selectArrowType<_Type_>() } From 1915992adbfedc30aa18ad1dad26fb893e2a86c5 Mon Sep 17 00:00:00 2001 From: Anton Alkin Date: Fri, 11 Sep 2020 11:41:53 +0200 Subject: [PATCH 2/3] Update ASoA.h --- Framework/Core/include/Framework/ASoA.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Framework/Core/include/Framework/ASoA.h b/Framework/Core/include/Framework/ASoA.h index 996733098cb3f..491ff025fc49f 100644 --- a/Framework/Core/include/Framework/ASoA.h +++ b/Framework/Core/include/Framework/ASoA.h @@ -1242,7 +1242,7 @@ constexpr auto is_binding_compatible_v() template \ bool setCurrent(T* current) \ { \ - if constexpr (soa::is_binding_compatible_v()) { \ + if constexpr (o2::soa::is_binding_compatible_v()) { \ assert(current != nullptr); \ this->mBinding = current; \ return true; \ From 220139bc79688162bb62e086fe00f4a38db4a653 Mon Sep 17 00:00:00 2001 From: Anton Alkin Date: Fri, 11 Sep 2020 14:36:27 +0200 Subject: [PATCH 3/3] Intersect original packs instead of columns to reduce template recursion --- Analysis/Tutorials/src/associatedExample.cxx | 2 +- Framework/Core/include/Framework/ASoA.h | 2 +- Framework/Foundation/include/Framework/Pack.h | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Analysis/Tutorials/src/associatedExample.cxx b/Analysis/Tutorials/src/associatedExample.cxx index f29f43e53fa8d..cbb44589fc32e 100644 --- a/Analysis/Tutorials/src/associatedExample.cxx +++ b/Analysis/Tutorials/src/associatedExample.cxx @@ -67,7 +67,7 @@ struct BTask { LOGF(INFO, "ID: %d", collision.globalIndex()); LOGF(INFO, "Tracks: %d", extTracks.size()); for (auto& track : extTracks) { - LOGF(INFO, "(%f, %f) - (%f, %f)", track.eta(), track.phi(), track.etas(), track.phis()); + LOGF(INFO, "(%f, %f) - (%f, %f)", track.eta(), track.phiraw(), track.etas(), track.phis()); } } }; diff --git a/Framework/Core/include/Framework/ASoA.h b/Framework/Core/include/Framework/ASoA.h index 491ff025fc49f..d4160f0d33a4c 100644 --- a/Framework/Core/include/Framework/ASoA.h +++ b/Framework/Core/include/Framework/ASoA.h @@ -1114,7 +1114,7 @@ template constexpr auto is_binding_compatible_v() { return framework::pack_size( - framework::intersected_pack_t{}) > 0; + framework::intersected_pack_t, originals_pack_t>{}) > 0; } } // namespace o2::soa diff --git a/Framework/Foundation/include/Framework/Pack.h b/Framework/Foundation/include/Framework/Pack.h index 0b97e72bd6feb..b357e51af53af 100644 --- a/Framework/Foundation/include/Framework/Pack.h +++ b/Framework/Foundation/include/Framework/Pack.h @@ -186,13 +186,13 @@ constexpr std::size_t has_type_at_t = decltype(select( } // namespace template -constexpr std::size_t has_type_at_v(o2::framework::pack<> p) +constexpr std::size_t has_type_at_v(o2::framework::pack<>) { return -1; } template -constexpr std::size_t has_type_at_v(o2::framework::pack p) +constexpr std::size_t has_type_at_v(o2::framework::pack) { return has_type_at_t; }