| The Gaudi Framework v28r2p1 (f1a77ff4)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

GaudiAlgs.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # =============================================================================
3 ## @file
4 #
5 # Helper module, which effectively 'imports' few useful C++ algorithmic
6 # base classes into Python
7 #
8 #
9 # The major imported classes are :
10 #
11 # - GaudiAlgo - analogue for GaudiAlgorithm C++ class from GaudiAlg package
12 # - HistoAlgo - analogue for GaudiHistoAlg C++ class from GaudiAlg package
13 # - TupleAlgo - analogue for GaudiTupleAlg C++ class from GaudiAlg package
14 #
15 # @author Vanya BELYAEV ibelyaev@physics.syr.edu
16 # @date 2006-11-26
17 # =============================================================================
18 """
19 *******************************************************************************
20 * * 'Physisics do not like it, *
21 * * physisics do not need it, *
22 * * physisics do not use it' *
23 * * ****************************
24 * *
25 * Helper module, which effectively 'imports' few useful C++ algorithmic *
26 * base classes into Python *
27 * *
28 *******************************************************************************
29 * The major imported classes are : *
30 * *
31 * (1) GaudiAlgo - analogue for GaudiAlgorithm C++ class from GaudiAlg package *
32 * (2) HistoAlgo - analogue for GaudiHistoAlg C++ class from GaudiAlg package *
33 * (3) TupleAlgo - analogue for GaudiTupleAlg C++ class from GaudiAlg package *
34 *******************************************************************************
35 """
36 # =============================================================================
37 __author__ = 'Vanya BELYAEV Ivan.Belyaev@lapp.in2p3.fr'
38 # =============================================================================
39 # list of "public" symbols
40 # =============================================================================
41 __all__ = (
42 'GaudiAlgo' , ## base class for algorithms
43 'HistoAlgo' , ## base class for histo-related algorithms
44 'TupleAlgo' , ## base class for tuple-related algorithms
45 'Tuple' , ## N-Tuple
46 'HistoID' , ## ID for N-tuples
47 'TupleID' , ## ID for Histograms
48 'aida2root' , ## AIDA -> ROOT converter
49 'SUCCESS' ## status code
50 )
51 # =============================================================================
52 # import core of Gaudi
53 import GaudiPython.Bindings ## The basic module
54 iAlgorithm = GaudiPython.Bindings.iAlgorithm ## Algorithm interface
55 iAlgTool = GaudiPython.Bindings.iAlgTool ## Tool interface
56
57 from GaudiPython.Bindings import (
58 SUCCESS , ## status code
59 InterfaceCast , ## "queryInterface"
60 iDataSvc , ## Data Service
61 iHistogramSvc , ## Histogram Service
62 iNTupleSvc , ## N-Tuple service
63 AppMgr ## Application Manager
64 )
65
66 from GaudiPython.Bindings import gbl as cpp ## global C++ namepspace
67 from GaudiPython.HistoUtils import aida2root ## AIDA -> ROTO converter
68
69 from GaudiKernel import ROOT6WorkAroundEnabled
70
71 # =============================================================================
72 # std C++ namespace
73 std = cpp.std ## std C++ namespace
74
75 ## "typedef" for GaudiPython::Vector
76 Vector = std.vector('double')
77 ## "typedef" for GaudiPython::Matrix
78 Matrix = std.vector('std::vector<double>')
79
80 ## histogram and N-Tuple universal identifier
81 HID = cpp.GaudiAlg.ID
82 HistoID = HID
83 TID = HID
84 TupleID = TID
85
86 ## get the decorator:
87 AlgDecorator = cpp.GaudiPython.AlgDecorator
88 HistoDecorator = cpp.GaudiPython.HistoDecorator
89 TupleAlgDecorator = cpp.GaudiPython.TupleAlgDecorator
90 TupleDecorator = cpp.GaudiPython.TupleDecorator
91
92 # =============================================================================
93 ## Useful method to locate the tool a certain
94 #
95 # Usage:
96 #
97 # @code
98 #
99 # # locate public tool
100 # t1 = self.tool(ITrExtrapolator,'TrParabolicExtrapolator')
101 # # locate private tool
102 # t2 = self.tool(ITrExtrapolator,'TrParabolicExtrapolator',parent=self)
103 # # locate public tool with defined name
104 # t3 = self.tool(ITrExtrapolator,'TrParabolicExtrapolator/MyExt1')
105 # # locate private tool with defined name
106 # t4 = self.tool(ITrExtrapolator,'TrParabolicExtrapolator/MyExt2',parent=self)
107 # # locate public tool with defined name
108 # t5 = self.tool(ITrExtrapolator,'TrParabolicExtrapolator','MyExt3')
109 # # locate private tool with defined name
110 # t6 = self.tool(ITrExtrapolator,'TrParabolicExtrapolator','MyExt4',parent=self)
111 #
112 # @endcode
113 #
114 # @author Vanya BELYAEV ibelyaev@physics.syr.edu
115 # @date 2006-11-26
116 def _tool_ ( self ,
117 interface ,
118 typename ,
119 name = None ,
120 parent = None ,
121 create = True ) :
122 """
123 Useful method to locate the tool a certain
124
125 Usage:
126
127 # locate public tool
128 t1 = self.tool(ITrExtrapolator,'TrParabolicExtrapolator')
129 # locate private tool
130 t2 = self.tool(ITrExtrapolator,'TrParabolicExtrapolator',parent=self)
131 # locate public tool with defined name
132 t3 = self.tool(ITrExtrapolator,'TrParabolicExtrapolator/MyExt1')
133 # locate private tool with defined name
134 t4 = self.tool(ITrExtrapolator,'TrParabolicExtrapolator/MyExt2',parent=self)
135 # locate public tool with defined name
136 t5 = self.tool(ITrExtrapolator,'TrParabolicExtrapolator','MyExt3')
137 # locate private tool with defined name
138 t6 = self.tool(ITrExtrapolator,'TrParabolicExtrapolator','MyExt4',parent=self)
139
140 """
141 if not interface : interface = cpp.IAlgTool
142 if not parent : parent = self
143 if name : typename += '/' + name
144 _tool = AlgDecorator.tool_( self , typename , parent , create )
145 if not _tool : return None
146 _tool = InterfaceCast(interface)(_tool)
147 if not _tool :
148 self.Warning('Invalid cast to interface %s' % interface )
149 return None
150 return _tool
151
152 # =============================================================================
153 ## Useful method to locate a service:
154 #
155 # Usage:
156 #
157 # @code
158 #
159 # ntsvc = self.svc( INTupleSvc , 'NTUpleSvc' )
160 #
161 # @endcode
162 #
163 # @author Vanya BELYAEV ibelyaev@physics.syr.edu
164 # @date 2006-11-26
165 def _service_ ( self ,
166 interface ,
167 name ,
168 create = True ) :
169 """
170 Useful method to locate a service:
171
172 Usage:
173
174 ntsvc = self.svc( INTupleSvc , 'NTUpleSvc' )
175
176 """
177 if not interface : interface = cpp.IInterface
178 _svc = AlgDecorator.svc_ ( self , name , create )
179 if not _svc : return None
180 _svc = InterfaceCast(interface)(_svc)
181 if not _svc :
182 self.Warning('Invalid cast to interface %s' % interface )
183 return None
184 return _svc
185
186 # =============================================================================
187 ## The constructor from unique algorithm instance name,
188 #
189 # @author Vanya BELYAEV ibelyaev@physics.syr.edu
190 # @date 2006-11-26
191 def _init_ ( self , name , **args ) :
192 """
193 The constructor from unique algorithm instance name & parameters
194 """
195 self._Base.__init__( self , self , name )
196 appMgr = AppMgr()
197 algMgr = appMgr._algmgr
198 status = algMgr.addAlgorithm( self )
199 if status.isFailure() :
200 raise RuntimeError, 'Unable to add Algorithm "' + name + '"'
201 iAlgorithm.__init__ ( self , name , self )
202 for key in args : setattr ( self , key , args[key] )
203 # take some care about the ownership of the algorithms
204 if not appMgr.__dict__.has_key ( 'GaudiPythonAlgos') :
205 appMgr.__dict__[ 'GaudiPythonAlgos'] = []
206 appMgr.__dict__[ 'GaudiPythonAlgos'].append( self )
207
208 # =============================================================================
209 ## The default initialization (initialization of base C++ class + data
210 #
211 # @author Vanya BELYAEV ibelyaev@physics.syr.edu
212 # @date 2006-11-26
213 def _initialize_ ( self ) :
214 """
215 The default initialization (initialization of base C++ class + data)
216 """
217 status = self._Base.initialize_( self )
218 if status.isFailure() : return status
219
220 # set the basic services
221 _e = self._Base.evtSvc( self )
222 _s = InterfaceCast(cpp.IService)(_e)
223 self._evtSvc_ = iDataSvc ( _s.name() , _e )
224
225 _d = self._Base.detSvc( self )
226 _s = InterfaceCast(cpp.IService)(_d)
227 self._detSvc_ = iDataSvc ( _s.name() , _d )
228
229 return status
230
231 # =============================================================================
232 ## The default initialization (initialization of base C++ class + data members)
233 #
234 # @author Vanya BELYAEV ibelyaev@physics.syr.edu
235 # @date 2006-11-26
236 def _initialize_histo_ ( self ) :
237 """
238 The default initialization (initialization of base C++ class + data members)
239 """
240 status = _initialize_( self )
241 if status.isFailure() : return status
242
243 # set the basic services
244 _h = self._Base.histoSvc( self )
245 _s = InterfaceCast(cpp.IService)(_h)
246 self._histoSvc_ = iHistogramSvc ( _s.name() , _h )
247
248 return status
249
250 # =============================================================================
251 ## The default initialization (initialization of base C++ class + data members)
252 #
253 # @author Vanya BELYAEV ibelyaev@physics.syr.edu
254 # @date 2006-11-26
255 def _initialize_tuple_ ( self ) :
256 """
257 The default initialization (initialization of base C++ class + data members)
258 """
259 status = _initialize_histo_( self )
260 if status.isFailure() : return status
261
262 # set the basic services
263 if self.produceNTuples() :
264 _n = self._Base.ntupleSvc( self )
265 _s = InterfaceCast(cpp.IService)(_n)
266 self._ntupleSvc_ = iNTupleSvc ( _s.name() , _n )
267
268 if self.produceEvtCols() :
269 _n = self._Base.evtColSvc( self )
270 _s = InterfaceCast(cpp.IService)(_n)
271 self._evtcolSvc_ = iNTupleSvc ( _s.name() , _n )
272
273 return status
274
275 # =============================================================================
276 ## Trivial helper function to access Event Data and Event Data Service
277 #
278 # Usage:
279 #
280 # @code
281 #
282 # # get event data service
283 # svc = self.evtSvc()
284 #
285 # # get the data
286 # hits = self.evtSvc('MC/Calo/Hits')
287 #
288 # @endcode
289 #
290 # @author Vanya BELYAEV ibelyaev@physics.syr.edu
291 # @date 2006-11-26
292 def _evtSvc ( self , location = None ) :
293 """
294 Trivial helper function to access Event Data and Event Data Service
295
296 Usage:
297
298 # get event data service
299 svc = self.evtSvc()
300
301 # get the data
302 hits = self.evtSvc('MC/Calo/Hits')
303 """
304 if not location :
305 return self._evtSvc_
306 return self._evtSvc_[location]
307
308 # =============================================================================
309 ## Trivial helper function to access Detector Data and Detector Data Service
310 #
311 # Usage:
312 #
313 # @code
314 #
315 # # get detector data service
316 # svc = self.detSvc()
317 #
318 # # get the data
319 # lhcb = self.detSvc('/dd/Structure/LHCb')
320 #
321 # @endcode
322 #
323 # @author Vanya BELYAEV ibelyaev@physics.syr.edu
324 # @date 2006-11-26
325 def _detSvc ( self ) :
326 """
327 Trivial helper function to access Detector Data and Event Data Service
328
329 Usage:
330 # get detector data service
331 svc = self.detSvc()
332
333 # get the data
334 lhcb = self.detSvc('/dd/Structure/LHCb')
335 """
336 if not location :
337 return self._detSvc_
338 return self._detSvc_[location]
339
340 # =============================================================================
341 ## Trivial helper function to access Histogram Data and Histogram Data Service
342 #
343 # Usage:
344 #
345 # @code
346 #
347 # # get histogram data service
348 # svc = self.histoSvc()
349 #
350 # # get the data
351 # histo = self.histoSvc('/stat/Calo/1')
352 #
353 # @endcode
354 #
355 # @author Vanya BELYAEV ibelyaev@physics.syr.edu
356 # @date 2006-11-26
357 def _histoSvc ( self , address = None ) :
358 """
359 Trivial helper function to access Histogram Data and Histogram Data Service
360
361 Usage:
362
363 # get histogram data service
364 svc = self.histoSvc()
365
366 # get the data
367 histo = self.histoSvc('/stat/Calo/1')
368 """
369 if not address : return self._histoSvc_
370 return self._histoSvc_[ address ]
371
372 # =============================================================================
373 ## Trivial function to access the data in TES
374 def _get ( self , location ) :
375 """
376 Trivial function to access the data in TES using the data service
377 """
378 return self._evtSvc_[location]
379
380 # =============================================================================
381 ## Trivial function to access the data in TDS
382 def _getDet ( self , location ) :
383 """
384 Trivial function to access the data in TDS using data service
385 """
386 return self._detSvc_[location]
387
388 # =============================================================================
389 ## get the data from TES using GaudiCommon methods, respecting RootInTES
390 def _get_ ( self , location , rootInTES = True ) :
391 """
392 Get the object from Transient Event Store using GaudiCommon machinery,
393 respecting RootInTES behaviour
394 """
395 return AlgDecorator.get_ ( self , location , rootInTES )
396 # =============================================================================
397 ## check the data from TES using GaudiCommon methods, respecting RootInTES
398 def _exist_ ( self , location , rootInTES = True ) :
399 """
400 Check the object in Transient Event Store using GaudiCommon machinery,
401 respecting RootInTES behaviour
402 """
403 return AlgDecorator.exist_ ( self , location , rootInTES )
404
405 # =============================================================================
406 ## Trivial helper function to access NTuple Service
407 def _ntupleSvc ( self ) :
408 """
409 Trivial function to access N-Tuple Service
410 """
411 return self._ntupleSvc_
412
413 # =============================================================================
414 ## Trivial helper function to access Event Collection Service
415 def _evtcolSvc ( self ) :
416 """
417 Trivial function to access Event Collection Service
418 """
419 return self._evtcolSvc_
420
421
422 # =============================================================================
423 ## The default finalization (finalization of base C++ class)
424 def _finalize_ ( self ) :
425 """
426 The default finalization : finalize the base C++ class
427 """
428 status = self._Base.finalize_ ( self )
429 return status
430 # =============================================================================
431 ## Dummy method returning success
432 def _success_ ( self ) : return SUCCESS
433
434
435 # =============================================================================
436 ## check the existence of the property with the given name
437 def _hasProperty_ ( self , pname ) :
438 """
439 The trivial function which checks the existence of the property with given name
440 """
441 return cpp.Gaudi.Utils.hasProperty ( self , pname )
442
443 # =============================================================================
444 ## get the value of the given property
445 def _getProperty_ ( self , pname ) :
446 """
447 Get the property by name
448 """
449 if not self.hasProperty( pname ) :
450 raise AttributeError, 'property %s does not exist' % pname
451 return iAlgorithm.__getattr__( self , pname )
452
453 # =============================================================================
454 ## set the value for the given property
455 def _setProperty_ ( self , pname , pvalue ) :
456 """
457 Set the property from the value
458 """
459 if not self.hasProperty( pname ) :
460 raise AttributeError, 'property %s does not exist' % pname
461 return iAlgorithm.__setattr__ ( self , pname , pvalue )
462
463 # =============================================================================
464 ## get the attribute or property
465 def _get_attr_ ( self , pname ) :
466 """
467 Get the attribute (or property)
468 - if the attribute name corresponds to the property name, property value is returned
469 """
470 if self.hasProperty( pname ) :
471 return iAlgorithm.__getattr__ ( self , pname )
472 raise AttributeError, 'attribute/property %s does not exist' % pname
473
474 # =============================================================================
475 ## set the attribute or property
476 def _set_attr_ ( self , pname , pvalue ) :
477 """
478 Set the attribute (or property) :
479 - if the attribute name corresponds to the property name, the property is updated
480 """
481 if not self.hasProperty( pname ) : self.__dict__[pname] = pvalue
482 else : iAlgorithm.__setattr__ ( self , pname , pvalue )
483
484
485 _GaudiAlgorithm = cpp.GaudiPython.PyAlg( 'GaudiAlgorithm' )
486 _GaudiHistoAlg = cpp.GaudiPython.PyAlg( 'GaudiHistoAlg' )
487 _GaudiTupleAlg = cpp.GaudiPython.PyAlg( 'GaudiTupleAlg' )
488
489 # =============================================================================
490 ## @class GaudiAlgo
491 # the base class for all algorithm
492 # Python-image of C++ clkass GaudiAlgorithm
493 #
494 # Usage:
495 #
496 # @code
497 #
498 # from GauidPython.GaudiAlgs import GaudiAlgo, SUCCESS
499 #
500 # class MyClass(GaudiAlgo) :
501 # """
502 # My specific Algorithm, derived from GaudiAlgo base class
503 # """
504 # def __init__( self , name , **args ) :
505 # """
506 # Constructor from algorithm instance name & parameters'
507 # """
508 # #invoke the constructor of base class
509 # GaudiAlgo.__init__(self , name , **args )
510 #
511 # def initialize ( self ) :
512 # 'Algorithm initialization'
513 # # initialize the base class
514 # status = GaudiAlgo.initialize( self )
515 # if status.isFailure() : return status
516 #
517 # # locate the services and tools
518 #
519 # # locate some tool:
520 # extrapolator = self.tool(ITrExtrapolator,'TrExtrapolator')
521 #
522 # # locate the service
523 # rndmSvc = self.svc(IRndmGenSvc, 'RndmGenSvc')
524 #
525 # return SUCCESS
526 #
527 #
528 # def execute ( self ) :
529 # 'Major method (from IAlgorithm interface)'
530 #
531 # # get some data from Transient Event Store
532 # tracks = self.get('/Event/Rec/Tracks')
533 #
534 # # use counters
535 # c1 = self.counter('#Tracks')
536 # c2 = self.counter('No Tracks')
537 # if tracks.empty :
538 # c2+=1
539 # c1 += tracks->size()
540 #
541 # if 1000 < tracks.size() :
542 # return self.Error('The event is *VERY* busy')
543 #
544 # return SUCCESS
545 #
546 # @endcode
547 #
548 # @see GaudiAlgorithm
549 #
550 # @author Vanya BELYAEV ibelyaev@physics.syr.edu
551 # @date 2006-11-26
552 class GaudiAlgo ( _GaudiAlgorithm , iAlgorithm ) :
553 """
554 *******************************************************************************
555 * * 'Physisics do not like it, *
556 * * physisics do not need it, *
557 * * physisics do not use it' *
558 * * ****************************
559 * Usage: *
560 * *
561 * from GaudiPython.GaudiAlgs import GaudiAlgo, SUCCESS *
562 * *
563 * class MyClass(GaudiAlgo) : *
564 * ' My specific Algorithm, derived from GaudiAlgo base class ' *
565 * def __init__( self , name , **args ) : *
566 * 'Constructor from algorithm instance name & parameters' *
567 * #invoke the constructor of base class *
568 * GaudiAlgo.__init__(self , name , **args ) *
569 * *
570 * def initialize ( self ) : *
571 * 'Algorithm initialization' *
572 * # initialize the base class *
573 * status = GaudiAlgo.initialize( self ) *
574 * if status.isFailure() : return status *
575 * *
576 * # locate the services and tools *
577 * *
578 * # locate some tool: *
579 * extrapolator = self.tool(ITrExtrapolator,'TrExtrapolator') *
580 * *
581 * # locate the service *
582 * rndmSvc = self.svc(IRndmGenSvc, 'RndmGenSvc') *
583 * *
584 * return SUCCESS *
585 * *
586 * *
587 * def execute ( self ) : *
588 * 'Major method (from IAlgorithm interface)' *
589 * *
590 * # get some data from Transient Event Store *
591 * tracks = self.get('/Event/Rec/Tracks') *
592 * *
593 * # use counters *
594 * c1 = self.counter('#Tracks') *
595 * c2 = self.counter('No Tracks') *
596 * if tracks.empty : *
597 * c2+=1 *
598 * c1 += tracks->size() *
599 * *
600 * if 1000 < tracks.size() : *
601 * return self.Error('The event is *VERY* busy') *
602 * *
603 * return SUCCESS *
604 * *
605 *******************************************************************************
606 """
607 pass
608
609 # =============================================================================
610 ## @class HistoAlgo
611 # The base class for easy histogramming
612 #
613 # Usage:
614 #
615 #
616 # @code
617 #
618 # from GaudiPython.GaudiAlgs import HistoAlgo, SUCCESS
619 #
620 # class MyClass(HistoAlgo) :
621 # ' My specific Algorithm, derived from GaudiAlgo base class '
622 # def __init__( self , name , **args ) :
623 # 'Constructor from algorithm instance name & parameters'
624 # #invoke the constructor of base class
625 # HistoAlgo.__init__(self , name , **args )
626 #
627 # def execute ( self ) :
628 # 'Major method (from IAlgorithm interface)'
629 #
630 # # get some data from Transient Event Store
631 # tracks = self.get('/Event/Rec/Tracks')
632 #
633 # self.plot1D ( tracks->size() , '#tracks' , 0 , 100 )
634 #
635 # return SUCCESS
636 #
637 # @endcode
638 #
639 # Alternatively the histogram could be booked in advance:
640 #
641 # @code
642 #
643 # class MyClass(HistoAlgo) :
644 # ' My specific Algorithm, derived from GaudiAlgo base class '
645 # def __init__( self , name ) :
646 # 'Constructor from algorithm instance name'
647 # #invoke the constructor of base class
648 # HistoAlgo.__init__(self , name )
649 #
650 # def initialize ( self ) :
651 # 'Algorithm initialization'
652 # # initialize the base class
653 # status = HistoAlgo.initialize( self )
654 # if status.isFailure() : return status
655 #
656 # # book the histogram
657 # self.h1 = selff.book1D ( '#tracks' , 0 , 100 )
658 #
659 # return SUCCESS
660 #
661 #
662 # def execute ( self ) :
663 # 'Major method (from IAlgorithm interface)'
664 #
665 # # get some data from Transient Event Store
666 # tracks = self.get('/Event/Rec/Tracks')
667 #
668 # # fill the histogram
669 # self.h1.fill ( tracks->size() )
670 #
671 # return SUCCESS
672 # @endcode
673 #
674 # @see GaudiHistoAlg
675 #
676 # @author Vanya BELYAEV ibelyaev@physics.syr.edu
677 # @date 2006-11-26
678 class HistoAlgo ( _GaudiHistoAlg , iAlgorithm ) :
679 """
680 *******************************************************************************
681 * * 'Physisics do not like it, *
682 * * physisics do not need it, *
683 * * physisics do not use it' *
684 * * ****************************
685 * Usage: *
686 * *
687 * from GaudiPython.GaudiAlgs import HistoAlgo, SUCCESS *
688 * *
689 * class MyClass(HistoAlgo) : *
690 * ' My specific Algorithm, derived from GaudiAlgo base class ' *
691 * def __init__( self , name , **args ) : *
692 * 'Constructor from algorithm instance name' *
693 * #invoke the constructor of base class *
694 * HistoAlgo.__init__(self , name , **args ) *
695 * *
696 * def execute ( self ) : *
697 * 'Major method (from IAlgorithm interface)' *
698 * *
699 * # get some data from Transient Event Store *
700 * tracks = self.get('/Event/Rec/Tracks') *
701 * *
702 * self.plot1D ( tracks->size() , '#tracks' , 0 , 100 ) *
703 * *
704 * return SUCCESS *
705 * *
706 * Alternatively the histogram could be booked in advance: *
707 * *
708 * class MyClass(HistoAlgo) : *
709 * ' My specific Algorithm, derived from GaudiAlgo base class ' *
710 * def __init__( self , name ) : *
711 * 'Constructor from algorithm instance name' *
712 * #invoke the constructor of base class *
713 * HistoAlgo.__init__(self , name ) *
714 * *
715 * def initialize ( self ) : *
716 * 'Algorithm initialization' *
717 * # initialize the base class *
718 * status = HistoAlgo.initialize( self ) *
719 * if status.isFailure() : return status *
720 * *
721 * # book the histogram *
722 * self.h1 = selff.book1D ( '#tracks' , 0 , 100 ) *
723 * *
724 * return SUCCESS *
725 * *
726 * *
727 * def execute ( self ) : *
728 * 'Major method (from IAlgorithm interface)' *
729 * *
730 * # get some data from Transient Event Store *
731 * tracks = self.get('/Event/Rec/Tracks') *
732 * *
733 * # fill the histogram *
734 * self.h1.fill ( tracks->size() ) *
735 * *
736 * return SUCCESS *
737 * *
738 *******************************************************************************
739 """
740 pass
741
742 # =============================================================================
743 ## @class TupleAlgo
744 # The base class for easy manupulations with N-Tuples
745 #
746 # Usage:
747 #
748 # @code
749 #
750 # from GaudiPython.GaudiAlgs import TupleAlgo, SUCCESS
751 #
752 # class MyClass(TupleAlgo) :
753 # ' My specific Algorithm, derived from TupleAlgo base class '
754 # def __init__( self , name , **args ) :
755 # 'Constructor from algorithm instance name& parameters'
756 # #invoke the constructor of base class
757 # TupleAlgo.__init__(self , name , **args )
758 #
759 # def execute ( self ) :
760 # 'Major method (from IAlgorithm interface)'
761 #
762 # # get some data from Transient Event Store
763 # tracks = self.get('/Event/Rec/Tracks')
764 #
765 # tup = self.nTuple('My N-Tuple')
766 #
767 # for track in tracks :
768 #
769 # pt = track.pt ()
770 # p = track.p ()
771 # chi2 = track.chi2 ()
772 #
773 # #fill N-tuple:
774 # tup.column ( 'pt' , pt )
775 # tup.column ( 'p' , p )
776 # tup.column ( 'chi2' , chi2 )
777 # #commit the row
778 # tup.write ()
779 #
780 # return SUCCESS
781 #
782 # @endcode
783 #
784 # @see GaudiTupleAlg
785 #
786 # @author Vanya BELYAEV ibelyaev@physics.syr.edu
787 # @date 2006-11-26
788 class TupleAlgo ( _GaudiTupleAlg , iAlgorithm ) :
789 """
790 *******************************************************************************
791 * * 'Physisics do not like it, *
792 * * physisics do not need it, *
793 * * physisics do not use it' *
794 * * ****************************
795 * Usage: *
796 * *
797 * from GaudiPython.GaudiAlgs import TupleAlgo, SUCCESS *
798 * *
799 * class MyClass(TupleAlgo) : *
800 * ' My specific Algorithm, derived from TupleAlgo base class ' *
801 * def __init__( self , name , **args ) : *
802 * 'Constructor from algorithm instance name & parameters' *
803 * #invoke the constructor of base class *
804 * TupleAlgo.__init__(self , name , **args ) *
805 * *
806 * def execute ( self ) : *
807 * 'Major method (from IAlgorithm interface)' *
808 * *
809 * # get some data from Transient Event Store *
810 * tracks = self.get('/Event/Rec/Tracks') *
811 * *
812 * tup = self.nTuple('My N-Tuple') *
813 * *
814 * for track in tracks : *
815 * *
816 * pt = track.pt () *
817 * p = track.p () *
818 * chi2 = track.chi2 () *
819 * *
820 * #fill N-tuple: *
821 * tup.column ( 'pt' , pt ) *
822 * tup.column ( 'p' , p ) *
823 * tup.column ( 'chi2' , chi2 ) *
824 * #commit the row *
825 * tup.write () *
826 * *
827 * return SUCCESS *
828 * *
829 *******************************************************************************
830 """
831 pass
832 class objectmethod(object) :
833 def __init__(self, m) :
834 self.method = m
835 def __call__(self, *args) :
836 print args
837 return self.method(*args )
838
839 GaudiAlgo._Base = _GaudiAlgorithm
840 HistoAlgo._Base = _GaudiHistoAlg
841 TupleAlgo._Base = _GaudiTupleAlg
842
843 # initialize is 'unique' method :
844 GaudiAlgo.initialize = _initialize_
845 HistoAlgo.initialize = _initialize_histo_
846 TupleAlgo.initialize = _initialize_tuple_
847
848 def _start_ ( self ) :
849 """
850 The stub 'start' method needed by the internal implementation of PyAlg<>.
851 """
852 # return self._Base.start_(self)
853 return SUCCESS
854
855 GaudiAlgo.start = _start_
856 HistoAlgo.start = _start_
857 TupleAlgo.start = _start_
858
859 def _execute_ ( self ) :
860 """
861 The fictive 'execute' method, which MUST be overwitten by user
862 """
863 raise RuntimeError, 'Execute method is not implemented for %s' % self.name()
864
865 GaudiAlgo.execute = _execute_
866 HistoAlgo.execute = _execute_
867 TupleAlgo.execute = _execute_
868
869 def _stop_ ( self ) :
870 """
871 The stub 'stop' method needed by the internal implementation of PyAlg<>.
872 """
873 # return self._Base.stop_(self)
874 return SUCCESS
875
876 GaudiAlgo.stop = _stop_
877 HistoAlgo.stop = _stop_
878 TupleAlgo.stop = _stop_
879
880 # =============================================================================
881 def _plot1D_ ( s, *a ) :
882 """
883 The basic method to fill (book-on-demand) 1D-histogram
884
885 The histogram will be created/booked dautomatically according to the
886 specifications:
887
888 - literal or numerical ID (optional)
889 - title
890 - low edge
891 - high edge
892 - number of bins (default is 100)
893
894 The reference to the histogram is returned and could be used for later manipulations
895
896 """
897 return HistoDecorator.plot1D (s,*a)
898 # =============================================================================
899 def _plot2D_ ( s, *a ) :
900 """
901 The basic method to fill (book-on-demand) 2D-histogram
902
903 The histogram will be created/booked dautomatically according to the
904 specifications:
905
906 - literal or numerical ID (optional)
907 - title
908 - low X-edge
909 - high X-edge
910 - low Y-edge
911 - high Y-edge
912 - number of X-bins (default is 50)
913 - number of Y-bins (default is 50)
914
915 The reference to the histogram is returned and could be used for later manipulations
916
917 """
918 return HistoDecorator.plot2D (s,*a)
919 # =============================================================================
920 def _plot3D_ ( s, *a ) :
921 """
922 The basic method to fill (book-on-demand) 3D-histogram
923
924 The histogram will be created/booked dautomatically according to the
925 specifications:
926
927 - literal or numerical ID (optional)
928 - title
929 - low X-edge
930 - high X-edge
931 - low Y-edge
932 - high Y-edge
933 - low Z-edge
934 - high Z-edge
935 - number of X-bins (default is 10)
936 - number of Y-bins (default is 10)
937 - number of Y-bins (default is 10)
938
939 The reference to the histogram is returned and could be used for later manipulations
940
941 """
942 return HistoDecorator.plot3D (s,*a)
943 # =============================================================================
944 def _profile1D_ ( s, *a ) :
945 """
946 The basic method to fill (book-on-demand) 1D profile histogram
947
948 The profile histogram will be created/booked dautomatically
949 according to the specifications:
950
951 - literal or numerical ID (optional)
952 - title
953 - low X-edge
954 - high X-edge
955 - number of X-bins (default is 100)
956
957 The reference to the histogram is returned and could be used for later manipulations
958
959 """
960 return HistoDecorator.profile1D (s,*a)
961 # =============================================================================
962 def _profile2D_ ( s, *a ) :
963 """
964 The basic method to fill (book-on-demand) 2D profile histiogram
965
966 The profile histogram will be created/booked automatically
967 according to the specifications:
968
969 - literal or numerical ID (optional)
970 - title
971 - low X-edge
972 - high X-edge
973 - low Y-edge
974 - high Y-edge
975 - number of X-bins (default is 50)
976 - number of Y-bins (default is 50)
977
978 The reference to the histogram is returned and could be used for later manipulations
979
980 """
981 return HistoDecorator.profile2D (s,*a)
982 # =============================================================================
983
984 _plot1D_ .__doc__ += '\n' + HistoDecorator.plot1D .__doc__
985 _plot2D_ .__doc__ += '\n' + HistoDecorator.plot2D .__doc__
986 _plot3D_ .__doc__ += '\n' + HistoDecorator.plot3D .__doc__
987 _profile1D_ .__doc__ += '\n' + HistoDecorator.profile1D .__doc__
988 _profile2D_ .__doc__ += '\n' + HistoDecorator.profile2D .__doc__
989
990 def _decorate_plots_ ( klasses ) :
991 t = type( klasses )
992 if not issubclass ( t , list ) and \
993 not issubclass ( t , tuple ) : klasses = [ klasses ]
994 for klass in klasses :
995 klass .plot = _plot1D_
996 klass .plot1D = _plot1D_
997 klass .plot2D = _plot2D_
998 klass .plot3D = _plot3D_
999 klass .profile1D = _profile1D_
1000 klass .profile2D = _profile2D_
1001
1002 _decorate_plots_ ( HistoAlgo )
1003 _decorate_plots_ ( TupleAlgo )
1004
1005
1006 # =============================================================================
1007 def _nTuple_ ( s , *a ) :
1008 """
1009 Retrieve (book-on-demand) N-Tuple object
1010 """
1011 return TupleAlgDecorator.nTuple ( s , *a )
1012 # =============================================================================
1013 def _evtCol_ ( s , *a ) :
1014 """
1015 Retrieve (book-on-demand) N-Tuple object for Event Tag Collections
1016 """
1017 return TupleAlgDecorator.evtCol ( s , *a )
1018
1019 _nTuple_.__doc__ += '\n' + TupleAlgDecorator.nTuple.__doc__
1020 _evtCol_.__doc__ += '\n' + TupleAlgDecorator.evtCol.__doc__
1021
1022 def _decorate_tuples_ ( klasses ) :
1023 t = type( klasses )
1024 if not issubclass ( t , list ) and \
1025 not issubclass ( t , tuple ) : klasses = [ klasses ]
1026 for klass in klasses :
1027 klass . nTuple = _nTuple_
1028 klass . evtCol = _evtCol_
1029 klass . ntupleSvc = _ntupleSvc
1030 klass . tupleSvc = _ntupleSvc
1031 klass . ntupSvc = _ntupleSvc
1032 klass . tupSvc = _ntupleSvc
1033 klass . evtColSvc = _evtcolSvc
1034 klass . evtcolSvc = _evtcolSvc
1035
1036 # ==========================================================
1037 _decorate_tuples_ ( TupleAlgo )
1038
1039
1040 # "decorate N-Tuple object
1041 Tuple = cpp.Tuples.Tuple
1042 _Dec = TupleDecorator
1043
1044 class TupleDecColumnDispatcher(object):
1045 '''Helper decorator class to workaround ROOT-6697'''
1046 def __init__(self, func):
1047 self.func = func
1048 self.__doc__ = func.__doc__
1049
1050 mapping = {int: 'int', bool: 'bool', float: 'double'}
1051 for k in mapping:
1052 signature = 'const Tuples::Tuple& tuple, const string& name, const %s value'%(mapping[k])
1053 mapping[k] = func.disp(signature)
1054 self.mapping = mapping
1055
1056 def __call__(self, *a):
1057 '''
1058 Explicitly call the explicit signature for the case with 3 arguments and
1059 the last one is 'int', 'bool' or 'float', for the other cases fall back
1060 on the default dispatcher.
1061 '''
1062 if len(a) == 3:
1063 t = type(a[-1])
1064 try:
1065 return self.mapping[t](*a)
1066 except KeyError:
1067 pass
1068 return self.func(*a)
1069
1070 if ROOT6WorkAroundEnabled('ROOT-6697'):
1071 _Dec.column = TupleDecColumnDispatcher(_Dec.column)
1072
1073 def _t_nTuple_ ( s , *a ) :
1074 """
1075 Access to underlying INTuple object
1076 """
1077 return _Dec.nTuple ( s , *a )
1078 def _t_ntuple_ ( s , *a ) :
1079 """
1080 Access to underlying NTuple::Tuple object
1081 """
1082 return _Dec.ntuple ( s , *a )
1083 def _t_valid_ ( s , *a ) :
1084 """
1085 Valid NTuple::Tuple object?
1086 """
1087 return _Dec.valid ( s , *a )
1088 def _t_write_ ( s , *a ) :
1089 """
1090 Commit the row/record to n-tuple
1091 """
1092 return _Dec.write ( s , *a )
1093 def _t_column_ ( s , *a ) :
1094 """
1095 Fill the certain column to n-tuple
1096 """
1097 return _Dec.column ( s , *a )
1098 def _t_column_ll_ ( s , *a ) :
1099 """
1100 Fill the 'long long' column
1101 """
1102 return _Dec.column_ll ( s , *a )
1103 def _t_column_ull_ ( s , *a ) :
1104 """
1105 Fill the 'unsigned long long' column
1106 """
1107 return _Dec.column_ull ( s , *a )
1108 def _t_array_ ( s , *a ) :
1109 """
1110 Fill the fixed-size array column
1111 """
1112 return _Dec.array ( s , *a )
1113 def _t_matrix_ ( s , *a ) :
1114 """
1115 Fill the fixed-size matrix column
1116 """
1117 return _Dec.matrix ( s , *a )
1118 def _t_farray_ ( s , *a ) :
1119 """
1120 Fill the floating-size array column
1121 """
1122 return _Dec.farray ( s , *a )
1123 def _t_fmatrix_ ( s , *a ) :
1124 """
1125 Fill the floating-size matrix column
1126 """
1127 return _Dec.fmatrix ( s , *a )
1128
1129 _t_nTuple_ . __doc__ += '\n' + _Dec.nTuple . __doc__
1130 _t_ntuple_ . __doc__ += '\n' + _Dec.ntuple . __doc__
1131 _t_valid_ . __doc__ += '\n' + _Dec.valid . __doc__
1132 _t_write_ . __doc__ += '\n' + _Dec.write . __doc__
1133 _t_column_ . __doc__ += '\n' + _Dec.column . __doc__
1134 _t_column_ll_ . __doc__ += '\n' + _Dec.column_ll . __doc__
1135 _t_column_ull_ . __doc__ += '\n' + _Dec.column_ull . __doc__
1136 _t_array_ . __doc__ += '\n' + _Dec.array . __doc__
1137 _t_matrix_ . __doc__ += '\n' + _Dec.matrix . __doc__
1138 _t_farray_ . __doc__ += '\n' + _Dec.farray . __doc__
1139 _t_fmatrix_ . __doc__ += '\n' + _Dec.fmatrix . __doc__
1140
1141 Tuple.nTuple = _t_nTuple_
1142 Tuple.ntuple = _t_ntuple_
1143 Tuple.valid = _t_valid_
1144 Tuple.write = _t_write_
1145 Tuple.column = _t_column_
1146 Tuple.column_ll = _t_column_ll_
1147 Tuple.column_ull = _t_column_ull_
1148 Tuple.array = _t_array_
1149 Tuple.matrix = _t_matrix_
1150 Tuple.farray = _t_farray_
1151 Tuple.fmatrix = _t_fmatrix_
1152
1153 _alg_map_ = {
1154 '__init__' : _init_ , # constructor
1155 'tool' : _tool_ , # service locator
1156 'svc' : _service_ , # tool locator
1157 'evtSvc' : _evtSvc , # event data service
1158 'eventSvc' : _evtSvc , # event data service
1159 'detSvc' : _detSvc , # detector data service
1160 'histoSvc' : _histoSvc , # histogram data service
1161 'histSvc' : _histoSvc , # histogram data service
1162 'get' : _get , # access to event data
1163 'get_' : _get_ , # access to event data
1164 'exist_' : _exist_ , # check the event data
1165 'getDet' : _getDet , # access to detector data
1166 'finalize' : _finalize_ , # algorithm finalization
1167 'beginRun' : _success_ , # dummy function returning success
1168 'endRun' : _success_ , # dummy function returning success
1169 #
1170 'hasProperty' : _hasProperty_ , # check the existence of property with given name
1171 'getProperty' : _getProperty_ , # get the property value with given name
1172 'setProperty' : _setProperty_ , # set the property with given name
1173 '__setattr__' : _set_attr_ , # set the attribute/property with given name
1174 '__getattr__' : _get_attr_ # set the attribute/property with given name
1175 }
1176
1177
1178 # decorate the classes with the useful methods
1179 def _decorate_algs_ ( klasses ) :
1180 t = type( klasses )
1181 if not issubclass ( t , list ) and \
1182 not issubclass ( t , tuple ) : klasses = [ klasses ]
1183 for _alg in klasses :
1184 for key in _alg_map_ : setattr( _alg , key , _alg_map_[key] )
1185
1186 # =
1187 _decorate_algs_ ( GaudiAlgo )
1188 _decorate_algs_ ( HistoAlgo )
1189 _decorate_algs_ ( TupleAlgo )
1190
1191 # =============================================================================
1192 # Helper function to fill histogram/ntuple using 'map'-operation
1193 # =============================================================================
1194 def mapvct ( func , sequence , ovct = None ) :
1195 """ Helper function to fill histogram/ntuple using 'map'-operation """
1196 if not ovct :
1197 vct = GaudiPython.Vector
1198 else :
1199 vct = ovct
1200 if hasattr( sequence, 'size' ) :
1201 vct.reserve ( vct.size() + sequence.size() )
1202 elif hasattr( sequence, '__len__' ) :
1203 vct.reserve ( vct.size() + len( sequence ) )
1204 for object in sequence :
1205 vct.push_back( func( object ) )
1206 if not ovct : return vct
1207 # =============================================================================
1208
1209
1210
1211
1212 # =============================================================================
1213 # get the list of tools
1214 # =============================================================================
1215 def _get_all_tools_ ( self , method ) :
1216 """
1217 Get all tools
1218 """
1219 _tools = std.vector('IAlgTool*')()
1220 _func = getattr ( AlgDecorator , method )
1221 _num = _func ( self , _tools )
1222 if _tools.size() != _num :
1223 raise RuntimeError, 'Unable to extract Tools'
1224 _res = []
1225 for _tool in _tools : _res += [ iAlgTool ( _tool.name() , _tool ) ]
1226 return _res
1227 # =============================================================================
1228 def _Tools_a_ ( self ) :
1229 """
1230 Retrieve the list of tools,
1231 aquired by component through GaudiCommon<TYPE> base:
1232
1233 >>> alg = ... ## get the algorithm
1234 >>> tools = alg.Tools() ## get the tools
1235 >>> for tool in tools :
1236 ... print tool
1237
1238 """
1239 _cmp = getattr ( self , '_ialg' )
1240 if not _cmp : self.retrieveInterface()
1241 _cmp = getattr ( self , '_ialg' )
1242 return _get_all_tools_ ( _cmp , '_tools_a_' )
1243 # =============================================================================
1244 def _Tools_t_ ( self ) :
1245 """
1246 Retrieve the list of tools,
1247 aquired by component through GaudiCommon<TYPE> base:
1248
1249 >>> tool = ... ## get the tool
1250 >>> tools = tool.Tools() ## get the tools
1251 >>> for t in tools :
1252 ... print t
1253
1254 """
1255 _cmp = getattr ( self , '_itool' )
1256 if not _cmp : self.retrieveInterface()
1257 _cmp = getattr ( self , '_itool' )
1258 return _get_all_tools_ ( _cmp , '_tools_t_' )
1259
1260
1261 # =============================================================================
1262 # get the list of counters
1263 # =============================================================================
1264 ## get all counters
1265 def _get_all_counters_ ( self , method , name = None ) :
1266 """
1267 get all counters
1268 """
1269 _cnts = std.vector('const StatEntity*')()
1270 _nams = std.vector('std::string') ()
1271 _func = getattr ( AlgDecorator , method )
1272 _num = _func ( self , _nams , _cnts )
1273 if _nams.size() != _num or _cnts.size() != _num :
1274 raise RuntimeError, 'Unable to extract Counters'
1275 _res = {}
1276 for _i in range(0,_num) :
1277 _nam = _nams[_i]
1278 _cnt = _cnts[_i]
1279 _res [ _nam ] = _cnt
1280 if not name : return _res
1281 return _res.get( name , None )
1282 # =============================================================================
1283 ## get all counters
1284 def _Counters_a_ ( self , name = None ) :
1285 """
1286 Retrieve the counters, managed GaudiCommon<TYPE> base:
1287
1288 >>> alg = ... ## get the algorithm
1289 >>> cnts = alg.Counters() ## get the counters
1290 >>> for key in cnts :
1291 ... print key, cnts[key]
1292
1293
1294 Retrieve the counter, managed GaudiCommon<TYPE> base by name:
1295
1296 >>> alg = ... ## get the algorithm
1297 >>> cnt = alg.Counters('MyCounter') ## get the counter
1298 >>> print cnt
1299
1300 """
1301 _cmp = getattr ( self , '_ialg' )
1302 if not _cmp : self.retrieveInterface()
1303 _cmp = getattr ( self , '_ialg' )
1304 return _get_all_counters_ ( _cmp , '_counters_a_' , name )
1305 # =============================================================================
1306 def _Counters_t_ ( self , name = None ) :
1307 """
1308 Retrieve the counters, managed GaudiCommon<TYPE> base:
1309
1310 >>> tool = ... ## get the tool
1311 >>> cnts = tool.Counters() ## get the counters
1312 >>> for key in cnts :
1313 ... print key, cnts[key]
1314
1315
1316 Retrieve the counter, managed GaudiCommon<TYPE> base by name:
1317
1318 >>> tool = ... ## get the tool
1319 >>> cnt = tool.Counters('MyCounter') ## get the counter
1320 >>> print cnt
1321
1322 """
1323 _cmp = getattr ( self , '_itool' )
1324 if not _cmp : self.retrieveInterface()
1325 _cmp = getattr ( self , '_itool' )
1326 return _get_all_counters_ ( _cmp , '_counters_t_' , name )
1327 # =============================================================================
1328 # get the counter
1329 # =============================================================================
1330 def _get_counter_ ( self , method , name ) :
1331 """
1332 get the counter
1333 """
1334 _func = getattr ( AlgDecorator , method )
1335 return _func ( self , name )
1336 # ==============================================================================
1337 def _Counter_a_ ( self , name ) :
1338 """
1339 Retrieve the counter managed GaudiCommon<TYPE> base by name:
1340
1341 >>> alg = ... ## get the algorithm
1342 >>> cnt = alg.Counter('#accept') ## get the counter
1343 >>> print cnt
1344
1345 """
1346 _cmp = getattr ( self , '_ialg' )
1347 if not _cmp : self.retrieveInterface()
1348 _cmp = getattr ( self , '_ialg' )
1349 return _get_counter_ ( _cmp , '_counter_a_' , name )
1350 # ==============================================================================
1351 def _Counter_t_ ( self , name ) :
1352 """
1353 Retrieve the counter managed GaudiCommon<TYPE> base by name:
1354
1355 >>> tool = ... ## get the tool
1356 >>> cnt = tool.Counter('#accept') ## get the counter
1357 >>> print cnt
1358
1359 """
1360 _cmp = getattr ( self , '_itool' )
1361 if not _cmp : self.retrieveInterface()
1362 _cmp = getattr ( self , '_itool' )
1363 return _get_counter_ ( _cmp , '_counter_t_' , name )
1364
1365 # =============================================================================
1366 # get all histos
1367 # =============================================================================
1368 cpp.GaudiAlg.ID .__repr__ = cpp.GaudiAlg.ID.idAsString
1369 cpp.GaudiAlg.ID . __str__ = cpp.GaudiAlg.ID.idAsString
1370 cpp.StatEntity .__repr__ = cpp.StatEntity.toString
1371 cpp.StatEntity . __str__ = cpp.StatEntity.toString
1372 # =============================================================================
1373 def _get_all_histos_ ( component , method , name ) :
1374 """
1375 Get All histogram form the component
1376 """
1377 _res = {}
1378 for _his in ( std.vector('AIDA::IProfile2D*' ) ,
1379 std.vector('AIDA::IProfile1D*' ) ,
1380 std.vector('AIDA::IHistogram3D*' ) ,
1381 std.vector('AIDA::IHistogram2D*' ) ,
1382 std.vector('AIDA::IHistogram1D*' ) ) :
1383 _his = _his()
1384 _ids = std.vector('GaudiAlg::ID') ()
1385 _fun = getattr ( HistoDecorator , method )
1386 _num = _fun ( component , _ids , _his )
1387 if _ids.size() != _num or _his.size() != _num :
1388 raise RuntimeError, 'Unable to extract Histos!'
1389 for _i in range(0,_num) :
1390 _id = _ids[ _i ]
1391 if _id.numeric() : _id = _id.numericID ()
1392 elif _id.literal() : _id = _id.literalID ()
1393 else : _id = _is.idAsString ()
1394 _res[ _id ] = _his[ _i ]
1395
1396 if not name : return _res ## return the dictionary
1397
1398 id = cpp.GaudiAlg.ID ( name )
1399 for i in ( name ,
1400 id.literalID () ,
1401 id.numericID () ,
1402 id.idAsString() , id ) :
1403 h = _res.get( i , None )
1404 if not not h : return h ## return the histogram
1405
1406 return None
1407 # =============================================================================
1408 def _Histos_a_ ( self , name = None ) :
1409 """
1410 Retrieve all histograms & profiles, booked through GauydiHistos<TYPE> base:
1411
1412 >>> alg = ... ## get the algorithm
1413 >>> histos = alg.Histos() ## get all histograms & profiles
1414 >>> for key in histos :
1415 ... print key, histos[key]
1416
1417 Retrive the histogram with the certain ID :
1418
1419 >>> alg = ... ## get the algorithm
1420 >>> histo = alg.Histos('some histo ID') ## get the histo by ID
1421 >>> print histo
1422
1423 """
1424 _cmp = getattr ( self , '_ialg' )
1425 if not _cmp : self.retrieveInterface()
1426 _cmp = getattr ( self , '_ialg' )
1427 return _get_all_histos_ ( _cmp , '_histos_a_' , name )
1428 # =============================================================================
1429 def _Histos_t_ ( self , name = None ) :
1430 """
1431 Retrieve all histograms & profiles, booked through GauydiHistos<TYPE> base:
1432
1433 >>> tool = ... ## get the tool
1434 >>> histos = tool.Histos() ## get all histograms & profiles
1435 >>> for key in histos :
1436 ... print key, histos[key]
1437
1438 Retrive the historgam with certain ID :
1439
1440 >>> tool = ... ## get the tool
1441 >>> histo = tool.Histos('some histo ID') ## get the histo by ID
1442 >>> print histo
1443
1444 """
1445 _cmp = getattr ( self , '_itool' )
1446 if not _cmp : self.retrieveInterface()
1447 _cmp = getattr ( self , '_itool' )
1448 return _get_all_histos_ ( _cmp , '_histos_t_' , name )
1449 # =============================================================================
1450
1451
1452 _Tools_a_ . __doc__ += '\n' + AlgDecorator . _tools_a_ . __doc__
1453 _Tools_t_ . __doc__ += '\n' + AlgDecorator . _tools_t_ . __doc__
1454 _Counters_a_ . __doc__ += '\n' + AlgDecorator . _counters_a_ . __doc__
1455 _Counters_t_ . __doc__ += '\n' + AlgDecorator . _counters_t_ . __doc__
1456 _Counter_a_ . __doc__ += '\n' + AlgDecorator . _counter_a_ . __doc__
1457 _Counter_t_ . __doc__ += '\n' + AlgDecorator . _counter_t_ . __doc__
1458 _Histos_a_ . __doc__ += '\n' + HistoDecorator . _histos_a_ . __doc__
1459 _Histos_t_ . __doc__ += '\n' + HistoDecorator . _histos_t_ . __doc__
1460
1461 iAlgorithm . Tools = _Tools_a_
1462 iAlgTool . Tools = _Tools_t_
1463 iAlgorithm . Counters = _Counters_a_
1464 iAlgTool . Counters = _Counters_t_
1465 iAlgorithm . Counter = _Counter_a_
1466 iAlgTool . Counter = _Counter_t_
1467 iAlgorithm . Histos = _Histos_a_
1468 iAlgTool . Histos = _Histos_t_
1469
1470 ## finally add some decoration for histograms
1471 import GaudiPython.HistoUtils
1472
1473 # =============================================================================
1474 # pseudo help
1475 # =============================================================================
1476 def _help_() :
1477 print __doc__ , __author__
1478 print '\t\t\tDoc-string for class GaudiAlgo \n' , GaudiAlgo.__doc__
1479 print '\t\t\tDoc-string for class HistoAlgo \n' , HistoAlgo.__doc__
1480 print '\t\t\tDoc-string for class TupleAlgo \n' , TupleAlgo.__doc__
1481
1482 # =============================================================================
1483 # pseudo-test suite
1484 # =============================================================================
1485 if __name__ == '__main__' :
1486 _help_()
1487
1488 # =============================================================================
1489 # The END
1490 # =============================================================================
GaudiPython.Bindings.iAlgorithm
Definition: Bindings.py:313
GaudiPython.GaudiAlgs._getDet
def _getDet(self, location)
Trivial function to access the data in TDS.
Definition: GaudiAlgs.py:382
GaudiPython.GaudiAlgs._Counter_a_
def _Counter_a_(self, name)
Definition: GaudiAlgs.py:1337
GaudiPython.GaudiAlgs._GaudiTupleAlg
_GaudiTupleAlg
Definition: GaudiAlgs.py:487
GaudiPython.GaudiAlgs._t_column_ull_
def _t_column_ull_(s, a)
Definition: GaudiAlgs.py:1103
GaudiPython.Bindings.InterfaceCast
Definition: Bindings.py:86
GaudiPython.GaudiAlgs._Tools_t_
def _Tools_t_(self)
Definition: GaudiAlgs.py:1244
GaudiPython.GaudiAlgs._profile2D_
def _profile2D_(s, a)
Definition: GaudiAlgs.py:962
GaudiPython.GaudiAlgs.TupleDecColumnDispatcher.mapping
mapping
Definition: GaudiAlgs.py:1054
GaudiPython.GaudiAlgs._Counter_t_
def _Counter_t_(self, name)
Definition: GaudiAlgs.py:1351
GaudiPython.GaudiAlgs._evtCol_
def _evtCol_(s, a)
Definition: GaudiAlgs.py:1013
GaudiPython.GaudiAlgs._decorate_tuples_
def _decorate_tuples_(klasses)
Definition: GaudiAlgs.py:1022
Gaudi::Functional::details::zip::range
decltype(auto) range(Args &&...args)
Zips multiple containers together to form a single range.
Definition: FunctionalDetails.h:57
GaudiPython.GaudiAlgs.TupleDecColumnDispatcher.__call__
def __call__(self, a)
Definition: GaudiAlgs.py:1056
GaudiPython.GaudiAlgs._get_all_counters_
def _get_all_counters_(self, method, name=None)
get all counters
Definition: GaudiAlgs.py:1265
GaudiPython.GaudiAlgs._t_ntuple_
def _t_ntuple_(s, a)
Definition: GaudiAlgs.py:1078
GaudiPython.GaudiAlgs._initialize_
def _initialize_(self)
The default initialization (initialization of base C++ class + data.
Definition: GaudiAlgs.py:213
GaudiPython.GaudiAlgs._detSvc
def _detSvc(self)
Trivial helper function to access Detector Data and Detector Data Service.
Definition: GaudiAlgs.py:325
GaudiPython.GaudiAlgs.TupleDecColumnDispatcher.__doc__
__doc__
Definition: GaudiAlgs.py:1048
GaudiPython.GaudiAlgs._nTuple_
def _nTuple_(s, a)
Definition: GaudiAlgs.py:1007
GaudiPython.GaudiAlgs._plot2D_
def _plot2D_(s, a)
Definition: GaudiAlgs.py:899
GaudiPython.GaudiAlgs.TupleDecColumnDispatcher.func
func
Definition: GaudiAlgs.py:1047
GaudiPython.GaudiAlgs.objectmethod.method
method
Definition: GaudiAlgs.py:834
GaudiPython.GaudiAlgs._init_
def _init_(self, name, args)
The constructor from unique algorithm instance name,.
Definition: GaudiAlgs.py:191
GaudiPython.GaudiAlgs._get_
def _get_(self, location, rootInTES=True)
get the data from TES using GaudiCommon methods, respecting RootInTES
Definition: GaudiAlgs.py:390
GaudiPython.GaudiAlgs._initialize_tuple_
def _initialize_tuple_(self)
The default initialization (initialization of base C++ class + data members)
Definition: GaudiAlgs.py:255
GaudiKernel.ROOT6WorkAroundEnabled
def ROOT6WorkAroundEnabled(id=None)
Definition: __init__.py:3
GaudiPython.GaudiAlgs._plot3D_
def _plot3D_(s, a)
Definition: GaudiAlgs.py:920
GaudiPython.GaudiAlgs.mapvct
def mapvct(func, sequence, ovct=None)
Definition: GaudiAlgs.py:1194
GaudiPython.GaudiAlgs._t_farray_
def _t_farray_(s, a)
Definition: GaudiAlgs.py:1118
GaudiPython.GaudiAlgs._evtSvc
def _evtSvc(self, location=None)
Trivial helper function to access Event Data and Event Data Service.
Definition: GaudiAlgs.py:292
GaudiPython.GaudiAlgs._service_
def _service_(self, interface, name, create=True)
Useful method to locate a service:
Definition: GaudiAlgs.py:168
GaudiPython.GaudiAlgs._get_all_histos_
def _get_all_histos_(component, method, name)
Definition: GaudiAlgs.py:1373
GaudiPython.GaudiAlgs._t_fmatrix_
def _t_fmatrix_(s, a)
Definition: GaudiAlgs.py:1123
GaudiPython.GaudiAlgs._t_array_
def _t_array_(s, a)
Definition: GaudiAlgs.py:1108
GaudiPython.GaudiAlgs.objectmethod
Definition: GaudiAlgs.py:832
GaudiPython.GaudiAlgs._decorate_algs_
def _decorate_algs_(klasses)
Definition: GaudiAlgs.py:1179
GaudiPython.GaudiAlgs._decorate_plots_
def _decorate_plots_(klasses)
Definition: GaudiAlgs.py:990
GaudiPluginService.cpluginsvc.func
func
Definition: cpluginsvc.py:218
GaudiPython.GaudiAlgs._get_counter_
def _get_counter_(self, method, name)
Definition: GaudiAlgs.py:1330
GaudiPython.GaudiAlgs._help_
def _help_()
Definition: GaudiAlgs.py:1476
GaudiPython.GaudiAlgs._get_attr_
def _get_attr_(self, pname)
get the attribute or property
Definition: GaudiAlgs.py:465
gaudirun.type
type
Definition: gaudirun.py:125
GaudiPython.GaudiAlgs._set_attr_
def _set_attr_(self, pname, pvalue)
set the attribute or property
Definition: GaudiAlgs.py:476
GaudiPython.GaudiAlgs._get
def _get(self, location)
Trivial function to access the data in TES.
Definition: GaudiAlgs.py:374
GaudiPython.GaudiAlgs._stop_
def _stop_(self)
Definition: GaudiAlgs.py:869
GaudiPython.GaudiAlgs._start_
def _start_(self)
Definition: GaudiAlgs.py:848
GaudiPython.GaudiAlgs._Tools_a_
def _Tools_a_(self)
Definition: GaudiAlgs.py:1228
GaudiPython.GaudiAlgs.HistoAlgo
The base class for easy histogramming.
Definition: GaudiAlgs.py:678
GaudiPython.GaudiAlgs._Histos_t_
def _Histos_t_(self, name=None)
Definition: GaudiAlgs.py:1429
GaudiPython.GaudiAlgs._Counters_a_
def _Counters_a_(self, name=None)
get all counters
Definition: GaudiAlgs.py:1284
GaudiPython.GaudiAlgs.TupleDecColumnDispatcher.__init__
def __init__(self, func)
Definition: GaudiAlgs.py:1046
GaudiPython.GaudiAlgs._initialize_histo_
def _initialize_histo_(self)
The default initialization (initialization of base C++ class + data members)
Definition: GaudiAlgs.py:236
GaudiPython.GaudiAlgs._Histos_a_
def _Histos_a_(self, name=None)
Definition: GaudiAlgs.py:1408
GaudiPython.GaudiAlgs._t_valid_
def _t_valid_(s, a)
Definition: GaudiAlgs.py:1083
GaudiPython.GaudiAlgs._evtcolSvc
def _evtcolSvc(self)
Trivial helper function to access Event Collection Service.
Definition: GaudiAlgs.py:415
std::vector
STL class.
GaudiPython.GaudiAlgs._execute_
def _execute_(self)
Definition: GaudiAlgs.py:859
GaudiPython.GaudiAlgs._get_all_tools_
def _get_all_tools_(self, method)
Definition: GaudiAlgs.py:1215
GaudiPython.Bindings
Definition: Bindings.py:1
GaudiPython.GaudiAlgs._t_column_ll_
def _t_column_ll_(s, a)
Definition: GaudiAlgs.py:1098
GaudiPython.GaudiAlgs._t_matrix_
def _t_matrix_(s, a)
Definition: GaudiAlgs.py:1113
GaudiPython.GaudiAlgs._tool_
def _tool_(self, interface, typename, name=None, parent=None, create=True)
Useful method to locate the tool a certain.
Definition: GaudiAlgs.py:121
GaudiPython.GaudiAlgs._t_write_
def _t_write_(s, a)
Definition: GaudiAlgs.py:1088
GaudiPython.GaudiAlgs._t_nTuple_
def _t_nTuple_(s, a)
Definition: GaudiAlgs.py:1073
GaudiPython.GaudiAlgs.TupleAlgo
The base class for easy manupulations with N-Tuples.
Definition: GaudiAlgs.py:788
GaudiPython.GaudiAlgs._GaudiAlgorithm
_GaudiAlgorithm
Definition: GaudiAlgs.py:485
GaudiPython.GaudiAlgs._exist_
def _exist_(self, location, rootInTES=True)
check the data from TES using GaudiCommon methods, respecting RootInTES
Definition: GaudiAlgs.py:398
GaudiPython.GaudiAlgs._histoSvc
def _histoSvc(self, address=None)
Trivial helper function to access Histogram Data and Histogram Data Service.
Definition: GaudiAlgs.py:357
GaudiPython.GaudiAlgs.GaudiAlgo
the base class for all algorithm Python-image of C++ clkass GaudiAlgorithm
Definition: GaudiAlgs.py:552
GaudiPython.GaudiAlgs._plot1D_
def _plot1D_(s, a)
Definition: GaudiAlgs.py:881
GaudiPython.GaudiAlgs._success_
def _success_(self)
Dummy method returning success.
Definition: GaudiAlgs.py:432
GaudiPython.GaudiAlgs._profile1D_
def _profile1D_(s, a)
Definition: GaudiAlgs.py:944
GaudiPython.GaudiAlgs._finalize_
def _finalize_(self)
The default finalization (finalization of base C++ class)
Definition: GaudiAlgs.py:424
GaudiPython.GaudiAlgs._GaudiHistoAlg
_GaudiHistoAlg
Definition: GaudiAlgs.py:486
GaudiPython.GaudiAlgs.TupleDecColumnDispatcher
Definition: GaudiAlgs.py:1044
GaudiPython.GaudiAlgs._ntupleSvc
def _ntupleSvc(self)
Trivial helper function to access NTuple Service.
Definition: GaudiAlgs.py:407
GaudiPython.GaudiAlgs.objectmethod.__init__
def __init__(self, m)
Definition: GaudiAlgs.py:833
GaudiPython.Bindings.AppMgr
Definition: Bindings.py:662
GaudiPython.GaudiAlgs._Counters_t_
def _Counters_t_(self, name=None)
Definition: GaudiAlgs.py:1306
GaudiPython.GaudiAlgs._setProperty_
def _setProperty_(self, pname, pvalue)
set the value for the given property
Definition: GaudiAlgs.py:455
GaudiPython.GaudiAlgs._t_column_
def _t_column_(s, a)
Definition: GaudiAlgs.py:1093
GaudiPython.GaudiAlgs.objectmethod.__call__
def __call__(self, args)
Definition: GaudiAlgs.py:835
GaudiPython.GaudiAlgs._getProperty_
def _getProperty_(self, pname)
get the value of the given property
Definition: GaudiAlgs.py:445
GaudiPython.Bindings.iAlgTool
Definition: Bindings.py:338
GaudiPython.HistoUtils
Definition: HistoUtils.py:1