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.
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',
'makeClass',
'setOwnership',
15 'getClass',
'loaddict',
'deprecation' ]
17 from GaudiKernel
import ROOT6WorkAroundEnabled
19 import os, sys, string, warnings, re
24 print "# WARNING: using PyCintex as cppyy implementation"
25 import PyCintex
as cppyy
36 from GaudiKernel.Proxy.Configurable
import Configurable, getNeededConfigurables
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 )
55 for l
in [ l
for l
in dir(Helper)
if re.match(
"^to.*Array$",l) ]:
56 exec
"%s = Helper.%s"%(l,l)
60 if hasattr(Helper,
"toArray"):
63 toArray =
lambda typ: getattr(Helper,
"toArray")
66 toArray =
lambda typ: getattr(Helper,
"toArray<%s>"%typ)
69 ROOT = cppyy.libPyROOT
70 makeNullPointer = cppyy.libPyROOT.MakeNullPointer
71 makeClass = cppyy.libPyROOT.MakeRootClass
72 setOwnership = cppyy.libPyROOT.SetOwnership
75 warnings.warn(
'GaudiPython: '+ message, DeprecationWarning, stacklevel=3)
79 """ Helper class to obtain the adequate interface from a component
80 by using the Gaudi queryInterface() mechanism """
89 if obj.queryInterface(self.type.interfaceID(), ip).isSuccess() :
92 print "ERROR: queryInterface failed for", obj,
"interface:", self.
type
94 print "ERROR: exception", e,
"caught when retrieving interface", self.
type,
"for object", obj
96 traceback.print_stack()
103 InterfaceCast.__init__(self,t)
109 """ Load a LCG dictionary using various mechanisms"""
110 if Helper.loadDynamicLib(dict) == 1 :
return
115 raise ImportError,
'Error loading dictionary library'
120 Function to retrieve a certain C++ class by name and to load dictionary if requested
124 from gaudimodule import getClass
125 # one knows that class is already loaded
126 AppMgr = getClass( 'ApplicationMgr' )
127 # one knows where to look for class, if not loaded yet
128 MCParticle = getClass( 'MCParticle' , 'EventDict' )
129 # one knows where to look for class, if not loaded yet
130 Vertex = getClass( 'Vertex' , ['EventDict', 'PhysEventDict'] )
133 if hasattr( gbl , name ) :
return getattr( gbl , name )
135 if type(libs)
is not list : libs = [libs]
138 if hasattr( gbl , name ) :
return getattr( gbl , name )
144 """ holds the value and the documentation string of a property """
149 if issubclass(
type(prop),GaudiHandleProperty) :
151 elif issubclass(
type(prop),GaudiHandleArrayProperty) :
152 self.
_value = prop.value()
155 try: self.
_value = eval( prop.toString() , {} , {} )
157 if hasattr ( prop ,
'value' ) : self.
_value = prop.value()
158 else : self.
_value = prop.toString()
160 self.
__doc__ +=
" --- Default value = " + str(self.
_value) +
" --- "
161 if prop.documentation() !=
'none':
170 "Return the underlying property itself "
179 """ Python equivalent to the C++ Property interface """
181 if ip : self.__dict__[
'_ip'] =
InterfaceCast(gbl.IProperty)(ip)
182 else : self.__dict__[
'_ip'] =
None
183 self.__dict__[
'_svcloc'] = gbl.Gaudi.svcLocator()
184 optsvc = Helper.service(self._svcloc,
'JobOptionsSvc')
185 if optsvc : self.__dict__[
'_optsvc'] =
InterfaceCast(gbl.IJobOptionsSvc)(optsvc)
186 else : self.__dict__[
'_optsvc'] =
None
187 self.__dict__[
'_name'] = name
194 if not getattr(self,ifname) : self.retrieveInterface()
195 return getattr(getattr(self,ifname),method)(*args)
198 The method which is used for setting the property from the given value.
199 - In the case of the valid instance it sets the property through IProperty interface
200 - In the case of placeholder the property is added to JobOptionsCatalogue
202 if hasattr( value,
'toStringProperty' ):
204 value =
'%s' % value.toStringProperty()
207 if not gbl.Gaudi.Utils.hasProperty ( ip , name ) :
208 raise AttributeError,
'property %s does not exist' % name
209 prop = ip.getProperty(name)
212 canSetValue = (hasattr(prop,
'value')
and
213 'const(&)[' not in prop.value.func_doc
and
216 canSetValue = (hasattr(prop,
'value')
and
220 if not prop.setValue(value) :
221 raise AttributeError,
'property %s could not be set from %s' % (name, value)
223 if tuple ==
type( value ) : value = str(value)
224 elif hasattr ( value ,
'toString' ) : value = value.toString()
225 elif not long ==
type( value ) : value =
'%s' % value
226 else : value =
'%d' % value
228 sc = cppyy.gbl.GaudiPython.Helper.setPropertyFromString(prop, value)
230 sc = prop.fromString(value)
232 raise AttributeError,
'property %s could not be set from %s' % (name,value)
234 if type(value) == str : value =
'"%s"' % value
235 elif type(value) == tuple : value = str(value)
236 elif hasattr( value ,
'toString' ) : value = value.toString()
237 elif type(value) == long: value =
'%d' % value
239 self._optsvc.addPropertyToCatalogue( self._name , sp )
242 The method which returns the value for the given property
243 - In the case of the valid instance it returns the valid property value through IProperty interface
244 - In the case of placeholder the property value is retrieved from JobOptionsCatalogue
248 if not gbl.Gaudi.Utils.hasProperty ( ip , name ) :
249 raise AttributeError,
'property %s does not exist' % name
250 prop = ip.getProperty(name)
251 if StringProperty ==
type( prop ) :
return prop.value()
252 elif StringPropertyRef ==
type( prop ) :
return prop.value()
253 try:
return eval( prop.toString(), {}, {} )
254 except :
return prop.value()
256 props = self._optsvc.getProperties(self._name)
258 if not p.name() == name :
continue
260 try:
return eval( p.value(), {}, {} )
261 except:
return p.value()
262 raise AttributeError,
'property %s does not exist' % name
268 props = ip.getProperties()
269 propsFrom = self._name
271 props = self._optsvc.getProperties( self._name )
272 propsFrom =
"jobOptionsSvc"
277 except (ValueError,TypeError),e:
278 raise ValueError,
"gaudimodule.iProperty.properties(): %s%s processing property %s.%s = %s" % \
279 (e.__class__.__name__, e.args, propsFrom, p.name(), p.value())
286 """ Python equivalent to IProperty interface """
288 iProperty.__init__(self, name, isvc )
289 if isvc : self.__dict__[
'_isvc'] =
InterfaceCast(gbl.IService)(isvc)
290 else : self.__dict__[
'_isvc'] =
None
292 isvc = Helper.service(self._svcloc,self._name)
293 if isvc : iService.__init__(self, self._name, isvc)
301 if self._isvc:
return True
306 """ Python equivalent to IAlgorithm interface """
308 iProperty.__init__(self, name, ialg )
309 if ialg : self.__dict__[
'_ialg'] =
InterfaceCast(gbl.IAlgorithm)(ialg)
310 else : self.__dict__[
'_ialg'] =
None
312 ialg = Helper.algorithm(
InterfaceCast(gbl.IAlgManager)(self._svcloc),self._name)
313 if ialg : iAlgorithm.__init__(self, self._name, ialg)
331 """ Python equivalent to IAlgTool interface (not completed yet) """
333 iProperty.__init__(self, name, itool )
334 if itool : self.__dict__[
'_itool'] = itool
335 else : self.__dict__[
'_itool'] =
None
336 svc = Helper.service( self._svcloc,
'ToolSvc',
True )
337 self.__dict__[
'_toolsvc']=
iToolSvc(
'ToolSvc', svc)
339 itool = self._toolsvc._retrieve(self._name)
340 if itool : iAlgTool.__init__(self, self._name, itool)
345 if self._itool :
return self._itool.name()
346 else :
return self._name
351 iService.__init__(self, name, idp )
352 self.__dict__[
'_idp'] =
InterfaceCast(gbl.IDataProviderSvc)(idp)
353 self.__dict__[
'_idm'] =
InterfaceCast(gbl.IDataManagerSvc)(idp)
355 if not self._idp :
raise AttributeError(
'C++ service %s does not exist' % self.__dict__[
'_name'])
356 return self._idp.registerObject(path,obj)
358 if not self._idp :
raise AttributeError(
'C++ service %s does not exist' % self.__dict__[
'_name'])
359 return self._idp.unregisterObject(path)
361 if not self._idp :
return None
362 return Helper.dataobject(self._idp, path)
367 Get the existing object in TransientStore for the given location
369 - loading of object from persistency is NOT triggered
370 - 'data-on-demand' action is NOT triggered
372 >>> svc = ... ## get the service
373 >>> path = ... ## get the path in Transient Store
374 >>> data = svc.findObject ( path ) ## use the method
377 if not self._idp :
raise IndexError(
'C++ service %s does not exist' % self.__dict__[
'_name'])
378 return Helper.findobject(self._idp, path)
383 Get object from Transient Store for the given location
386 - path : Location of object in Transient Store
387 - retrieve (bool) True : retrieve versus find
388 - disable on-demand (bool) False : temporary disable 'on-demand' actions
390 >>> svc = ... ## get the service
391 >>> path = ... ## get the path
393 >>> data = svc.getObject ( path , False ) ## find object in Transient Store
395 ## find object in Transient Store
396 # load form tape or use 'on-demand' action for missing objects :
397 >>> data = svc.getObject ( path , True )
399 ## find object in Transient Store
400 # load from tape or for missing objects, disable 'on-demand'-actions
401 >>> data = svc.getObject ( path , True , True )
404 if not self._idp :
raise IndexError(
'C++ service %s does not exist' % self.__dict__[
'_name'])
405 return Helper.getobject(self._idp, path, *args )
408 if not self._idp :
raise IndexError(
'C++ service %s does not exist' % self.__dict__[
'_name'])
409 return Helper.dataobject(self._idp, path)
411 if not self._idp :
raise IndexError(
'C++ service %s does not exist' % self.__dict__[
'_name'])
412 return self._idp.registerObject(path,obj)
414 if not self._idp :
raise IndexError(
'C++ service %s does not exist' % self.__dict__[
'_name'])
415 return self._idp.unregisterObject(path)
418 ll = gbl.std.vector(
'IRegistry*')()
421 if self._idm.objectLeaves(node, ll).isSuccess() :
return ll
425 if root : node = root.registry()
427 print node.identifier()
430 def getList(self, node=None, lst=[], rootFID=None) :
434 node = root.registry()
435 rootFID = node.address().
par()
439 Helper.dataobject( self._idp, node.identifier() )
441 lst.append( node.identifier() )
442 for l
in self.
leaves(node) :
443 if l.address()
and l.address().
par() == rootFID :
452 node = root.registry()
456 Helper.dataobject( self._idp, node.identifier() )
458 lst.append( node.identifier() )
459 for l
in self.
leaves(node) :
466 if not self._idm :
raise IndexError(
'C++ service %s does not exist' % self.__dict__[
'_name'])
467 return self._idm.setRoot(name,obj)
469 if not self._idm :
raise IndexError(
'C++ service %s does not exist' % self.__dict__[
'_name'])
470 return self._idm.clearStore()
476 self.__dict__[
'_ihs'] =
InterfaceCast(gbl.IHistogramSvc)(ihs)
477 iDataSvc.__init__(self, name, ihs)
479 return Helper.histo1D(self._ihs, path)
481 return Helper.histo2D(self._ihs, path)
483 return Helper.histo3D(self._ihs, path)
485 return Helper.profile1D(self._ihs, path)
487 return Helper.profile2D(self._ihs, path)
490 Retrieve AIDA histogram or AIDA profile histogram by path in Histogram Transient Store
492 >>> histo = svc.retrieve ( 'path/to/my/histogram' )
502 Book the histograms(1D,2D&3D) , see IHistogramSvc::book
504 >>> histo = svc.book( .... )
506 return apply(self._ihs.book,args)
509 Book the profile(1D&2D) histograms, see IHistogramSvc::bookProf
511 >>> histo = svc.bookProf( .... )
513 return apply(self._ihs.bookProf,args)
516 Retrieve the object from Histogram Transient Store (by path)
517 The reference to AIDA histogram is returned (if possible)
519 >>> histo = svc['path/to/my/histogram']
523 return iDataSvc.__getitem__( self , path )
526 Retrieve the histogram from Histogram Transient Store (by path)
527 The reference to AIDA histogram is returned (if possible)
529 >>> histo = svc.getAsAIDA ( 'path/to/my/histogram' )
534 Retrieve the histogram from Histogram Transient Store (by path)
535 The Underlying native ROOT object is returned (if possible)
537 >>> histo = svc.getAsROOT ( 'path/to/my/histogram' )
539 fun = gbl.Gaudi.Utils.Aida2ROOT.aida2root
548 iDataSvc.__init__(self, name, ints)
550 return apply(self._ints.book, args)
552 """ Defines the mapping between logical names and the output file
554 defineOutput({'LUN1':'MyFile1.root', 'LUN2':'Myfile2.root'}, svc='Gaudi::RootCnvSvc')
556 import Persistency
as prs
557 helper = prs.get(typ)
558 helper.configure(
AppMgr())
559 self.
Output = [helper.formatOutput(files[lun], lun=lun)
for lun
in files]
560 if AppMgr().HistogramPersistency ==
'NONE':
561 AppMgr().HistogramPersistency =
"ROOT"
563 return iDataSvc.__getitem__( self , path )
570 iService.__init__(self, name, its)
572 sol = _gaudi.OutputLevel
574 if name.rfind(
'.') == -1 :
575 itool = Helper.tool(self._its,
'', name,
None,
False )
576 elif name[0:8] ==
'ToolSvc.' :
577 itool = Helper.tool(self._its,
'', name[8:],
None,
False )
578 elif name.count(
'.') > 1 :
579 ptool = self.
_retrieve(name[:name.rfind(
'.')])
580 itool = Helper.tool(self._its,
'', name[name.rfind(
'.')+1:], ptool,
False )
582 prop = _gaudi.property(name[:name.rfind(
'.')])
583 itool = Helper.tool(self._its,
'', name[name.rfind(
'.')+1:], prop._ip,
False )
588 def create(self, typ, name=None, parent=None, interface=None) :
589 if not name : name = typ
590 itool = Helper.tool(self._its, typ, name, parent,
True )
596 if type(itool)
is iAlgTool :
597 self._its.releaseTool(itool._itool)
602 Python-image of C++ class IJobOptionsSvc
607 self.__dict__[
'_optsvc'] =
InterfaceCast(gbl.IJobOptionsSvc)(svc)
608 return iService.__init__( self , name , svc )
611 Extract *ALL* properties of the given component
613 >>> jos = gaudi.optSvc()
614 >>> props = jos.getProperties( 'Name' )
616 props = self._optsvc.getProperties( component )
618 if not props :
return prps
620 prop = p.name().upper()
622 value = eval( p.value() , {} , {} )
623 except: value = p.value()
624 prps [ prop ] = value
629 Get a certain property of the certain component
632 >>> extServices = jos.getProperty( 'ApplicationMgr', 'ExtSvc' )
636 return all.get( name.upper() ,
None )
641 iService.__init__(self,
'EventSelector', Helper.service(gbl.Gaudi.svcLocator(),
'EventSelector'))
642 self.__dict__[
'g'] =
AppMgr()
643 def open(self, stream, typ = 'Gaudi::RootCnvSvc
', **kwargs):
644 import Persistency
as prs
645 helper = prs.get(typ)
646 helper.configure(self.g)
647 self.
Input = helper.formatInput(stream, **kwargs)
658 newobj = object.__new__( cls )
659 cls.__init__(newobj, *args, **kwargs)
667 self._evtpro.release()
668 self._svcloc.release()
669 self._appmgr.release()
675 def __init__(self, outputlevel = -1, joboptions = None, selfoptions = {},
676 dllname =
None, factname =
None) :
680 self.__dict__[
'_exit_called'] =
False
682 self.__dict__[
'_gaudi_ns'] = Gaudi
684 from GaudiKernel.Proxy.Configurable
import expandvars
687 expandvars =
lambda data : data
688 if dllname
and factname:
689 self.__dict__[
'_appmgr'] = gbl.Gaudi.createApplicationMgr(dllname,factname)
691 self.__dict__[
'_appmgr'] = gbl.Gaudi.createApplicationMgr(dllname)
693 self.__dict__[
'_appmgr'] = gbl.Gaudi.createApplicationMgr()
694 self.__dict__[
'_svcloc'] = gbl.Gaudi.svcLocator()
695 self.__dict__[
'_algmgr'] =
InterfaceCast(gbl.IAlgManager)(self._appmgr)
696 self.__dict__[
'_evtpro'] =
InterfaceCast(gbl.IEventProcessor)(self._appmgr)
697 self.__dict__[
'_svcmgr'] =
InterfaceCast(gbl.ISvcManager)(self._appmgr)
698 self.__dict__[
'pyalgorithms'] = []
699 iService.__init__(self,
'ApplicationMgr', self._appmgr )
701 if self.
FSMState() < Gaudi.StateMachine.CONFIGURED :
707 import GaudiKernel.Proxy.Configurable
708 if hasattr(GaudiKernel.Proxy.Configurable,
"applyConfigurableUsers"):
709 GaudiKernel.Proxy.Configurable.applyConfigurableUsers()
712 selfprops = Configurable.allConfigurables.get(
'ApplicationMgr',{})
713 if selfprops : selfprops =
expandvars(selfprops.getValuedProperties())
714 for p,v
in selfprops.items() : setattr(self, p, v)
715 for p,v
in selfoptions.items() : setattr(self, p, v)
717 if outputlevel != -1 : self.
OutputLevel = outputlevel
720 ms = self.
service(
'MessageSvc')
721 if 'MessageSvc' in Configurable.allConfigurables:
722 msprops = Configurable.allConfigurables[
'MessageSvc']
723 ms = self.
service(
'MessageSvc')
724 if hasattr(msprops,
"getValuedProperties"):
725 msprops =
expandvars(msprops.getValuedProperties())
726 for p,v
in msprops.items():
728 if outputlevel != -1 : ms.OutputLevel = outputlevel
730 self.__dict__[
'_optsvc'] =
InterfaceCast(gbl.IJobOptionsSvc)(Helper.service(self._svcloc,
'JobOptionsSvc'))
733 c = Configurable.allConfigurables[n]
734 if n
in [
'ApplicationMgr',
'MessageSvc'] :
continue
735 for p, v
in c.getValuedProperties().items() :
738 if hasattr(Configurable,
"PropertyReference")
and type(v) == Configurable.PropertyReference:
742 if type(v) == str : v =
'"%s"' % v
743 elif type(v) == long: v =
'%d' % v
745 if hasattr(Configurable,
"_configurationLocked"):
746 Configurable._configurationLocked =
True
750 atexit.register(self.
exit)
754 root_handler_installed =
False
755 for h
in atexit._exithandlers:
757 if hasattr(func,
"__module__")
and func.__module__ ==
"ROOT":
758 root_handler_installed =
True
764 if not root_handler_installed:
765 orig_register = atexit.register
766 def register(func, *targs, **kargs):
767 orig_register(func, *targs, **kargs)
768 if hasattr(func,
"__module__")
and func.__module__ ==
"ROOT":
769 orig_register(self.
exit)
772 register.__doc__ = (orig_register.__doc__ +
773 "\nNote: version hacked by GaudiPython to work " +
774 "around a problem with the ROOT exit handler")
775 atexit.register = register
777 def state(self) :
return self._isvc.FSMState()
781 svc = Helper.service( self._svcloc, name )
787 self._svcmgr.declareSvcType(svcname, svctype)
789 return Helper.service( self._svcloc, name,
True )
791 l = self._svcloc.getServices()
794 for i
in range(l.size()) :
795 s.append(nl.front().
name())
799 alg = Helper.algorithm( self._algmgr, name , createIf )
800 if not alg :
return iAlgorithm ( name , alg )
801 else :
return iAlgorithm ( alg.name() , alg )
803 l = self._algmgr.getAlgorithms()
806 for i
in range(l.size()) :
807 s.append(nl.front().
name())
818 svc = Helper.service( self._svcloc, name )
821 return self.
datasvc(
'EventDataSvc')
823 return self.
datasvc(
'DetectorDataSvc')
825 return self.
datasvc(
'FileRecordDataSvc')
828 if not hasattr(self,
'_evtsel') : self.__dict__[
'_evtsel'] =
iEventSelector()
831 svc = Helper.service( self._svcloc, name )
834 if name
not in self.ExtSvc : self.ExtSvc += [name]
836 svc = Helper.service( self._svcloc, name,
True )
840 svc = Helper.service( self._svcloc,
'ParticlePropertySvc' )
843 svc = Helper.service( self._svcloc, name,
True )
845 def optSvc (self, name='JobOptionsSvc') :
846 svc = Helper.service( self._svcloc, name,
True )
849 return self._optsvc.readOptions(file)
851 """ Add an Algorithm to the list of Top algorithms. It can be either a instance of
852 an Algorithm class or it name """
853 if type(alg)
is str :
856 self.pyalgorithms.append(alg)
862 self.
topAlg += [alg.name()]
864 """ Set the list of Top Algorithms.
865 It can be an individual of a list of algorithms names or instances """
866 if type(algs)
is not list : algs = [algs]
869 if type(alg)
is str : names.append(alg)
871 self.pyalgorithms.append(alg)
876 names.append(alg.name())
879 """ Remove an Algorithm to the list of Top algorithms. It can be either a instance of
880 an Algorithm class or it name """
882 if type(alg)
is str :
885 tmp.remove(alg.name())
886 self.pyalgorithms.remove(alg)
891 Simple utility to perform the configuration of Gaudi application.
892 It reads the set of input job-options files, and set few
893 additional parameters 'options' through the usage of temporary *.opts file
895 gaudi.config( files = [ '$GAUSSOPTS/Gauss.opts' ,
896 '$DECFILESROOT/options/10022_010.0GeV.opts' ] ,
897 options = [ 'EventSelector.PrintFreq = 5 ' ] )
899 files = args.get(
'files',[])
903 raise RuntimeError ,
' Unable to read file "' + file +
'" '
904 options = args.get(
'options',
None)
907 tmpfilename = tempfile.mktemp()
908 tmpfile = open( tmpfilename,
'w' )
909 tmpfile.write (
'#pragma print on \n' )
910 tmpfile.write (
'/// File "' + tmpfilename+
'" generated by GaudiPython \n\n' )
912 if type(options)
is dict :
913 tmpfile.write(
' \t ' + opt +
' = '+ options[opt]+
' ; // added by GaudiPython \n' )
915 tmpfile.write(
' \t ' + opt +
' ; // added by GaudiPython \n' )
916 tmpfile.write (
'/// End of file "' + tmpfilename+
'" generated by GaudiPython \n\n' )
920 raise RuntimeError ,
' Unable to read file "' + tmpfilename +
'" '
921 os.remove( tmpfilename )
923 if self.
FSMState() != Gaudi.StateMachine.OFFLINE :
929 _dlls = jos.getProperty ( self.
name() ,
'DLLs' )
932 libs = [ l
for l
in _dlls
if not l
in self.DLLs ]
933 if libs : self.DLLs += libs
936 _svcs = jos.getProperty ( self.
name() ,
'ExtSvc' )
939 svcs = [ s
for s
in _svcs
if not s
in self.ExtSvc ]
940 if svcs : self.ExtSvc += svcs
943 props = jos.getProperties ( self.
name() )
946 if 'DLLS' == key
or 'EXTSVC' == key :
continue
950 return self._appmgr.configure()
952 return self._appmgr.start()
954 if self.
FSMState() == Gaudi.StateMachine.CONFIGURED :
956 if sc.isFailure()
or self.ReturnCode != 0:
958 if self.
FSMState() == Gaudi.StateMachine.INITIALIZED :
960 if sc.isFailure()
or self.ReturnCode != 0:
962 return self._evtpro.executeRun(n)
964 return self._evtpro.executeEvent()
966 return self._evtpro.executeEvent()
968 if self.
FSMState() == Gaudi.StateMachine.CONFIGURED :
970 if sc.isFailure():
return sc
971 if self.
FSMState() == Gaudi.StateMachine.INITIALIZED :
973 if sc.isFailure():
return sc
975 if not hasattr(self,
'_perssvc'): self.__dict__[
'_perssvc'] = self.
service(
'EventPersistencySvc',
'IAddressCreator')
976 if not hasattr(self,
'_filecat'): self.__dict__[
'_filecat'] = self.
service(
'FileCatalog',
'Gaudi::IFileCatalog')
977 if not hasattr(self,
'_evtmgr'): self.__dict__[
'_evtmgr'] = self.
service(
'EventDataSvc',
'IDataManagerSvc')
979 if pfn.find(
'PFN:') == 0: pfn = pfn[4:]
982 if not self._filecat.existsFID(fid) : self._filecat.registerPFN(fid, pfn,
'')
984 if type(events)
is not list : events = (events,)
987 gadd = gbl.GenericAddress(0x02, 1, fid,
'/Event', 0, evt)
989 self._perssvc.createAddress(gadd.svcType(),gadd.clID(),gadd.par(),gadd.ipar(),oadd)
991 self._evtmgr.clearStore()
992 self._evtmgr.setRoot(
'/Event',oadd)
993 self._evtpro.executeEvent()
996 if not self._exit_called:
997 self.__dict__[
'_exit_called'] =
True
998 Gaudi = self._gaudi_ns
999 if self.
FSMState() == Gaudi.StateMachine.RUNNING:
1000 self._appmgr.stop().ignore()
1001 if self.
FSMState() == Gaudi.StateMachine.INITIALIZED:
1002 self._appmgr.finalize().ignore()
1003 if self.
FSMState() == Gaudi.StateMachine.CONFIGURED:
1004 self._appmgr.terminate()
1011 ntupleSvc = ntuplesvc
1019 tfile = gbl.TFile.Open(pfn)
1020 if not tfile :
raise 'Cannot open ROOT file ', pfn
1021 tree = tfile.Get(
'##Params')
1023 text = tree.db_string
1024 if 'NAME=FID' in text :
1025 fid = text[text.rfind(
'VALUE=')+6:-1]
1026 nevt = tfile.Get(
'_Event').GetEntries()
1032 """ Get all the properties of a component as a Python dictionary.
1033 The component is instantiated using the component library
1036 if name ==
'GaudiCoreSvc' :
1037 if Helper.loadDynamicLib(name) != 1 :
1038 raise ImportError,
'Error loading component library '+ name
1039 factorylist = gbl.FactoryTable.instance().getEntries()
1041 g =
AppMgr(outputlevel=7)
1043 g =
AppMgr(outputlevel=7)
1044 if Helper.loadDynamicLib(name) != 1 :
1045 raise ImportError,
'Error loading component library '+ name
1046 factorylist = gbl.FactoryTable.instance().getEntries()
1048 svcloc = gbl.Gaudi.svcLocator()
1049 dummysvc = gbl.Service(
'DummySvc',svcloc)
1050 for factory
in factories :
1051 if InterfaceCast(gbl.IAlgFactory)(factory) : ctype =
'Algorithm'
1052 elif InterfaceCast(gbl.ISvcFactory)(factory) : ctype =
'Service'
1053 elif InterfaceCast(gbl.IToolFactory)(factory) : ctype =
'AlgTool'
1054 elif factory.ident() ==
'ApplicationMgr' : ctype =
'ApplicationMgr'
1055 else : ctype =
'Unknown'
1056 cname = factory.ident().split()[-1]
1057 if ctype
in (
'Algorithm',
'Service',
'AlgTool',
'ApplicationMgr') :
1059 if ctype ==
'AlgTool' :
1060 obj = factory.instantiate(dummysvc)
1062 obj = factory.instantiate(svcloc)
1063 except RuntimeError, text :
1064 print 'Error instantiating', cname,
' from ', name
1068 properties[cname] = [ctype, prop.properties()]
1075 for i
in range(factories.size()) :
1076 factory = factories.front()
1077 result.append(factory)
1078 factories.pop_front()
1079 for factory
in result :
1080 factories.push_back(factory)
1085 _CallbackStreamBufBase = gbl.GaudiPython.CallbackStreamBuf
1088 _CallbackStreamBufBase.__init__(self, self)
1091 if not string :
return 0
1097 _PyAlgorithm = gbl.GaudiPython.PyAlgorithm
1100 if not name : name = self.__class__.__name__
1101 _PyAlgorithm.__init__(self, self, name)
1104 sc = self._algmgr.addAlgorithm(self)
1105 if sc.isFailure() :
raise RuntimeError,
'Unable to add Algorithm'
1107 sc = self._algmgr.removeAlgorithm(self)
1108 if sc.isFailure() :
pass
1119 import rlcompleter, readline
1120 readline.parse_and_bind(
"tab: complete")
def getComponentProperties
def __del__
Custom destructor to ensure that the application is correctly finalized when exiting from python...
def _copyFactoriesFromList
def getNeededConfigurables
def ROOT6WorkAroundEnabled
_property
keep the original property
double fun(const std::vector< double > &x)
def getObject
get or retrieve object, possible switch-off 'on-demand' actions
NamedRange_< CONTAINER > range(const CONTAINER &cnt, const std::string &name)
simple function to create the named range form arbitrary container
def __call_interface_method__
def findObject
get object from TES