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-2021 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  DecoratorAlg<C,D,N>::DecoratorAlg(
13  const std::string& name, ISvcLocator* svcloc):
14  AthReentrantAlgorithm(name, svcloc)
15  {
16  }
17 
18  template <typename C, typename D, typename N>
19  StatusCode DecoratorAlg<C,D,N>::initialize()
20  {
21  return initializeInternal();
22  }
23 
24  template <typename C, typename D, typename N>
25  StatusCode DecoratorAlg<C,D,N>::initializeInternal(
26  DecoratorAlg::ExtraDependencies extraDeps)
27  {
28  ATH_CHECK(m_containerKey.initialize());
29  ATH_CHECK(m_constituentKey.initialize());
30 
31  ATH_CHECK(m_decorator.retrieve());
32 
33  std::set<std::string> veto(
34  m_undeclaredReadDecorKeys.begin(),
35  m_undeclaredReadDecorKeys.end());
36 
37  // now we build data dependencies from the internal tools. We have
38  // to reserve the vectors here to prevent a segfault since read /
39  // write handles aren't movable once declaired as a property.
40  auto auxKeys = m_decorator->getAuxInputKeys();
41  auxKeys.merge(extraDeps);
42  m_aux.reserve(auxKeys.size());
43  for (const std::string& key: auxKeys) {
44  const std::string full = m_containerKey.key() + "." + key;
45  if (veto.count(full)) {
46  ATH_MSG_DEBUG("Not declaring accessor: " + full);
47  continue;
48  }
49  ATH_MSG_DEBUG("Adding accessor: " + full);
50  m_aux.emplace_back(this, key, full, "");
51  ATH_CHECK(m_aux.back().initialize());
52  }
53  m_constituentAux.reserve(m_decorator->getConstituentAuxInputKeys().size());
54  for (const std::string& key: m_decorator->getConstituentAuxInputKeys()) {
55  const std::string full = m_constituentKey.key() + "." + key;
56  if (veto.count(full)) {
57  ATH_MSG_DEBUG("Not declaring accessor: " + full);
58  continue;
59  }
60  ATH_MSG_DEBUG("Adding constituent accessor: " + full);
61  m_constituentAux.emplace_back(this, key, full, "");
62  ATH_CHECK(m_constituentAux.back().initialize());
63  }
64  m_decor.reserve(m_decorator->getDecoratorKeys().size());
65  for (const std::string& key: m_decorator->getDecoratorKeys()) {
66  const std::string full = m_containerKey.key() + "." + key;
67  ATH_MSG_DEBUG("Adding decorator: " + full);
68  m_decor.emplace_back(this, key, full, "");
69  ATH_CHECK(m_decor.back().initialize());
70  }
71  ATH_MSG_DEBUG("Finished setting up");
72  return StatusCode::SUCCESS;
73  }
74 
75 
76  template <typename C, typename D, typename N>
77  StatusCode DecoratorAlg<C,D,N>::execute(const EventContext& cxt ) const {
78  SG::ReadHandle<C> container(
79  m_containerKey, cxt);
80  if (!container.isValid()) {
81  ATH_MSG_ERROR("no container " << container.key());
82  return StatusCode::FAILURE;
83  }
84  ATH_MSG_DEBUG(
85  "Decorating " + std::to_string(container->size()) + " elements");
86  for (const auto* element: *container) {
87  m_decorator->decorate(*element);
88  }
89  return StatusCode::SUCCESS;
90  }
91 
92  template <typename C, typename D, typename N>
93  StatusCode DecoratorAlg<C,D,N>::finalize() {
94  return StatusCode::SUCCESS;
95  }
96 
97 }