ATLAS Offline Software
LinkCounterAlg.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
6 
7 #include "StoreGate/ReadDecorHandle.h"
8 #include "StoreGate/WriteDecorHandle.h"
9 #include "AthLinks/ElementLink.h"
10 
11 
12 namespace FlavorTagDiscriminants {
13 
14  template <typename T, typename C>
15  LinkCounterAlg<T,C>::LinkCounterAlg(
16  const std::string& name, ISvcLocator* svcloc):
17  AthReentrantAlgorithm(name, svcloc)
18  {
19  // cppcheck-suppress missingReturn; false positive
20  }
21 
22  template <typename T, typename C>
23  StatusCode LinkCounterAlg<T,C>::initialize()
24  {
25  if (m_links.empty()) {
26  ATH_MSG_ERROR("link not specified");
27  return StatusCode::FAILURE;
28  }
29  ATH_CHECK(m_links.initialize());
30  ATH_CHECK(m_flag.initialize());
31  return StatusCode::SUCCESS;
32  }
33 
34  template <typename T, typename C>
35  StatusCode LinkCounterAlg<T,C>::execute(const EventContext& cxt) const {
36  using TV = std::vector<ElementLink<T>>;
37  SG::ReadDecorHandle<C, TV> links_handle(m_links, cxt);
38  SG::WriteDecorHandle<C, char> flag_handle(m_flag, cxt);
39  for (const auto* jet: *links_handle) {
40  const auto& links = links_handle(*jet);
41  flag_handle(*jet) = (links.size() >= m_minimumLinks) ? 1 : 0;
42  }
43  return StatusCode::SUCCESS;
44  }
45 
46 } // end namespace FlavorTagDiscriminants