ATLAS Offline Software
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 
11 #include "CaloEvent/CaloTowerSeg.h"
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 )
30  , m_towerContainerKey("")
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 
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 
112 StatusCode 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 }
CaloTowerAlgorithm::m_chrono
ServiceHandle< IChronoStatSvc > m_chrono
Definition: CaloTowerAlgorithm.h:59
CaloTowerAlgorithm::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: CaloTowerAlgorithm.cxx:112
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
CaloTowerAlgorithm::m_nEtaTowers
unsigned int m_nEtaTowers
Definition: CaloTowerAlgorithm.h:63
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
CaloTowerAlgorithm.h
CaloTowerAlgorithm::m_maxEta
double m_maxEta
Definition: CaloTowerAlgorithm.h:65
CaloTowerSeg.h
CaloTowerAlgorithm::CaloTowerAlgorithm
CaloTowerAlgorithm(const std::string &name, ISvcLocator *pService)
Algorithm constructor.
Definition: CaloTowerAlgorithm.cxx:19
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
CaloTowerAlgorithm::m_ptools
ToolHandleArray< ICaloTowerBuilderToolBase > m_ptools
Definition: CaloTowerAlgorithm.h:72
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
CaloTowerAlgorithm::~CaloTowerAlgorithm
virtual ~CaloTowerAlgorithm()
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::WriteHandle::ptr
pointer_type ptr()
Dereference the pointer.
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CaloTowerAlgorithm::m_minEta
double m_minEta
Definition: CaloTowerAlgorithm.h:65
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
CaloTowerAlgorithm::finalize
virtual StatusCode finalize() override
Definition: CaloTowerAlgorithm.cxx:168
CaloTowerAlgorithm::m_genericLink
bool m_genericLink
Definition: CaloTowerAlgorithm.h:68
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
errorcheck.h
Helpers for checking error return status codes and reporting errors.
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
CaloTowerAlgorithm::m_towerContainerKey
SG::WriteHandleKey< CaloTowerContainer > m_towerContainerKey
Definition: CaloTowerAlgorithm.h:74
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
CaloTowerAlgorithm::initialize
virtual StatusCode initialize() override
inherited from Algorithm
Definition: CaloTowerAlgorithm.cxx:55
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
CaloTowerSeg
Data object stores CaloTower segmentation.
Definition: CaloTowerSeg.h:37
CaloTowerAlgorithm::m_doChronoStat
bool m_doChronoStat
Definition: CaloTowerAlgorithm.h:60
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
CaloTowerAlgorithm::m_nPhiTowers
unsigned int m_nPhiTowers
Definition: CaloTowerAlgorithm.h:64