ATLAS Offline Software
Loading...
Searching...
No Matches
CaloTowerAlgorithm.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
5
6// Gaudi includes
7#include "GaudiKernel/IChronoStatSvc.h"
8
10
12#include "CaloEvent/CaloTowerContainer.h"
13#include "CaloTowerAlgorithm.h"
14
15#include <string>
16#include <vector>
17#include <iomanip>
18
20 ISvcLocator* pSvcLocator)
21 : AthReentrantAlgorithm(name,pSvcLocator)
22 , m_chrono("ChronoStatSvc", name)
23 , m_doChronoStat(true)
24 , m_nEtaTowers(50)
25 , m_nPhiTowers(64)
26 , m_minEta(-2.5)
27 , m_maxEta(2.5)
28 , m_genericLink(true)
29 , m_ptools( this )
31{
32 // chrono
33 declareProperty("EnableChronoStat", m_doChronoStat);
34 // tool names
35 //declareProperty("TowerBuilderTools",m_toolNames);
36 declareProperty("TowerBuilderTools",m_ptools);
37 // output data
38 declareProperty("TowerContainerName",m_towerContainerKey);
39 // tower grid
40 declareProperty("NumberOfEtaTowers",m_nEtaTowers);
41 declareProperty("NumberOfPhiTowers",m_nPhiTowers);
42 declareProperty("EtaMin",m_minEta);
43 declareProperty("EtaMax",m_maxEta);
44 // linkable
45 declareProperty("GenericLinked",m_genericLink);
46}
47
49= default;
50
52// Initialize //
54
56{
57 // Retrieve ChronoStatSvc
58 if (m_doChronoStat) {
59 ATH_CHECK( m_chrono.retrieve() );
60 }
61
62 ATH_CHECK(m_towerContainerKey.initialize());
64 // Allocate Tools //
66
67 // check tool names
68 if (m_ptools.empty()) {
69 ATH_MSG_ERROR(" no tools given for this algorithm.");
70 return StatusCode::FAILURE;
71 }
72
73 // find tools
74
75
77
78
79 unsigned int toolCtr = 0;
80 ATH_MSG_INFO(" ");
81 ATH_MSG_INFO("List of tools in execution sequence:");
82 ATH_MSG_INFO("------------------------------------");
83
84 ATH_CHECK(m_ptools.retrieve());
85
86 for (ToolHandle<ICaloTowerBuilderToolBase>& tool : m_ptools) {
87 toolCtr++;
88
89 ATH_MSG_INFO(std::setw(2) << toolCtr << ".) " << tool->type()
90 << "::name() = \042" << tool->name() << "\042");
91
92 ATH_MSG_INFO("------------------------------------");
93 ATH_MSG_INFO(" ");
94
95 ATH_MSG_DEBUG(" set correct tower seg for this tool "
96 << tool->name());
97
98 tool->setTowerSeg(theTowerSeg);
99
100// if (tool->initializeTool().isFailure()) {
101// ATH_MSG_WARNING(" Tool failed to initialize");
102// }
103
104 } //close iteration over tools
105 return StatusCode::SUCCESS;
106}
107
109// Execute //
111
112StatusCode CaloTowerAlgorithm::execute (const EventContext& ctx) const
113{
114
116 // Tool Processing //
118
120
122 ATH_CHECK( theTowers.record(std::make_unique<CaloTowerContainer>(theTowerSeg)) );
123
124
125 ToolHandleArray<ICaloTowerBuilderToolBase>::const_iterator firstITool = m_ptools.begin();
126 ToolHandleArray<ICaloTowerBuilderToolBase>::const_iterator lastITool = m_ptools.end();
127 StatusCode processStatus = StatusCode::SUCCESS;
128 //
129 // loop stops only when Failure indicated by one of the tools
130 //
131
132 ATH_MSG_DEBUG("In execute() ");
133
134 while (!processStatus.isFailure() && firstITool != lastITool) {
135
136 if (m_doChronoStat) {
137 m_chrono->chronoStart((*firstITool)->name());
138 }
139
140 processStatus = (*firstITool)->execute(ctx, theTowers.ptr());
141
142 if (m_doChronoStat) {
143 m_chrono->chronoStop((*firstITool)->name());
144 }
145 if (!processStatus.isFailure()) {
146 ATH_MSG_DEBUG((*firstITool)->name()
147 << ": CaloTowerContainer::size() = " << theTowers->size());
148
149 ++firstITool;
150 } else {
151 // some problem - but do not skip event loop!
152 ATH_MSG_ERROR("problems while or after processing tool \042"
153 << (*firstITool)->name()
154 << "\042 - cross-check CaloTowerContainer::size() = "
155 << theTowers->size());
156
157 ++firstITool;
158 }
159 }
160
161 return StatusCode::SUCCESS;
162}
163
165// Finalize //
167
169{
170 return StatusCode::SUCCESS;
171}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
Helpers for checking error return status codes and reporting errors.
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
An algorithm that can be simultaneously executed in multiple threads.
SG::WriteHandleKey< CaloTowerContainer > m_towerContainerKey
ServiceHandle< IChronoStatSvc > m_chrono
virtual StatusCode finalize() override
virtual ~CaloTowerAlgorithm()
virtual StatusCode initialize() override
inherited from Algorithm
ToolHandleArray< ICaloTowerBuilderToolBase > m_ptools
virtual StatusCode execute(const EventContext &ctx) const override
CaloTowerAlgorithm(const std::string &name, ISvcLocator *pService)
Algorithm constructor.
Data object stores CaloTower segmentation.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
pointer_type ptr()
Dereference the pointer.