ATLAS Offline Software
Loading...
Searching...
No Matches
VectorExploderAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5/****************************************************************
6 * @file VectorExploderAlg.cxx
7 * @brief Algorithm to "explode" a vector<float> jet decoration into
8 * multiple scalar float decorations, one per vector index.
9 *
10 * Ported from TDD FTagDumper/src/VectorExploderAlg.cxx.
11 * Namespace FlavorTagJetDecorators; hardcoded xAOD::JetContainer.
12 ****************************************************************/
13
14#include "VectorExploderAlg.h"
15
18
19namespace FlavorTagJetDecorators {
20
22 ISvcLocator* pSvcLocator)
23 : AthReentrantAlgorithm(name, pSvcLocator) {}
24
26 ATH_MSG_INFO("Initializing " << name() << "...");
27
28 ATH_CHECK(m_collectionKey.initialize());
29 ATH_CHECK(m_inputVectorKey.initialize());
30
31 if (m_outputNamesMap.value().empty()) {
32 ATH_MSG_ERROR("OutputNamesMap property must contain at least one entry.");
33 return StatusCode::FAILURE;
34 }
35
36 // Create and initialize the output decoration keys.
37 // We MUST reserve first: declare(key) saves a pointer to the key object,
38 // so if the vector resizes the pointer is invalidated → segfault.
39 m_maxIndex = -1;
40 m_outputKeys.reserve(m_outputNamesMap.value().size());
41 for (const auto& [index, outName] : m_outputNamesMap.value()) {
43 m_outputKeys.emplace_back(index,
45 m_collectionKey.key() + "." + outName});
46 auto& key = m_outputKeys.back().second;
47 ATH_CHECK(key.initialize());
48 declare(key);
49 }
50
51 return StatusCode::SUCCESS;
52}
53
54StatusCode VectorExploderAlg::execute(const EventContext& ctx) const {
55 ATH_MSG_DEBUG("Executing " << name() << "...");
56
58 if (!collection.isValid()) {
59 ATH_MSG_ERROR("Could not retrieve jet collection with key "
60 << m_collectionKey.key());
61 return StatusCode::FAILURE;
62 }
63
64 // Input read-decor handle for the vector<float> decoration.
66 vectorReader(m_inputVectorKey, ctx);
67
68 // Build write handles once per event (not per jet).
69 std::vector<std::pair<int, SG::WriteDecorHandle<xAOD::JetContainer, float>>>
70 outHandles;
71 outHandles.reserve(m_outputKeys.size());
72 for (const auto& [index, key] : m_outputKeys) {
73 outHandles.emplace_back(index,
75 }
76
77 for (const xAOD::Jet* jet : *collection) {
78 if (!vectorReader.isAvailable()) {
79 ATH_MSG_ERROR("Input vector decoration '"
80 << m_inputVectorKey.key()
81 << "' not found for the specified jet collection.");
82 return StatusCode::FAILURE;
83 }
84
85 const auto& inVec = vectorReader(*jet);
86
87 if (inVec.size() < static_cast<size_t>(m_maxIndex + 1)) {
88 ATH_MSG_ERROR("Input vector size " << inVec.size()
89 << " is smaller than the maximum index used in "
90 << "OutputNamesMap (" << m_maxIndex << ")");
91 return StatusCode::FAILURE;
92 }
93
94 for (auto& [index, handle] : outHandles) {
95 handle(*jet) = inVec.at(index);
96 }
97 }
98
99 return StatusCode::SUCCESS;
100}
101
102} // namespace FlavorTagJetDecorators
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
Handle class for reading a decoration on an object.
Handle class for adding a decoration to an object.
An algorithm that can be simultaneously executed in multiple threads.
VectorExploderAlg(const std::string &name, ISvcLocator *pSvcLocator)
Gaudi::Property< std::map< int, std::string > > m_outputNamesMap
Mapping from vector index to output scalar decoration name.
SG::ReadHandleKey< xAOD::JetContainer > m_collectionKey
Input jet collection.
SG::ReadDecorHandleKey< xAOD::JetContainer > m_inputVectorKey
Name of the input vector<float> decoration to explode.
int m_maxIndex
Maximum index used in OutputNamesMap (for bounds check).
std::vector< std::pair< int, SG::WriteDecorHandleKey< xAOD::JetContainer > > > m_outputKeys
Initialized output keys (index, WriteDecorHandleKey) pairs.
virtual StatusCode execute(const EventContext &ctx) const override
Handle class for reading a decoration on an object.
bool isAvailable()
Test to see if this variable exists in the store, for the referenced object.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Property holding a SG store/key/clid/attr name from which a WriteDecorHandle is made.
Handle class for adding a decoration to an object.
Definition index.py:1
Jet_v1 Jet
Definition of the current "jet version".