1 // In case the extension is confusing, this is a -*- C++ -*- file
3 Copyright (C) 2002-2021 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)
18 template <typename C, typename D, typename N>
19 StatusCode DecoratorAlg<C,D,N>::initialize()
21 return initializeInternal();
24 template <typename C, typename D, typename N>
25 StatusCode DecoratorAlg<C,D,N>::initializeInternal(
26 DecoratorAlg::ExtraDependencies extraDeps)
28 ATH_CHECK(m_containerKey.initialize());
29 ATH_CHECK(m_constituentKey.initialize());
31 ATH_CHECK(m_decorator.retrieve());
33 std::set<std::string> veto(
34 m_undeclaredReadDecorKeys.begin(),
35 m_undeclaredReadDecorKeys.end());
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);
49 ATH_MSG_DEBUG("Adding accessor: " + full);
50 m_aux.emplace_back(this, key, full, "");
51 ATH_CHECK(m_aux.back().initialize());
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);
60 ATH_MSG_DEBUG("Adding constituent accessor: " + full);
61 m_constituentAux.emplace_back(this, key, full, "");
62 ATH_CHECK(m_constituentAux.back().initialize());
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());
71 ATH_MSG_DEBUG("Finished setting up");
72 return StatusCode::SUCCESS;
76 template <typename C, typename D, typename N>
77 StatusCode DecoratorAlg<C,D,N>::execute(const EventContext& cxt ) const {
78 SG::ReadHandle<C> container(
80 if (!container.isValid()) {
81 ATH_MSG_ERROR("no container " << container.key());
82 return StatusCode::FAILURE;
85 "Decorating " + std::to_string(container->size()) + " elements");
86 for (const auto* element: *container) {
87 m_decorator->decorate(*element);
89 return StatusCode::SUCCESS;
92 template <typename C, typename D, typename N>
93 StatusCode DecoratorAlg<C,D,N>::finalize() {
94 return StatusCode::SUCCESS;