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