| The Gaudi Framework v27r1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

Bindings.py
Go to the documentation of this file.
1 # File: GaudiPython/Bindings.py
2 # Author: Pere Mato (pere.mato@cern.ch)
3
4 """ GaudiPython.Bindings module.
5 This module provides the basic bindings of the main Gaudi
6 components to Python. It is itself based on the ROOT cppyy
7 Python extension module.
8 """
9
10 __all__ = [ 'gbl','InterfaceCast', 'Interface', 'PropertyEntry',
11 'AppMgr', 'PyAlgorithm', 'CallbackStreamBuf',
12 'iAlgorithm', 'iDataSvc', 'iHistogramSvc','iNTupleSvc','iService', 'iAlgTool', 'Helper',
13 'SUCCESS', 'FAILURE', 'toArray',
14 'ROOT', 'makeNullPointer', 'setOwnership',
15 'getClass', 'loaddict', 'deprecation' ]
16
17 from GaudiKernel import ROOT6WorkAroundEnabled
18
19 import os, sys, string, warnings, re
20 try:
21 import cppyy
22 except ImportError:
23 # FIXME: backward compatibility
24 print "# WARNING: using PyCintex as cppyy implementation"
25 import PyCintex as cppyy
26
27 if ROOT6WorkAroundEnabled('ROOT-5478'):
28 # Trigger the loading of GaudiKernelDict
29 cppyy.gbl.DataObject
30 # Trigger the loading of GaudiPythonDict
31 cppyy.gbl.Chrono
32
33 import Pythonizations
34 # Import Configurable from AthenaCommon or GaudiKernel if the first is not
35 # available.
36 from GaudiKernel.Proxy.Configurable import Configurable, getNeededConfigurables
37
38 #namespaces
39 gbl = cppyy.gbl
40 Gaudi = gbl.Gaudi
41
42 _gaudi = None
43
44 #----Useful shortcuts for classes -------------------------------------------------------
45 Helper = gbl.GaudiPython.Helper
46 StringProperty = gbl.SimpleProperty ('string','BoundedVerifier<string>')
47 StringPropertyRef = gbl.SimplePropertyRef ('string','NullVerifier<string>')
48 GaudiHandleProperty = gbl.GaudiHandleProperty
49 GaudiHandleArrayProperty = gbl.GaudiHandleArrayProperty
50 DataObject = gbl.DataObject
51 SUCCESS = gbl.StatusCode( gbl.StatusCode.SUCCESS, True )
52 FAILURE = gbl.StatusCode( gbl.StatusCode.FAILURE, True )
53
54 # toIntArray, toShortArray, etc.
55 for l in [ l for l in dir(Helper) if re.match("^to.*Array$",l) ]:
56 exec "%s = Helper.%s"%(l,l)
57 __all__.append(l)
58
59 # FIXME: (MCl) Hack to handle ROOT 5.18 and ROOT >= 5.20
60 if hasattr(Helper,"toArray"):
61 # This is not backward compatible, but allows to use the same signature
62 # with all the versions of ROOT.
63 toArray = lambda typ: getattr(Helper,"toArray")
64 else:
65 # forward to the actual implementation of GaudiPython::Helper::toArray<T>
66 toArray = lambda typ: getattr(Helper,"toArray<%s>"%typ)
67
68 #----Convenient accessors to PyROOT functionality ---------------------------------------
69 ROOT = cppyy.libPyROOT
70 makeNullPointer = cppyy.libPyROOT.MakeNullPointer
71 setOwnership = cppyy.libPyROOT.SetOwnership
72
73 def deprecation(message):
74 warnings.warn('GaudiPython: '+ message, DeprecationWarning, stacklevel=3)
75
76 #----InterfaceCast class ----------------------------------------------------------------
77 class InterfaceCast(object) :
78 """ Helper class to obtain the adequate interface from a component
79 by using the Gaudi queryInterface() mechanism """
80 def __init__(self, t ) :
81 if type(t) is str:
82 t = getattr(gbl, t)
83 self.type = t
84 def __call__(self, obj) :
85 if obj :
86 ip = makeNullPointer(self.type)
87 try:
88 if obj.queryInterface(self.type.interfaceID(), ip).isSuccess() :
89 return ip
90 else :
91 print "ERROR: queryInterface failed for", obj, "interface:", self.type
92 except Exception, e:
93 print "ERROR: exception", e, "caught when retrieving interface", self.type, "for object", obj
94 import traceback
95 traceback.print_stack()
96 return None
97 cast = __call__
98 #---Interface class (for backward compatibility)-----------------------------------------
99 class Interface(InterfaceCast) :
100 def __init__(self, t ):
101 deprecation('Use InterfaceCast class instead')
102 InterfaceCast.__init__(self,t)
103 def cast(self, obj) :
104 return self(obj)
105
106 #----load dictionary function using Gaudi function---------------------------------------
107 def loaddict(dict) :
108 """ Load a LCG dictionary using various mechanisms"""
109 if Helper.loadDynamicLib(dict) == 1 : return
110 else :
111 try:
112 cppyy.loadDict(dict)
113 except:
114 raise ImportError, 'Error loading dictionary library'
115
116 #---get a class (by loading modules if needed)--------------------------------------------
117 def getClass( name , libs = [] ) :
118 """
119 Function to retrieve a certain C++ class by name and to load dictionary if requested
120
121 Usage:
122
123 from gaudimodule import getClass
124 # one knows that class is already loaded
125 AppMgr = getClass( 'ApplicationMgr' )
126 # one knows where to look for class, if not loaded yet
127 MCParticle = getClass( 'MCParticle' , 'EventDict' )
128 # one knows where to look for class, if not loaded yet
129 Vertex = getClass( 'Vertex' , ['EventDict', 'PhysEventDict'] )
130 """
131 # see if class is already loaded
132 if hasattr( gbl , name ) : return getattr( gbl , name )
133 # try to load dictionaries and look for the required class
134 if type(libs) is not list : libs = [libs]
135 for lib in libs :
136 loaddict( lib )
137 if hasattr( gbl , name ) : return getattr( gbl , name )
138 # return None ( or raise exception? I do not know... )
139 return None
140
141 #----PropertyEntry class---------------------------------------------------------------------
142 class PropertyEntry(object) :
143 """ holds the value and the documentation string of a property """
144 def __init__(self, prop) :
145 self._type = type(prop).__name__
146 self.__doc__ = " --- Property type is " + self.ptype()
147
148 if issubclass(type(prop),GaudiHandleProperty) :
149 self._value = prop.value() # do nothing for ATLAS' handles
150 elif issubclass(type(prop),GaudiHandleArrayProperty) :
151 self._value = prop.value() # do nothing for ATLAS' handles
152 else :
153 # for all other types try to extract the native python type
154 try: self._value = eval( prop.toString() , {} , {} )
155 except:
156 if hasattr ( prop , 'value' ) : self._value = prop.value()
157 else : self._value = prop.toString()
158
159 self.__doc__ += " --- Default value = " + str(self._value) + " --- "
160 if prop.documentation() != 'none':
161 self.__doc__ = prop.documentation() + '\\n' + self.__doc__
162 ## keep the original property
163 self._property = prop # property itself
164 def value(self) :
165 return self._value
166 def ptype(self) :
167 return self._type
168 def property(self):
169 "Return the underlying property itself "
170 return self._property
171 def documentation(self) :
172 return self.__doc__
173 def hasDoc(self):
174 return len(self.__doc__)>0 and self.__doc__ != 'none'
175
176 #----iProperty class---------------------------------------------------------------------
177 class iProperty(object) :
178 """ Python equivalent to the C++ Property interface """
179 def __init__(self, name, ip = None) :
180 if ip : self.__dict__['_ip'] = InterfaceCast(gbl.IProperty)(ip)
181 else : self.__dict__['_ip'] = None
182 self.__dict__['_svcloc'] = gbl.Gaudi.svcLocator()
183 optsvc = Helper.service(self._svcloc,'JobOptionsSvc')
184 if optsvc : self.__dict__['_optsvc'] = InterfaceCast(gbl.IJobOptionsSvc)(optsvc)
185 else : self.__dict__['_optsvc'] = None
186 self.__dict__['_name'] = name
187 def getInterface(self) :
188 if not self._ip : self.retrieveInterface()
189 return self._ip
190 def retrieveInterface(self) :
191 pass
192 def __call_interface_method__(self,ifname,method,*args):
193 if not getattr(self,ifname) : self.retrieveInterface()
194 return getattr(getattr(self,ifname),method)(*args)
195 def __setattr__(self, name, value):
196 """
197 The method which is used for setting the property from the given value.
198 - In the case of the valid instance it sets the property through IProperty interface
199 - In the case of placeholder the property is added to JobOptionsCatalogue
200 """
201 if hasattr( value, 'toStringProperty' ):
202 # user defined behaviour
203 value = '%s' % value.toStringProperty()
204 ip = self.getInterface()
205 if ip :
206 if not gbl.Gaudi.Utils.hasProperty ( ip , name ) :
207 raise AttributeError, 'property %s does not exist' % name
208 prop = ip.getProperty(name)
209
210 if ROOT6WorkAroundEnabled('ROOT-7201'):
211 canSetValue = (hasattr(prop, 'value') and
212 'const&[' not in prop.value.func_doc and
213 type(value) == type(prop.value()))
214 else:
215 canSetValue = (hasattr(prop, 'value') and
216 type(value) == type(prop.value()))
217
218 if canSetValue:
219 if not prop.setValue(value) :
220 raise AttributeError, 'property %s could not be set from %s' % (name, value)
221 else:
222 if tuple == type( value ) : value = str(value)
223 elif hasattr ( value , 'toString' ) : value = value.toString()
224 elif not long == type( value ) : value = '%s' % value
225 else : value = '%d' % value
226 if ROOT6WorkAroundEnabled('ROOT-6028'):
227 sc = cppyy.gbl.GaudiPython.Helper.setPropertyFromString(prop, value)
228 else:
229 sc = prop.fromString(value)
230 if sc.isFailure() :
231 raise AttributeError, 'property %s could not be set from %s' % (name,value)
232 else :
233 if type(value) == str : value = '"%s"' % value # need double quotes
234 elif type(value) == tuple : value = str(value)
235 elif hasattr( value , 'toString' ) : value = value.toString()
236 elif type(value) == long: value = '%d' % value # prevent pending 'L'
237 sp = StringProperty( name , str(value))
238 self._optsvc.addPropertyToCatalogue( self._name , sp )
239 def __getattr__(self, name ):
240 """
241 The method which returns the value for the given property
242 - In the case of the valid instance it returns the valid property value through IProperty interface
243 - In the case of placeholder the property value is retrieved from JobOptionsCatalogue
244 """
245 ip = self.getInterface()
246 if ip :
247 if not gbl.Gaudi.Utils.hasProperty ( ip , name ) :
248 raise AttributeError, 'property %s does not exist' % name
249 prop = ip.getProperty(name)
250 if StringProperty == type( prop ) : return prop.value()
251 elif StringPropertyRef == type( prop ) : return prop.value()
252 try: return eval( prop.toString(), {}, {} )
253 except : return prop.value()
254 else :
255 props = self._optsvc.getProperties(self._name)
256 for p in props :
257 if not p.name() == name : continue
258 # from JobOptionsSvc we always have only strings
259 try: return eval( p.value(), {}, {} )
260 except: return p.value()
261 raise AttributeError, 'property %s does not exist' % name
262 def properties(self):
263 dct = {}
264 props = None
265 ip = self.getInterface()
266 if ip :
267 props = ip.getProperties()
268 propsFrom = self._name # "interface"
269 else:
270 props = self._optsvc.getProperties( self._name )
271 propsFrom = "jobOptionsSvc"
272 if props:
273 for p in props :
274 try:
275 dct[p.name()] = PropertyEntry(p)
276 except (ValueError,TypeError),e:
277 raise ValueError, "gaudimodule.iProperty.properties(): %s%s processing property %s.%s = %s" % \
278 (e.__class__.__name__, e.args, propsFrom, p.name(), p.value())
279 return dct
280 def name(self) :
281 return self._name
282
283 #----iService class---------------------------------------------------------------------
284 class iService(iProperty) :
285 """ Python equivalent to IProperty interface """
286 def __init__(self, name, isvc = None ) :
287 iProperty.__init__(self, name, isvc )
288 if isvc : self.__dict__['_isvc'] = InterfaceCast(gbl.IService)(isvc)
289 else : self.__dict__['_isvc'] = None
290 def retrieveInterface(self) :
291 isvc = Helper.service(self._svcloc,self._name)
292 if isvc : iService.__init__(self, self._name, isvc)
293 initialize = lambda self : self.__call_interface_method__("_isvc","initialize")
294 start = lambda self : self.__call_interface_method__("_isvc","start")
295 stop = lambda self : self.__call_interface_method__("_isvc","stop")
296 finalize = lambda self : self.__call_interface_method__("_isvc","finalize")
297 reinitialize = lambda self : self.__call_interface_method__("_isvc","reinitialize")
298 restart = lambda self : self.__call_interface_method__("_isvc","restart")
299 def isValid(self) :
300 if self._isvc: return True
301 else : return False
302
303 #----iAlgorithm class---------------------------------------------------------------------
304 class iAlgorithm(iProperty) :
305 """ Python equivalent to IAlgorithm interface """
306 def __init__(self, name, ialg = None ) :
307 iProperty.__init__(self, name, ialg )
308 if ialg : self.__dict__['_ialg'] = InterfaceCast(gbl.IAlgorithm)(ialg)
309 else : self.__dict__['_ialg'] = None
310 def retrieveInterface(self) :
311 ialg = Helper.algorithm(InterfaceCast(gbl.IAlgManager)(self._svcloc),self._name)
312 if ialg : iAlgorithm.__init__(self, self._name, ialg)
313 initialize = lambda self : self.__call_interface_method__("_ialg","initialize")
314 start = lambda self : self.__call_interface_method__("_ialg","start")
315 execute = lambda self : self.__call_interface_method__("_ialg","execute")
316 stop = lambda self : self.__call_interface_method__("_ialg","stop")
317 finalize = lambda self : self.__call_interface_method__("_ialg","finalize")
318 reinitialize = lambda self : self.__call_interface_method__("_ialg","reinitialize")
319 restart = lambda self : self.__call_interface_method__("_ialg","restart")
320 sysInitialize = lambda self : self.__call_interface_method__("_ialg","sysInitialize")
321 sysStart = lambda self : self.__call_interface_method__("_ialg","sysStart")
322 sysExecute = lambda self : self.__call_interface_method__("_ialg","sysExecute")
323 sysStop = lambda self : self.__call_interface_method__("_ialg","sysStop")
324 sysFinalize = lambda self : self.__call_interface_method__("_ialg","sysFinalize")
325 sysReinitialize = lambda self : self.__call_interface_method__("_ialg","sysReinitialize")
326 sysRestart = lambda self : self.__call_interface_method__("_ialg","sysRestart")
327
328 #----iAlgTool class---------------------------------------------------------------------
329 class iAlgTool(iProperty) :
330 """ Python equivalent to IAlgTool interface (not completed yet) """
331 def __init__(self, name, itool = None ) :
332 iProperty.__init__(self, name, itool )
333 if itool : self.__dict__['_itool'] = itool
334 else : self.__dict__['_itool'] = None
335 svc = Helper.service( self._svcloc, 'ToolSvc', True )
336 self.__dict__['_toolsvc']= iToolSvc('ToolSvc', svc)
337 def retrieveInterface(self) :
338 itool = self._toolsvc._retrieve(self._name)
339 if itool : iAlgTool.__init__(self, self._name, itool)
340 start = lambda self : self.__call_interface_method__("_itool","start")
341 stop = lambda self : self.__call_interface_method__("_itool","stop")
342 type = lambda self : self.__call_interface_method__("_itool","type")
343 def name(self) :
344 if self._itool : return self._itool.name()
345 else : return self._name
346
347 #----iDataSvc class---------------------------------------------------------------------
348 class iDataSvc(iService) :
349 def __init__(self, name, idp) :
350 iService.__init__(self, name, idp )
351 self.__dict__['_idp'] = InterfaceCast(gbl.IDataProviderSvc)(idp)
352 self.__dict__['_idm'] = InterfaceCast(gbl.IDataManagerSvc)(idp)
353 def registerObject(self, path, obj) :
354 if not self._idp : raise AttributeError('C++ service %s does not exist' % self.__dict__['_name'])
355 return self._idp.registerObject(path,obj)
356 def unregisterObject(self, path) :
357 if not self._idp : raise AttributeError('C++ service %s does not exist' % self.__dict__['_name'])
358 return self._idp.unregisterObject(path)
359 def retrieveObject(self, path) :
360 if not self._idp : return None
361 return Helper.dataobject(self._idp, path)
362 ## get object from TES
363 def findObject(self, path) :
364 """
365
366 Get the existing object in TransientStore for the given location
367
368 - loading of object from persistency is NOT triggered
369 - 'data-on-demand' action is NOT triggered
370
371 >>> svc = ... ## get the service
372 >>> path = ... ## get the path in Transient Store
373 >>> data = svc.findObject ( path ) ## use the method
374
375 """
376 if not self._idp : raise IndexError('C++ service %s does not exist' % self.__dict__['_name'])
377 return Helper.findobject(self._idp, path)
378
379 ## get or retrieve object, possible switch-off 'on-demand' actions
380 def getObject ( self , path , *args ) :
381 """
382 Get object from Transient Store for the given location
383
384 arguments :
385 - path : Location of object in Transient Store
386 - retrieve (bool) True : retrieve versus find
387 - disable on-demand (bool) False : temporary disable 'on-demand' actions
388
389 >>> svc = ... ## get the service
390 >>> path = ... ## get the path
391
392 >>> data = svc.getObject ( path , False ) ## find object in Transient Store
393
394 ## find object in Transient Store
395 # load form tape or use 'on-demand' action for missing objects :
396 >>> data = svc.getObject ( path , True )
397
398 ## find object in Transient Store
399 # load from tape or for missing objects, disable 'on-demand'-actions
400 >>> data = svc.getObject ( path , True , True )
401
402 """
403 if not self._idp : raise IndexError('C++ service %s does not exist' % self.__dict__['_name'])
404 return Helper.getobject(self._idp, path, *args )
405
406 def __getitem__(self, path) :
407 if not self._idp : raise IndexError('C++ service %s does not exist' % self.__dict__['_name'])
408 return Helper.dataobject(self._idp, path)
409 def __setitem__(self, path, obj) :
410 if not self._idp : raise IndexError('C++ service %s does not exist' % self.__dict__['_name'])
411 return self._idp.registerObject(path,obj)
412 def __delitem__(self, path) :
413 if not self._idp : raise IndexError('C++ service %s does not exist' % self.__dict__['_name'])
414 return self._idp.unregisterObject(path)
415 def leaves(self, node=None) :
416 if not node : node = self.retrieveObject('')
417 ll = gbl.std.vector('IRegistry*')()
418 if type(node) is str : obj = self.retrieveObject(node)
419 else : obj = node
420 if self._idm.objectLeaves(node, ll).isSuccess() : return ll
421 def dump(self, node=None) :
422 if not node :
423 root = self.retrieveObject('')
424 if root : node = root.registry()
425 else : return
426 print node.identifier()
427 if node.object() :
428 for l in self.leaves(node) : self.dump(l)
429 def getList(self, node=None, lst=[], rootFID=None) :
430 if not node :
431 root = self.retrieveObject('')
432 if root :
433 node = root.registry()
434 rootFID = node.address().par()
435 lst = []
436 else :
437 return
438 Helper.dataobject( self._idp, node.identifier() )
439 if node.object() :
440 lst.append( node.identifier() )
441 for l in self.leaves(node) :
442 if l.address() and l.address().par() == rootFID :
443 self.getList(l,lst,rootFID)
444 else :
445 continue
446 return lst
447 def getHistoNames( self, node=None, lst=[] ) :
448 if not node :
449 root = self.retrieveObject('')
450 if root :
451 node = root.registry()
452 # rootFID = node.address().par()
453 lst = []
454 else : return
455 Helper.dataobject( self._idp, node.identifier() )
456 if node.object() :
457 lst.append( node.identifier() )
458 for l in self.leaves(node) :
459 if l.name() : # and l.address().par() == rootFID :
460 self.getHistoNames(l,lst)
461 else :
462 continue
463 return lst
464 def setRoot(self, name, obj):
465 if not self._idm : raise IndexError('C++ service %s does not exist' % self.__dict__['_name'])
466 return self._idm.setRoot(name,obj)
467 def clearStore(self):
468 if not self._idm : raise IndexError('C++ service %s does not exist' % self.__dict__['_name'])
469 return self._idm.clearStore()
470
471
472 #----iHistogramSvc class---------------------------------------------------------------------
473 class iHistogramSvc(iDataSvc) :
474 def __init__(self, name, ihs) :
475 self.__dict__['_ihs'] = InterfaceCast(gbl.IHistogramSvc)(ihs)
476 iDataSvc.__init__(self, name, ihs)
477 def retrieve1D(self, path) :
478 return Helper.histo1D(self._ihs, path)
479 def retrieve2D(self, path) :
480 return Helper.histo2D(self._ihs, path)
481 def retrieve3D(self, path) :
482 return Helper.histo3D(self._ihs, path)
483 def retrieveProfile1D(self, path) :
484 return Helper.profile1D(self._ihs, path)
485 def retrieveProfile2D(self, path) :
486 return Helper.profile2D(self._ihs, path)
487 def retrieve(self,path):
488 """
489 Retrieve AIDA histogram or AIDA profile histogram by path in Histogram Transient Store
490 >>> svc = ...
491 >>> histo = svc.retrieve ( 'path/to/my/histogram' )
492 """
493 h = self.retrieve1D(path)
494 if not h : h = self.retrieve2D(path)
495 if not h : h = self.retrieve3D(path)
496 if not h : h = self.retrieveProfile1D(path)
497 if not h : h = self.retrieveProfile2D(path)
498 return h
499 def book(self, *args) :
500 """
501 Book the histograms(1D,2D&3D) , see IHistogramSvc::book
502 >>> svc = ...
503 >>> histo = svc.book( .... )
504 """
505 return apply(self._ihs.book,args)
506 def bookProf(self, *args) :
507 """
508 Book the profile(1D&2D) histograms, see IHistogramSvc::bookProf
509 >>> svc = ...
510 >>> histo = svc.bookProf( .... )
511 """
512 return apply(self._ihs.bookProf,args)
513 def __getitem__ ( self, path ) :
514 """
515 Retrieve the object from Histogram Transient Store (by path)
516 The reference to AIDA histogram is returned (if possible)
517 >>> svc = ...
518 >>> histo = svc['path/to/my/histogram']
519 """
520 h = self.retrieve ( path )
521 if h : return h
522 return iDataSvc.__getitem__( self , path )
523 def getAsAIDA ( self , path ) :
524 """
525 Retrieve the histogram from Histogram Transient Store (by path)
526 The reference to AIDA histogram is returned (if possible)
527 >>> svc = ...
528 >>> histo = svc.getAsAIDA ( 'path/to/my/histogram' )
529 """
530 return self.__getitem__( path )
531 def getAsROOT ( self , path ) :
532 """
533 Retrieve the histogram from Histogram Transient Store (by path)
534 The Underlying native ROOT object is returned (if possible)
535 >>> svc = ...
536 >>> histo = svc.getAsROOT ( 'path/to/my/histogram' )
537 """
538 fun = gbl.Gaudi.Utils.Aida2ROOT.aida2root
539 return fun( self.getAsAIDA( path ) )
540
541 #----iNTupleSvc class---------------------------------------------------------------------
542 class iNTupleSvc(iDataSvc) :
543 RowWiseTuple = 42
544 ColumnWiseTuple = 43
545 def __init__(self, name, ints) :
546 self.__dict__['_ints'] = InterfaceCast(gbl.INTupleSvc)(ints)
547 iDataSvc.__init__(self, name, ints)
548 def book(self, *args) :
549 return apply(self._ints.book, args)
550 def defineOutput(self, files, typ="Gaudi::RootCnvSvc"):
551 """ Defines the mapping between logical names and the output file
552 Usage:
553 defineOutput({'LUN1':'MyFile1.root', 'LUN2':'Myfile2.root'}, svc='Gaudi::RootCnvSvc')
554 """
555 import Persistency as prs
556 helper = prs.get(typ)
557 helper.configure(AppMgr())
558 self.Output = [helper.formatOutput(files[lun], lun=lun) for lun in files]
559 if AppMgr().HistogramPersistency == 'NONE':
560 AppMgr().HistogramPersistency = "ROOT"
561 def __getitem__ ( self, path ) :
562 return iDataSvc.__getitem__( self , path )
563
564
565 #----iToolSvc class---------------------------------------------------------------------
566 class iToolSvc(iService) :
567 def __init__(self, name, its) :
568 self.__dict__['_its'] = InterfaceCast(gbl.IToolSvc)(its)
569 iService.__init__(self, name, its)
570 def _retrieve(self, name, quiet=True):
571 sol = _gaudi.OutputLevel
572 if quiet : self.OutputLevel = 6
573 if name.rfind('.') == -1 :
574 itool = Helper.tool(self._its, '', name, None, False )
575 elif name[0:8] == 'ToolSvc.' :
576 itool = Helper.tool(self._its, '', name[8:], None, False )
577 elif name.count('.') > 1 :
578 ptool = self._retrieve(name[:name.rfind('.')])
579 itool = Helper.tool(self._its, '', name[name.rfind('.')+1:], ptool, False )
580 elif _gaudi :
581 prop = _gaudi.property(name[:name.rfind('.')])
582 itool = Helper.tool(self._its, '', name[name.rfind('.')+1:], prop._ip, False )
583 if quiet : self.OutputLevel = sol
584 return itool
585 def retrieve(self, name):
586 return iAlgTool(name, self._retrieve(name,quiet=False))
587 def create(self, typ, name=None, parent=None, interface=None) :
588 if not name : name = typ
589 itool = Helper.tool(self._its, typ, name, parent, True )
590 if interface :
591 return InterfaceCast(interface)(itool)
592 else :
593 return iAlgTool(name,itool)
594 def release(self, itool) :
595 if type(itool) is iAlgTool :
596 self._its.releaseTool(itool._itool)
597
598 #----iJopOptSvc class-------------------------------------------------------------------
599 class iJobOptSvc(iService) :
600 """
601 Python-image of C++ class IJobOptionsSvc
602 """
603 ## constructor
604 def __init__( self , name , svc ) :
605 """ constructor """
606 self.__dict__['_optsvc'] = InterfaceCast(gbl.IJobOptionsSvc)(svc)
607 return iService.__init__( self , name , svc )
608 def getProperties( self , component ) :
609 """
610 Extract *ALL* properties of the given component
611 Usage :
612 >>> jos = gaudi.optSvc()
613 >>> props = jos.getProperties( 'Name' )
614 """
615 props = self._optsvc.getProperties( component )
616 prps = {}
617 if not props : return prps # RETURN
618 for p in props :
619 prop = p.name().upper()
620 try :
621 value = eval( p.value() , {} , {} )
622 except: value = p.value()
623 prps [ prop ] = value
624
625 return prps # RETURN
626 def getProperty ( self , component , name ) :
627 """
628 Get a certain property of the certain component
629 Usage:
630 >>> jos = ...
631 >>> extServices = jos.getProperty( 'ApplicationMgr', 'ExtSvc' )
632 """
633 ## get all properties of the component
634 all = self.getProperties ( component )
635 return all.get( name.upper() , None ) # RETURN
636
637 #----iEventSelector class------------------------------------------------------------------
638 class iEventSelector(iService):
639 def __init__(self):
640 iService.__init__(self, 'EventSelector', Helper.service(gbl.Gaudi.svcLocator(),'EventSelector'))
641 self.__dict__['g'] = AppMgr()
642 def open(self, stream, typ = 'Gaudi::RootCnvSvc', **kwargs):
643 import Persistency as prs
644 helper = prs.get(typ)
645 helper.configure(self.g)
646 self.Input = helper.formatInput(stream, **kwargs)
647 self.reinitialize()
648 def rewind(self):
649 # It is not possible to reinitialize EventSelector only
650 self.g.service('EventLoopMgr').reinitialize()
651
652 #----AppMgr class---------------------------------------------------------------------
653 class AppMgr(iService) :
654 def __new__ ( cls, *args, **kwargs ):
655 global _gaudi
656 if not _gaudi :
657 newobj = object.__new__( cls )
658 cls.__init__(newobj, *args, **kwargs)
659 _gaudi = newobj
660 return _gaudi
661 def __reset__(self):
662 global _gaudi
663 # Stop, Finalize and Terminate the current AppMgr
664 self.exit()
665 # release interfaces
666 self._evtpro.release()
667 self._svcloc.release()
668 self._appmgr.release()
669 # Reset the C++ globals
670 gbl.Gaudi.setInstance(makeNullPointer('ISvcLocator'))
671 gbl.Gaudi.setInstance(makeNullPointer('IAppMgrUI'))
672 # Reset the Python global
673 _gaudi = None
674 def __init__(self, outputlevel = -1, joboptions = None, selfoptions = {},
675 dllname = None, factname = None) :
676 global _gaudi
677 if _gaudi : return
678 # Protection against multiple calls to exit() if the finalization fails
679 self.__dict__['_exit_called'] = False
680 # keep the Gaudi namespace around (so it is still available during atexit shutdown)...
681 self.__dict__['_gaudi_ns'] = Gaudi
682 try:
683 from GaudiKernel.Proxy.Configurable import expandvars
684 except ImportError:
685 # pass-through implementation if expandvars is not defined (AthenaCommon)
686 expandvars = lambda data : data
687 if dllname and factname:
688 self.__dict__['_appmgr'] = gbl.Gaudi.createApplicationMgr(dllname,factname)
689 elif dllname:
690 self.__dict__['_appmgr'] = gbl.Gaudi.createApplicationMgr(dllname)
691 else:
692 self.__dict__['_appmgr'] = gbl.Gaudi.createApplicationMgr()
693 self.__dict__['_svcloc'] = gbl.Gaudi.svcLocator()
694 self.__dict__['_algmgr'] = InterfaceCast(gbl.IAlgManager)(self._appmgr)
695 self.__dict__['_evtpro'] = InterfaceCast(gbl.IEventProcessor)(self._appmgr)
696 self.__dict__['_svcmgr'] = InterfaceCast(gbl.ISvcManager)(self._appmgr)
697 self.__dict__['pyalgorithms'] = []
698 iService.__init__(self, 'ApplicationMgr', self._appmgr )
699 #------python specific initialization-------------------------------------
700 if self.FSMState() < Gaudi.StateMachine.CONFIGURED : # Not yet configured
701 self.JobOptionsType = 'NONE'
702 if joboptions :
703 from GaudiKernel.ProcessJobOptions import importOptions
704 importOptions(joboptions)
705 # Ensure that the ConfigurableUser instances have been applied
706 import GaudiKernel.Proxy.Configurable
707 if hasattr(GaudiKernel.Proxy.Configurable, "applyConfigurableUsers"):
708 GaudiKernel.Proxy.Configurable.applyConfigurableUsers()
709 # This is the default and could be overridden with "selfopts"
710 self.OutputLevel = 3
711 selfprops = Configurable.allConfigurables.get('ApplicationMgr',{})
712 if selfprops : selfprops = expandvars(selfprops.getValuedProperties())
713 for p,v in selfprops.items() : setattr(self, p, v)
714 for p,v in selfoptions.items() : setattr(self, p, v)
715 # Override job options
716 if outputlevel != -1 : self.OutputLevel = outputlevel
717 self.configure()
718 #---MessageSvc------------------------------------------------------------
719 ms = self.service('MessageSvc')
720 if 'MessageSvc' in Configurable.allConfigurables:
721 msprops = Configurable.allConfigurables['MessageSvc']
722 ms = self.service('MessageSvc')
723 if hasattr(msprops,"getValuedProperties"):
724 msprops = expandvars(msprops.getValuedProperties())
725 for p,v in msprops.items():
726 setattr(ms, p, v)
727 if outputlevel != -1 : ms.OutputLevel = outputlevel
728 #---JobOptions------------------------------------------------------------
729 self.__dict__['_optsvc'] = InterfaceCast(gbl.IJobOptionsSvc)(Helper.service(self._svcloc,'JobOptionsSvc'))
730 #------Configurables initialization (part2)-------------------------------
731 for n in getNeededConfigurables():
732 c = Configurable.allConfigurables[n]
733 if n in ['ApplicationMgr','MessageSvc'] : continue # These are already done---
734 for p, v in c.getValuedProperties().items() :
735 v = expandvars(v)
736 # Note: AthenaCommon.Configurable does not have Configurable.PropertyReference
737 if hasattr(Configurable,"PropertyReference") and type(v) == Configurable.PropertyReference:
738 # this is done in "getFullName", but the exception is ignored,
739 # so we do it again to get it
740 v = v.__resolve__()
741 if type(v) == str : v = '"%s"' % v # need double quotes
742 elif type(v) == long: v = '%d' % v # prevent pending 'L'
743 self._optsvc.addPropertyToCatalogue(n, StringProperty(p,str(v)))
744 if hasattr(Configurable,"_configurationLocked"):
745 Configurable._configurationLocked = True
746
747 # Ensure that the exit method is called when exiting from Python
748 import atexit
749 atexit.register(self.exit)
750
751 #---Hack to avoid bad interactions with the ROOT exit handler
752 # Look for an exit handler installed by ROOT
753 root_handler_installed = False
754 for h in atexit._exithandlers:
755 func = h[0]
756 if hasattr(func, "__module__") and func.__module__ == "ROOT":
757 root_handler_installed = True
758 break
759
760 # If the handler is not yet installed, let's install our private version
761 # that detects that the ROOT exit handler is installed and add our own
762 # after it to ensure it is called before.
763 if not root_handler_installed:
764 orig_register = atexit.register
765 def register(func, *targs, **kargs):
766 orig_register(func, *targs, **kargs)
767 if hasattr(func, "__module__") and func.__module__ == "ROOT":
768 orig_register(self.exit)
769 # we do not need to remove out handler from the list because
770 # it can be safely called more than once
771 register.__doc__ = (orig_register.__doc__ +
772 "\nNote: version hacked by GaudiPython to work " +
773 "around a problem with the ROOT exit handler")
774 atexit.register = register
775
776 def state(self) : return self._isvc.FSMState()
777 def FSMState(self) : return self._isvc.FSMState()
778 def targetFSMState(self) : return self._isvc.targetFSMState()
779 def service(self, name, interface = None) :
780 svc = Helper.service( self._svcloc, name )
781 if interface :
782 return InterfaceCast(interface)(svc)
783 else :
784 return iService(name, svc )
785 def declSvcType(self, svcname, svctype ) :
786 self._svcmgr.declareSvcType(svcname, svctype)
787 def createSvc(self, name ) :
788 return Helper.service( self._svcloc, name, True )
789 def services(self) :
790 l = self._svcloc.getServices()
791 return [s.name() for s in l]
792 def algorithm(self, name , createIf = False ) :
793 alg = Helper.algorithm( self._algmgr, name , createIf )
794 if not alg : return iAlgorithm ( name , alg )
795 else : return iAlgorithm ( alg.name() , alg )
796 def algorithms(self) :
797 l = self._algmgr.getAlgorithms()
798 return [a.name() for a in l]
799 def tool(self, name ) :
800 return iAlgTool(name)
801 def property( self , name ) :
802 if name in self.algorithms() : return self.algorithm( name )
803 elif name in self.services() : return self.service(name )
804 else : return iProperty( name )
805 def datasvc(self, name) :
806 if self.state() == Gaudi.StateMachine.CONFIGURED : self.initialize()
807 svc = Helper.service( self._svcloc, name )
808 return iDataSvc(name, svc)
809 def evtsvc(self) :
810 return self.datasvc('EventDataSvc')
811 def detsvc(self) :
812 return self.datasvc('DetectorDataSvc')
813 def filerecordsvc(self) :
814 return self.datasvc('FileRecordDataSvc')
815 def evtsel(self):
816 if self.state() == Gaudi.StateMachine.CONFIGURED : self.initialize()
817 if not hasattr(self,'_evtsel') : self.__dict__['_evtsel'] = iEventSelector()
818 return self._evtsel
819 def histsvc(self, name='HistogramDataSvc') :
820 svc = Helper.service( self._svcloc, name )
821 return iHistogramSvc(name, svc)
822 def ntuplesvc(self, name='NTupleSvc') :
823 if name not in self.ExtSvc : self.ExtSvc += [name]
824 # if self.HistogramPersistency == 'NONE' : self.HistogramPersistency = 'ROOT'
825 svc = Helper.service( self._svcloc, name, True )
826 return iNTupleSvc(name, svc)
827 def partsvc(self ) :
828 if self.FSMState() == Gaudi.StateMachine.CONFIGURED : self.initialize()
829 svc = Helper.service( self._svcloc, 'ParticlePropertySvc' )
830 return InterfaceCast(gbl.IParticlePropertySvc)(svc)
831 def toolsvc(self, name='ToolSvc') :
832 svc = Helper.service( self._svcloc, name, True )
833 return iToolSvc(name, svc)
834 def optSvc (self, name='JobOptionsSvc') :
835 svc = Helper.service( self._svcloc, name, True )
836 return iJobOptSvc(name, svc)
837 def readOptions(self, file) :
838 return self._optsvc.readOptions(file)
839 def addAlgorithm(self, alg) :
840 """ Add an Algorithm to the list of Top algorithms. It can be either a instance of
841 an Algorithm class or it name """
842 if type(alg) is str :
843 self.topAlg += [alg]
844 else :
845 self.pyalgorithms.append(alg)
846 setOwnership(alg,0)
847 if self.targetFSMState() >= Gaudi.StateMachine.INITIALIZED :
848 alg.sysInitialize()
849 if self.targetFSMState() == Gaudi.StateMachine.RUNNING :
850 alg.sysStart()
851 self.topAlg += [alg.name()]
852 def setAlgorithms(self, algs) :
853 """ Set the list of Top Algorithms.
854 It can be an individual of a list of algorithms names or instances """
855 if type(algs) is not list : algs = [algs]
856 names = []
857 for alg in algs :
858 if type(alg) is str : names.append(alg)
859 else :
860 self.pyalgorithms.append(alg)
861 if self.targetFSMState() >= Gaudi.StateMachine.INITIALIZED :
862 alg.sysInitialize()
863 if self.targetFSMState() == Gaudi.StateMachine.RUNNING :
864 alg.sysStart()
865 names.append(alg.name())
866 self.topAlg = names
867 def removeAlgorithm(self, alg) :
868 """ Remove an Algorithm to the list of Top algorithms. It can be either a instance of
869 an Algorithm class or it name """
870 tmp = self.topAlg
871 if type(alg) is str :
872 tmp.remove(alg)
873 else :
874 tmp.remove(alg.name())
875 self.pyalgorithms.remove(alg)
876 setOwnership(alg,1)
877 self.topAlg = tmp
878 def printAlgsSequences(self):
879 """
880 Print the sequence of Algorithms.
881 """
882 def printAlgo( algName, appMgr, prefix = ' ') :
883 print prefix + algName
884 alg = appMgr.algorithm( algName.split( "/" )[ -1 ] )
885 prop = alg.properties()
886 if prop.has_key( "Members" ) :
887 subs = prop[ "Members" ].value()
888 for i in subs : printAlgo( i.strip( '"' ), appMgr, prefix + " " )
889 mp = self.properties()
890 prefix = 'ApplicationMgr SUCCESS '
891 print prefix + "****************************** Algorithm Sequence ****************************"
892 for i in mp["TopAlg"].value(): printAlgo( i, self, prefix )
893 print prefix + "******************************************************************************"
894 def config ( self, **args ):
895 """
896 Simple utility to perform the configuration of Gaudi application.
897 It reads the set of input job-options files, and set few
898 additional parameters 'options' through the usage of temporary *.opts file
899 Usage:
900 gaudi.config( files = [ '$GAUSSOPTS/Gauss.opts' ,
901 '$DECFILESROOT/options/10022_010.0GeV.opts' ] ,
902 options = [ 'EventSelector.PrintFreq = 5 ' ] )
903 """
904 files = args.get('files',[])
905 for file in files :
906 sc = self.readOptions(file)
907 if sc.isFailure() :
908 raise RuntimeError , ' Unable to read file "' + file +'" '
909 options = args.get('options',None)
910 if options :
911 import tempfile
912 tmpfilename = tempfile.mktemp()
913 tmpfile = open( tmpfilename, 'w' )
914 tmpfile.write ( '#pragma print on \n' )
915 tmpfile.write ( '/// File "' + tmpfilename+'" generated by GaudiPython \n\n' )
916 for opt in options :
917 if type(options) is dict :
918 tmpfile.write( ' \t ' + opt + ' = '+ options[opt]+ ' ; // added by GaudiPython \n' )
919 else :
920 tmpfile.write( ' \t ' + opt + ' ; // added by GaudiPython \n' )
921 tmpfile.write ( '/// End of file "' + tmpfilename+'" generated by GaudiPython \n\n' )
922 tmpfile.close()
923 sc = self.readOptions( tmpfilename )
924 if sc.isFailure() :
925 raise RuntimeError , ' Unable to read file "' + tmpfilename +'" '
926 os.remove( tmpfilename )
927 # We need to make sure that the options are taken by the ApplicationMgr
928 if self.FSMState() != Gaudi.StateMachine.OFFLINE : # The state is already configured, so we need to do something....
929
930 ## get job-options-service, @see class iJobOptSvc
931 jos = self.optSvc()
932
933 ## list of all libraries
934 _dlls = jos.getProperty ( self.name() , 'DLLs' )
935 ## take care about libraries : APPEND if not done yet
936 if _dlls :
937 libs = [ l for l in _dlls if not l in self.DLLs ]
938 if libs : self.DLLs += libs
939
940 ## all external services
941 _svcs = jos.getProperty ( self.name() , 'ExtSvc' )
942 ## take care about services : APPEND if not done yet
943 if _svcs :
944 svcs = [ s for s in _svcs if not s in self.ExtSvc ]
945 if svcs : self.ExtSvc += svcs
946
947 ## get all properties
948 props = jos.getProperties ( self.name() )
949 ## finally treat all other properties (presumably scalar properties)
950 for key in props :
951 if 'DLLS' == key or 'EXTSVC' == key : continue
952 self.__setattr__( key , props[key] )
953 return SUCCESS # RETURN
954 def configure(self) :
955 return self._appmgr.configure()
956 def start(self) :
957 return self._appmgr.start()
958 def terminate(self):
959 return self._appmgr.terminate()
960 def run(self, n) :
961 if self.FSMState() == Gaudi.StateMachine.CONFIGURED :
962 sc = self.initialize()
963 if sc.isFailure() or self.ReturnCode != 0:
964 return sc
965 if self.FSMState() == Gaudi.StateMachine.INITIALIZED :
966 sc = self.start()
967 if sc.isFailure() or self.ReturnCode != 0:
968 return sc
969 return self._evtpro.executeRun(n)
970 def executeEvent(self) :
971 return self._evtpro.executeEvent()
972 def execute(self) :
973 return self._evtpro.executeEvent()
974 def runSelectedEvents(self, pfn, events):
975 if self.FSMState() == Gaudi.StateMachine.CONFIGURED :
976 sc = self.initialize()
977 if sc.isFailure(): return sc
978 if self.FSMState() == Gaudi.StateMachine.INITIALIZED :
979 sc = self.start()
980 if sc.isFailure(): return sc
981 #--- Access a number of services ----
982 if not hasattr(self,'_perssvc'): self.__dict__['_perssvc'] = self.service('EventPersistencySvc','IAddressCreator')
983 if not hasattr(self,'_filecat'): self.__dict__['_filecat'] = self.service('FileCatalog','Gaudi::IFileCatalog')
984 if not hasattr(self,'_evtmgr'): self.__dict__['_evtmgr'] = self.service('EventDataSvc','IDataManagerSvc')
985 #--- Get FID from PFN and number of events in file
986 if pfn.find('PFN:') == 0: pfn = pfn[4:]
987 fid, maxevt = _getFIDandEvents(pfn)
988 #--- Add FID into catalog if needed ---
989 if not self._filecat.existsFID(fid) : self._filecat.registerPFN(fid, pfn, '')
990 #--- Loop over events
991 if type(events) is not list : events = (events,)
992 for evt in events :
993 #--- Create POOL Address from Generic Address
994 gadd = gbl.GenericAddress(0x02, 1, fid, '/Event', 0, evt)
995 oadd = makeNullPointer('IOpaqueAddress')
996 self._perssvc.createAddress(gadd.svcType(),gadd.clID(),gadd.par(),gadd.ipar(),oadd)
997 #--- Clear TES, set root and run all algorithms
998 self._evtmgr.clearStore()
999 self._evtmgr.setRoot('/Event',oadd)
1000 self._evtpro.executeEvent()
1001 def exit(self):
1002 # Protection against multiple calls to exit() if the finalization fails
1003 if not self._exit_called:
1004 self.__dict__['_exit_called'] = True
1005 Gaudi = self._gaudi_ns
1006 if self.FSMState() == Gaudi.StateMachine.RUNNING:
1007 self._appmgr.stop().ignore()
1008 if self.FSMState() == Gaudi.StateMachine.INITIALIZED:
1009 self._appmgr.finalize().ignore()
1010 if self.FSMState() == Gaudi.StateMachine.CONFIGURED:
1011 self._appmgr.terminate()
1012 return SUCCESS
1013 ## Custom destructor to ensure that the application is correctly finalized when exiting from python.
1014 def __del__(self):
1015 self.exit()
1016 evtSvc = evtsvc
1017 histSvc = histsvc
1018 ntupleSvc = ntuplesvc
1019 evtSel = evtsel
1020 detSvc = detsvc
1021 toolSvc = toolsvc
1022 partSvc = partsvc
1023
1024 #--------------------------------------------------------------------------------------
1025 def _getFIDandEvents( pfn ):
1026 tfile = gbl.TFile.Open(pfn)
1027 if not tfile : raise 'Cannot open ROOT file ', pfn
1028 tree = tfile.Get('##Params')
1029 tree.GetEvent(0)
1030 text = tree.db_string
1031 if 'NAME=FID' in text :
1032 fid = text[text.rfind('VALUE=')+6:-1]
1033 nevt = tfile.Get('_Event').GetEntries()
1034 tfile.Close()
1035 return fid, nevt
1036
1037 #--------------------------------------------------------------------------------------
1038 def getComponentProperties( name ):
1039 """ Get all the properties of a component as a Python dictionary.
1040 The component is instantiated using the component library
1041 """
1042 properties = {}
1043 if name == 'GaudiCoreSvc' :
1044 if Helper.loadDynamicLib(name) != 1 :
1045 raise ImportError, 'Error loading component library '+ name
1046 factorylist = gbl.FactoryTable.instance().getEntries()
1047 factories = _copyFactoriesFromList(factorylist)
1048 g = AppMgr(outputlevel=7)
1049 else :
1050 g = AppMgr(outputlevel=7)
1051 if Helper.loadDynamicLib(name) != 1 :
1052 raise ImportError, 'Error loading component library '+ name
1053 factorylist = gbl.FactoryTable.instance().getEntries()
1054 factories = _copyFactoriesFromList(factorylist)
1055 svcloc = gbl.Gaudi.svcLocator()
1056 dummysvc = gbl.Service('DummySvc',svcloc)
1057 for factory in factories :
1058 if InterfaceCast(gbl.IAlgFactory)(factory) : ctype = 'Algorithm'
1059 elif InterfaceCast(gbl.ISvcFactory)(factory) : ctype = 'Service'
1060 elif InterfaceCast(gbl.IToolFactory)(factory) : ctype = 'AlgTool'
1061 elif factory.ident() == 'ApplicationMgr' : ctype = 'ApplicationMgr'
1062 else : ctype = 'Unknown'
1063 cname = factory.ident().split()[-1]
1064 if ctype in ('Algorithm','Service', 'AlgTool', 'ApplicationMgr') :
1065 try :
1066 if ctype == 'AlgTool' :
1067 obj = factory.instantiate(dummysvc)
1068 else :
1069 obj = factory.instantiate(svcloc)
1070 except RuntimeError, text :
1071 print 'Error instantiating', cname, ' from ', name
1072 print text
1073 continue
1074 prop = iProperty('dummy', obj)
1075 properties[cname] = [ctype, prop.properties()]
1076 try: obj.release()
1077 except: pass
1078 return properties
1079
1080 def _copyFactoriesFromList(factories) :
1081 result = []
1082 for i in range(factories.size()) :
1083 factory = factories.front()
1084 result.append(factory)
1085 factories.pop_front()
1086 for factory in result :
1087 factories.push_back(factory)
1088 return result
1089
1090 #----CallbackStreamBuf----------------------------------------------------------------
1091 # Used for redirecting C++ messages to python
1092 _CallbackStreamBufBase = gbl.GaudiPython.CallbackStreamBuf
1093 class CallbackStreamBuf (_CallbackStreamBufBase):
1094 def __init__(self, callback):
1095 _CallbackStreamBufBase.__init__(self, self)
1096 self.callback = callback
1097 def _sync(self, string = None):
1098 if not string : return 0
1099 self.callback(string)
1100 return 0
1101
1102 #----PyAlgorithm----------------------------------------------------------------------
1103 # Used to implement Algorithms in Python
1104 _PyAlgorithm = gbl.GaudiPython.PyAlgorithm
1105 class PyAlgorithm (_PyAlgorithm) :
1106 def __init__(self, name=None) :
1107 if not name : name = self.__class__.__name__
1108 _PyAlgorithm.__init__(self, self, name)
1109 self._svcloc = gbl.Gaudi.svcLocator()
1110 self._algmgr = InterfaceCast(gbl.IAlgManager)(self._svcloc)
1111 sc = self._algmgr.addAlgorithm(self)
1112 if sc.isFailure() : raise RuntimeError, 'Unable to add Algorithm'
1113 def __del__(self):
1114 sc = self._algmgr.removeAlgorithm(self)
1115 if sc.isFailure() : pass
1116 def initialize(self) : return 1
1117 def start(self) : return 1
1118 def execute(self) : return 1
1119 def stop(self) : return 1
1120 def finalize(self) : return 1
1121 def beginRun(self) : return 1
1122 def endRun(self) : return 1
1123
1124 #----Enable tab completion------------------------------------------------------------
1125 try:
1126 import rlcompleter, readline
1127 readline.parse_and_bind("tab: complete")
1128 except:
1129 pass
GaudiPython.Bindings.AppMgr.declSvcType
def declSvcType(self, svcname, svctype)
Definition: Bindings.py:785
GaudiPython.Bindings.PyAlgorithm
Definition: Bindings.py:1105
GaudiPython.Bindings.iAlgorithm
Definition: Bindings.py:304
GaudiPython.Bindings.AppMgr.services
def services(self)
Definition: Bindings.py:789
GaudiKernel.Configurable.getNeededConfigurables
def getNeededConfigurables()
Definition: Configurable.py:1490
GaudiPython.Bindings.AppMgr.FSMState
def FSMState(self)
Definition: Bindings.py:777
GaudiPython.Bindings.AppMgr.setAlgorithms
def setAlgorithms(self, algs)
Definition: Bindings.py:852
GaudiPython.Bindings.AppMgr.__reset__
def __reset__(self)
Definition: Bindings.py:661
GaudiPython.Bindings.AppMgr.printAlgsSequences
def printAlgsSequences(self)
Definition: Bindings.py:878
GaudiPython.Bindings.AppMgr.createSvc
def createSvc(self, name)
Definition: Bindings.py:787
GaudiPython.Bindings.iNTupleSvc.__init__
def __init__(self, name, ints)
Definition: Bindings.py:545
GaudiPython.Bindings.PropertyEntry._value
_value
Definition: Bindings.py:149
GaudiPython.Bindings.InterfaceCast
Definition: Bindings.py:77
GaudiPython.Bindings.AppMgr.detsvc
def detsvc(self)
Definition: Bindings.py:811
GaudiPython.Bindings.iProperty.retrieveInterface
def retrieveInterface(self)
Definition: Bindings.py:190
GaudiPython.Bindings.AppMgr.optSvc
def optSvc
Definition: Bindings.py:834
GaudiPython.Bindings.PyAlgorithm.beginRun
def beginRun(self)
Definition: Bindings.py:1121
GaudiPython.Bindings.iDataSvc.getHistoNames
def getHistoNames
Definition: Bindings.py:447
GaudiPython.Bindings.iService.initialize
tuple initialize
Definition: Bindings.py:293
GaudiPython.Bindings.AppMgr.runSelectedEvents
def runSelectedEvents(self, pfn, events)
Definition: Bindings.py:974
GaudiPython.Bindings.iDataSvc.__getitem__
def __getitem__(self, path)
Definition: Bindings.py:406
GaudiPython.Bindings.iDataSvc.findObject
def findObject(self, path)
get object from TES
Definition: Bindings.py:363
GaudiPython.Bindings.AppMgr.JobOptionsType
JobOptionsType
Definition: Bindings.py:701
GaudiPython.Bindings.PropertyEntry.__init__
def __init__(self, prop)
Definition: Bindings.py:144
GaudiPython.Bindings.iDataSvc.unregisterObject
def unregisterObject(self, path)
Definition: Bindings.py:356
GaudiPython.Bindings.iDataSvc
Definition: Bindings.py:348
GaudiPython.Bindings.AppMgr.terminate
def terminate(self)
Definition: Bindings.py:958
GaudiPython.Bindings.iProperty.name
def name(self)
Definition: Bindings.py:280
GaudiPython.Bindings.AppMgr.targetFSMState
def targetFSMState(self)
Definition: Bindings.py:778
GaudiPython.Bindings.AppMgr.tool
def tool(self, name)
Definition: Bindings.py:799
GaudiPython.Bindings.CallbackStreamBuf._sync
def _sync
Definition: Bindings.py:1097
GaudiPython.Bindings.CallbackStreamBuf
Definition: Bindings.py:1093
GaudiPython.Bindings.AppMgr.state
def state(self)
Definition: Bindings.py:776
GaudiPython.Bindings.getClass
def getClass
Definition: Bindings.py:117
GaudiPython.Bindings.AppMgr.filerecordsvc
def filerecordsvc(self)
Definition: Bindings.py:813
GaudiPython.Bindings.iHistogramSvc.retrieveProfile1D
def retrieveProfile1D(self, path)
Definition: Bindings.py:483
GaudiPython.Bindings.iService.isValid
def isValid(self)
Definition: Bindings.py:299
GaudiPython.Bindings.PropertyEntry.property
def property(self)
Definition: Bindings.py:168
GaudiPython.Bindings.iService.__init__
def __init__
Definition: Bindings.py:286
GaudiPython.Bindings.AppMgr.__init__
def __init__
Definition: Bindings.py:675
GaudiPython.Bindings.iHistogramSvc.getAsAIDA
def getAsAIDA(self, path)
Definition: Bindings.py:523
GaudiPython.Bindings.PropertyEntry.value
def value(self)
Definition: Bindings.py:164
GaudiPython.Bindings.iJobOptSvc.getProperties
def getProperties(self, component)
Definition: Bindings.py:608
GaudiPython.Bindings.PropertyEntry.hasDoc
def hasDoc(self)
Definition: Bindings.py:173
GaudiPython.Bindings.iAlgTool.__init__
def __init__
Definition: Bindings.py:331
GaudiPython.Bindings.AppMgr.algorithm
def algorithm
Definition: Bindings.py:792
GaudiPython.Bindings._getFIDandEvents
def _getFIDandEvents(pfn)
Definition: Bindings.py:1025
GaudiPython.Bindings._CallbackStreamBufBase
_CallbackStreamBufBase
Definition: Bindings.py:1092
GaudiPython.Bindings.AppMgr.exit
def exit(self)
Definition: Bindings.py:1001
GaudiPython.Bindings.iHistogramSvc.bookProf
def bookProf(self, args)
Definition: Bindings.py:506
GaudiPython.Bindings.iEventSelector.open
def open(self, stream, typ='Gaudi::RootCnvSvc', kwargs)
Definition: Bindings.py:642
GaudiKernel.ProcessJobOptions
Definition: ProcessJobOptions.py:1
GaudiPython.Bindings.Interface.cast
def cast(self, obj)
Definition: Bindings.py:103
GaudiPython.Bindings.PyAlgorithm.__del__
def __del__(self)
Definition: Bindings.py:1113
GaudiPython.Bindings.AppMgr.toolsvc
def toolsvc
Definition: Bindings.py:831
GaudiPython.Bindings.iService.reinitialize
tuple reinitialize
Definition: Bindings.py:297
GaudiPython.Bindings.PyAlgorithm._algmgr
_algmgr
Definition: Bindings.py:1110
GaudiPython.Bindings.iHistogramSvc.__getitem__
def __getitem__(self, path)
Definition: Bindings.py:513
GaudiPython.Bindings.PropertyEntry
Definition: Bindings.py:142
GaudiPython.Bindings.iHistogramSvc.book
def book(self, args)
Definition: Bindings.py:499
GaudiPython.Bindings.iDataSvc.getList
def getList
Definition: Bindings.py:429
GaudiPython.Bindings.iJobOptSvc
Definition: Bindings.py:599
GaudiPython.Bindings.iNTupleSvc.Output
Output
Definition: Bindings.py:558
GaudiPython.Bindings.PyAlgorithm.start
def start(self)
Definition: Bindings.py:1117
SimpleProperty< std::string >
GaudiPython.Bindings.iDataSvc.getObject
def getObject(self, path, args)
get or retrieve object, possible switch-off 'on-demand' actions
Definition: Bindings.py:380
GaudiPython.Bindings.PropertyEntry._type
_type
Definition: Bindings.py:145
GaudiPython.Bindings.iProperty.__init__
def __init__
Definition: Bindings.py:179
GaudiPython.Bindings.CallbackStreamBuf.__init__
def __init__(self, callback)
Definition: Bindings.py:1094
GaudiPython.Bindings.iToolSvc.__init__
def __init__(self, name, its)
Definition: Bindings.py:567
GaudiPython.Bindings.iAlgorithm.retrieveInterface
def retrieveInterface(self)
Definition: Bindings.py:310
GaudiPython.Bindings.iHistogramSvc.retrieve1D
def retrieve1D(self, path)
Definition: Bindings.py:477
GaudiPython.Bindings.iProperty
Definition: Bindings.py:177
GaudiPython.Bindings.AppMgr.service
def service
Definition: Bindings.py:779
GaudiPython.Bindings.iHistogramSvc.retrieve3D
def retrieve3D(self, path)
Definition: Bindings.py:481
GaudiPython.Bindings.PropertyEntry.__doc__
__doc__
Definition: Bindings.py:146
compareOutputFiles.par
string par
Definition: compareOutputFiles.py:386
GaudiPython.Bindings.makeNullPointer
makeNullPointer
Definition: Bindings.py:70
GaudiPython.Bindings.iJobOptSvc.__init__
def __init__(self, name, svc)
constructor
Definition: Bindings.py:604
gaudirun.type
string type
Definition: gaudirun.py:151
GaudiPython.Bindings.Interface
Definition: Bindings.py:99
Gaudi::range
NamedRange_< CONTAINER > range(const CONTAINER &cnt, std::string name)
simple function to create the named range form arbitrary container
Definition: NamedRange.h:130
GaudiPython.Bindings.AppMgr.__new__
def __new__(cls, args, kwargs)
Definition: Bindings.py:654
GaudiPython.Bindings.PyAlgorithm._svcloc
_svcloc
Definition: Bindings.py:1109
GaudiPython.Bindings.AppMgr.removeAlgorithm
def removeAlgorithm(self, alg)
Definition: Bindings.py:867
GaudiPython.Bindings.iDataSvc.__init__
def __init__(self, name, idp)
Definition: Bindings.py:349
GaudiPython.Bindings.PyAlgorithm.execute
def execute(self)
Definition: Bindings.py:1118
GaudiPython.Bindings.CallbackStreamBuf.callback
callback
Definition: Bindings.py:1096
GaudiPython.Bindings.iDataSvc.leaves
def leaves
Definition: Bindings.py:415
GaudiKernel.ProcessJobOptions.importOptions
def importOptions(optsfile)
Definition: ProcessJobOptions.py:432
GaudiPython.Bindings.iDataSvc.__delitem__
def __delitem__(self, path)
Definition: Bindings.py:412
GaudiPython.Bindings._PyAlgorithm
_PyAlgorithm
Definition: Bindings.py:1104
GaudiPython.Bindings.PyAlgorithm.stop
def stop(self)
Definition: Bindings.py:1119
dump_component_properties.value
list value
Definition: dump_component_properties.py:12
GaudiPython.Bindings.iAlgTool.name
def name(self)
Definition: Bindings.py:343
GaudiKernel.ROOT6WorkAroundEnabled
def ROOT6WorkAroundEnabled
Definition: __init__.py:3
GaudiPython.Bindings.AppMgr.addAlgorithm
def addAlgorithm(self, alg)
Definition: Bindings.py:839
GaudiPython.Bindings.iHistogramSvc.retrieveProfile2D
def retrieveProfile2D(self, path)
Definition: Bindings.py:485
GaudiPython.Bindings.iHistogramSvc.retrieve2D
def retrieve2D(self, path)
Definition: Bindings.py:479
GaudiPython.Bindings.AppMgr.algorithms
def algorithms(self)
Definition: Bindings.py:796
GaudiPython.Bindings.iToolSvc.OutputLevel
OutputLevel
Definition: Bindings.py:572
GaudiPython.Bindings.AppMgr.__del__
def __del__(self)
Custom destructor to ensure that the application is correctly finalized when exiting from python...
Definition: Bindings.py:1014
GaudiPython.Bindings.iJobOptSvc.getProperty
def getProperty(self, component, name)
Definition: Bindings.py:626
GaudiPython.Bindings.PyAlgorithm.initialize
def initialize(self)
Definition: Bindings.py:1116
GaudiPython.Bindings.iDataSvc.__setitem__
def __setitem__(self, path, obj)
Definition: Bindings.py:409
GaudiPython.Bindings.loaddict
def loaddict(dict)
Definition: Bindings.py:107
GaudiPython.Bindings.iService.retrieveInterface
def retrieveInterface(self)
Definition: Bindings.py:290
GaudiPython.Bindings.PyAlgorithm.finalize
def finalize(self)
Definition: Bindings.py:1120
GaudiPython.Bindings.iDataSvc.dump
def dump
Definition: Bindings.py:421
GaudiPython.Bindings.iHistogramSvc
Definition: Bindings.py:473
GaudiPython.Bindings.iProperty.properties
def properties(self)
Definition: Bindings.py:262
GaudiPython.Bindings.iEventSelector.Input
Input
Definition: Bindings.py:646
GaudiPython.Bindings.PyAlgorithm.endRun
def endRun(self)
Definition: Bindings.py:1122
GaudiPython.Bindings.iHistogramSvc.__init__
def __init__(self, name, ihs)
Definition: Bindings.py:474
GaudiPython.Bindings.PyAlgorithm.__init__
def __init__
Definition: Bindings.py:1106
GaudiPython.Bindings.iToolSvc.release
def release(self, itool)
Definition: Bindings.py:594
GaudiPython.Bindings.AppMgr.OutputLevel
OutputLevel
Definition: Bindings.py:710
GaudiPython.Bindings.AppMgr.datasvc
def datasvc(self, name)
Definition: Bindings.py:805
GaudiPython.Bindings.iHistogramSvc.getAsROOT
def getAsROOT(self, path)
Definition: Bindings.py:531
GaudiPython.Bindings.InterfaceCast.type
type
Definition: Bindings.py:83
GaudiPython.Bindings.iAlgorithm.__init__
def __init__
Definition: Bindings.py:306
GaudiPython.Bindings.AppMgr.property
def property(self, name)
Definition: Bindings.py:801
GaudiPython.Bindings.AppMgr.configure
def configure(self)
Definition: Bindings.py:954
GaudiPython.Bindings.AppMgr.executeEvent
def executeEvent(self)
Definition: Bindings.py:970
GaudiPython.Bindings.AppMgr.run
def run(self, n)
Definition: Bindings.py:960
GaudiPython.Bindings.iNTupleSvc
Definition: Bindings.py:542
GaudiPython.Bindings.setOwnership
setOwnership
Definition: Bindings.py:71
GaudiPython.Bindings.iEventSelector.__init__
def __init__(self)
Definition: Bindings.py:639
GaudiPython.Bindings.PropertyEntry._property
_property
keep the original property
Definition: Bindings.py:163
GaudiPython.Bindings.AppMgr.config
def config(self, args)
Definition: Bindings.py:894
GaudiPython.Bindings.iToolSvc.retrieve
def retrieve(self, name)
Definition: Bindings.py:585
fun
double fun(const std::vector< double > &x)
Definition: PFuncTest.cpp:26
GaudiPython.Bindings.InterfaceCast.__call__
def __call__(self, obj)
Definition: Bindings.py:84
GaudiPython.Bindings.AppMgr.execute
def execute(self)
Definition: Bindings.py:972
GaudiPython.Bindings.iProperty.__call_interface_method__
def __call_interface_method__(self, ifname, method, args)
Definition: Bindings.py:192
GaudiPython.Bindings.iEventSelector.rewind
def rewind(self)
Definition: Bindings.py:648
GaudiPython.Bindings.iDataSvc.retrieveObject
def retrieveObject(self, path)
Definition: Bindings.py:359
GaudiPython.Bindings.iNTupleSvc.__getitem__
def __getitem__(self, path)
Definition: Bindings.py:561
GaudiPython.Bindings.AppMgr.partsvc
def partsvc(self)
Definition: Bindings.py:827
GaudiPython.Bindings._copyFactoriesFromList
def _copyFactoriesFromList(factories)
Definition: Bindings.py:1080
GaudiPython.Bindings.iService
Definition: Bindings.py:284
GaudiPython.Bindings.AppMgr.evtsel
def evtsel(self)
Definition: Bindings.py:815
GaudiKernel.Configurable.expandvars
def expandvars(data)
Definition: Configurable.py:29
GaudiPython.Bindings.AppMgr.ntuplesvc
def ntuplesvc
Definition: Bindings.py:822
GaudiPython.Bindings.iDataSvc.setRoot
def setRoot(self, name, obj)
Definition: Bindings.py:464
GaudiPython.Bindings.iProperty.getInterface
def getInterface(self)
Definition: Bindings.py:187
GaudiPython.Bindings.iToolSvc
Definition: Bindings.py:566
GaudiPython.Bindings.AppMgr.histsvc
def histsvc
Definition: Bindings.py:819
GaudiPython.Bindings.Interface.__init__
def __init__(self, t)
Definition: Bindings.py:100
GaudiPython.Bindings.AppMgr.topAlg
topAlg
Definition: Bindings.py:866
GaudiPython.Bindings.AppMgr.start
def start(self)
Definition: Bindings.py:956
GaudiPython.Bindings.iDataSvc.registerObject
def registerObject(self, path, obj)
Definition: Bindings.py:353
GaudiPython.Bindings.PropertyEntry.ptype
def ptype(self)
Definition: Bindings.py:166
GaudiPython.Bindings.getComponentProperties
def getComponentProperties(name)
Definition: Bindings.py:1038
GaudiPython.Bindings.InterfaceCast.__init__
def __init__(self, t)
Definition: Bindings.py:80
GaudiPython.Bindings.iEventSelector
Definition: Bindings.py:638
GaudiPython.Bindings.iNTupleSvc.defineOutput
def defineOutput
Definition: Bindings.py:550
GaudiPython.Bindings.AppMgr.evtsvc
def evtsvc(self)
Definition: Bindings.py:809
GaudiPython.Bindings.iService.start
tuple start
Definition: Bindings.py:294
GaudiPython.Bindings.iDataSvc.clearStore
def clearStore(self)
Definition: Bindings.py:467
GaudiPython.Bindings.PropertyEntry.documentation
def documentation(self)
Definition: Bindings.py:171
GaudiPython.Bindings.iToolSvc._retrieve
def _retrieve
Definition: Bindings.py:570
GaudiPython.Bindings.AppMgr
Definition: Bindings.py:653
GaudiPython.Bindings.iAlgTool.retrieveInterface
def retrieveInterface(self)
Definition: Bindings.py:337
GaudiPython.Bindings.iNTupleSvc.book
def book(self, args)
Definition: Bindings.py:548
GaudiPython.Bindings.iToolSvc.create
def create
Definition: Bindings.py:587
GaudiPython.Bindings.iHistogramSvc.retrieve
def retrieve(self, path)
Definition: Bindings.py:487
GaudiPython.Bindings.iProperty.__getattr__
def __getattr__(self, name)
Definition: Bindings.py:239
GaudiPython.Bindings.AppMgr.readOptions
def readOptions(self, file)
Definition: Bindings.py:837
GaudiPython.Bindings.iProperty.__setattr__
def __setattr__(self, name, value)
Definition: Bindings.py:195
GaudiPython.Bindings.deprecation
def deprecation(message)
Definition: Bindings.py:73
GaudiPython.Bindings.iAlgTool
Definition: Bindings.py:329