ATLAS Offline Software
DecoratorAlg.icc
Go to the documentation of this file.
1 // In case the extension is confusing, this is a -*- C++ -*- file
2 /*
3  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
4 */
5 
6 #include "StoreGate/ReadDecorHandle.h"
7 
8 #include <exception>
9 
10 namespace FlavorTagDiscriminants {
11  template <typename C, typename D, typename N>
12  StatusCode DecoratorAlg<C,D,N>::initialize()
13  {
14  return initializeInternal();
15  }
16 
17  template <typename C, typename D, typename N>
18  StatusCode DecoratorAlg<C,D,N>::initializeInternal(
19  DecoratorAlg::ExtraDependencies extraDeps)
20  {
21  ATH_CHECK(m_containerKey.initialize());
22  ATH_CHECK(m_constituentKey.initialize());
23 
24  ATH_CHECK(m_decorator.retrieve());
25 
26  std::set<std::string> veto(
27  m_undeclaredReadDecorKeys.begin(),
28  m_undeclaredReadDecorKeys.end());
29 
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);
40  continue;
41  }
42  ATH_MSG_DEBUG("Adding accessor: " + full);
43  m_aux.emplace_back(this, key, full, "");
44  ATH_CHECK(m_aux.back().initialize());
45  }
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);
51  continue;
52  }
53  ATH_MSG_DEBUG("Adding constituent accessor: " + full);
54  m_constituentAux.emplace_back(this, key, full, "");
55  ATH_CHECK(m_constituentAux.back().initialize());
56  }
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());
63  // look up auxids
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);
68  }
69  ATH_MSG_DEBUG("Finished setting up");
70  return StatusCode::SUCCESS;
71  }
72 
73 
74  template <typename C, typename D, typename N>
75  StatusCode DecoratorAlg<C,D,N>::execute(const EventContext& cxt ) const {
76  SG::ReadHandle<C> container(
77  m_containerKey, cxt);
78  if (!container.isValid()) {
79  ATH_MSG_ERROR("no container " << container.key());
80  return StatusCode::FAILURE;
81  }
82  ATH_MSG_DEBUG(
83  "Decorating " + std::to_string(container->size()) + " elements");
84  for (const auto* element: *container) {
85  m_decorator->decorate(*element);
86  }
87 
88  // Lock the decorations
89  //
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);
93  }
94 
95  return StatusCode::SUCCESS;
96  }
97 
98  template <typename C, typename D, typename N>
99  StatusCode DecoratorAlg<C,D,N>::finalize() {
100  return StatusCode::SUCCESS;
101  }
102 
103 }