ATLAS Offline Software
TBAlgoSequencer.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
6 #include "TBAlgoSequencer.h"
7 #include "GaudiKernel/ListItem.h"
8 
9 #include <string>
10 #include <map>
11 #include <iostream>
12 
14 // Constructors and Destructor //
16 
18  ISvcLocator* pSvcLocator) :
19  ::AthLegacySequence ( name, pSvcLocator )
20  , m_timingOn(true)
21  , m_eventPrintFreq(100)
22  , m_eventCounter(0)
23  , m_rejectCounter(0)
24  , m_rejectNoEvent(0)
25  {
26  // job options
27  declareProperty("SubAlgorithms", m_subAlgoNames);
28  declareProperty("PrintFrequency", m_eventPrintFreq);
29  declareProperty("TimingOn", m_timingOn);
30 }
31 
33 { }
34 
36 // Initialization //
38 
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 
52  StatusCode registerAlgs;
53  unsigned int numberOfAlgorithms = 0;
54  unsigned int acceptedAlgos = 0;
55  while ( numberOfAlgorithms < m_subAlgoNames.size() &&
56  ! registerAlgs.isFailure() )
57  {
58  ListItem 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  std::string myName = theAlgItem.name();
66  m_subAlgos[acceptedAlgos] = theAlgo;
67  m_algoNameStore[acceptedAlgos] = myName;
69  ( "Subalgorithm ("
70  << std::setw(2)
71  << acceptedAlgos
72  << ") ... created type/name ... "
73  << theAlgItem.type()
74  << "/"
75  << theAlgItem.name() );
76  // set common properties
77  // theAlgo->
78  // setProperty(StringProperty("EventHeaderKey",m_eventHeaderKey));
79  // theAlgo->initialize();
80  // register algorithm with accumulators
81  m_rejectPattern[m_algoNameStore[acceptedAlgos]] = 0;
82  m_acceptPattern[m_algoNameStore[acceptedAlgos]] = 0;
83  // increment accepted algo counter
84  acceptedAlgos++;
85  }
86  numberOfAlgorithms++;
87  ++subAlgos;
88  }
89 
91  // Prepare Statistics //
93 
94  m_rejectPattern.clear();
95 
96  // return numberOfAlgorithms > 0
97  // ? StatusCode::SUCCESS
98  // : StatusCode::FAILURE;
99 
100  if (numberOfAlgorithms == 0) return StatusCode::FAILURE;
101 
103 
104 }
105 
107 // Execute //
109 
112 {
113  IChronoStatSvc* theTicker = chronoSvc();
114 
115  m_timingOn = theTicker != 0 && m_timingOn;
116 
118  // Event Statistics //
120 
121  m_eventCounter++;
122 
123  if ( m_eventCounter == 1 || m_eventCounter % m_eventPrintFreq == 0 )
124  {
126  ( "Number of events processed: "
127  << std::setw(9)
128  << m_eventCounter );
129  // << ", this event: Run "
130  // << setw(6)
131  // << theEvent->getRunNumber()
132  // << " Event "
133  // << setw(6)
134  // << theEvent->getEventNumber()
135  // << endmsg;
136  }
137 
139  // Algorithm Loop //
141 
142  AlgoIterator algoCounter = m_subAlgos.begin();
143  StatusCode executeAlgs;
144 
145  const EventContext& ctx = getContext();
146 
147  unsigned int algoIndex = 0;
148  while ( ! executeAlgs.isFailure() && algoCounter != m_subAlgos.end() )
149  {
150  // execute the algorithm
151  if ( m_timingOn ) theTicker->chronoStart(m_algoNameStore[algoIndex]);
152  executeAlgs = (*algoCounter)->execute(ctx);
153  if ( m_timingOn ) theTicker->chronoStop(m_algoNameStore[algoIndex]);
154  // failure/reject
155  if ( executeAlgs.isFailure() )
156  {
157  m_rejectPattern[m_algoNameStore[algoIndex]]++;
158  m_rejectCounter++;
159  }
160  else
161  {
162  m_acceptPattern[m_algoNameStore[algoIndex]]++;
163  }
164  // iterator and counter increments
165  algoIndex++;
166  ++algoCounter;
167  }
168  // this is the trick - catch it before the framework terminates the job!
169  return StatusCode::SUCCESS;
170 }
171 
173 // Finalize //
175 
178 {
180  // Summary on Accepts/Rejects //
182 
183  double allReject = m_eventCounter > 0
185  : 100.;
186  double noEvtReject = m_eventCounter > 0
188  : 100;
189 
191  ( "======================================================== " );
193  ( "Total events analyzed .................: "
194  << std::setw(6)
195  << m_eventCounter );
196  ATH_MSG_INFO
197  ( "Total events rejected .................: "
198  << std::setw(6)
199  << m_rejectCounter
200  << " ("
201  // << fixed()
202  << allReject
203  << " %)" );
205  ( "Events without EventHeader (rejected) .: "
206  << std::setw(6)
207  << m_rejectNoEvent
208  << " ("
209  // << fixed()
210  << noEvtReject
211  << " %)" );
213  ( "-------------------------------------------------------- " );
215  ( "Reject patterns: " );
217  ( "-------------------------------------------------------- " );
218 
219  for (const std::pair<const std::string, unsigned int>& p : m_rejectPattern)
220  {
221  double percentReject = m_eventCounter > 0
222  ? ((double)p.second)/((double)m_eventCounter)*100.
223  : 100;
224  msg() << MSG::INFO
225  << "Algorithm ";
226  msg().width(20);
227  msg() << MSG::INFO
228  << p.first
229  << " rejected "
230  << std::setw(6)
231  << p.second
232  << " events (";
233  msg() << MSG::INFO
234  << std::setprecision(5)
235  << percentReject
236  << " %)"
237  << endmsg;
238  }
240  ( "-------------------------------------------------------- " );
242  ( "Accept patterns: " );
244  ( "-------------------------------------------------------- " );
245  for (const std::pair<const std::string, unsigned int>& p : m_acceptPattern)
246  {
247  double percentAccept = m_eventCounter > 0
248  ? ((double)p.second)/((double)m_eventCounter)*100.
249  : 100;
250  msg() << MSG::INFO
251  << "Algorithm ";
252  msg().width(20);
253  msg() << MSG::INFO
254  << p.first
255  << " accepted "
256  << std::setw(6)
257  << p.second
258  << " events (";
259  msg().setf(std::ios::fixed);
260  msg() << MSG::INFO
261  << std::setprecision(5)
262  << percentAccept
263  << " %)"
264  << endmsg;
265  }
267  ( "======================================================== " );
268 
269 
271 
272 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
Athena::details::AthLegacySequenceAdapter::getContext
const EventContext & getContext() const
Definition: AthLegacySequence.h:36
python.tests.PyTestsLib.finalize
def finalize(self)
_info( "content of StoreGate..." ) self.sg.dump()
Definition: PyTestsLib.py:53
TBAlgoSequencer::m_eventPrintFreq
unsigned int m_eventPrintFreq
Definition: TBAlgoSequencer.h:52
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
TBAlgoSequencer::m_rejectCounter
unsigned int m_rejectCounter
Definition: TBAlgoSequencer.h:54
AthCommonDataStore< AthCommonMsg< Gaudi::Sequence > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
initialize
void initialize()
Definition: run_EoverP.cxx:894
TBAlgoSequencer::m_subAlgoNames
std::vector< std::string > m_subAlgoNames
Definition: TBAlgoSequencer.h:43
python.FakeAthena.Algorithm
def Algorithm(name)
Definition: FakeAthena.py:41
TBAlgoSequencer::AlgoIterator
AlgoStore::iterator AlgoIterator
Definition: TBAlgoSequencer.h:26
TBAlgoSequencer::m_subAlgos
AlgoStore m_subAlgos
Definition: TBAlgoSequencer.h:44
TBAlgoSequencer::initialize
virtual StatusCode initialize() override
Definition: TBAlgoSequencer.cxx:40
TBAlgoSequencer::~TBAlgoSequencer
virtual ~TBAlgoSequencer()
Definition: TBAlgoSequencer.cxx:32
AthLegacySequence
Alias for backward compatibility.
Definition: AthLegacySequence.h:63
TBAlgoSequencer::finalize
virtual StatusCode finalize() override
Definition: TBAlgoSequencer.cxx:177
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
TBAlgoSequencer::m_algoNameStore
std::vector< std::string > m_algoNameStore
Definition: TBAlgoSequencer.h:45
TBAlgoSequencer::m_timingOn
bool m_timingOn
Definition: TBAlgoSequencer.h:46
xAOD::double
double
Definition: CompositeParticle_v1.cxx:159
TBAlgoSequencer.h
TBAlgoSequencer::TBAlgoSequencer
TBAlgoSequencer(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TBAlgoSequencer.cxx:17
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
TBAlgoSequencer::m_rejectNoEvent
unsigned int m_rejectNoEvent
Definition: TBAlgoSequencer.h:55
TBAlgoSequencer::m_acceptPattern
std::map< std::string, unsigned int > m_acceptPattern
Definition: TBAlgoSequencer.h:57
AthCommonMsg< Gaudi::Sequence >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
TBAlgoSequencer::execute
virtual StatusCode execute() override
Definition: TBAlgoSequencer.cxx:111
TBAlgoSequencer::m_eventCounter
unsigned int m_eventCounter
Definition: TBAlgoSequencer.h:53
TBAlgoSequencer::m_rejectPattern
std::map< std::string, unsigned int > m_rejectPattern
Definition: TBAlgoSequencer.h:56