ATLAS Offline Software
Loading...
Searching...
No Matches
AnaAlgorithm.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7
8
9//
10// includes
11//
12
14
16#include <TH1.h>
17#include <TH2.h>
18#include <TH3.h>
19#include <TEfficiency.h>
20#include <stdexcept>
21
22#ifdef XAOD_STANDALONE
26#endif
27
28#ifndef XAOD_STANDALONE
29#include <GaudiKernel/IIncidentSvc.h>
30#include <GaudiKernel/ServiceHandle.h>
31#endif
32
33//
34// method implementations
35//
36
37namespace EL
38{
39 AnaAlgorithm ::
40 AnaAlgorithm (const std::string& name,
41 ISvcLocator*
42#ifndef XAOD_STANDALONE
43 pSvcLocator
44#endif
45 )
46#ifdef XAOD_STANDALONE
47 : AsgComponent (name)
50#else
51 : AthHistogramAlgorithm (name, pSvcLocator)
52 , m_inputMetaStore ("StoreGateSvc/InputMetaDataStore", name)
53 , m_outputMetaStore ("StoreGateSvc/MetaDataStore", name)
54#endif
55 {
56#ifdef XAOD_STANDALONE
57 declareProperty ("RootStreamName", m_treeStreamName = "ANALYSIS",
58 "Name of the stream to put trees into");
59#endif
60
61 ANA_MSG_DEBUG ("AnaAlgorithm: " << name);
62 }
63
64
65
67 {
68#ifdef XAOD_STANDALONE
69 return &m_inputMetaStore;
70#else
71 return m_inputMetaStore;
72#endif // XAOD_STANDALONE
73 }
74
76 {
77#ifdef XAOD_STANDALONE
78 return &m_inputMetaStore;
79#else
80 return m_inputMetaStore;
81#endif // XAOD_STANDALONE
82 }
83
84
85
87 {
88#ifdef XAOD_STANDALONE
89 return &m_outputMetaStore;
90#else
91 return m_outputMetaStore;
92#endif // XAOD_STANDALONE
93 }
94
96 {
97#ifdef XAOD_STANDALONE
98 return &m_outputMetaStore;
99#else
100 return m_outputMetaStore;
101#endif // XAOD_STANDALONE
102 }
103
104
105
106#ifdef XAOD_STANDALONE
107 asg::SgEvent *AnaAlgorithm ::
108 evtStore () const
109 {
110 if (!m_evtStore)
111 throw std::logic_error ("no evtStore set on algorithm " + name());
112 return m_evtStore;
113 }
114
115
116
117 ::StatusCode AnaAlgorithm ::
118 book (const TH1& hist)
119 {
120 histogramWorker()->addOutput (hist.Clone());
121 return ::StatusCode::SUCCESS;
122 }
123
124
125
126 ::StatusCode AnaAlgorithm ::
127 book (const TEfficiency& hist)
128 {
129 histogramWorker()->addOutput (hist.Clone());
130 return ::StatusCode::SUCCESS;
131 }
132
133
134
135 template<> TObject *AnaAlgorithm ::
136 hist<TObject> (const std::string& name) const
137 {
138 return histogramWorker()->getOutputHist (name);
139 }
140
141
142
143 TH2 *AnaAlgorithm ::
144 hist2d (const std::string& name) const
145 {
146 return hist<TH2>(name);
147 }
148
149
150
151 TH3 *AnaAlgorithm ::
152 hist3d (const std::string& name) const
153 {
154 return hist<TH3>(name);
155 }
156
157
158
159 TEfficiency *AnaAlgorithm ::
160 histeff (const std::string& name) const
161 {
162 return hist<TEfficiency>(name);
163 }
164
165
166
167 IHistogramWorker *AnaAlgorithm ::
168 histogramWorker () const
169 {
170 if (!m_histogramWorker)
171 throw std::logic_error ("no histogram worker set on algorithm " + name());
172 return m_histogramWorker;
173 }
174
175
176
177 ::StatusCode AnaAlgorithm ::
178 book (const TTree& tree)
179 {
181 ANA_CHECK( treeWorker()->addTree( tree, m_treeStreamName ) );
182 return ::StatusCode::SUCCESS;
183 }
184
185
186
187 TTree *AnaAlgorithm ::
188 tree (const std::string& name) const
189 {
190 return treeWorker()->getOutputTree( name, m_treeStreamName );
191 }
192
193
194
195 ITreeWorker *AnaAlgorithm ::
196 treeWorker () const
197 {
198 if( ! m_treeWorker ) {
199 throw std::logic_error( "no tree worker set on algorithm " + name() );
200 }
201 return m_treeWorker;
202 }
203
204
205
206 bool AnaAlgorithm ::
207 filterPassed() const
208 {
209 return filterWorker()->filterPassed();
210 }
211
212
213
214 void AnaAlgorithm ::
215 setFilterPassed (bool val_filterPassed)
216 {
217 filterWorker()->setFilterPassed (val_filterPassed);
218 }
219
220
221
222 IFilterWorker *AnaAlgorithm ::
223 filterWorker () const
224 {
225 if (!m_filterWorker)
226 throw std::logic_error ("no filter worker set on algorithm " + name());
227 return m_filterWorker;
228 }
229
230
231
232 IWorker *AnaAlgorithm ::
233 wk () const
234 {
235 if (!m_wk)
236 throw std::logic_error ("no worker set on algorithm " + name());
237 return m_wk;
238 }
239#endif
240
241
242
243 StatusCode AnaAlgorithm ::
244 requestFileExecute ()
245 {
246 m_hasFileExecute = true;
247
248#ifndef XAOD_STANDALONE
249 // Connect to the IncidentSvc:
250 ServiceHandle< IIncidentSvc > incSvc( "IncidentSvc", name() );
251 ATH_CHECK( incSvc.retrieve() );
252
253 // Set up the right callback, but ensure we don't double-register
254 // if we are called twice
255 incSvc->removeListener( this, IncidentType::BeginInputFile );
256 incSvc->addListener( this, IncidentType::BeginInputFile, 0, true );
257#endif
258
259 return StatusCode::SUCCESS;
260 }
261
262
263
264 StatusCode AnaAlgorithm ::
265 requestBeginInputFile ()
266 {
267 m_hasBeginInputFile = true;
268
269#ifndef XAOD_STANDALONE
270 // Connect to the IncidentSvc:
271 ServiceHandle< IIncidentSvc > incSvc( "IncidentSvc", name() );
272 ATH_CHECK( incSvc.retrieve() );
273
274 // Set up the right callback, but ensure we don't double-register
275 // if we are called twice
276 incSvc->removeListener( this, IncidentType::BeginInputFile );
277 incSvc->addListener( this, IncidentType::BeginInputFile, 0, true );
278#endif
279
280 return StatusCode::SUCCESS;
281 }
282
283
284
285 StatusCode AnaAlgorithm ::
286 requestEndInputFile ()
287 {
288 m_hasEndInputFile = true;
289
290#ifndef XAOD_STANDALONE
291 // Connect to the IncidentSvc:
292 ServiceHandle< IIncidentSvc > incSvc( "IncidentSvc", name() );
293 ATH_CHECK( incSvc.retrieve() );
294
295 // Set up the right callback, but ensure we don't double-register
296 // if we are called twice
297 incSvc->removeListener( this, IncidentType::EndInputFile );
298 incSvc->addListener( this, IncidentType::EndInputFile, 0, true );
299#endif
300
301 return StatusCode::SUCCESS;
302 }
303
304
305
306 ::StatusCode AnaAlgorithm ::
307 initialize ()
308 {
309 return StatusCode::SUCCESS;
310 }
311
312
313
314 ::StatusCode AnaAlgorithm ::
315 execute ()
316 {
317 return StatusCode::SUCCESS;
318 }
319
320
321
322 ::StatusCode AnaAlgorithm ::
323 execute (const EventContext& /*ctx*/)
324 {
325 // By default we invoke the deprecated method:
326 return execute();
327 }
328
329
330
331 ::StatusCode AnaAlgorithm ::
332 finalize ()
333 {
334 return StatusCode::SUCCESS;
335 }
336
337
338
339 void AnaAlgorithm ::
340 print () const
341 {}
342
343
344
345 ::StatusCode AnaAlgorithm ::
346 fileExecute ()
347 {
348 return StatusCode::SUCCESS;
349 }
350
351
352
353 ::StatusCode AnaAlgorithm ::
354 beginInputFile ()
355 {
356 return StatusCode::SUCCESS;
357 }
358
359
360
361 ::StatusCode AnaAlgorithm ::
362 endInputFile ()
363 {
364 return StatusCode::SUCCESS;
365 }
366
367
368
369#ifdef XAOD_STANDALONE
370 ::StatusCode AnaAlgorithm ::
371 sysInitialize ()
372 {
373 return initialize ();
374 }
375
376
377
378 ::StatusCode AnaAlgorithm ::
379 sysExecute (const EventContext& ctx)
380 {
381 return execute (ctx);
382 }
383
384
385
386 ::StatusCode AnaAlgorithm ::
387 sysFinalize ()
388 {
389 return finalize ();
390 }
391
392
393
394 void AnaAlgorithm ::
395 sysPrint ()
396 {
397 print ();
398 }
399
400
401
402 ::StatusCode AnaAlgorithm ::
403 sysFileExecute ()
404 {
405 if (m_hasFileExecute == false)
406 {
407 ANA_MSG_FATAL ("called fileExecute(), though it was not registered");
408 return StatusCode::FAILURE;
409 }
410 return fileExecute ();
411 }
412
413
414
415 ::StatusCode AnaAlgorithm ::
416 sysBeginInputFile ()
417 {
418 if (m_hasBeginInputFile == false)
419 {
420 ANA_MSG_FATAL ("called beginInputFile(), though it was not registered");
421 return StatusCode::FAILURE;
422 }
423 return beginInputFile ();
424 }
425
426
427
428 ::StatusCode AnaAlgorithm ::
429 sysEndInputFile ()
430 {
431 if (m_hasEndInputFile == false)
432 {
433 ANA_MSG_FATAL ("called endInputFile(), though it was not registered");
434 return StatusCode::FAILURE;
435 }
436 return endInputFile ();
437 }
438
439
440
441 void AnaAlgorithm ::
442 setEvtStore (asg::SgEvent *val_evtStore)
443 {
444 if (m_evtStore)
445 throw std::logic_error ("set evtStore twice on algorithm " + name());
446 m_evtStore = val_evtStore;
447 m_inputMetaStore = asg::SgEventMeta (asg::SgEventMeta::InputStore,
448 val_evtStore->event());
449 m_outputMetaStore = asg::SgEventMeta (asg::SgEventMeta::OutputStore,
450 val_evtStore->event());
451 }
452
453
454
455 void AnaAlgorithm ::
456 setHistogramWorker (IHistogramWorker *val_histogramWorker)
457 {
458 if (m_histogramWorker)
459 throw std::logic_error ("set histogram worker twice on algorithm " + name());
460 m_histogramWorker = val_histogramWorker;
461 }
462
463
464
465 void AnaAlgorithm ::
466 setTreeWorker (ITreeWorker *val_treeWorker)
467 {
468 if( m_treeWorker ) {
469 throw std::logic_error( "set tree worker twice on algorithm " +
470 name() );
471 }
472 m_treeWorker = val_treeWorker;
473 }
474
475
476
477 void AnaAlgorithm ::
478 setFilterWorker (IFilterWorker *val_filterWorker)
479 {
480 if (m_filterWorker)
481 throw std::logic_error ("set filter worker twice on algorithm " + name());
482 m_filterWorker = val_filterWorker;
483 }
484
485
486
487 void AnaAlgorithm ::
488 setWk (IWorker *val_wk)
489 {
490 if (m_wk)
491 throw std::logic_error ("set wk twice on algorithm " + name());
492 m_wk = val_wk;
493 }
494
495
496
497 bool AnaAlgorithm ::
498 hasFileExecute () const noexcept
499 {
500 return m_hasFileExecute;
501 }
502
503
504
505 bool AnaAlgorithm ::
506 hasBeginInputFile () const noexcept
507 {
508 return m_hasBeginInputFile;
509 }
510
511
512
513 bool AnaAlgorithm ::
514 hasEndInputFile () const noexcept
515 {
516 return m_hasEndInputFile;
517 }
518#endif
519
520
521
522#ifndef XAOD_STANDALONE
523 void AnaAlgorithm ::
524 handle (const Incident& inc)
525 {
526 if (inc.type() == IncidentType::BeginInputFile)
527 {
532 } else if (inc.type() == IncidentType::EndInputFile)
533 {
536 } else
537 {
538 ATH_MSG_WARNING( "Unknown incident type received: " << inc.type() );
539 }
540 }
541#endif
542}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x,...)
macros for messaging and checking status codes
#define ANA_MSG_DEBUG(xmsg)
Macro printing debug messages.
#define ANA_CHECK(EXP)
check whether the given expression was successful
#define ANA_MSG_FATAL(xmsg)
Macro printing fatal messages.
#define ANA_CHECK_THROW(EXP)
check whether the given expression was successful, throwing an exception on failure
#define ANA_CHECK_SET_TYPE(TYPE)
set the type for ANA_CHECK to report failures
void print(char *figname, TCanvas *c1)
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
AthHistogramAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
virtual::StatusCode endInputFile()
perform the action for the end of an input file
ConstMetaStorePtr_t inputMetaStore() const
virtual::StatusCode fileExecute()
perform the action exactly once for each file in the dataset
const ServiceHandle< StoreGateSvc > & ConstMetaStorePtr_t
bool m_hasBeginInputFile
the value of hasBeginInputFile
bool m_hasFileExecute
the value of hasFileExecute
MetaStore_t m_outputMetaStore
Object accessing the output metadata store.
ServiceHandle< StoreGateSvc > & MetaStorePtr_t
Type of the metadata store pointer in Athena.
MetaStore_t m_inputMetaStore
Object accessing the input metadata store.
virtual::StatusCode execute()
execute this algorithm
bool m_hasEndInputFile
the value of hasEndInputFile
virtual::StatusCode beginInputFile()
perform the action for the beginning of an input file
ConstMetaStorePtr_t outputMetaStore() const
the interface to the filter functions in the algorithm sequence
the interface to histogram storage on the worker
The interface to TTree storage on the worker.
Definition ITreeWorker.h:32
the interface for algorithms to access IWorker
Definition IWorker.h:40
@ InputStore
This store is used to access the input metadata.
Definition SgEventMeta.h:50
@ OutputStore
This store is used to access the output metadata.
Definition SgEventMeta.h:51
Wrapper for Event to make it look like StoreGate.
Definition SgEvent.h:44
xAOD::Event * event() const
Return the underlying event manager.
Definition SgEvent.cxx:24
This module defines the arguments passed from the BATCH driver to the BATCH worker.
::StatusCode StatusCode
StatusCode definition for legacy code.
finalize(self)
_info( "content of StoreGate..." ) self.sg.dump()
Definition PyTestsLib.py:50
void initialize()
TChain * tree