|
| 1 | +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. |
| 2 | +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. |
| 3 | +// All rights not expressly granted are reserved. |
| 4 | +// |
| 5 | +// This software is distributed under the terms of the GNU General Public |
| 6 | +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". |
| 7 | +// |
| 8 | +// In applying this license CERN does not waive the privileges and immunities |
| 9 | +// granted to it by virtue of its status as an Intergovernmental Organization |
| 10 | +// or submit itself to any jurisdiction. |
| 11 | + |
| 12 | +/// |
| 13 | +/// \file udParticles2udTracks.cxx |
| 14 | +/// \author Roman Lavička |
| 15 | +/// \since 2025-04-15 |
| 16 | +/// \brief A task to create a reverse index from UDMcCollisions to UDCollisions |
| 17 | +/// |
| 18 | + |
| 19 | +#include "Framework/runDataProcessing.h" |
| 20 | +#include "Framework/AnalysisDataModel.h" |
| 21 | +#include "Framework/AnalysisTask.h" |
| 22 | +#include "PWGUD/DataModel/UDTables.h" |
| 23 | +#include "PWGUD/DataModel/UDIndex.h" |
| 24 | + |
| 25 | +using namespace o2; |
| 26 | +using namespace o2::framework; |
| 27 | + |
| 28 | +struct UDMcCollisions2UDCollisions { |
| 29 | + using LabeledCollisions = soa::Join<aod::UDCollisions, aod::UDMcCollsLabels>; |
| 30 | + Produces<aod::UDMcCollisionsToUDCollisions> udmcc2udc; |
| 31 | + |
| 32 | + std::vector<int> collisionIds; |
| 33 | + |
| 34 | + void init(InitContext&) |
| 35 | + { |
| 36 | + } |
| 37 | + |
| 38 | + void process(aod::UDMcCollisions const& mcCollisions) |
| 39 | + { |
| 40 | + if (doprocessIndexingCentral || doprocessIndexingCentralFast) { |
| 41 | + udmcc2udc.reserve(mcCollisions.size()); |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + void processIndexingCentralFast(aod::UDMcCollisions const& mcCollisions, LabeledCollisions const& collisions) |
| 46 | + { |
| 47 | + // faster version, but will use more memory due to pre-allocation |
| 48 | + std::vector<std::vector<int>> mccoll2coll(mcCollisions.size()); |
| 49 | + for (auto& collision : collisions) { |
| 50 | + if (collision.has_mcCollision()) |
| 51 | + mccoll2coll[collision.mcCollisionId()].push_back(collision.globalIndex()); |
| 52 | + } |
| 53 | + for (auto& mcCollision : mcCollisions) { |
| 54 | + udmcc2udc(mccoll2coll[mcCollision.globalIndex()]); |
| 55 | + } |
| 56 | + } |
| 57 | + PROCESS_SWITCH(UDMcCollisions2UDCollisions, processIndexingCentralFast, "Create reverse index from mccollisions to collision: more memory use but potentially faster", true); |
| 58 | + |
| 59 | + void processIndexingCentral(aod::UDMcCollisions const&, soa::SmallGroups<LabeledCollisions> const& collisions) |
| 60 | + { |
| 61 | + collisionIds.clear(); |
| 62 | + for (auto& collision : collisions) { |
| 63 | + collisionIds.push_back(collision.globalIndex()); |
| 64 | + } |
| 65 | + udmcc2udc(collisionIds); |
| 66 | + } |
| 67 | + PROCESS_SWITCH(UDMcCollisions2UDCollisions, processIndexingCentral, "Create reverse index from mccollisions to collision", false); |
| 68 | + |
| 69 | +}; |
| 70 | + |
| 71 | +WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) |
| 72 | +{ |
| 73 | + return WorkflowSpec{adaptAnalysisTask<UDMcCollisions2UDCollisions>(cfgc)}; |
| 74 | +} |
0 commit comments