| The Gaudi Framework v30r0 (c919700c)

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