ATLAS Offline Software
Loading...
Searching...
No Matches
TBAlgoSequencer.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5
6#include "TBAlgoSequencer.h"
7#include "GaudiKernel/TypeNameString.h"
8
9#include <string>
10#include <map>
11#include <iostream>
12
14// Constructors and Destructor //
16
17TBAlgoSequencer::TBAlgoSequencer(const std::string& name,
18 ISvcLocator* pSvcLocator) :
19 ::AthLegacySequence ( name, pSvcLocator )
20 , m_timingOn(true)
21 , m_eventPrintFreq(100)
25 {
26 // job options
27 declareProperty("SubAlgorithms", m_subAlgoNames);
28 declareProperty("PrintFrequency", m_eventPrintFreq);
29 declareProperty("TimingOn", m_timingOn);
30}
31
34
36// Initialization //
38
39StatusCode
41{
42 ATH_MSG_INFO ( "initialize..." );
43
45 // Register and Initialize (Sub)Algorithms //
47
48 m_algoNameStore.resize(m_subAlgoNames.size());
49 m_subAlgos.resize(m_subAlgoNames.size());
50
51 std::vector<std::string>::iterator subAlgos = m_subAlgoNames.begin();
52 StatusCode registerAlgs;
53 unsigned int numberOfAlgorithms = 0;
54 unsigned int acceptedAlgos = 0;
55 while ( numberOfAlgorithms < m_subAlgoNames.size() &&
56 ! registerAlgs.isFailure() )
57 {
58 Gaudi::Utils::TypeNameString theAlgItem(*subAlgos);
59 Gaudi::Algorithm* theAlgo;
60 registerAlgs = createSubAlgorithm(theAlgItem.type(),theAlgItem.name(),
61 theAlgo);
62 if ( ! registerAlgs.isFailure() && theAlgo != 0 )
63 {
64 // store sub-algo
65 m_subAlgos[acceptedAlgos] = theAlgo;
66 m_algoNameStore[acceptedAlgos] = theAlgItem.name();
68 ( "Subalgorithm ("
69 << std::setw(2)
70 << acceptedAlgos
71 << ") ... created type/name ... "
72 << theAlgItem.type()
73 << "/"
74 << theAlgItem.name() );
75 // set common properties
76 // theAlgo->
77 // setProperty(StringProperty("EventHeaderKey",m_eventHeaderKey));
78 // theAlgo->initialize();
79 // register algorithm with accumulators
80 m_rejectPattern[m_algoNameStore[acceptedAlgos]] = 0;
81 m_acceptPattern[m_algoNameStore[acceptedAlgos]] = 0;
82 // increment accepted algo counter
83 acceptedAlgos++;
84 }
85 numberOfAlgorithms++;
86 ++subAlgos;
87 }
88
90 // Prepare Statistics //
92
93 m_rejectPattern.clear();
94
95 // return numberOfAlgorithms > 0
96 // ? StatusCode::SUCCESS
97 // : StatusCode::FAILURE;
98
99 if (numberOfAlgorithms == 0) return StatusCode::FAILURE;
100
101 return AthLegacySequence::initialize();
102
103}
104
106// Execute //
108
109StatusCode
111{
112 IChronoStatSvc* theTicker = chronoSvc();
113
114 m_timingOn = theTicker != 0 && m_timingOn;
115
117 // Event Statistics //
119
121
123 {
125 ( "Number of events processed: "
126 << std::setw(9)
127 << m_eventCounter );
128 // << ", this event: Run "
129 // << setw(6)
130 // << theEvent->getRunNumber()
131 // << " Event "
132 // << setw(6)
133 // << theEvent->getEventNumber()
134 // << endmsg;
135 }
136
138 // Algorithm Loop //
140
141 AlgoIterator algoCounter = m_subAlgos.begin();
142 StatusCode executeAlgs;
143
144 const EventContext& ctx = getContext();
145
146 unsigned int algoIndex = 0;
147 while ( ! executeAlgs.isFailure() && algoCounter != m_subAlgos.end() )
148 {
149 // execute the algorithm
150 if ( m_timingOn ) theTicker->chronoStart(m_algoNameStore[algoIndex]);
151 executeAlgs = (*algoCounter)->execute(ctx);
152 if ( m_timingOn ) theTicker->chronoStop(m_algoNameStore[algoIndex]);
153 // failure/reject
154 if ( executeAlgs.isFailure() )
155 {
156 m_rejectPattern[m_algoNameStore[algoIndex]]++;
158 }
159 else
160 {
161 m_acceptPattern[m_algoNameStore[algoIndex]]++;
162 }
163 // iterator and counter increments
164 algoIndex++;
165 ++algoCounter;
166 }
167 // this is the trick - catch it before the framework terminates the job!
168 return StatusCode::SUCCESS;
169}
170
172// Finalize //
174
175StatusCode
177{
179 // Summary on Accepts/Rejects //
181
182 double allReject = m_eventCounter > 0
183 ? ((double)m_rejectCounter)/((double)m_eventCounter)*100.
184 : 100.;
185 double noEvtReject = m_eventCounter > 0
186 ? ((double)m_rejectNoEvent)/((double)m_eventCounter)*100.
187 : 100;
188
190 ( "======================================================== " );
192 ( "Total events analyzed .................: "
193 << std::setw(6)
194 << m_eventCounter );
196 ( "Total events rejected .................: "
197 << std::setw(6)
199 << " ("
200 // << fixed()
201 << allReject
202 << " %)" );
204 ( "Events without EventHeader (rejected) .: "
205 << std::setw(6)
207 << " ("
208 // << fixed()
209 << noEvtReject
210 << " %)" );
212 ( "-------------------------------------------------------- " );
214 ( "Reject patterns: " );
216 ( "-------------------------------------------------------- " );
217
218 for (const std::pair<const std::string, unsigned int>& p : m_rejectPattern)
219 {
220 double percentReject = m_eventCounter > 0
221 ? ((double)p.second)/((double)m_eventCounter)*100.
222 : 100;
223 msg() << MSG::INFO
224 << "Algorithm ";
225 msg().width(20);
226 msg() << MSG::INFO
227 << p.first
228 << " rejected "
229 << std::setw(6)
230 << p.second
231 << " events (";
232 msg() << MSG::INFO
233 << std::setprecision(5)
234 << percentReject
235 << " %)"
236 << endmsg;
237 }
239 ( "-------------------------------------------------------- " );
241 ( "Accept patterns: " );
243 ( "-------------------------------------------------------- " );
244 for (const std::pair<const std::string, unsigned int>& p : m_acceptPattern)
245 {
246 double percentAccept = m_eventCounter > 0
247 ? ((double)p.second)/((double)m_eventCounter)*100.
248 : 100;
249 msg() << MSG::INFO
250 << "Algorithm ";
251 msg().width(20);
252 msg() << MSG::INFO
253 << p.first
254 << " accepted "
255 << std::setw(6)
256 << p.second
257 << " events (";
258 msg().setf(std::ios::fixed);
259 msg() << MSG::INFO
260 << std::setprecision(5)
261 << percentAccept
262 << " %)"
263 << endmsg;
264 }
266 ( "======================================================== " );
267
268
269 return AthLegacySequence::finalize();
270
271}
#define endmsg
#define ATH_MSG_INFO(x)
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Alias for backward compatibility.
const EventContext & getContext() const
unsigned int m_rejectCounter
std::map< std::string, unsigned int > m_rejectPattern
std::map< std::string, unsigned int > m_acceptPattern
unsigned int m_rejectNoEvent
virtual StatusCode initialize() override
virtual StatusCode execute() override
unsigned int m_eventPrintFreq
virtual StatusCode finalize() override
TBAlgoSequencer(const std::string &name, ISvcLocator *pSvcLocator)
unsigned int m_eventCounter
AlgoStore::iterator AlgoIterator
virtual ~TBAlgoSequencer()
std::vector< std::string > m_algoNameStore
std::vector< std::string > m_subAlgoNames
MsgStream & msg
Definition testRead.cxx:32