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  }
20 
21  template <typename T, typename C>
22  StatusCode LinkCounterAlg<T,C>::initialize()
23  {
24  if (m_links.empty()) {
25  ATH_MSG_ERROR("link not specified");
26  return StatusCode::FAILURE;
27  }
28  ATH_CHECK(m_links.initialize());
29  ATH_CHECK(m_flag.initialize());
30  return StatusCode::SUCCESS;
31  }
32 
33  template <typename T, typename C>
34  StatusCode LinkCounterAlg<T,C>::execute(const EventContext& cxt) const {
35  using TV = std::vector<ElementLink<T>>;
36  SG::ReadDecorHandle<C, TV> links_handle(m_links, cxt);
37  SG::WriteDecorHandle<C, char> flag_handle(m_flag, cxt);
38  for (const auto* jet: *links_handle) {
39  const auto& links = links_handle(*jet);
40  flag_handle(*jet) = (links.size() >= m_minimumLinks) ? 1 : 0;
41  }
42  return StatusCode::SUCCESS;
43  }
44 
45 } // end namespace FlavorTagDiscriminants