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
66 AnaAlgorithm ::
67 ~AnaAlgorithm () noexcept
68 {}
69
70
71
73 {
74#ifdef XAOD_STANDALONE
75 return &m_inputMetaStore;
76#else
77 return m_inputMetaStore;
78#endif // XAOD_STANDALONE
79 }
80
82 {
83#ifdef XAOD_STANDALONE
84 return &m_inputMetaStore;
85#else
86 return m_inputMetaStore;
87#endif // XAOD_STANDALONE
88 }
90
91
93 {
94#ifdef XAOD_STANDALONE
95 return &m_outputMetaStore;
96#else
97 return m_outputMetaStore;
98#endif // XAOD_STANDALONE
99 }
100
102 {
103#ifdef XAOD_STANDALONE
104 return &m_outputMetaStore;
105#else
106 return m_outputMetaStore;
107#endif // XAOD_STANDALONE
108 }
109
110
111
112#ifdef XAOD_STANDALONE
113 asg::SgEvent *AnaAlgorithm ::
114 evtStore () const
115 {
116 if (!m_evtStore)
117 throw std::logic_error ("no evtStore set on algorithm " + name());
118 return m_evtStore;
119 }
120
121
122
123 ::StatusCode AnaAlgorithm ::
124 book (const TH1& hist)
125 {
126 histogramWorker()->addOutput (hist.Clone());
127 return ::StatusCode::SUCCESS;
128 }
129
130
131
132 ::StatusCode AnaAlgorithm ::
133 book (const TEfficiency& hist)
134 {
135 histogramWorker()->addOutput (hist.Clone());
136 return ::StatusCode::SUCCESS;
137 }
138
139
140
141 template<> TObject *AnaAlgorithm ::
142 hist<TObject> (const std::string& name) const
143 {
144 return histogramWorker()->getOutputHist (name);
145 }
146
147
148
149 TH2 *AnaAlgorithm ::
150 hist2d (const std::string& name) const
151 {
152 return hist<TH2>(name);
153 }
154
155
156
157 TH3 *AnaAlgorithm ::
158 hist3d (const std::string& name) const
159 {
160 return hist<TH3>(name);
161 }
162
163
164
165 TEfficiency *AnaAlgorithm ::
166 histeff (const std::string& name) const
167 {
168 return hist<TEfficiency>(name);
169 }
170
171
172
173 IHistogramWorker *AnaAlgorithm ::
174 histogramWorker () const
175 {
176 if (!m_histogramWorker)
177 throw std::logic_error ("no histogram worker set on algorithm " + name());
178 return m_histogramWorker;
179 }
180
181
182
183 ::StatusCode AnaAlgorithm ::
184 book (const TTree& tree)
185 {
187 ANA_CHECK( treeWorker()->addTree( tree, m_treeStreamName ) );
188 return ::StatusCode::SUCCESS;
189 }
190
191
192
193 TTree *AnaAlgorithm ::
194 tree (const std::string& name) const
195 {
196 return treeWorker()->getOutputTree( name, m_treeStreamName );
197 }
198
199
200
201 ITreeWorker *AnaAlgorithm ::
202 treeWorker () const
203 {
204 if( ! m_treeWorker ) {
205 throw std::logic_error( "no tree worker set on algorithm " + name() );
206 }
207 return m_treeWorker;
208 }
209
210
211
212 bool AnaAlgorithm ::
213 filterPassed() const
214 {
215 return filterWorker()->filterPassed();
216 }
217
218
219
220 void AnaAlgorithm ::
221 setFilterPassed (bool val_filterPassed)
222 {
223 filterWorker()->setFilterPassed (val_filterPassed);
224 }
225
226
227
228 IFilterWorker *AnaAlgorithm ::
229 filterWorker () const
230 {
231 if (!m_filterWorker)
232 throw std::logic_error ("no filter worker set on algorithm " + name());
233 return m_filterWorker;
234 }
235
236
237
238 IWorker *AnaAlgorithm ::
239 wk () const
240 {
241 if (!m_wk)
242 throw std::logic_error ("no worker set on algorithm " + name());
243 return m_wk;
244 }
245#endif
246
247
248
249 StatusCode AnaAlgorithm ::
250 requestFileExecute ()
251 {
252 m_hasFileExecute = true;
253
254#ifndef XAOD_STANDALONE
255 // Connect to the IncidentSvc:
256 ServiceHandle< IIncidentSvc > incSvc( "IncidentSvc", name() );
257 ATH_CHECK( incSvc.retrieve() );
258
259 // Set up the right callback, but ensure we don't double-register
260 // if we are called twice
261 incSvc->removeListener( this, IncidentType::BeginInputFile );
262 incSvc->addListener( this, IncidentType::BeginInputFile, 0, true );
263#endif
264
265 return StatusCode::SUCCESS;
266 }
267
268
269
270 StatusCode AnaAlgorithm ::
271 requestBeginInputFile ()
272 {
273 m_hasBeginInputFile = true;
274
275#ifndef XAOD_STANDALONE
276 // Connect to the IncidentSvc:
277 ServiceHandle< IIncidentSvc > incSvc( "IncidentSvc", name() );
278 ATH_CHECK( incSvc.retrieve() );
279
280 // Set up the right callback, but ensure we don't double-register
281 // if we are called twice
282 incSvc->removeListener( this, IncidentType::BeginInputFile );
283 incSvc->addListener( this, IncidentType::BeginInputFile, 0, true );
284#endif
285
286 return StatusCode::SUCCESS;
287 }
288
289
290
291 StatusCode AnaAlgorithm ::
292 requestEndInputFile ()
293 {
294 m_hasEndInputFile = true;
295
296#ifndef XAOD_STANDALONE
297 // Connect to the IncidentSvc:
298 ServiceHandle< IIncidentSvc > incSvc( "IncidentSvc", name() );
299 ATH_CHECK( incSvc.retrieve() );
300
301 // Set up the right callback, but ensure we don't double-register
302 // if we are called twice
303 incSvc->removeListener( this, IncidentType::EndInputFile );
304 incSvc->addListener( this, IncidentType::EndInputFile, 0, true );
305#endif
306
307 return StatusCode::SUCCESS;
308 }
309
310
311
312 ::StatusCode AnaAlgorithm ::
313 initialize ()
314 {
315 return StatusCode::SUCCESS;
316 }
317
318
319
320 ::StatusCode AnaAlgorithm ::
321 execute ()
322 {
323 return StatusCode::SUCCESS;
324 }
325
326
327
328 ::StatusCode AnaAlgorithm ::
329 execute (const EventContext& /*ctx*/)
330 {
331 // By default we invoke the deprecated method:
332 return execute();
333 }
334
335
336
337 ::StatusCode AnaAlgorithm ::
338 finalize ()
339 {
340 return StatusCode::SUCCESS;
341 }
342
343
344
345 void AnaAlgorithm ::
346 print () const
347 {}
348
349
350
351 ::StatusCode AnaAlgorithm ::
352 fileExecute ()
353 {
354 return StatusCode::SUCCESS;
355 }
356
357
358
359 ::StatusCode AnaAlgorithm ::
360 beginInputFile ()
361 {
362 return StatusCode::SUCCESS;
363 }
364
365
366
367 ::StatusCode AnaAlgorithm ::
368 endInputFile ()
369 {
370 return StatusCode::SUCCESS;
371 }
372
373
374
375#ifdef XAOD_STANDALONE
376 ::StatusCode AnaAlgorithm ::
377 sysInitialize ()
378 {
379 return initialize ();
380 }
381
382
383
384 ::StatusCode AnaAlgorithm ::
385 sysExecute (const EventContext& ctx)
386 {
387 return execute (ctx);
388 }
389
390
391
392 ::StatusCode AnaAlgorithm ::
393 sysFinalize ()
394 {
395 return finalize ();
396 }
397
398
399
400 void AnaAlgorithm ::
401 sysPrint ()
402 {
403 print ();
404 }
405
406
407
408 ::StatusCode AnaAlgorithm ::
409 sysFileExecute ()
410 {
411 if (m_hasFileExecute == false)
412 {
413 ANA_MSG_FATAL ("called fileExecute(), though it was not registered");
414 return StatusCode::FAILURE;
415 }
416 return fileExecute ();
417 }
418
419
420
421 ::StatusCode AnaAlgorithm ::
422 sysBeginInputFile ()
423 {
424 if (m_hasBeginInputFile == false)
425 {
426 ANA_MSG_FATAL ("called beginInputFile(), though it was not registered");
427 return StatusCode::FAILURE;
428 }
429 return beginInputFile ();
430 }
431
432
433
434 ::StatusCode AnaAlgorithm ::
435 sysEndInputFile ()
436 {
437 if (m_hasEndInputFile == false)
438 {
439 ANA_MSG_FATAL ("called endInputFile(), though it was not registered");
440 return StatusCode::FAILURE;
441 }
442 return endInputFile ();
443 }
444
445
446
447 void AnaAlgorithm ::
448 setEvtStore (asg::SgEvent *val_evtStore)
449 {
450 if (m_evtStore)
451 throw std::logic_error ("set evtStore twice on algorithm " + name());
452 m_evtStore = val_evtStore;
453 m_inputMetaStore = asg::SgEventMeta (asg::SgEventMeta::InputStore,
454 val_evtStore->event());
455 m_outputMetaStore = asg::SgEventMeta (asg::SgEventMeta::OutputStore,
456 val_evtStore->event());
457 }
458
459
460
461 void AnaAlgorithm ::
462 setHistogramWorker (IHistogramWorker *val_histogramWorker)
463 {
464 if (m_histogramWorker)
465 throw std::logic_error ("set histogram worker twice on algorithm " + name());
466 m_histogramWorker = val_histogramWorker;
467 }
468
469
470
471 void AnaAlgorithm ::
472 setTreeWorker (ITreeWorker *val_treeWorker)
473 {
474 if( m_treeWorker ) {
475 throw std::logic_error( "set tree worker twice on algorithm " +
476 name() );
477 }
478 m_treeWorker = val_treeWorker;
479 }
480
481
482
483 void AnaAlgorithm ::
484 setFilterWorker (IFilterWorker *val_filterWorker)
485 {
486 if (m_filterWorker)
487 throw std::logic_error ("set filter worker twice on algorithm " + name());
488 m_filterWorker = val_filterWorker;
489 }
490
491
492
493 void AnaAlgorithm ::
494 setWk (IWorker *val_wk)
495 {
496 if (m_wk)
497 throw std::logic_error ("set wk twice on algorithm " + name());
498 m_wk = val_wk;
499 }
500
501
502
503 bool AnaAlgorithm ::
504 hasFileExecute () const noexcept
505 {
506 return m_hasFileExecute;
507 }
508
509
510
511 bool AnaAlgorithm ::
512 hasBeginInputFile () const noexcept
513 {
514 return m_hasBeginInputFile;
515 }
516
517
518
519 bool AnaAlgorithm ::
520 hasEndInputFile () const noexcept
521 {
522 return m_hasEndInputFile;
523 }
524#endif
525
526
527
528#ifndef XAOD_STANDALONE
529 void AnaAlgorithm ::
530 handle (const Incident& inc)
531 {
532 if (inc.type() == IncidentType::BeginInputFile)
533 {
538 } else if (inc.type() == IncidentType::EndInputFile)
539 {
542 } else
543 {
544 ATH_MSG_WARNING( "Unknown incident type received: " << inc.type() );
545 }
546 }
547#endif
548}
#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
bool m_hasBeginInputFile
the value of hasBeginInputFile
bool m_hasFileExecute
the value of hasFileExecute
MetaStore_t m_outputMetaStore
Object accessing the output metadata store.
MetaStore_t m_inputMetaStore
Object accessing the input metadata store.
virtual::StatusCode execute()
execute this algorithm
ServiceHandle< StoreGateSvc > & MetaStorePtr_t
Type of the metadata store pointer in standalone mode.
bool m_hasEndInputFile
the value of hasEndInputFile
const ServiceHandle< StoreGateSvc > & ConstMetaStorePtr_t
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