2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
7 #include "StoreGate/ReadDecorHandle.h"
8 #include "StoreGate/WriteDecorHandle.h"
9 #include "AthLinks/ElementLink.h"
12 namespace FlavorTagDiscriminants {
14 template <typename T, typename C>
15 LinkCounterAlg<T,C>::LinkCounterAlg(
16 const std::string& name, ISvcLocator* svcloc):
17 AthReentrantAlgorithm(name, svcloc)
19 // cppcheck-suppress missingReturn; false positive
22 template <typename T, typename C>
23 StatusCode LinkCounterAlg<T,C>::initialize()
25 if (m_links.empty()) {
26 ATH_MSG_ERROR("link not specified");
27 return StatusCode::FAILURE;
29 ATH_CHECK(m_links.initialize());
30 ATH_CHECK(m_flag.initialize());
31 return StatusCode::SUCCESS;
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;
43 return StatusCode::SUCCESS;
46 } // end namespace FlavorTagDiscriminants