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