From d547b8b825fba0718172b4318786d83a5ab15668 Mon Sep 17 00:00:00 2001 From: Anton Alkin Date: Fri, 12 Nov 2021 09:33:21 +0100 Subject: [PATCH] Tutorials: extendedColumns.cxx now correctly uses soa::Extend<> --- Tutorials/src/extendedColumns.cxx | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Tutorials/src/extendedColumns.cxx b/Tutorials/src/extendedColumns.cxx index 25ed84b898c..e4db704ee54 100644 --- a/Tutorials/src/extendedColumns.cxx +++ b/Tutorials/src/extendedColumns.cxx @@ -28,13 +28,20 @@ using namespace o2; using namespace o2::framework; struct ExtendTable { - void process(aod::Collision const&, aod::Tracks const& tracks) + void process(aod::Collisions const& collisions, aod::Tracks const& tracks) { + // note that this needs to be done only once, as it is done for the whole table + // the extension is temporary and is lost when the variable it is assigned to + // goes out of scope auto table_extension = soa::Extend(tracks); - for (auto& row : table_extension) { - if (row.trackType() != 3) { - if (row.index() % 100 == 0) { - LOGF(info, "P^2 = %.3f", row.p2()); + for (auto& collision : collisions) { + auto trackSlice = table_extension.sliceBy(aod::track::collisionId, collision.globalIndex()); + LOGP(info, "Collision {}", collision.globalIndex()); + for (auto& row : trackSlice) { + if (row.trackType() != 3) { + if (row.index() % 100 == 0) { + LOGP(info, "P^2 = {}", row.p2()); + } } } }