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 StatusCode DecoratorAlg<C,D,N>::initialize()
14 return initializeInternal();
17 template <typename C, typename D, typename N>
18 StatusCode DecoratorAlg<C,D,N>::initializeInternal(
19 DecoratorAlg::ExtraDependencies extraDeps)
21 ATH_CHECK(m_containerKey.initialize());
22 ATH_CHECK(m_constituentKey.initialize());
24 ATH_CHECK(m_decorator.retrieve());
26 std::set<std::string> veto(
27 m_undeclaredReadDecorKeys.begin(),
28 m_undeclaredReadDecorKeys.end());
30 // now we build data dependencies from the internal tools. We have
31 // to reserve the vectors here to prevent a segfault since read /
32 // write handles aren't movable once declaired as a property.
33 auto auxKeys = m_decorator->getAuxInputKeys();
34 auxKeys.merge(extraDeps);
35 m_aux.reserve(auxKeys.size());
36 for (const std::string& key: auxKeys) {
37 const std::string full = m_containerKey.key() + "." + key;
38 if (veto.count(full)) {
39 ATH_MSG_DEBUG("Not declaring accessor: " + full);
42 ATH_MSG_DEBUG("Adding accessor: " + full);
43 m_aux.emplace_back(this, key, full, "");
44 ATH_CHECK(m_aux.back().initialize());
46 m_constituentAux.reserve(m_decorator->getConstituentAuxInputKeys().size());
47 for (const std::string& key: m_decorator->getConstituentAuxInputKeys()) {
48 const std::string full = m_constituentKey.key() + "." + key;
49 if (veto.count(full)) {
50 ATH_MSG_DEBUG("Not declaring accessor: " + full);
53 ATH_MSG_DEBUG("Adding constituent accessor: " + full);
54 m_constituentAux.emplace_back(this, key, full, "");
55 ATH_CHECK(m_constituentAux.back().initialize());
57 std::set<std::string> keys = m_decorator->getDecoratorKeys();
58 m_decor.reserve(keys.size());
59 for (const std::string& key: keys) {
60 const std::string full = m_containerKey.key() + "." + key;
61 m_decor.emplace_back(this, key, full, "");
62 ATH_CHECK(m_decor.back().initialize());
64 SG::auxid_t auxid = SG::AuxTypeRegistry::instance().findAuxID(key);
65 ATH_MSG_DEBUG("Added decorator: " + full + ","
66 " key " + key + " has auxid " + std::to_string(auxid) );
67 m_auxids.push_back(auxid);
69 ATH_MSG_DEBUG("Finished setting up");
70 return StatusCode::SUCCESS;
74 template <typename C, typename D, typename N>
75 StatusCode DecoratorAlg<C,D,N>::execute(const EventContext& cxt ) const {
76 SG::ReadHandle<C> container(
78 if (!container.isValid()) {
79 ATH_MSG_ERROR("no container " << container.key());
80 return StatusCode::FAILURE;
83 "Decorating " + std::to_string(container->size()) + " elements");
84 for (const auto* element: *container) {
85 m_decorator->decorate(*element);
88 // Lock the decorations
90 for (SG::auxid_t id: m_auxids) {
91 ATH_MSG_DEBUG("locking auxid " << id << " in " << m_containerKey.key());
92 const_cast<C*>(container.cptr())->lockDecoration(id);
95 return StatusCode::SUCCESS;
98 template <typename C, typename D, typename N>
99 StatusCode DecoratorAlg<C,D,N>::finalize() {
100 return StatusCode::SUCCESS;