1 // In case the extension is confusing, this is a -*- C++ -*- file
3 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
6 #include "StoreGate/ReadDecorHandle.h"
10 namespace FlavorTagDiscriminants {
11 template <typename C, typename D, typename N>
12 DecoratorAlg<C,D,N>::DecoratorAlg(
13 const std::string& name, ISvcLocator* svcloc):
14 AthReentrantAlgorithm(name, svcloc)
16 // cppcheck-suppress missingReturn; false positive
19 template <typename C, typename D, typename N>
20 StatusCode DecoratorAlg<C,D,N>::initialize()
22 return initializeInternal();
25 template <typename C, typename D, typename N>
26 StatusCode DecoratorAlg<C,D,N>::initializeInternal(
27 DecoratorAlg::ExtraDependencies extraDeps)
29 ATH_CHECK(m_containerKey.initialize());
30 ATH_CHECK(m_constituentKey.initialize());
32 ATH_CHECK(m_decorator.retrieve());
34 std::set<std::string> veto(
35 m_undeclaredReadDecorKeys.begin(),
36 m_undeclaredReadDecorKeys.end());
38 // now we build data dependencies from the internal tools. We have
39 // to reserve the vectors here to prevent a segfault since read /
40 // write handles aren't movable once declaired as a property.
41 auto auxKeys = m_decorator->getAuxInputKeys();
42 auxKeys.merge(extraDeps);
43 m_aux.reserve(auxKeys.size());
44 for (const std::string& key: auxKeys) {
45 const std::string full = m_containerKey.key() + "." + key;
46 if (veto.count(full)) {
47 ATH_MSG_DEBUG("Not declaring accessor: " + full);
50 ATH_MSG_DEBUG("Adding accessor: " + full);
51 m_aux.emplace_back(this, key, full, "");
52 ATH_CHECK(m_aux.back().initialize());
54 m_constituentAux.reserve(m_decorator->getConstituentAuxInputKeys().size());
55 for (const std::string& key: m_decorator->getConstituentAuxInputKeys()) {
56 const std::string full = m_constituentKey.key() + "." + key;
57 if (veto.count(full)) {
58 ATH_MSG_DEBUG("Not declaring accessor: " + full);
61 ATH_MSG_DEBUG("Adding constituent accessor: " + full);
62 m_constituentAux.emplace_back(this, key, full, "");
63 ATH_CHECK(m_constituentAux.back().initialize());
65 m_decor.reserve(m_decorator->getDecoratorKeys().size());
66 for (const std::string& key: m_decorator->getDecoratorKeys()) {
67 const std::string full = m_containerKey.key() + "." + key;
68 m_decor.emplace_back(this, key, full, "");
69 ATH_CHECK(m_decor.back().initialize());
71 SG::auxid_t auxid = SG::AuxTypeRegistry::instance().findAuxID(key);
72 ATH_MSG_DEBUG("Added decorator: " + full + ","
73 " key " + key + " has auxid " + std::to_string(auxid) );
74 m_auxids.push_back(auxid);
76 ATH_MSG_DEBUG("Finished setting up");
77 return StatusCode::SUCCESS;
81 template <typename C, typename D, typename N>
82 StatusCode DecoratorAlg<C,D,N>::execute(const EventContext& cxt ) const {
83 SG::ReadHandle<C> container(
85 if (!container.isValid()) {
86 ATH_MSG_ERROR("no container " << container.key());
87 return StatusCode::FAILURE;
90 "Decorating " + std::to_string(container->size()) + " elements");
91 for (const auto* element: *container) {
92 m_decorator->decorate(*element);
95 // Lock the decorations
97 for (SG::auxid_t id: m_auxids) {
98 ATH_MSG_DEBUG("locking auxid " << id << " in " << m_containerKey.key());
99 const_cast<C*>(container.cptr())->lockDecoration(id);
102 return StatusCode::SUCCESS;
105 template <typename C, typename D, typename N>
106 StatusCode DecoratorAlg<C,D,N>::finalize() {
107 return StatusCode::SUCCESS;