ATLAS Offline Software
Loading...
Searching...
No Matches
AnaAlgorithm.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 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::SgTEvent *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 finalize ()
330 {
331 return StatusCode::SUCCESS;
332 }
333
334
335
336 void AnaAlgorithm ::
337 print () const
338 {}
339
340
341
342 ::StatusCode AnaAlgorithm ::
343 fileExecute ()
344 {
345 return StatusCode::SUCCESS;
346 }
347
348
349
350 ::StatusCode AnaAlgorithm ::
351 beginInputFile ()
352 {
353 return StatusCode::SUCCESS;
354 }
355
356
357
358 ::StatusCode AnaAlgorithm ::
359 endInputFile ()
360 {
361 return StatusCode::SUCCESS;
362 }
363
364
365
366#ifdef XAOD_STANDALONE
367 ::StatusCode AnaAlgorithm ::
368 sysInitialize ()
369 {
370 return initialize ();
371 }
372
373
374
375 ::StatusCode AnaAlgorithm ::
376 sysExecute ()
377 {
378 return execute ();
379 }
380
381
382
383 ::StatusCode AnaAlgorithm ::
384 sysFinalize ()
385 {
386 return finalize ();
387 }
388
389
390
391 void AnaAlgorithm ::
392 sysPrint ()
393 {
394 print ();
395 }
396
397
398
399 ::StatusCode AnaAlgorithm ::
400 sysFileExecute ()
401 {
402 if (m_hasFileExecute == false)
403 {
404 ANA_MSG_FATAL ("called fileExecute(), though it was not registered");
405 return StatusCode::FAILURE;
406 }
407 return fileExecute ();
408 }
409
410
411
412 ::StatusCode AnaAlgorithm ::
413 sysBeginInputFile ()
414 {
415 if (m_hasBeginInputFile == false)
416 {
417 ANA_MSG_FATAL ("called beginInputFile(), though it was not registered");
418 return StatusCode::FAILURE;
419 }
420 return beginInputFile ();
421 }
422
423
424
425 ::StatusCode AnaAlgorithm ::
426 sysEndInputFile ()
427 {
428 if (m_hasEndInputFile == false)
429 {
430 ANA_MSG_FATAL ("called endInputFile(), though it was not registered");
431 return StatusCode::FAILURE;
432 }
433 return endInputFile ();
434 }
435
436
437
438 void AnaAlgorithm ::
439 setEvtStore (asg::SgTEvent *val_evtStore)
440 {
441 if (m_evtStore)
442 throw std::logic_error ("set evtStore twice on algorithm " + name());
443 m_evtStore = val_evtStore;
444 m_inputMetaStore = asg::SgTEventMeta (asg::SgTEventMeta::InputStore,
445 val_evtStore->event());
446 m_outputMetaStore = asg::SgTEventMeta (asg::SgTEventMeta::OutputStore,
447 val_evtStore->event());
448 }
449
450
451
452 void AnaAlgorithm ::
453 setHistogramWorker (IHistogramWorker *val_histogramWorker)
454 {
455 if (m_histogramWorker)
456 throw std::logic_error ("set histogram worker twice on algorithm " + name());
457 m_histogramWorker = val_histogramWorker;
458 }
459
460
461
462 void AnaAlgorithm ::
463 setTreeWorker (ITreeWorker *val_treeWorker)
464 {
465 if( m_treeWorker ) {
466 throw std::logic_error( "set tree worker twice on algorithm " +
467 name() );
468 }
469 m_treeWorker = val_treeWorker;
470 }
471
472
473
474 void AnaAlgorithm ::
475 setFilterWorker (IFilterWorker *val_filterWorker)
476 {
477 if (m_filterWorker)
478 throw std::logic_error ("set filter worker twice on algorithm " + name());
479 m_filterWorker = val_filterWorker;
480 }
481
482
483
484 void AnaAlgorithm ::
485 setWk (IWorker *val_wk)
486 {
487 if (m_wk)
488 throw std::logic_error ("set wk twice on algorithm " + name());
489 m_wk = val_wk;
490 }
491
492
493
494 bool AnaAlgorithm ::
495 hasFileExecute () const noexcept
496 {
497 return m_hasFileExecute;
498 }
499
500
501
502 bool AnaAlgorithm ::
503 hasBeginInputFile () const noexcept
504 {
505 return m_hasBeginInputFile;
506 }
507
508
509
510 bool AnaAlgorithm ::
511 hasEndInputFile () const noexcept
512 {
513 return m_hasEndInputFile;
514 }
515#endif
516
517
518
519#ifndef XAOD_STANDALONE
520 void AnaAlgorithm ::
521 handle (const Incident& inc)
522 {
523 if (inc.type() == IncidentType::BeginInputFile)
524 {
529 } else if (inc.type() == IncidentType::EndInputFile)
530 {
533 } else
534 {
535 ATH_MSG_WARNING( "Unknown incident type received: " << inc.type() );
536 }
537 }
538#endif
539}
#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.
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
@ OutputStore
This store is used to access the output metadata.
@ InputStore
This store is used to access the input metadata.
Wrapper for TEvent to make it look like StoreGate.
Definition SgTEvent.h:44
xAOD::TEvent * event() const
Return the underlying event manager.
Definition SgTEvent.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