ATLAS Offline Software
CaloRingerReaderJetUtils.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 #ifndef CALORINGERTOOLS_CALORINGERREADERJETUTILS_ICC
6 #define CALORINGERTOOLS_CALORINGERREADERJETUTILS_ICC
7 
8 
9 // Kernel includes:
10 #include "GaudiKernel/StatusCode.h"
11 #include "GaudiKernel/ToolHandle.h"
12 
13 // Interface includes:
14 #include "CaloRingerTools/ICaloRingsBuilder.h"
15 
16 // xAOD includes:
17 #include "xAODCaloEvent/CaloClusterContainer.h"
18 #include "xAODCaloRings/CaloRingsContainer.h"
19 #include "xAODCaloRings/RingSetContainer.h"
20 #include "xAODCaloRings/CaloRingsAuxContainer.h"
21 #include "xAODCaloRings/RingSetAuxContainer.h"
22 #include "xAODCaloRings/tools/getCaloRingsDecorator.h"
23 
24 
25 #include "CaloRingerTools/ICaloRingerInputReader.h"
26 
27 namespace Ringer {
28 
29 // =====================================================================================
30 template<typename container_t>
31 StatusCode BuildCaloRingsJetFctor<container_t>::prepareJetToLoopFor( std::size_t nParticles ) {
32  // Call overridden method
33  ATH_CHECK( base_t::prepareJetToLoopFor( nParticles ) );
34  // Make the decorator key
35  m_decor = new decor_t( m_decorKey );
36  return StatusCode::SUCCESS;
37 }
38 
39 // =====================================================================================
40 template<typename container_t>
41 void BuildCaloRingsJetFctor<container_t>::checkJetRelease() {
42  // Call overridden method
43  base_t::checkJetRelease();
44  if ( m_part_counter == m_part_size ) {
45  delete m_decor; m_decor = nullptr;
46  }
47 }
48 
49 // =====================================================================================
50 template<typename container_t>
51 void BuildCaloRingsJetFctor<container_t>::displayLoopingMessage() const {
52  if (msgLvl(MSG::DEBUG)) {
53  msg() << MSG::DEBUG << " ---------- Reading "
54  << endmsg;
55  }
56 }
57 
58 
59 // =====================================================================================
60 template< typename container_t >
61 void BuildCaloRingsJetFctor<container_t>::operator() ( const particle_t *part )
62 {
63 
64  auto ringsELReader = xAOD::getCaloRingsReader();
65  const xAOD::CaloRingsLinks *caloRingsLinks(nullptr);
66 
67  try {
68  caloRingsLinks = &(ringsELReader(*part));
69  } catch ( const std::exception &e) {
70  ATH_MSG_DEBUG("Couldn't retrieve CaloRingsELVec. Reason: " << e.what());
71  }
72 
73  incrementCounter(); displayLoopingMessage();
74 
75  // Make CaloRings ElementLink Holder:
76  xAOD::CaloRingsLinks clRingsLinks;
77 
78  // The CaloRings ElementLink:
79  ElementLink<xAOD::CaloRingsContainer> ringsEL;
80 
81  if (m_builder->execute( *part, ringsEL ).isFailure()){
82  throw std::runtime_error("Error while executing CaloRings builder.");
83  }
84 
85  // Push it back:
86  clRingsLinks.push_back( ringsEL );
87 
88 
89  if(!caloRingsLinks){
90  // Decorate particle with CaloRings:
91  m_decor->operator()( *part ) = clRingsLinks;
92  }
93 
94  checkJetRelease();
95 }
96 
97 // =====================================================================================
98 template<typename container_t>
99 StatusCode BuildCaloRingsJetFctor<container_t>::initialize()
100 {
101  ATH_CHECK( m_decorKey.initialize() );
102  m_decorKey.owner()->declare(m_decorKey);
103  return StatusCode::SUCCESS;
104 }
105 
106 
107 } // namespace Ringer
108 
109 #endif // CALORINGERTOOLS_RINGERREADERUTILS_ICC
110 
111 // vim: filetype=cpp: