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