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