2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
5 #ifndef CALORINGERTOOLS_CALORINGERREADERUTILS_ICC
6 #define CALORINGERTOOLS_CALORINGERREADERUTILS_ICC
10 #include "GaudiKernel/StatusCode.h"
11 #include "GaudiKernel/ToolHandle.h"
13 // Interface includes:
14 #include "CaloRingerTools/ICaloRingsBuilder.h"
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"
25 #include "CaloRingerTools/ICaloRingerInputReader.h"
29 // =====================================================================================
30 template<typename container_t>
31 StatusCode BuildCaloRingsFctor<container_t>::prepareToLoopFor( std::size_t nParticles ) {
32 // Call overridden method
33 ATH_CHECK( base_t::prepareToLoopFor( nParticles ) );
34 // Make the decorator key
35 m_decor = new decor_t( m_decorKey );
36 return StatusCode::SUCCESS;
39 // =====================================================================================
40 template<typename container_t>
41 void BuildCaloRingsFctor<container_t>::checkRelease() {
42 // Call overridden method
43 base_t::checkRelease();
44 if ( m_part_counter == m_part_size ) {
45 delete m_decor; m_decor = nullptr;
49 // =====================================================================================
50 template<typename container_t>
51 void BuildCaloRingsFctor<container_t>::displayLoopingMessage() const {
52 if (msgLvl(MSG::DEBUG)) {
53 std::string str = ((m_particle_has_cluster)?"(with cluster access)":
54 "(without cluster access)");
55 msg() << MSG::DEBUG << " ---------- Reading "
56 << m_particle_name << " " << str << " candidate "
57 << this->m_part_counter << "/" << this->m_part_size
58 << " ----------- " << endmsg;
63 // =====================================================================================
64 template< typename container_t >
65 void BuildCaloRingsFctor<container_t>::operator() ( const particle_t *part )
68 auto ringsELReader = xAOD::getCaloRingsReader();
69 const xAOD::CaloRingsLinks *caloRingsLinks(nullptr);
72 caloRingsLinks = &(ringsELReader(*part));
73 } catch ( const std::exception &e) {
74 ATH_MSG_DEBUG("Couldn't retrieve CaloRingsELVec. Reason: " << e.what());
77 incrementCounter(); displayLoopingMessage();
79 // Retrieve clusters element links:
80 const auto &clustersLinks = part->caloClusterLinks();
82 // Make CaloRings ElementLink Holder:
83 xAOD::CaloRingsLinks clRingsLinks;
85 if ( m_particle_has_cluster ) {
86 // We'll assume to have one CaloRings for each cluster, reserve memory for
88 clRingsLinks.reserve( clustersLinks.size() );
90 unsigned int cl_counter = 0;
92 // Loop over them to build CaloRings:
93 for ( const auto& clusLink : clustersLinks) {
95 ATH_MSG_DEBUG("Reading particle cluster " << ++cl_counter << "/"
96 << clustersLinks.size());
98 // This cluster CaloRings:
99 ElementLink<xAOD::CaloRingsContainer> ringsEL;
101 if (this->m_builder->execute( **clusLink, ringsEL ).isFailure()){
102 throw std::runtime_error("Error while executing CaloRings builder.");
106 clRingsLinks.push_back( ringsEL );
112 // The CaloRings ElementLink:
113 ElementLink<xAOD::CaloRingsContainer> ringsEL;
115 if (m_builder->execute( *part, ringsEL ).isFailure()){
116 throw std::runtime_error("Error while executing CaloRings builder.");
120 clRingsLinks.push_back( ringsEL );
124 // Decorate particle with CaloRings:
125 m_decor->operator()( *part ) = clRingsLinks;
131 // =====================================================================================
132 template<typename container_t>
133 StatusCode BuildCaloRingsFctor<container_t>::initialize()
135 ATH_CHECK( m_decorKey.initialize() );
136 m_decorKey.owner()->declare(m_decorKey);
137 return StatusCode::SUCCESS;
141 } // namespace Ringer
143 #endif // CALORINGERTOOLS_RINGERREADERUTILS_ICC
145 // vim: filetype=cpp: