| # Gaudi Framework, version v22r0 |

Home |  | Generated: 9 Feb 2011

# GaudiAlgs.py

Go to the documentation of this file.

    00001 #!/usr/bin/env python
    00002 # =============================================================================
    00003 # $Id: GaudiAlgs.py,v 1.2 2008/07/15 16:05:53 marcocle Exp $
    00004 # =============================================================================
    00005 ## @file
    00006 #
    00007 # Helper module, which effectively 'imports' few useful C++ algorithmic
    00008 # base classes into Python
    00009 #
    00010 #
    00011 #              The major imported classes are :
    00012 #
    00013 # - GaudiAlgo - analogue for GaudiAlgorithm C++ class from GaudiAlg package
    00014 # - HistoAlgo - analogue for GaudiHistoAlg  C++ class from GaudiAlg package
    00015 # - TupleAlgo - analogue for GaudiTupleAlg  C++ class from GaudiAlg package
    00016 #
    00017 # @author Vanya BELYAEV ibelyaev@physics.syr.edu
    00018 # @date 2006-11-26
    00019 # =============================================================================
    00020 """
    00021 *******************************************************************************
    00022 *                                                * 'Physisics do not like it, *
    00023 *                                                *  physisics do not need it, *
    00024 *                                                *  physisics do not use  it' *
    00025 *                                                * ****************************
    00026 *                                                                             *
    00027 * Helper module, which effectively 'imports' few useful C++ algorithmic       *
    00028 * base classes into Python                                                    *
    00029 *                                                                             *
    00030 *******************************************************************************
    00031 *              The major imported classes are :                               *
    00032 *                                                                             *
    00033 * (1) GaudiAlgo - analogue for GaudiAlgorithm C++ class from GaudiAlg package *
    00034 * (2) HistoAlgo - analogue for GaudiHistoAlg  C++ class from GaudiAlg package *
    00035 * (3) TupleAlgo - analogue for GaudiTupleAlg  C++ class from GaudiAlg package *
    00036 *******************************************************************************
    00037 """
    00038 # =============================================================================
    00039 __author__ = 'Vanya BELYAEV  Ivan.Belyaev@lapp.in2p3.fr'
    00040 # =============================================================================
    00041 # list of "public" symbols
    00042 # =============================================================================
    00043 __all__ = (
    00044     'GaudiAlgo' ,                    ##               base class for algorithms
    00045     'HistoAlgo' ,                    ## base class for histo-related algorithms
    00046     'TupleAlgo' ,                    ## base class for tuple-related algorithms
    00047     'Tuple'     ,                    ##                                 N-Tuple
    00048     'HistoID'   ,                    ##                         ID for N-tuples
    00049     'TupleID'   ,                    ##                       ID for Histograms
    00050     'aida2root' ,                    ##                  AIDA -> ROOT converter
    00051     'SUCCESS'                        ##                             status code
    00052     )
    00053 # =============================================================================
    00054 # import core of Gaudi
    00055 import GaudiPython.Bindings                           ##       The basic module
    00056 iAlgorithm = GaudiPython.Bindings.iAlgorithm          ##    Algorithm interface
    00057 iAlgTool   = GaudiPython.Bindings.iAlgTool            ##         Tool interface
    00058 #
    00059 from GaudiPython.Bindings import (
    00060     SUCCESS        ,                                  ##            status code
    00061     InterfaceCast  ,                                  ##       "queryInterface"
    00062     iDataSvc       ,                                  ##           Data Service
    00063     iHistogramSvc  ,                                  ##      Histogram Service
    00064     iNTupleSvc     ,                                  ##        N-Tuple service
    00065     AppMgr                                            ##    Application Manager
    00066     )
    00067 #
    00068 from GaudiPython.Bindings   import gbl as cpp         ##  global C++ namepspace
    00069 from GaudiPython.HistoUtils import aida2root          ## AIDA -> ROTO converter
    00070 # =============================================================================
    00071 # std C++ namespace
    00072 std = cpp.std                                         ## std C++ namespace
    00073
    00074 ## "typedef" for GaudiPython::Vector
    00075 Vector = std.vector('double')
    00076 ## "typedef" for GaudiPython::Matrix
    00077 Matrix = std.vector('std::vector<double>')
    00078
    00079 ## histogram and N-Tuple universal identifier
    00080 HID       = cpp.GaudiAlg.ID
    00081 HistoID   = HID
    00082 TID       = HID
    00083 TupleID   = TID
    00084
    00085 ## get the decorator:
    00086 AlgDecorator      = cpp.GaudiPython.AlgDecorator
    00087 HistoDecorator    = cpp.GaudiPython.HistoDecorator
    00088 TupleAlgDecorator = cpp.GaudiPython.TupleAlgDecorator
    00089 TupleDecorator    = cpp.GaudiPython.TupleDecorator
    00090
    00091 # =============================================================================
    00092 ## Useful method to locate the tool a certain
    00093 #
    00094 #  Usage:
    00095 #
    00096 #  @code
    00097 #
    00098 #      # locate public tool
    00099 #      t1 = self.tool(ITrExtrapolator,'TrParabolicExtrapolator')
    00100 #      # locate private tool
    00101 #      t2 = self.tool(ITrExtrapolator,'TrParabolicExtrapolator',parent=self)
    00102 #      # locate public tool with defined name
    00103 #      t3 = self.tool(ITrExtrapolator,'TrParabolicExtrapolator/MyExt1')
    00104 #      # locate private tool with defined name
    00105 #      t4 = self.tool(ITrExtrapolator,'TrParabolicExtrapolator/MyExt2',parent=self)
    00106 #      # locate public tool with defined name
    00107 #      t5 = self.tool(ITrExtrapolator,'TrParabolicExtrapolator','MyExt3')
    00108 #      # locate private tool with defined name
    00109 #      t6 = self.tool(ITrExtrapolator,'TrParabolicExtrapolator','MyExt4',parent=self)
    00110 #
    00111 #  @endcode
    00112 #
    00113 #  @author Vanya BELYAEV ibelyaev@physics.syr.edu
    00114 #  @date 2006-11-26
    00115 def _tool_ ( self             ,
    00116              interface        ,
    00117              typename         ,
    00118              name     = None  ,
    00119              parent   = None  ,
    00120              create   = True  ) :
    00121     """
    00122     Useful method to locate the tool a certain
    00123
    00124     Usage:
    00125
    00126     # locate public tool
    00127     t1 = self.tool(ITrExtrapolator,'TrParabolicExtrapolator')
    00128     # locate private tool
    00129     t2 = self.tool(ITrExtrapolator,'TrParabolicExtrapolator',parent=self)
    00130     # locate public tool with defined name
    00131     t3 = self.tool(ITrExtrapolator,'TrParabolicExtrapolator/MyExt1')
    00132     # locate private tool with defined name
    00133     t4 = self.tool(ITrExtrapolator,'TrParabolicExtrapolator/MyExt2',parent=self)
    00134     # locate public tool with defined name
    00135     t5 = self.tool(ITrExtrapolator,'TrParabolicExtrapolator','MyExt3')
    00136     # locate private tool with defined name
    00137     t6 = self.tool(ITrExtrapolator,'TrParabolicExtrapolator','MyExt4',parent=self)
    00138
    00139     """
    00140     if not interface : interface = cpp.IAlgTool
    00141     if not parent    : parent    = self
    00142     if name          : typename  += '/' + name
    00143     _tool = AlgDecorator.tool_( self , typename , parent , create )
    00144     if not _tool : return None
    00145     _tool = InterfaceCast(interface)(_tool)
    00146     if not _tool :
    00147         self.Warning('Invalid cast to interface %s' % interface )
    00148         return None
    00149     return _tool
    00150
    00151 # =============================================================================
    00152 ## Useful method to locate a service:
    00153 #
    00154 #     Usage:
    00155 #
    00156 #  @code
    00157 #
    00158 #     ntsvc = self.svc( INTupleSvc , 'NTUpleSvc' )
    00159 #
    00160 #  @endcode
    00161 #
    00162 #  @author Vanya BELYAEV ibelyaev@physics.syr.edu
    00163 #  @date 2006-11-26
    00164 def _service_ ( self            ,
    00165                 interface       ,
    00166                 name            ,
    00167                 create   = True ) :
    00168     """
    00169     Useful method to locate a service:
    00170
    00171     Usage:
    00172
    00173     ntsvc = self.svc( INTupleSvc , 'NTUpleSvc' )
    00174
    00175     """
    00176     if not interface : interface = cpp.IInterface
    00177     _svc = AlgDecorator.svc_ ( self , name , create )
    00178     if not _svc : return None
    00179     _svc = InterfaceCast(interface)(_svc)
    00180     if not _svc :
    00181         self.Warning('Invalid cast to interface %s' % interface )
    00182         return None
    00183     return _svc
    00184
    00185 # =============================================================================
    00186 ## The constructor from unique algorithm instance name,
    00187 #
    00188 #  @author Vanya BELYAEV ibelyaev@physics.syr.edu
    00189 #  @date 2006-11-26
    00190 def _init_ ( self , name , **args ) :
    00191     """
    00192     The constructor from unique algorithm instance name & parameters
    00193     """
    00194     self._Base.__init__( self , self , name )
    00195     appMgr = AppMgr()
    00196     algMgr = appMgr._algmgr
    00197     status = algMgr.addAlgorithm( self )
    00198     if status.isFailure() :
    00199         raise RuntimeError, 'Unable to add Algorithm "' + name + '"'
    00200     iAlgorithm.__init__ ( self , name , self )
    00201     for key in args : setattr ( self , key , args[key] )
    00202     # take some care about the ownership of the algorithms
    00203     if not appMgr.__dict__.has_key ( 'GaudiPythonAlgos') :
    00204         appMgr.__dict__[ 'GaudiPythonAlgos'] = []
    00205     appMgr.__dict__[ 'GaudiPythonAlgos'].append( self )
    00206
    00207 # =============================================================================
    00208 ## The default initialization (initialization of base C++ class + data
    00209 #
    00210 #  @author Vanya BELYAEV ibelyaev@physics.syr.edu
    00211 #  @date 2006-11-26
    00212 def _initialize_ ( self ) :
    00213     """
    00214     The default initialization (initialization of base C++ class + data)
    00215     """
    00216     status = self._Base.initialize_( self )
    00217     if status.isFailure() : return status
    00218
    00219     # set the basic services
    00220     _e = self._Base.evtSvc( self )
    00221     _s = InterfaceCast(cpp.IService)(_e)
    00222     self._evtSvc_ = iDataSvc ( _s.name() , _e )
    00223
    00224     _d = self._Base.detSvc( self )
    00225     _s = InterfaceCast(cpp.IService)(_d)
    00226     self._detSvc_ = iDataSvc ( _s.name() , _d )
    00227
    00228     return status
    00229
    00230 # =============================================================================
    00231 ## The default initialization (initialization of base C++ class + data members)
    00232 #
    00233 #  @author Vanya BELYAEV ibelyaev@physics.syr.edu
    00234 #  @date 2006-11-26
    00235 def _initialize_histo_ ( self ) :
    00236     """
    00237     The default initialization (initialization of base C++ class + data members)
    00238     """
    00239     status = _initialize_( self )
    00240     if status.isFailure() : return status
    00241
    00242     # set the basic services
    00243     _h = self._Base.histoSvc( self )
    00244     _s = InterfaceCast(cpp.IService)(_h)
    00245     self._histoSvc_ = iHistogramSvc ( _s.name() , _h )
    00246
    00247     return status
    00248
    00249 # =============================================================================
    00250 ## The default initialization (initialization of base C++ class + data members)
    00251 #
    00252 #  @author Vanya BELYAEV ibelyaev@physics.syr.edu
    00253 #  @date 2006-11-26
    00254 def _initialize_tuple_ ( self ) :
    00255     """
    00256     The default initialization (initialization of base C++ class + data members)
    00257     """
    00258     status = _initialize_histo_( self )
    00259     if status.isFailure() : return status
    00260
    00261     # set the basic services
    00262     if self.produceNTuples() :
    00263         _n = self._Base.ntupleSvc( self )
    00264         _s = InterfaceCast(cpp.IService)(_n)
    00265         self._ntupleSvc_ = iNTupleSvc ( _s.name() , _n )
    00266
    00267     if self.produceEvtCols() :
    00268         _n = self._Base.evtColSvc( self )
    00269         _s = InterfaceCast(cpp.IService)(_n)
    00270         self._evtcolSvc_ = iNTupleSvc ( _s.name() , _n )
    00271
    00272     return status
    00273
    00274 # =============================================================================
    00275 ## Trivial helper function to access Event Data and Event Data Service
    00276 #
    00277 #    Usage:
    00278 #
    00279 #  @code
    00280 #
    00281 #    # get event data service
    00282 #    svc = self.evtSvc()
    00283 #
    00284 #    # get the data
    00285 #    hits = self.evtSvc('MC/Calo/Hits')
    00286 #
    00287 #  @endcode
    00288 #
    00289 #  @author Vanya BELYAEV ibelyaev@physics.syr.edu
    00290 #  @date 2006-11-26
    00291 def _evtSvc   ( self , location = None ) :
    00292     """
    00293     Trivial helper function to access Event Data and Event Data Service
    00294
    00295     Usage:
    00296
    00297     # get event data service
    00298     svc = self.evtSvc()
    00299
    00300     # get the data
    00301     hits = self.evtSvc('MC/Calo/Hits')
    00302     """
    00303     if not location :
    00304         return self._evtSvc_
    00305     return self._evtSvc_[location]
    00306
    00307 # =============================================================================
    00308 ## Trivial helper function to access Detector Data and Detector  Data Service
    00309 #
    00310 #    Usage:
    00311 #
    00312 #  @code
    00313 #
    00314 #    # get detector data service
    00315 #    svc = self.detSvc()
    00316 #
    00317 #    # get the data
    00318 #    lhcb = self.detSvc('/dd/Structure/LHCb')
    00319 #
    00320 #  @endcode
    00321 #
    00322 #  @author Vanya BELYAEV ibelyaev@physics.syr.edu
    00323 #  @date 2006-11-26
    00324 def _detSvc   ( self ) :
    00325     """
    00326     Trivial helper function to access Detector Data and Event Data Service
    00327
    00328     Usage:
    00329     # get detector data service
    00330     svc = self.detSvc()
    00331
    00332     # get the data
    00333     lhcb = self.detSvc('/dd/Structure/LHCb')
    00334     """
    00335     if not location :
    00336         return self._detSvc_
    00337     return self._detSvc_[location]
    00338
    00339 # =============================================================================
    00340 ## Trivial helper function to access Histogram  Data and Histogram  Data Service
    00341 #
    00342 #    Usage:
    00343 #
    00344 #  @code
    00345 #
    00346 #    # get histogram data service
    00347 #    svc = self.histoSvc()
    00348 #
    00349 #    # get the data
    00350 #    histo = self.histoSvc('/stat/Calo/1')
    00351 #
    00352 #  @endcode
    00353 #
    00354 #  @author Vanya BELYAEV ibelyaev@physics.syr.edu
    00355 #  @date 2006-11-26
    00356 def _histoSvc  ( self , address = None ) :
    00357     """
    00358     Trivial helper function to access Histogram  Data and Histogram  Data Service
    00359
    00360     Usage:
    00361
    00362     # get histogram data service
    00363     svc = self.histoSvc()
    00364
    00365     # get the data
    00366     histo = self.histoSvc('/stat/Calo/1')
    00367     """
    00368     if not address : return self._histoSvc_
    00369     return self._histoSvc_[ address ]
    00370
    00371 # =============================================================================
    00372 ## Trivial function to access the data in TES
    00373 def _get      ( self , location ) :
    00374     """
    00375     Trivial function to access the data in TES
    00376     """
    00377     return self._evtSvc_[location]
    00378
    00379 # =============================================================================
    00380 ## Trivial function to access the data in TDS
    00381 def _getDet   ( self , location ) :
    00382     """
    00383     Trivial function to access the data in TDS
    00384     """
    00385     return self._detSvc_[location]
    00386
    00387 # =============================================================================
    00388 ## Trivial helper function to access NTuple Service
    00389 def _ntupleSvc ( self ) :
    00390     """
    00391     Trivial function to access N-Tuple Service
    00392     """
    00393     return self._ntupleSvc_
    00394
    00395 # =============================================================================
    00396 ## Trivial helper function to access Event Collection Service
    00397 def _evtcolSvc ( self ) :
    00398     """
    00399     Trivial function to access Event Collection Service
    00400     """
    00401     return self._evtcolSvc_
    00402
    00403
    00404 # =============================================================================
    00405 ## The default finalization (finalization of base C++ class)
    00406 def _finalize_   ( self ) :
    00407     """
    00408     The default finalization : finalize the base C++ class
    00409     """
    00410     status = self._Base.finalize_  ( self )
    00411     return status
    00412 # =============================================================================
    00413 ## Dummy method returning success
    00414 def _success_ ( self ) : return SUCCESS
    00415
    00416
    00417 # =============================================================================
    00418 ## check the existence of the property with the given name
    00419 def _hasProperty_ ( self , pname ) :
    00420     """
    00421     The trivial function which checks the existence of the property with given name
    00422     """
    00423     return cpp.Gaudi.Utils.hasProperty ( self , pname )
    00424
    00425 # =============================================================================
    00426 ## get the value of the given property
    00427 def _getProperty_ ( self , pname ) :
    00428     """
    00429     Get the property by name
    00430     """
    00431     if not self.hasProperty( pname ) :
    00432         raise AttributeError, 'property %s does not exist' % pname
    00433     return iAlgorithm.__getattr__( self , pname )
    00434
    00435 # =============================================================================
    00436 ## set the value for the given property
    00437 def _setProperty_ ( self , pname , pvalue ) :
    00438     """
    00439     Set the property from the value
    00440     """
    00441     if not self.hasProperty( pname ) :
    00442         raise AttributeError, 'property %s does not exist' % pname
    00443     return iAlgorithm.__setattr__ ( self , pname , pvalue )
    00444
    00445 # =============================================================================
    00446 ## get the attribute or property
    00447 def _get_attr_ ( self , pname ) :
    00448     """
    00449     Get the attribute (or property)
    00450     - if the attribute name corresponds to the property name, property value is returned
    00451     """
    00452     if self.hasProperty( pname ) :
    00453         return iAlgorithm.__getattr__ ( self , pname )
    00454     raise AttributeError, 'attribute/property %s does not exist' % pname
    00455
    00456 # =============================================================================
    00457 ## set the attribute or property
    00458 def _set_attr_ ( self , pname , pvalue ) :
    00459     """
    00460     Set the attribute (or property) :
    00461     - if the attribute name corresponds to the property name, the property is updated
    00462     """
    00463     if not self.hasProperty( pname ) : self.__dict__[pname] = pvalue
    00464     else : iAlgorithm.__setattr__ ( self , pname , pvalue )
    00465
    00466
    00467 _GaudiAlgorithm = cpp.GaudiPython.PyAlg( 'GaudiAlgorithm' )
    00468 _GaudiHistoAlg  = cpp.GaudiPython.PyAlg( 'GaudiHistoAlg'  )
    00469 _GaudiTupleAlg  = cpp.GaudiPython.PyAlg( 'GaudiTupleAlg'  )
    00470
    00471 # =============================================================================
    00472 ## @class GaudiAlgo
    00473 #  the base class for all algorithm
    00474 #  Python-image of C++ clkass GaudiAlgorithm
    00475 #
    00476 #  Usage:
    00477 #
    00478 #  @code
    00479 #
    00480 #  from GauidPython.GaudiAlgs   import GaudiAlgo, SUCCESS
    00481 #
    00482 #  class MyClass(GaudiAlgo) :
    00483 #       """
    00484 #       My specific Algorithm, derived from GaudiAlgo base class
    00485 #       """
    00486 #       def __init__( self , name , **args ) :
    00487 #           """
    00488 #           Constructor from algorithm instance name & parameters'
    00489 #           """
    00490 #           #invoke the constructor of base class
    00491 #           GaudiAlgo.__init__(self , name , **args )
    00492 #
    00493 #       def initialize ( self ) :
    00494 #           'Algorithm initialization'
    00495 #           # initialize the base class
    00496 #           status = GaudiAlgo.initialize( self )
    00497 #           if status.isFailure() : return status
    00498 #
    00499 #           # locate the services and tools
    00500 #
    00501 #           # locate some tool:
    00502 #           extrapolator = self.tool(ITrExtrapolator,'TrExtrapolator')
    00503 #
    00504 #           # locate the service
    00505 #           rndmSvc = self.svc(IRndmGenSvc, 'RndmGenSvc')
    00506 #
    00507 #           return SUCCESS
    00508 #
    00509 #
    00510 #       def execute ( self ) :
    00511 #            'Major method (from IAlgorithm interface)'
    00512 #
    00513 #           # get some data from Transient Event Store
    00514 #           tracks = self.get('/Event/Rec/Tracks')
    00515 #
    00516 #           # use counters
    00517 #           c1 = self.counter('#Tracks')
    00518 #           c2 = self.counter('No Tracks')
    00519 #           if tracks.empty :
    00520 #              c2+=1
    00521 #           c1 += tracks->size()
    00522 #
    00523 #           if 1000 < tracks.size() :
    00524 #                return self.Error('The event is *VERY* busy')
    00525 #
    00526 #           return SUCCESS
    00527 #
    00528 #  @endcode
    00529 #
    00530 #  @see GaudiAlgorithm
    00531 #
    00532 #  @author Vanya BELYAEV ibelyaev@physics.syr.edu
    00533 #  @date 2006-11-26
    00534 class GaudiAlgo ( _GaudiAlgorithm , iAlgorithm ) :
    00535     """
    00536 *******************************************************************************
    00537 *                                                * 'Physisics do not like it, *
    00538 *                                                *  physisics do not need it, *
    00539 *                                                *  physisics do not use  it' *
    00540 *                                                * ****************************
    00541 *  Usage:                                                                     *
    00542 *                                                                             *
    00543 *  from GaudiPython.GaudiAlgs   import GaudiAlgo, SUCCESS                     *
    00544 *                                                                             *
    00545 *  class MyClass(GaudiAlgo) :                                                 *
    00546 *       ' My specific Algorithm, derived from GaudiAlgo base class '          *
    00547 *       def __init__( self , name , **args ) :                                *
    00548 *            'Constructor from algorithm instance name & parameters'          *
    00549 *             #invoke the constructor of base class                           *
    00550 *             GaudiAlgo.__init__(self , name , **args )                       *
    00551 *                                                                             *
    00552 *       def initialize ( self ) :                                             *
    00553 *           'Algorithm initialization'                                        *
    00554 *           # initialize the base class                                       *
    00555 *           status = GaudiAlgo.initialize( self )                             *
    00556 *           if status.isFailure() : return status                             *
    00557 *                                                                             *
    00558 *           # locate the services and tools                                   *
    00559 *                                                                             *
    00560 *           # locate some tool:                                               *
    00561 *           extrapolator = self.tool(ITrExtrapolator,'TrExtrapolator')        *
    00562 *                                                                             *
    00563 *           # locate the service                                              *
    00564 *           rndmSvc = self.svc(IRndmGenSvc, 'RndmGenSvc')                     *
    00565 *                                                                             *
    00566 *           return SUCCESS                                                    *
    00567 *                                                                             *
    00568 *                                                                             *
    00569 *       def execute ( self ) :                                                *
    00570 *            'Major method (from IAlgorithm interface)'                       *
    00571 *                                                                             *
    00572 *           # get some data from Transient Event Store                        *
    00573 *           tracks = self.get('/Event/Rec/Tracks')                            *
    00574 *                                                                             *
    00575 *           # use counters                                                    *
    00576 *           c1 = self.counter('#Tracks')                                      *
    00577 *           c2 = self.counter('No Tracks')                                    *
    00578 *           if tracks.empty :                                                 *
    00579 *              c2+=1                                                          *
    00580 *           c1 += tracks->size()                                              *
    00581 *                                                                             *
    00582 *           if 1000 < tracks.size() :                                         *
    00583 *                return self.Error('The event is *VERY* busy')                *
    00584 *                                                                             *
    00585 *           return SUCCESS                                                    *
    00586 *                                                                             *
    00587 *******************************************************************************
    00588     """
    00589     pass
    00590
    00591 # =============================================================================
    00592 ## @class HistoAlgo
    00593 #  The base class for easy histogramming
    00594 #
    00595 #  Usage:
    00596 #
    00597 #
    00598 #  @code
    00599 #
    00600 #  from GaudiPython.GaudiAlgs import HistoAlgo, SUCCESS
    00601 #
    00602 #  class MyClass(HistoAlgo) :
    00603 #       ' My specific Algorithm, derived from GaudiAlgo base class '
    00604 #       def __init__( self , name , **args ) :
    00605 #            'Constructor from algorithm instance name & parameters'
    00606 #             #invoke the constructor of base class
    00607 #             HistoAlgo.__init__(self , name , **args )
    00608 #
    00609 #       def execute ( self ) :
    00610 #            'Major method (from IAlgorithm interface)'
    00611 #
    00612 #           # get some data from Transient Event Store
    00613 #           tracks = self.get('/Event/Rec/Tracks')
    00614 #
    00615 #           self.plot1D ( tracks->size() , '#tracks' , 0 , 100 )
    00616 #
    00617 #           return SUCCESS
    00618 #
    00619 #  @endcode
    00620 #
    00621 # Alternatively the histogram  could be booked in advance:
    00622 #
    00623 #  @code
    00624 #
    00625 #  class MyClass(HistoAlgo) :
    00626 #       ' My specific Algorithm, derived from GaudiAlgo base class '
    00627 #       def __init__( self , name ) :
    00628 #            'Constructor from algorithm instance name'
    00629 #             #invoke the constructor of base class
    00630 #             HistoAlgo.__init__(self , name )
    00631 #
    00632 #       def initialize ( self ) :
    00633 #           'Algorithm initialization'
    00634 #           # initialize the base class
    00635 #           status = HistoAlgo.initialize( self )
    00636 #           if status.isFailure() : return status
    00637 #
    00638 #           # book the histogram
    00639 #           self.h1 = selff.book1D ( '#tracks' , 0 , 100 )
    00640 #
    00641 #           return SUCCESS
    00642 #
    00643 #
    00644 #       def execute ( self ) :
    00645 #            'Major method (from IAlgorithm interface)'
    00646 #
    00647 #           # get some data from Transient Event Store
    00648 #           tracks = self.get('/Event/Rec/Tracks')
    00649 #
    00650 #           # fill the histogram
    00651 #           self.h1.fill ( tracks->size() )
    00652 #
    00653 #            return SUCCESS
    00654 #  @endcode
    00655 #
    00656 #  @see GaudiHistoAlg
    00657 #
    00658 #  @author Vanya BELYAEV ibelyaev@physics.syr.edu
    00659 #  @date 2006-11-26
    00660 class HistoAlgo ( _GaudiHistoAlg , iAlgorithm ) :
    00661     """
    00662 *******************************************************************************
    00663 *                                                * 'Physisics do not like it, *
    00664 *                                                *  physisics do not need it, *
    00665 *                                                *  physisics do not use  it' *
    00666 *                                                * ****************************
    00667 *  Usage:                                                                     *
    00668 *                                                                             *
    00669 *  from GaudiPython.GaudiAlgs import HistoAlgo, SUCCESS                       *
    00670 *                                                                             *
    00671 *  class MyClass(HistoAlgo) :                                                 *
    00672 *       ' My specific Algorithm, derived from GaudiAlgo base class '          *
    00673 *       def __init__( self , name , **args ) :                                *
    00674 *            'Constructor from algorithm instance name'                       *
    00675 *             #invoke the constructor of base class                           *
    00676 *             HistoAlgo.__init__(self , name , **args )                       *
    00677 *                                                                             *
    00678 *       def execute ( self ) :                                                *
    00679 *            'Major method (from IAlgorithm interface)'                       *
    00680 *                                                                             *
    00681 *           # get some data from Transient Event Store                        *
    00682 *           tracks = self.get('/Event/Rec/Tracks')                            *
    00683 *                                                                             *
    00684 *           self.plot1D ( tracks->size() , '#tracks' , 0 , 100 )              *
    00685 *                                                                             *
    00686 *           return SUCCESS                                                    *
    00687 *                                                                             *
    00688 * Alternatively the histogram  could be booked in advance:                    *
    00689 *                                                                             *
    00690 *  class MyClass(HistoAlgo) :                                                 *
    00691 *       ' My specific Algorithm, derived from GaudiAlgo base class '          *
    00692 *       def __init__( self , name ) :                                         *
    00693 *            'Constructor from algorithm instance name'                       *
    00694 *             #invoke the constructor of base class                           *
    00695 *             HistoAlgo.__init__(self , name )                                *
    00696 *                                                                             *
    00697 *       def initialize ( self ) :                                             *
    00698 *           'Algorithm initialization'                                        *
    00699 *           # initialize the base class                                       *
    00700 *           status = HistoAlgo.initialize( self )                             *
    00701 *           if status.isFailure() : return status                             *
    00702 *                                                                             *
    00703 *           # book the histogram                                              *
    00704 *           self.h1 = selff.book1D ( '#tracks' , 0 , 100 )                    *
    00705 *                                                                             *
    00706 *           return SUCCESS                                                    *
    00707 *                                                                             *
    00708 *                                                                             *
    00709 *       def execute ( self ) :                                                *
    00710 *            'Major method (from IAlgorithm interface)'                       *
    00711 *                                                                             *
    00712 *           # get some data from Transient Event Store                        *
    00713 *           tracks = self.get('/Event/Rec/Tracks')                            *
    00714 *                                                                             *
    00715 *           # fill the histogram                                              *
    00716 *           self.h1.fill ( tracks->size() )                                   *
    00717 *                                                                             *
    00718 *           return SUCCESS                                                    *
    00719 *                                                                             *
    00720 *******************************************************************************
    00721     """
    00722     pass
    00723
    00724 # =============================================================================
    00725 ## @class TupleAlgo
    00726 #  The base class for easy manupulations with N-Tuples
    00727 #
    00728 #  Usage:
    00729 #
    00730 #  @code
    00731 #
    00732 #  from GaudiPython.GaudiAlgs import TupleAlgo, SUCCESS
    00733 #
    00734 #  class MyClass(TupleAlgo) :
    00735 #       ' My specific Algorithm, derived from TupleAlgo base class '
    00736 #       def __init__( self , name , **args ) :
    00737 #            'Constructor from algorithm instance name& parameters'
    00738 #             #invoke the constructor of base class
    00739 #             TupleAlgo.__init__(self , name , **args )
    00740 #
    00741 #       def execute ( self ) :
    00742 #            'Major method (from IAlgorithm interface)'
    00743 #
    00744 #           # get some data from Transient Event Store
    00745 #           tracks = self.get('/Event/Rec/Tracks')
    00746 #
    00747 #           tup = self.nTuple('My N-Tuple')
    00748 #
    00749 #           for track in tracks :
    00750 #
    00751 #                 pt   = track.pt   ()
    00752 #                 p    = track.p    ()
    00753 #                 chi2 = track.chi2 ()
    00754 #
    00755 #                 #fill N-tuple:
    00756 #                 tup.column ( 'pt'   ,  pt   )
    00757 #                 tup.column ( 'p'    ,  p    )
    00758 #                 tup.column ( 'chi2' ,  chi2 )
    00759 #                 #commit the row
    00760 #                 tup.write  ()
    00761 #
    00762 #           return SUCCESS
    00763 #
    00764 #  @endcode
    00765 #
    00766 #  @see GaudiTupleAlg
    00767 #
    00768 #  @author Vanya BELYAEV ibelyaev@physics.syr.edu
    00769 #  @date 2006-11-26
    00770 class TupleAlgo ( _GaudiTupleAlg  , iAlgorithm ) :
    00771     """
    00772 *******************************************************************************
    00773 *                                                * 'Physisics do not like it, *
    00774 *                                                *  physisics do not need it, *
    00775 *                                                *  physisics do not use  it' *
    00776 *                                                * ****************************
    00777 *  Usage:                                                                     *
    00778 *                                                                             *
    00779 *  from GaudiPython.GaudiAlgs import TupleAlgo, SUCCESS                       *
    00780 *                                                                             *
    00781 *  class MyClass(TupleAlgo) :                                                 *
    00782 *       ' My specific Algorithm, derived from TupleAlgo base class '          *
    00783 *       def __init__( self , name , **args ) :                                *
    00784 *            'Constructor from algorithm instance name & parameters'          *
    00785 *             #invoke the constructor of base class                           *
    00786 *             TupleAlgo.__init__(self , name , **args )                       *
    00787 *                                                                             *
    00788 *       def execute ( self ) :                                                *
    00789 *            'Major method (from IAlgorithm interface)'                       *
    00790 *                                                                             *
    00791 *           # get some data from Transient Event Store                        *
    00792 *           tracks = self.get('/Event/Rec/Tracks')                            *
    00793 *                                                                             *
    00794 *           tup = self.nTuple('My N-Tuple')                                   *
    00795 *                                                                             *
    00796 *           for track in tracks :                                             *
    00797 *                                                                             *
    00798 *                 pt   = track.pt   ()                                        *
    00799 *                 p    = track.p    ()                                        *
    00800 *                 chi2 = track.chi2 ()                                        *
    00801 *                                                                             *
    00802 *                 #fill N-tuple:                                              *
    00803 *                 tup.column ( 'pt'   ,  pt   )                               *
    00804 *                 tup.column ( 'p'    ,  p    )                               *
    00805 *                 tup.column ( 'chi2' ,  chi2 )                               *
    00806 *                 #commit the row                                             *
    00807 *                 tup.write  ()                                               *
    00808 *                                                                             *
    00809 *           return SUCCESS                                                    *
    00810 *                                                                             *
    00811 *******************************************************************************
    00812     """
    00813     pass
    00814 class objectmethod(object) :
    00815     def __init__(self, m) :
    00816         self.method = m
    00817     def __call__(self, *args) :
    00818         print args
    00819         return self.method(*args )
    00820
    00821 GaudiAlgo._Base = _GaudiAlgorithm
    00822 HistoAlgo._Base = _GaudiHistoAlg
    00823 TupleAlgo._Base = _GaudiTupleAlg
    00824
    00825 # initialize is 'unique' method :
    00826 GaudiAlgo.initialize = _initialize_
    00827 HistoAlgo.initialize = _initialize_histo_
    00828 TupleAlgo.initialize = _initialize_tuple_
    00829
    00830 def _start_ ( self ) :
    00831     """
    00832     The stub 'start' method needed by the internal implementation of PyAlg<>.
    00833     """
    00834     # return self._Base.start_(self)
    00835     return SUCCESS
    00836
    00837 GaudiAlgo.start = _start_
    00838 HistoAlgo.start = _start_
    00839 TupleAlgo.start = _start_
    00840
    00841 def _execute_ ( self ) :
    00842     """
    00843     The fictive 'execute' method, which MUST be overwitten by user
    00844     """
    00845     raise RuntimeError, 'Execute method is not implemented for %s' % self.name()
    00846
    00847 GaudiAlgo.execute = _execute_
    00848 HistoAlgo.execute = _execute_
    00849 TupleAlgo.execute = _execute_
    00850
    00851 def _stop_ ( self ) :
    00852     """
    00853     The stub 'stop' method needed by the internal implementation of PyAlg<>.
    00854     """
    00855     # return self._Base.stop_(self)
    00856     return SUCCESS
    00857
    00858 GaudiAlgo.stop = _stop_
    00859 HistoAlgo.stop = _stop_
    00860 TupleAlgo.stop = _stop_
    00861
    00862 # =============================================================================
    00863 def _plot1D_    ( s, *a ) :
    00864     """
    00865     The basic method to fill (book-on-demand) 1D-histogram
    00866
    00867     The histogram will be created/booked dautomatically according to the
    00868     specifications:
    00869
    00870        - literal or numerical ID (optional)
    00871        - title
    00872        - low edge
    00873        - high edge
    00874        - number of bins (default is 100)
    00875
    00876     The reference to the histogram is returned and could be used for later manipulations
    00877
    00878     """
    00879     return HistoDecorator.plot1D    (s,*a)
    00880 # =============================================================================
    00881 def _plot2D_    ( s, *a ) :
    00882     """
    00883     The basic method to fill (book-on-demand) 2D-histogram
    00884
    00885     The histogram will be created/booked dautomatically according to the
    00886     specifications:
    00887
    00888        - literal or numerical ID (optional)
    00889        - title
    00890        - low X-edge
    00891        - high X-edge
    00892        - low Y-edge
    00893        - high Y-edge
    00894        - number of X-bins (default is 50)
    00895        - number of Y-bins (default is 50)
    00896
    00897     The reference to the histogram is returned and could be used for later manipulations
    00898
    00899     """
    00900     return HistoDecorator.plot2D    (s,*a)
    00901 # =============================================================================
    00902 def _plot3D_    ( s, *a ) :
    00903     """
    00904     The basic method to fill (book-on-demand) 3D-histogram
    00905
    00906     The histogram will be created/booked dautomatically according to the
    00907     specifications:
    00908
    00909        - literal or numerical ID (optional)
    00910        - title
    00911        - low X-edge
    00912        - high X-edge
    00913        - low Y-edge
    00914        - high Y-edge
    00915        - low Z-edge
    00916        - high Z-edge
    00917        - number of X-bins (default is 10)
    00918        - number of Y-bins (default is 10)
    00919        - number of Y-bins (default is 10)
    00920
    00921     The reference to the histogram is returned and could be used for later manipulations
    00922
    00923     """
    00924     return HistoDecorator.plot3D    (s,*a)
    00925 # =============================================================================
    00926 def _profile1D_ ( s, *a ) :
    00927     """
    00928     The basic method to fill (book-on-demand) 1D profile histogram
    00929
    00930     The profile histogram will be created/booked dautomatically
    00931     according to the specifications:
    00932
    00933        - literal or numerical ID (optional)
    00934        - title
    00935        - low X-edge
    00936        - high X-edge
    00937        - number of X-bins (default is 100)
    00938
    00939     The reference to the histogram is returned and could be used for later manipulations
    00940
    00941     """
    00942     return HistoDecorator.profile1D (s,*a)
    00943 # =============================================================================
    00944 def _profile2D_ ( s, *a ) :
    00945     """
    00946     The basic method to fill (book-on-demand) 2D profile histiogram
    00947
    00948     The profile histogram will be created/booked automatically
    00949     according to the specifications:
    00950
    00951        - literal or numerical ID (optional)
    00952        - title
    00953        - low X-edge
    00954        - high X-edge
    00955        - low Y-edge
    00956        - high Y-edge
    00957        - number of X-bins (default is 50)
    00958        - number of Y-bins (default is 50)
    00959
    00960     The reference to the histogram is returned and could be used for later manipulations
    00961
    00962     """
    00963     return HistoDecorator.profile2D (s,*a)
    00964 # =============================================================================
    00965
    00966 _plot1D_    .__doc__ += HistoDecorator.plot1D    .__doc__
    00967 _plot2D_    .__doc__ += HistoDecorator.plot2D    .__doc__
    00968 _plot3D_    .__doc__ += HistoDecorator.plot3D    .__doc__
    00969 _profile1D_ .__doc__ += HistoDecorator.profile1D .__doc__
    00970 _profile2D_ .__doc__ += HistoDecorator.profile2D .__doc__
    00971
    00972 def _decorate_plots_ ( klasses ) :
    00973     t = type( klasses )
    00974     if not issubclass ( t , list  ) and  \
    00975        not issubclass ( t , tuple ) : klasses = [ klasses ]
    00976     for klass in klasses :
    00977         klass .plot       = _plot1D_
    00978         klass .plot1D     = _plot1D_
    00979         klass .plot2D     = _plot2D_
    00980         klass .plot3D     = _plot3D_
    00981         klass .profile1D  = _profile1D_
    00982         klass .profile2D  = _profile2D_
    00983
    00984 _decorate_plots_ ( HistoAlgo )
    00985 _decorate_plots_ ( TupleAlgo )
    00986
    00987
    00988 # =============================================================================
    00989 def _nTuple_ ( s , *a )  :
    00990     """
    00991     Retrieve (book-on-demand) N-Tuple object
    00992     """
    00993     return TupleAlgDecorator.nTuple ( s , *a )
    00994 # =============================================================================
    00995 def _evtCol_ ( s , *a )  :
    00996     """
    00997     Retrieve (book-on-demand) N-Tuple object for Event Tag Collections
    00998     """
    00999     return TupleAlgDecorator.evtCol ( s , *a )
    01000
    01001 _nTuple_.__doc__  += TupleAlgDecorator.nTuple.__doc__
    01002 _evtCol_.__doc__  += TupleAlgDecorator.evtCol.__doc__
    01003
    01004 def _decorate_tuples_ ( klasses ) :
    01005     t = type( klasses )
    01006     if not issubclass ( t , list  ) and  \
    01007        not issubclass ( t , tuple ) : klasses = [ klasses ]
    01008     for klass in klasses :
    01009         klass . nTuple    = _nTuple_
    01010         klass . evtCol    = _evtCol_
    01011         klass . ntupleSvc = _ntupleSvc
    01012         klass .  tupleSvc = _ntupleSvc
    01013         klass .   ntupSvc = _ntupleSvc
    01014         klass .    tupSvc = _ntupleSvc
    01015         klass . evtColSvc = _evtcolSvc
    01016         klass . evtcolSvc = _evtcolSvc
    01017
    01018 # ==========================================================
    01019 _decorate_tuples_ ( TupleAlgo )
    01020
    01021
    01022 # "decorate N-Tuple object
    01023 Tuple = cpp.Tuples.Tuple
    01024 _Dec  = TupleDecorator
    01025 def _t_nTuple_  (s,*a) : return _Dec.nTuple (s,*a)
    01026 def _t_ntuple_  (s,*a) : return _Dec.ntuple (s,*a)
    01027 def _t_valid_   (s,*a) : return _Dec.valid  (s,*a)
    01028 def _t_write_   (s,*a) : return _Dec.write  (s,*a)
    01029 def _t_column_  (s,*a) : return _Dec.column (s,*a)
    01030 def _t_array_   (s,*a) : return _Dec.array  (s,*a)
    01031 def _t_matrix_  (s,*a) : return _Dec.matrix (s,*a)
    01032 def _t_farray_  (s,*a) : return _Dec.farray (s,*a)
    01033 def _t_fmatrix_ (s,*a) : return _Dec.fmatrix (s,*a)
    01034
    01035 _t_nTuple_ .__doc__ = _Dec.nTuple  .__doc__
    01036 _t_ntuple_ .__doc__ = _Dec.ntuple  .__doc__
    01037 _t_valid_  .__doc__ = _Dec.valid   .__doc__
    01038 _t_write_  .__doc__ = _Dec.write   .__doc__
    01039 _t_column_ .__doc__ = _Dec.column  .__doc__
    01040 _t_array_  .__doc__ = _Dec.array   .__doc__
    01041 _t_matrix_ .__doc__ = _Dec.matrix  .__doc__
    01042 _t_farray_ .__doc__ = _Dec.farray  .__doc__
    01043 _t_fmatrix_.__doc__ = _Dec.fmatrix .__doc__
    01044
    01045 Tuple.nTuple  = _t_nTuple_
    01046 Tuple.ntuple  = _t_ntuple_
    01047 Tuple.valid   = _t_valid_
    01048 Tuple.write   = _t_write_
    01049 Tuple.column  = _t_column_
    01050 Tuple.array   = _t_array_
    01051 Tuple.matrix  = _t_matrix_
    01052 Tuple.farray  = _t_farray_
    01053 Tuple.fmatrix = _t_fmatrix_
    01054
    01055 _alg_map_ = {
    01056     '__init__'    : _init_        , # constructor
    01057     'tool'        : _tool_        , # service locator
    01058     'svc'         : _service_     , # tool locator
    01059     'evtSvc'      : _evtSvc       , # event data service
    01060     'eventSvc'    : _evtSvc       , # event data service
    01061     'detSvc'      : _detSvc       , # detector data service
    01062     'histoSvc'    : _histoSvc     , # histogram data service
    01063     'histSvc'     : _histoSvc     , # histogram data service
    01064     'get'         : _get          , # access to event data
    01065     'getDet'      : _getDet       , # access to detector data
    01066     'finalize'    : _finalize_    , # algorithm finalization
    01067     'beginRun'    : _success_     , # dummy function returning success
    01068     'endRun'      : _success_     , # dummy function returning success
    01069     #
    01070     'hasProperty' : _hasProperty_ , # check the existence of property with given name
    01071     'getProperty' : _getProperty_ , # get the property value with given name
    01072     'setProperty' : _setProperty_ , # set the property with given name
    01073     '__setattr__' : _set_attr_    , # set the attribute/property with given name
    01074     '__getattr__' : _get_attr_      # set the attribute/property with given name
    01075     }
    01076
    01077
    01078 # decorate the classes with the useful methods
    01079 def _decorate_algs_ ( klasses ) :
    01080     t = type( klasses )
    01081     if not issubclass ( t , list  ) and  \
    01082        not issubclass ( t , tuple ) : klasses = [ klasses ]
    01083     for _alg in klasses :
    01084         for key in _alg_map_ : setattr( _alg , key , _alg_map_[key] )
    01085
    01086 # =
    01087 _decorate_algs_ ( GaudiAlgo )
    01088 _decorate_algs_ ( HistoAlgo )
    01089 _decorate_algs_ ( TupleAlgo )
    01090
    01091 # =============================================================================
    01092 # Helper function to fill histogram/ntuple using 'map'-operation
    01093 # =============================================================================
    01094 def mapvct ( func , sequence , ovct = None ) :
    01095     """ Helper function to fill histogram/ntuple using 'map'-operation """
    01096     if not ovct :
    01097         vct = GaudiPython.Vector
    01098     else :
    01099         vct = ovct
    01100     if   hasattr( sequence, 'size' ) :
    01101         vct.reserve ( vct.size() + sequence.size() )
    01102     elif hasattr( sequence, '__len__' ) :
    01103         vct.reserve ( vct.size() + len( sequence ) )
    01104     for object in sequence :
    01105         vct.push_back( func( object ) )
    01106     if not ovct : return vct
    01107 # =============================================================================
    01108
    01109
    01110
    01111
    01112 # =============================================================================
    01113 # get the list of tools
    01114 # =============================================================================
    01115 def _get_all_tools_ ( self , method ) :
    01116     """
    01117     Get all tools
    01118     """
    01119     _tools = std.vector('IAlgTool*')()
    01120     _func  = getattr ( AlgDecorator , method )
    01121     _num   = _func ( self , _tools )
    01122     if _tools.size() != _num :
    01123         raise RuntimeError, 'Unable to extract Tools'
    01124     _res = []
    01125     for _tool in _tools : _res += [ iAlgTool ( _tool.name() , _tool ) ]
    01126     return _res
    01127 # =============================================================================
    01128 def _Tools_a_ ( self ) :
    01129     """
    01130     Retrieve the list of tools,
    01131         aquired by component through GaudiCommon<TYPE> base:
    01132
    01133     >>> alg   = ...             ## get the algorithm
    01134     >>> tools = alg.Tools()     ## get the tools
    01135     >>> for tool in tools :
    01136     ...        print tool
    01137
    01138     """
    01139     _cmp  = getattr ( self , '_ialg' )
    01140     if not _cmp : self.retrieveInterface()
    01141     _cmp  = getattr ( self , '_ialg' )
    01142     return _get_all_tools_ ( _cmp , '_tools_a_' )
    01143 # =============================================================================
    01144 def _Tools_t_ ( self ) :
    01145     """
    01146     Retrieve the list of tools,
    01147         aquired by component through GaudiCommon<TYPE> base:
    01148
    01149     >>> tool  = ...              ## get the tool
    01150     >>> tools = tool.Tools()     ## get the tools
    01151     >>> for t in tools :
    01152     ...        print t
    01153
    01154     """
    01155     _cmp  = getattr ( self , '_itool' )
    01156     if not _cmp : self.retrieveInterface()
    01157     _cmp  = getattr ( self , '_itool' )
    01158     return _get_all_tools_ ( _cmp , '_tools_t_' )
    01159
    01160
    01161 # =============================================================================
    01162 # get the list of counters
    01163 # =============================================================================
    01164 ## get all counters
    01165 def _get_all_counters_ ( self , method , name = None ) :
    01166     """
    01167     get all counters
    01168     """
    01169     _cnts = std.vector('const StatEntity*')()
    01170     _nams = std.vector('std::string')      ()
    01171     _func = getattr ( AlgDecorator , method )
    01172     _num  = _func   ( self , _nams , _cnts )
    01173     if _nams.size() != _num or _cnts.size() != _num  :
    01174         raise RuntimeError, 'Unable to extract Counters'
    01175     _res = {}
    01176     for _i in range(0,_num) :
    01177         _nam = _nams[_i]
    01178         _cnt = _cnts[_i]
    01179         _res [ _nam ] = _cnt
    01180     if not name : return _res
    01181     return _res.get( name , None )
    01182 # =============================================================================
    01183 ## get all counters
    01184 def _Counters_a_ ( self , name = None ) :
    01185     """
    01186     Retrieve the counters, managed GaudiCommon<TYPE> base:
    01187
    01188     >>> alg  = ...             ## get the algorithm
    01189     >>> cnts = alg.Counters()  ## get the counters
    01190     >>> for key in cnts :
    01191     ...        print key, cnts[key]
    01192
    01193
    01194     Retrieve the counter, managed GaudiCommon<TYPE> base by name:
    01195
    01196     >>> alg = ...                        ## get the algorithm
    01197     >>> cnt = alg.Counters('MyCounter')  ## get the counter
    01198     >>> print cnt
    01199
    01200     """
    01201     _cmp  = getattr ( self , '_ialg' )
    01202     if not _cmp : self.retrieveInterface()
    01203     _cmp  = getattr ( self , '_ialg' )
    01204     return _get_all_counters_ ( _cmp , '_counters_a_' , name )
    01205 # =============================================================================
    01206 def _Counters_t_ ( self , name = None ) :
    01207     """
    01208     Retrieve the counters, managed GaudiCommon<TYPE> base:
    01209
    01210     >>> tool = ...              ## get the tool
    01211     >>> cnts = tool.Counters()  ## get the counters
    01212     >>> for key in cnts :
    01213     ...        print key, cnts[key]
    01214
    01215
    01216     Retrieve the counter, managed GaudiCommon<TYPE> base by name:
    01217
    01218     >>> tool = ...                         ## get the tool
    01219     >>> cnt  = tool.Counters('MyCounter')  ## get the counter
    01220     >>> print cnt
    01221
    01222     """
    01223     _cmp  = getattr ( self , '_itool' )
    01224     if not _cmp : self.retrieveInterface()
    01225     _cmp  = getattr ( self , '_itool' )
    01226     return _get_all_counters_ ( _cmp , '_counters_t_' , name )
    01227 # =============================================================================
    01228 # get the counter
    01229 # =============================================================================
    01230 def _get_counter_ ( self , method , name ) :
    01231     """
    01232     get the counter
    01233     """
    01234     _func = getattr ( AlgDecorator , method )
    01235     return _func ( self , name )
    01236 # ==============================================================================
    01237 def _Counter_a_ ( self , name ) :
    01238     """
    01239     Retrieve the counter managed GaudiCommon<TYPE> base by name:
    01240
    01241     >>> alg  = ...                     ## get the algorithm
    01242     >>> cnt  = alg.Counter('#accept')  ## get the counter
    01243     >>> print cnt
    01244
    01245     """
    01246     _cmp  = getattr ( self , '_ialg' )
    01247     if not _cmp : self.retrieveInterface()
    01248     _cmp  = getattr ( self , '_ialg' )
    01249     return _get_counter_ ( _cmp , '_counter_a_' , name )
    01250 # ==============================================================================
    01251 def _Counter_t_ ( self , name ) :
    01252     """
    01253     Retrieve the counter managed GaudiCommon<TYPE> base by name:
    01254
    01255     >>> tool = ...                      ## get the tool
    01256     >>> cnt  = tool.Counter('#accept')  ## get the counter
    01257     >>> print cnt
    01258
    01259     """
    01260     _cmp  = getattr ( self , '_itool' )
    01261     if not _cmp : self.retrieveInterface()
    01262     _cmp  = getattr ( self , '_itool' )
    01263     return _get_counter_ ( _cmp , '_counter_t_' , name )
    01264
    01265 # =============================================================================
    01266 # get all histos
    01267 # =============================================================================
    01268 cpp.GaudiAlg.ID .__repr__ = cpp.GaudiAlg.ID.idAsString
    01269 cpp.GaudiAlg.ID . __str__ = cpp.GaudiAlg.ID.idAsString
    01270 cpp.StatEntity  .__repr__ = cpp.StatEntity.toString
    01271 cpp.StatEntity  . __str__ = cpp.StatEntity.toString
    01272 # =============================================================================
    01273 def _get_all_histos_  ( component , method , name ) :
    01274     """
    01275     Get All histogram form the component
    01276     """
    01277     _res = {}
    01278     for _his in (  std.vector('AIDA::IProfile2D*'   ) ,
    01279                    std.vector('AIDA::IProfile1D*'   ) ,
    01280                    std.vector('AIDA::IHistogram3D*' ) ,
    01281                    std.vector('AIDA::IHistogram2D*' ) ,
    01282                    std.vector('AIDA::IHistogram1D*' ) ) :
    01283         _his = _his()
    01284         _ids = std.vector('GaudiAlg::ID')     ()
    01285         _fun = getattr ( HistoDecorator , method )
    01286         _num = _fun ( component , _ids , _his )
    01287         if _ids.size() != _num or _his.size() != _num  :
    01288             raise RuntimeError, 'Unable to extract Histos!'
    01289         for _i in range(0,_num) :
    01290             _id = _ids[ _i ]
    01291             if   _id.numeric() : _id = _id.numericID  ()
    01292             elif _id.literal() : _id = _id.literalID  ()
    01293             else               : _id = _is.idAsString ()
    01294             _res [ _id ] = _his[ _i ]
    01295
    01296     if not name : return _res                          ## return the dictionary
    01297
    01298     id = cpp.GaudiAlg.ID ( name )
    01299     for i in ( name            ,
    01300                id.literalID () ,
    01301                id.numericID () ,
    01302                id.idAsString() , id  ) :
    01303         h = _res.get( i , None  )
    01304         if not not h : return h   ## return the histogram
    01305
    01306     return None
    01307 # =============================================================================
    01308 def _Histos_a_ ( self , name = None ) :
    01309     """
    01310     Retrieve all histograms & profiles, booked through GauydiHistos<TYPE> base:
    01311
    01312     >>> alg = ...              ## get the algorithm
    01313     >>> histos = alg.Histos()  ## get all histograms & profiles
    01314     >>> for key in histos :
    01315     ...        print key, histos[key]
    01316
    01317     Retrive the histogram with the certain ID :
    01318
    01319     >>> alg = ...                           ## get the algorithm
    01320     >>> histo = alg.Histos('some histo ID') ## get the histo by ID
    01321     >>> print histo
    01322
    01323     """
    01324     _cmp  = getattr ( self , '_ialg' )
    01325     if not _cmp : self.retrieveInterface()
    01326     _cmp  = getattr ( self , '_ialg' )
    01327     return _get_all_histos_ ( _cmp , '_histos_a_' , name )
    01328 # =============================================================================
    01329 def _Histos_t_ ( self , name = None ) :
    01330     """
    01331     Retrieve all histograms & profiles, booked through GauydiHistos<TYPE> base:
    01332
    01333     >>> tool = ...              ## get the tool
    01334     >>> histos = tool.Histos()  ## get all histograms & profiles
    01335     >>> for key in histos :
    01336     ...        print key, histos[key]
    01337
    01338     Retrive the historgam with certain ID :
    01339
    01340     >>> tool = ...                           ## get the tool
    01341     >>> histo = tool.Histos('some histo ID') ## get the histo by ID
    01342     >>> print histo
    01343
    01344     """
    01345     _cmp  = getattr ( self , '_itool' )
    01346     if not _cmp : self.retrieveInterface()
    01347     _cmp  = getattr ( self , '_itool' )
    01348     return _get_all_histos_ ( _cmp , '_histos_t_' , name )
    01349 # =============================================================================
    01350
    01351
    01352 _Tools_a_    . __doc__ += AlgDecorator   . _tools_a_    . __doc__
    01353 _Tools_t_    . __doc__ += AlgDecorator   . _tools_t_    . __doc__
    01354 _Counters_a_ . __doc__ += AlgDecorator   . _counters_a_ . __doc__
    01355 _Counters_t_ . __doc__ += AlgDecorator   . _counters_t_ . __doc__
    01356 _Counter_a_  . __doc__ += AlgDecorator   . _counter_a_  . __doc__
    01357 _Counter_t_  . __doc__ += AlgDecorator   . _counter_t_  . __doc__
    01358 _Histos_a_   . __doc__ += HistoDecorator . _histos_a_ . __doc__
    01359 _Histos_t_   . __doc__ += HistoDecorator . _histos_t_ . __doc__
    01360
    01361
    01362 iAlgorithm   . Tools    = _Tools_a_
    01363 iAlgTool     . Tools    = _Tools_t_
    01364 iAlgorithm   . Counters = _Counters_a_
    01365 iAlgTool     . Counters = _Counters_t_
    01366 iAlgorithm   . Counter  = _Counter_a_
    01367 iAlgTool     . Counter  = _Counter_t_
    01368 iAlgorithm   . Histos   = _Histos_a_
    01369 iAlgTool     . Histos   = _Histos_t_
    01370
    01371 ## finally add some decoration for histograms
    01372 import GaudiPython.HistoUtils
    01373
    01374 # =============================================================================
    01375 # pseudo help
    01376 # =============================================================================
    01377 def _help_() :
    01378     print __doc__ , __author__
    01379     print '\t\t\tDoc-string for class GaudiAlgo \n' , GaudiAlgo.__doc__
    01380     print '\t\t\tDoc-string for class HistoAlgo \n' , HistoAlgo.__doc__
    01381     print '\t\t\tDoc-string for class TupleAlgo \n' , TupleAlgo.__doc__
    01382
    01383 # =============================================================================
    01384 # pseudo-test suite
    01385 # =============================================================================
    01386 if __name__ == '__main__' :
    01387     _help_()
    01388
    01389 # =============================================================================
    01390 # The END
    01391 # =============================================================================

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines