21 *******************************************************************************
22 * * 'Physisics do not like it, *
23 * * physisics do not need it, *
24 * * physisics do not use it' *
25 * * ****************************
27 * Helper module, which effectively 'imports' few useful C++ algorithmic *
28 * base classes into Python *
30 *******************************************************************************
31 * The major imported classes are : *
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 *******************************************************************************
39 __author__ =
'Vanya BELYAEV Ivan.Belyaev@lapp.in2p3.fr'
71 from GaudiKernel
import ROOT6WorkAroundEnabled
78 Vector = std.vector(
'double')
80 Matrix = std.vector(
'std::vector<double>')
89 AlgDecorator = cpp.GaudiPython.AlgDecorator
90 HistoDecorator = cpp.GaudiPython.HistoDecorator
91 TupleAlgDecorator = cpp.GaudiPython.TupleAlgDecorator
92 TupleDecorator = cpp.GaudiPython.TupleDecorator
125 Useful method to locate the tool a certain
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)
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
150 self.Warning(
'Invalid cast to interface %s' % interface )
172 Useful method to locate a service:
176 ntsvc = self.svc( INTupleSvc , 'NTUpleSvc' )
179 if not interface : interface = cpp.IInterface
180 _svc = AlgDecorator.svc_ ( self , name , create )
181 if not _svc :
return None
184 self.Warning(
'Invalid cast to interface %s' % interface )
195 The constructor from unique algorithm instance name & parameters
197 self._Base.__init__( self , self , name )
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] )
206 if not appMgr.__dict__.has_key (
'GaudiPythonAlgos') :
207 appMgr.__dict__[
'GaudiPythonAlgos'] = []
208 appMgr.__dict__[
'GaudiPythonAlgos'].append( self )
217 The default initialization (initialization of base C++ class + data)
219 status = self._Base.initialize_( self )
220 if status.isFailure() :
return status
223 _e = self._Base.evtSvc( self )
225 self._evtSvc_ = iDataSvc ( _s.name() , _e )
227 _d = self._Base.detSvc( self )
229 self._detSvc_ = iDataSvc ( _s.name() , _d )
240 The default initialization (initialization of base C++ class + data members)
243 if status.isFailure() :
return status
246 _h = self._Base.histoSvc( self )
248 self._histoSvc_ = iHistogramSvc ( _s.name() , _h )
259 The default initialization (initialization of base C++ class + data members)
262 if status.isFailure() :
return status
265 if self.produceNTuples() :
266 _n = self._Base.ntupleSvc( self )
268 self._ntupleSvc_ = iNTupleSvc ( _s.name() , _n )
270 if self.produceEvtCols() :
271 _n = self._Base.evtColSvc( self )
273 self._evtcolSvc_ = iNTupleSvc ( _s.name() , _n )
296 Trivial helper function to access Event Data and Event Data Service
300 # get event data service
304 hits = self.evtSvc('MC/Calo/Hits')
308 return self._evtSvc_[location]
329 Trivial helper function to access Detector Data and Event Data Service
332 # get detector data service
336 lhcb = self.detSvc('/dd/Structure/LHCb')
340 return self._detSvc_[location]
361 Trivial helper function to access Histogram Data and Histogram Data Service
365 # get histogram data service
366 svc = self.histoSvc()
369 histo = self.histoSvc('/stat/Calo/1')
371 if not address :
return self._histoSvc_
372 return self._histoSvc_[ address ]
378 Trivial function to access the data in TES using the data service
380 return self._evtSvc_[location]
386 Trivial function to access the data in TDS using data service
388 return self._detSvc_[location]
392 def _get_ ( self , location , rootInTES = True ) :
394 Get the object from Transient Event Store using GaudiCommon machinery,
395 respecting RootInTES behaviour
397 return AlgDecorator.get_ ( self , location , rootInTES )
400 def _exist_ ( self , location , rootInTES = True ) :
402 Check the object in Transient Event Store using GaudiCommon machinery,
403 respecting RootInTES behaviour
405 return AlgDecorator.exist_ ( self , location , rootInTES )
411 Trivial function to access N-Tuple Service
413 return self._ntupleSvc_
419 Trivial function to access Event Collection Service
421 return self._evtcolSvc_
428 The default finalization : finalize the base C++ class
430 status = self._Base.finalize_ ( self )
439 def _hasProperty_ ( self , pname ) :
441 The trivial function which checks the existence of the property with given name
443 return cpp.Gaudi.Utils.hasProperty ( self , pname )
449 Get the property by name
451 if not self.hasProperty( pname ) :
452 raise AttributeError,
'property %s does not exist' % pname
453 return iAlgorithm.__getattr__( self , pname )
459 Set the property from the value
461 if not self.hasProperty( pname ) :
462 raise AttributeError,
'property %s does not exist' % pname
463 return iAlgorithm.__setattr__ ( self , pname , pvalue )
469 Get the attribute (or property)
470 - if the attribute name corresponds to the property name, property value is returned
472 if self.hasProperty( pname ) :
473 return iAlgorithm.__getattr__ ( self , pname )
474 raise AttributeError,
'attribute/property %s does not exist' % pname
480 Set the attribute (or property) :
481 - if the attribute name corresponds to the property name, the property is updated
483 if not self.hasProperty( pname ) : self.__dict__[pname] = pvalue
484 else : iAlgorithm.__setattr__ ( self , pname , pvalue )
487 _GaudiAlgorithm = cpp.GaudiPython.PyAlg(
'GaudiAlgorithm' )
488 _GaudiHistoAlg = cpp.GaudiPython.PyAlg(
'GaudiHistoAlg' )
489 _GaudiTupleAlg = cpp.GaudiPython.PyAlg(
'GaudiTupleAlg' )
556 *******************************************************************************
557 * * 'Physisics do not like it, *
558 * * physisics do not need it, *
559 * * physisics do not use it' *
560 * * ****************************
563 * from GaudiPython.GaudiAlgs import GaudiAlgo, SUCCESS *
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 ) *
572 * def initialize ( self ) : *
573 * 'Algorithm initialization' *
574 * # initialize the base class *
575 * status = GaudiAlgo.initialize( self ) *
576 * if status.isFailure() : return status *
578 * # locate the services and tools *
580 * # locate some tool: *
581 * extrapolator = self.tool(ITrExtrapolator,'TrExtrapolator') *
583 * # locate the service *
584 * rndmSvc = self.svc(IRndmGenSvc, 'RndmGenSvc') *
589 * def execute ( self ) : *
590 * 'Major method (from IAlgorithm interface)' *
592 * # get some data from Transient Event Store *
593 * tracks = self.get('/Event/Rec/Tracks') *
596 * c1 = self.counter('#Tracks') *
597 * c2 = self.counter('No Tracks') *
598 * if tracks.empty : *
600 * c1 += tracks->size() *
602 * if 1000 < tracks.size() : *
603 * return self.Error('The event is *VERY* busy') *
607 *******************************************************************************
682 *******************************************************************************
683 * * 'Physisics do not like it, *
684 * * physisics do not need it, *
685 * * physisics do not use it' *
686 * * ****************************
689 * from GaudiPython.GaudiAlgs import HistoAlgo, SUCCESS *
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 ) *
698 * def execute ( self ) : *
699 * 'Major method (from IAlgorithm interface)' *
701 * # get some data from Transient Event Store *
702 * tracks = self.get('/Event/Rec/Tracks') *
704 * self.plot1D ( tracks->size() , '#tracks' , 0 , 100 ) *
708 * Alternatively the histogram could be booked in advance: *
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 ) *
717 * def initialize ( self ) : *
718 * 'Algorithm initialization' *
719 * # initialize the base class *
720 * status = HistoAlgo.initialize( self ) *
721 * if status.isFailure() : return status *
723 * # book the histogram *
724 * self.h1 = selff.book1D ( '#tracks' , 0 , 100 ) *
729 * def execute ( self ) : *
730 * 'Major method (from IAlgorithm interface)' *
732 * # get some data from Transient Event Store *
733 * tracks = self.get('/Event/Rec/Tracks') *
735 * # fill the histogram *
736 * self.h1.fill ( tracks->size() ) *
740 *******************************************************************************
792 *******************************************************************************
793 * * 'Physisics do not like it, *
794 * * physisics do not need it, *
795 * * physisics do not use it' *
796 * * ****************************
799 * from GaudiPython.GaudiAlgs import TupleAlgo, SUCCESS *
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 ) *
808 * def execute ( self ) : *
809 * 'Major method (from IAlgorithm interface)' *
811 * # get some data from Transient Event Store *
812 * tracks = self.get('/Event/Rec/Tracks') *
814 * tup = self.nTuple('My N-Tuple') *
816 * for track in tracks : *
820 * chi2 = track.chi2 () *
823 * tup.column ( 'pt' , pt ) *
824 * tup.column ( 'p' , p ) *
825 * tup.column ( 'chi2' , chi2 ) *
831 *******************************************************************************
839 return self.
method(*args )
841 GaudiAlgo._Base = _GaudiAlgorithm
842 HistoAlgo._Base = _GaudiHistoAlg
843 TupleAlgo._Base = _GaudiTupleAlg
846 GaudiAlgo.initialize = _initialize_
847 HistoAlgo.initialize = _initialize_histo_
848 TupleAlgo.initialize = _initialize_tuple_
852 The stub 'start' method needed by the internal implementation of PyAlg<>.
857 GaudiAlgo.start = _start_
858 HistoAlgo.start = _start_
859 TupleAlgo.start = _start_
863 The fictive 'execute' method, which MUST be overwitten by user
865 raise RuntimeError,
'Execute method is not implemented for %s' % self.name()
867 GaudiAlgo.execute = _execute_
868 HistoAlgo.execute = _execute_
869 TupleAlgo.execute = _execute_
873 The stub 'stop' method needed by the internal implementation of PyAlg<>.
878 GaudiAlgo.stop = _stop_
879 HistoAlgo.stop = _stop_
880 TupleAlgo.stop = _stop_
885 The basic method to fill (book-on-demand) 1D-histogram
887 The histogram will be created/booked dautomatically according to the
890 - literal or numerical ID (optional)
894 - number of bins (default is 100)
896 The reference to the histogram is returned and could be used for later manipulations
899 return HistoDecorator.plot1D (s,*a)
903 The basic method to fill (book-on-demand) 2D-histogram
905 The histogram will be created/booked dautomatically according to the
908 - literal or numerical ID (optional)
914 - number of X-bins (default is 50)
915 - number of Y-bins (default is 50)
917 The reference to the histogram is returned and could be used for later manipulations
920 return HistoDecorator.plot2D (s,*a)
924 The basic method to fill (book-on-demand) 3D-histogram
926 The histogram will be created/booked dautomatically according to the
929 - literal or numerical ID (optional)
937 - number of X-bins (default is 10)
938 - number of Y-bins (default is 10)
939 - number of Y-bins (default is 10)
941 The reference to the histogram is returned and could be used for later manipulations
944 return HistoDecorator.plot3D (s,*a)
948 The basic method to fill (book-on-demand) 1D profile histogram
950 The profile histogram will be created/booked dautomatically
951 according to the specifications:
953 - literal or numerical ID (optional)
957 - number of X-bins (default is 100)
959 The reference to the histogram is returned and could be used for later manipulations
962 return HistoDecorator.profile1D (s,*a)
966 The basic method to fill (book-on-demand) 2D profile histiogram
968 The profile histogram will be created/booked automatically
969 according to the specifications:
971 - literal or numerical ID (optional)
977 - number of X-bins (default is 50)
978 - number of Y-bins (default is 50)
980 The reference to the histogram is returned and could be used for later manipulations
983 return HistoDecorator.profile2D (s,*a)
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__
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_
1004 _decorate_plots_ ( HistoAlgo )
1005 _decorate_plots_ ( TupleAlgo )
1011 Retrieve (book-on-demand) N-Tuple object
1013 return TupleAlgDecorator.nTuple ( s , *a )
1017 Retrieve (book-on-demand) N-Tuple object for Event Tag Collections
1019 return TupleAlgDecorator.evtCol ( s , *a )
1021 _nTuple_.__doc__ +=
'\n' + TupleAlgDecorator.nTuple.__doc__
1022 _evtCol_.__doc__ +=
'\n' + TupleAlgDecorator.evtCol.__doc__
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
1039 _decorate_tuples_ ( TupleAlgo )
1043 Tuple = cpp.Tuples.Tuple
1044 _Dec = TupleDecorator
1047 '''Helper decorator class to workaround ROOT-6697'''
1052 mapping = {int:
'int', bool:
'bool', float:
'double'}
1054 signature =
'const Tuples::Tuple& tuple, const string& name, const %s value'%(mapping[k])
1055 mapping[k] = func.disp(signature)
1060 Explicitly call the explicit signature for the case with 3 arguments and
1061 the last one is 'int', 'bool' or 'float', for the other cases fall back
1062 on the default dispatcher.
1070 return self.
func(*a)
1077 Access to underlying INTuple object
1079 return _Dec.nTuple ( s , *a )
1082 Access to underlying NTuple::Tuple object
1084 return _Dec.ntuple ( s , *a )
1087 Valid NTuple::Tuple object?
1089 return _Dec.valid ( s , *a )
1092 Commit the row/record to n-tuple
1094 return _Dec.write ( s , *a )
1097 Fill the certain column to n-tuple
1099 return _Dec.column ( s , *a )
1102 Fill the 'long long' column
1104 return _Dec.column_ll ( s , *a )
1107 Fill the 'unsigned long long' column
1109 return _Dec.column_ull ( s , *a )
1112 Fill the fixed-size array column
1114 return _Dec.array ( s , *a )
1117 Fill the fixed-size matrix column
1119 return _Dec.matrix ( s , *a )
1122 Fill the floating-size array column
1124 return _Dec.farray ( s , *a )
1127 Fill the floating-size matrix column
1129 return _Dec.fmatrix ( s , *a )
1131 _t_nTuple_ . __doc__ +=
'\n' + _Dec.nTuple . __doc__
1132 _t_ntuple_ . __doc__ +=
'\n' + _Dec.ntuple . __doc__
1133 _t_valid_ . __doc__ +=
'\n' + _Dec.valid . __doc__
1134 _t_write_ . __doc__ +=
'\n' + _Dec.write . __doc__
1135 _t_column_ . __doc__ +=
'\n' + _Dec.column . __doc__
1136 _t_column_ll_ . __doc__ +=
'\n' + _Dec.column_ll . __doc__
1137 _t_column_ull_ . __doc__ +=
'\n' + _Dec.column_ull . __doc__
1138 _t_array_ . __doc__ +=
'\n' + _Dec.array . __doc__
1139 _t_matrix_ . __doc__ +=
'\n' + _Dec.matrix . __doc__
1140 _t_farray_ . __doc__ +=
'\n' + _Dec.farray . __doc__
1141 _t_fmatrix_ . __doc__ +=
'\n' + _Dec.fmatrix . __doc__
1143 Tuple.nTuple = _t_nTuple_
1144 Tuple.ntuple = _t_ntuple_
1145 Tuple.valid = _t_valid_
1146 Tuple.write = _t_write_
1147 Tuple.column = _t_column_
1148 Tuple.column_ll = _t_column_ll_
1149 Tuple.column_ull = _t_column_ull_
1150 Tuple.array = _t_array_
1151 Tuple.matrix = _t_matrix_
1152 Tuple.farray = _t_farray_
1153 Tuple.fmatrix = _t_fmatrix_
1156 '__init__' : _init_ ,
1159 'evtSvc' : _evtSvc ,
1160 'eventSvc' : _evtSvc ,
1161 'detSvc' : _detSvc ,
1162 'histoSvc' : _histoSvc ,
1163 'histSvc' : _histoSvc ,
1166 'exist_' : _exist_ ,
1167 'getDet' : _getDet ,
1168 'finalize' : _finalize_ ,
1169 'beginRun' : _success_ ,
1170 'endRun' : _success_ ,
1172 'hasProperty' : _hasProperty_ ,
1173 'getProperty' : _getProperty_ ,
1174 'setProperty' : _setProperty_ ,
1175 '__setattr__' : _set_attr_ ,
1176 '__getattr__' : _get_attr_
1183 if not issubclass ( t , list )
and \
1184 not issubclass ( t , tuple ) : klasses = [ klasses ]
1185 for _alg
in klasses :
1186 for key
in _alg_map_ : setattr( _alg , key , _alg_map_[key] )
1189 _decorate_algs_ ( GaudiAlgo )
1190 _decorate_algs_ ( HistoAlgo )
1191 _decorate_algs_ ( TupleAlgo )
1196 def mapvct ( func , sequence , ovct = None ) :
1197 """ Helper function to fill histogram/ntuple using 'map'-operation """
1199 vct = GaudiPython.Vector
1202 if hasattr( sequence,
'size' ) :
1203 vct.reserve ( vct.size() + sequence.size() )
1204 elif hasattr( sequence,
'__len__' ) :
1205 vct.reserve ( vct.size() + len( sequence ) )
1206 for object
in sequence :
1207 vct.push_back(
func( object ) )
1208 if not ovct :
return vct
1221 _tools = std.vector(
'IAlgTool*')()
1222 _func = getattr ( AlgDecorator , method )
1223 _num = _func ( self , _tools )
1224 if _tools.size() != _num :
1225 raise RuntimeError,
'Unable to extract Tools'
1227 for _tool
in _tools : _res += [ iAlgTool ( _tool.name() , _tool ) ]
1232 Retrieve the list of tools,
1233 aquired by component through GaudiCommon<TYPE> base:
1235 >>> alg = ... ## get the algorithm
1236 >>> tools = alg.Tools() ## get the tools
1237 >>> for tool in tools :
1241 _cmp = getattr ( self ,
'_ialg' )
1242 if not _cmp : self.retrieveInterface()
1243 _cmp = getattr ( self ,
'_ialg' )
1244 return _get_all_tools_ ( _cmp ,
'_tools_a_' )
1248 Retrieve the list of tools,
1249 aquired by component through GaudiCommon<TYPE> base:
1251 >>> tool = ... ## get the tool
1252 >>> tools = tool.Tools() ## get the tools
1253 >>> for t in tools :
1257 _cmp = getattr ( self ,
'_itool' )
1258 if not _cmp : self.retrieveInterface()
1259 _cmp = getattr ( self ,
'_itool' )
1260 return _get_all_tools_ ( _cmp ,
'_tools_t_' )
1271 _cnts = std.vector(
'const StatEntity*')()
1272 _nams = std.vector(
'std::string') ()
1273 _func = getattr ( AlgDecorator , method )
1274 _num = _func ( self , _nams , _cnts )
1275 if _nams.size() != _num
or _cnts.size() != _num :
1276 raise RuntimeError,
'Unable to extract Counters'
1278 for _i
in range(0,_num) :
1281 _res [ _nam ] = _cnt
1282 if not name :
return _res
1283 return _res.get( name ,
None )
1288 Retrieve the counters, managed GaudiCommon<TYPE> base:
1290 >>> alg = ... ## get the algorithm
1291 >>> cnts = alg.Counters() ## get the counters
1292 >>> for key in cnts :
1293 ... print key, cnts[key]
1296 Retrieve the counter, managed GaudiCommon<TYPE> base by name:
1298 >>> alg = ... ## get the algorithm
1299 >>> cnt = alg.Counters('MyCounter') ## get the counter
1303 _cmp = getattr ( self ,
'_ialg' )
1304 if not _cmp : self.retrieveInterface()
1305 _cmp = getattr ( self ,
'_ialg' )
1306 return _get_all_counters_ ( _cmp ,
'_counters_a_' , name )
1310 Retrieve the counters, managed GaudiCommon<TYPE> base:
1312 >>> tool = ... ## get the tool
1313 >>> cnts = tool.Counters() ## get the counters
1314 >>> for key in cnts :
1315 ... print key, cnts[key]
1318 Retrieve the counter, managed GaudiCommon<TYPE> base by name:
1320 >>> tool = ... ## get the tool
1321 >>> cnt = tool.Counters('MyCounter') ## get the counter
1325 _cmp = getattr ( self ,
'_itool' )
1326 if not _cmp : self.retrieveInterface()
1327 _cmp = getattr ( self ,
'_itool' )
1328 return _get_all_counters_ ( _cmp ,
'_counters_t_' , name )
1336 _func = getattr ( AlgDecorator , method )
1337 return _func ( self , name )
1341 Retrieve the counter managed GaudiCommon<TYPE> base by name:
1343 >>> alg = ... ## get the algorithm
1344 >>> cnt = alg.Counter('#accept') ## get the counter
1348 _cmp = getattr ( self ,
'_ialg' )
1349 if not _cmp : self.retrieveInterface()
1350 _cmp = getattr ( self ,
'_ialg' )
1351 return _get_counter_ ( _cmp ,
'_counter_a_' , name )
1355 Retrieve the counter managed GaudiCommon<TYPE> base by name:
1357 >>> tool = ... ## get the tool
1358 >>> cnt = tool.Counter('#accept') ## get the counter
1362 _cmp = getattr ( self ,
'_itool' )
1363 if not _cmp : self.retrieveInterface()
1364 _cmp = getattr ( self ,
'_itool' )
1365 return _get_counter_ ( _cmp ,
'_counter_t_' , name )
1370 cpp.GaudiAlg.ID .__repr__ = cpp.GaudiAlg.ID.idAsString
1371 cpp.GaudiAlg.ID . __str__ = cpp.GaudiAlg.ID.idAsString
1372 cpp.StatEntity .__repr__ = cpp.StatEntity.toString
1373 cpp.StatEntity . __str__ = cpp.StatEntity.toString
1377 Get All histogram form the component
1380 for _his
in ( std.vector(
'AIDA::IProfile2D*' ) ,
1381 std.vector(
'AIDA::IProfile1D*' ) ,
1382 std.vector(
'AIDA::IHistogram3D*' ) ,
1383 std.vector(
'AIDA::IHistogram2D*' ) ,
1384 std.vector(
'AIDA::IHistogram1D*' ) ) :
1386 _ids = std.vector(
'GaudiAlg::ID') ()
1387 _fun = getattr ( HistoDecorator , method )
1388 _num = _fun ( component , _ids , _his )
1389 if _ids.size() != _num
or _his.size() != _num :
1390 raise RuntimeError,
'Unable to extract Histos!'
1391 for _i
in range(0,_num) :
1393 if _id.numeric() : _id = _id.numericID ()
1394 elif _id.literal() : _id = _id.literalID ()
1395 else : _id = _is.idAsString ()
1396 _res[ _id ] = _his[ _i ]
1398 if not name :
return _res
1400 id = cpp.GaudiAlg.ID ( name )
1404 id.idAsString() , id ) :
1405 h = _res.get( i ,
None )
1406 if not not h :
return h
1412 Retrieve all histograms & profiles, booked through GauydiHistos<TYPE> base:
1414 >>> alg = ... ## get the algorithm
1415 >>> histos = alg.Histos() ## get all histograms & profiles
1416 >>> for key in histos :
1417 ... print key, histos[key]
1419 Retrive the histogram with the certain ID :
1421 >>> alg = ... ## get the algorithm
1422 >>> histo = alg.Histos('some histo ID') ## get the histo by ID
1426 _cmp = getattr ( self ,
'_ialg' )
1427 if not _cmp : self.retrieveInterface()
1428 _cmp = getattr ( self ,
'_ialg' )
1429 return _get_all_histos_ ( _cmp ,
'_histos_a_' , name )
1433 Retrieve all histograms & profiles, booked through GauydiHistos<TYPE> base:
1435 >>> tool = ... ## get the tool
1436 >>> histos = tool.Histos() ## get all histograms & profiles
1437 >>> for key in histos :
1438 ... print key, histos[key]
1440 Retrive the historgam with certain ID :
1442 >>> tool = ... ## get the tool
1443 >>> histo = tool.Histos('some histo ID') ## get the histo by ID
1447 _cmp = getattr ( self ,
'_itool' )
1448 if not _cmp : self.retrieveInterface()
1449 _cmp = getattr ( self ,
'_itool' )
1450 return _get_all_histos_ ( _cmp ,
'_histos_t_' , name )
1454 _Tools_a_ . __doc__ +=
'\n' + AlgDecorator . _tools_a_ . __doc__
1455 _Tools_t_ . __doc__ +=
'\n' + AlgDecorator . _tools_t_ . __doc__
1456 _Counters_a_ . __doc__ +=
'\n' + AlgDecorator . _counters_a_ . __doc__
1457 _Counters_t_ . __doc__ +=
'\n' + AlgDecorator . _counters_t_ . __doc__
1458 _Counter_a_ . __doc__ +=
'\n' + AlgDecorator . _counter_a_ . __doc__
1459 _Counter_t_ . __doc__ +=
'\n' + AlgDecorator . _counter_t_ . __doc__
1460 _Histos_a_ . __doc__ +=
'\n' + HistoDecorator . _histos_a_ . __doc__
1461 _Histos_t_ . __doc__ +=
'\n' + HistoDecorator . _histos_t_ . __doc__
1463 iAlgorithm . Tools = _Tools_a_
1464 iAlgTool . Tools = _Tools_t_
1465 iAlgorithm . Counters = _Counters_a_
1466 iAlgTool . Counters = _Counters_t_
1467 iAlgorithm . Counter = _Counter_a_
1468 iAlgTool . Counter = _Counter_t_
1469 iAlgorithm . Histos = _Histos_a_
1470 iAlgTool . Histos = _Histos_t_
1479 print __doc__ , __author__
1480 print '\t\t\tDoc-string for class GaudiAlgo \n' , GaudiAlgo.__doc__
1481 print '\t\t\tDoc-string for class HistoAlgo \n' , HistoAlgo.__doc__
1482 print '\t\t\tDoc-string for class TupleAlgo \n' , TupleAlgo.__doc__
1487 if __name__ ==
'__main__' :
def _getDet(self, location)
Trivial function to access the data in TDS.
def _Counter_a_(self, name)
def _Counter_t_(self, name)
def _decorate_tuples_(klasses)
def _initialize_(self)
The default initialization (initialization of base C++ class + data.
def _detSvc(self)
Trivial helper function to access Detector Data and Detector Data Service.
def _service_
Useful method to locate a service:
def _init_(self, name, args)
The constructor from unique algorithm instance name,.
def _tool_
Useful method to locate the tool a certain.
def _initialize_tuple_(self)
The default initialization (initialization of base C++ class + data members)
def _get_all_counters_
get all counters
def _Counters_a_
get all counters
def _get_all_histos_(component, method, name)
def _decorate_algs_(klasses)
def _decorate_plots_(klasses)
def _get_counter_(self, method, name)
def _get_attr_(self, pname)
get the attribute or property
def _set_attr_(self, pname, pvalue)
set the attribute or property
def _get(self, location)
Trivial function to access the data in TES.
The base class for easy histogramming.
def ROOT6WorkAroundEnabled
def _initialize_histo_(self)
The default initialization (initialization of base C++ class + data members)
def _evtcolSvc(self)
Trivial helper function to access Event Collection Service.
def _get_all_tools_(self, method)
def _histoSvc
Trivial helper function to access Histogram Data and Histogram Data Service.
def _exist_
check the data from TES using GaudiCommon methods, respecting RootInTES
The base class for easy manupulations with N-Tuples.
the base class for all algorithm Python-image of C++ clkass GaudiAlgorithm
def _success_(self)
Dummy method returning success.
def _get_
get the data from TES using GaudiCommon methods, respecting RootInTES
def _evtSvc
Trivial helper function to access Event Data and Event Data Service.
NamedRange_< CONTAINER > range(const CONTAINER &cnt, const std::string &name)
simple function to create the named range form arbitrary container
def _finalize_(self)
The default finalization (finalization of base C++ class)
def _ntupleSvc(self)
Trivial helper function to access NTuple Service.
def _setProperty_(self, pname, pvalue)
set the value for the given property
def _getProperty_(self, pname)
get the value of the given property