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 PyCintex
7 extersion module provided by LCG/ROOT that provided
8 dynamic bindigns of classes for which LCG dictionaires exists.
11 __all__ = [
'gbl',
'InterfaceCast',
'Interface',
'PropertyEntry',
12 'AppMgr',
'PyAlgorithm',
'CallbackStreamBuf',
13 'iAlgorithm',
'iDataSvc',
'iHistogramSvc',
'iNTupleSvc',
'iService',
'iAlgTool',
'Helper',
14 'SUCCESS',
'FAILURE',
'toArray',
15 'ROOT',
'makeNullPointer',
'makeClass',
'setOwnership',
16 'getClass',
'loaddict',
'deprecation' ]
18 import os, sys, string, warnings, re
23 from GaudiKernel.Proxy.Configurable
import Configurable, getNeededConfigurables
26 gbl = PyCintex.makeNamespace(
'')
33 Helper = gbl.GaudiPython.Helper
34 StringProperty = gbl.SimpleProperty (
'string',
'BoundedVerifier<string>')
35 StringPropertyRef = gbl.SimplePropertyRef (
'string',
'NullVerifier<string>')
36 GaudiHandleProperty = gbl.GaudiHandleProperty
37 GaudiHandleArrayProperty = gbl.GaudiHandleArrayProperty
38 DataObject = gbl.DataObject
39 SUCCESS = gbl.StatusCode( gbl.StatusCode.SUCCESS,
True )
40 FAILURE = gbl.StatusCode( gbl.StatusCode.FAILURE,
True )
42 for l
in [ l
for l
in dir(Helper)
if re.match(
"^to.*Array$",l) ]:
43 exec
"%s = Helper.%s"%(l,l)
47 if hasattr(Helper,
"toArray"):
50 toArray =
lambda typ: getattr(Helper,
"toArray")
53 toArray =
lambda typ: getattr(Helper,
"toArray<%s>"%typ)
56 ROOT = PyCintex.libPyROOT
57 makeNullPointer = PyCintex.libPyROOT.MakeNullPointer
58 makeClass = PyCintex.libPyROOT.MakeRootClass
59 setOwnership = PyCintex.libPyROOT.SetOwnership
62 warnings.warn(
'GaudiPython: '+ message, DeprecationWarning, stacklevel=3)
66 """ Helper class to obtain the adequate interface from a component
67 by using the Gaudi queryInterface() mechanism """
69 if type(t)
is str : t = PyCintex.makeClass(t)
73 ip = PyCintex.libPyROOT.MakeNullPointer(self.
type)
75 if obj.queryInterface(self.type.interfaceID(), ip).isSuccess() :
78 print "ERROR: queryInterface failed for", obj,
"interface:", self.
type
80 print "ERROR: exception", e,
"caught when retrieving interface", self.
type,
"for object", obj
82 traceback.print_stack()
89 InterfaceCast.__init__(self,t)
95 """ Load a LCG dictionary using various mechanisms"""
96 if Helper.loadDynamicLib(dict) == 1 :
return
99 PyCintex.loadDict(dict)
101 raise ImportError,
'Error loading dictionary library'
106 Function to retrieve a certain C++ class by name and to load dictionary if requested
110 from gaudimodule import getClass
111 # one knows that class is already loaded
112 AppMgr = getClass( 'ApplicationMgr' )
113 # one knows where to look for class, if not loaded yet
114 MCParticle = getClass( 'MCParticle' , 'EventDict' )
115 # one knows where to look for class, if not loaded yet
116 Vertex = getClass( 'Vertex' , ['EventDict', 'PhysEventDict'] )
119 if hasattr( gbl , name ) :
return getattr( gbl , name )
121 if type(libs)
is not list : libs = [libs]
124 if hasattr( gbl , name ) :
return getattr( gbl , name )
130 """ holds the value and the documentation string of a property """
135 if issubclass(
type(prop),GaudiHandleProperty) :
137 elif issubclass(
type(prop),GaudiHandleArrayProperty) :
138 self.
_value = prop.value()
141 try: self.
_value = eval( prop.toString() , {} , {} )
143 if hasattr ( prop ,
'value' ) : self.
_value = prop.value()
144 else : self.
_value = prop.toString()
146 self.
__doc__ +=
" --- Default value = " + str(self.
_value) +
" --- "
147 if prop.documentation() !=
'none':
156 "Return the underlying property itself "
165 """ Python equivalent to the C++ Property interface """
167 if ip : self.__dict__[
'_ip'] =
InterfaceCast(gbl.IProperty)(ip)
168 else : self.__dict__[
'_ip'] =
None
169 self.__dict__[
'_svcloc'] = gbl.Gaudi.svcLocator()
170 optsvc = Helper.service(self._svcloc,
'JobOptionsSvc')
171 if optsvc : self.__dict__[
'_optsvc'] =
InterfaceCast(gbl.IJobOptionsSvc)(optsvc)
172 else : self.__dict__[
'_optsvc'] =
None
173 self.__dict__[
'_name'] = name
180 if not getattr(self,ifname) : self.retrieveInterface()
181 return getattr(getattr(self,ifname),method)(*args)
184 The method which is used for setting the property from the given value.
185 - In the case of the valid instance it sets the property through IProperty interface
186 - In the case of placeholder the property is added to JobOptionsCatalogue
188 if hasattr( value,
'toStringProperty' ):
190 value =
'%s' % value.toStringProperty()
193 if not gbl.Gaudi.Utils.hasProperty ( ip , name ) :
194 raise AttributeError,
'property %s does not exist' % name
195 prop = ip.getProperty(name)
196 if not hasattr ( prop ,
'value' )
or not type( value ) ==
type( prop.value() ) :
197 if tuple ==
type( value ) : value = str(value)
198 elif hasattr ( value ,
'toString' ) : value = value.toString()
199 elif not long ==
type( value ) : value =
'%s' % value
200 else : value =
'%d' % value
201 if prop.fromString( value ).isFailure() :
202 raise AttributeError,
'property %s could not be set from %s' % (name,value)
204 if not prop.setValue( value ) :
205 raise AttributeError,
'property %s could not be set from %s' % (name,value)
207 if type(value) == str : value =
'"%s"' % value
208 elif type(value) == tuple : value = str(value)
209 elif hasattr( value ,
'toString' ) : value = value.toString()
210 elif type(value) == long: value =
'%d' % value
212 self._optsvc.addPropertyToCatalogue( self._name , sp )
215 The method which returns the value for the given property
216 - In the case of the valid instance it returns the valid property value through IProperty interface
217 - In the case of placeholder the property value is retrieved from JobOptionsCatalogue
221 if not gbl.Gaudi.Utils.hasProperty ( ip , name ) :
222 raise AttributeError,
'property %s does not exist' % name
223 prop = ip.getProperty(name)
224 if StringProperty ==
type( prop ) :
return prop.value()
225 elif StringPropertyRef ==
type( prop ) :
return prop.value()
226 try:
return eval( prop.toString(), {}, {} )
227 except :
return prop.value()
229 props = self._optsvc.getProperties(self._name)
231 if not p.name() == name :
continue
233 try:
return eval( p.value(), {}, {} )
234 except:
return p.value()
235 raise AttributeError,
'property %s does not exist' % name
241 props = ip.getProperties()
242 propsFrom = self._name
244 props = self._optsvc.getProperties( self._name )
245 propsFrom =
"jobOptionsSvc"
250 except (ValueError,TypeError),e:
251 raise ValueError,
"gaudimodule.iProperty.properties(): %s%s processing property %s.%s = %s" % \
252 (e.__class__.__name__, e.args, propsFrom, p.name(), p.value())
259 """ Python equivalent to IProperty interface """
261 iProperty.__init__(self, name, isvc )
262 if isvc : self.__dict__[
'_isvc'] =
InterfaceCast(gbl.IService)(isvc)
263 else : self.__dict__[
'_isvc'] =
None
265 isvc = Helper.service(self._svcloc,self._name)
266 if isvc : iService.__init__(self, self._name, isvc)
274 if self._isvc:
return True
279 """ Python equivalent to IAlgorithm interface """
281 iProperty.__init__(self, name, ialg )
282 if ialg : self.__dict__[
'_ialg'] =
InterfaceCast(gbl.IAlgorithm)(ialg)
283 else : self.__dict__[
'_ialg'] =
None
285 ialg = Helper.algorithm(
InterfaceCast(gbl.IAlgManager)(self._svcloc),self._name)
286 if ialg : iAlgorithm.__init__(self, self._name, ialg)
304 """ Python equivalent to IAlgTool interface (not completed yet) """
306 iProperty.__init__(self, name, itool )
307 if itool : self.__dict__[
'_itool'] = itool
308 else : self.__dict__[
'_itool'] =
None
309 svc = Helper.service( self._svcloc,
'ToolSvc',
True )
310 self.__dict__[
'_toolsvc']=
iToolSvc(
'ToolSvc', svc)
312 itool = self._toolsvc._retrieve(self._name)
313 if itool : iAlgTool.__init__(self, self._name, itool)
318 if self._itool :
return self._itool.name()
319 else :
return self._name
324 iService.__init__(self, name, idp )
325 self.__dict__[
'_idp'] =
InterfaceCast(gbl.IDataProviderSvc)(idp)
326 self.__dict__[
'_idm'] =
InterfaceCast(gbl.IDataManagerSvc)(idp)
328 if not self._idp :
raise AttributeError(
'C++ service %s does not exist' % self.__dict__[
'_name'])
329 return self._idp.registerObject(path,obj)
331 if not self._idp :
raise AttributeError(
'C++ service %s does not exist' % self.__dict__[
'_name'])
332 return self._idp.unregisterObject(path)
334 if not self._idp :
return None
335 return Helper.dataobject(self._idp, path)
340 Get the existing object in TransientStore for the given location
342 - loading of object from persistency is NOT triggered
343 - 'data-on-demand' action is NOT triggered
345 >>> svc = ... ## get the service
346 >>> path = ... ## get the path in Transient Store
347 >>> data = svc.findObject ( path ) ## use the method
350 if not self._idp :
raise IndexError(
'C++ service %s does not exist' % self.__dict__[
'_name'])
351 return Helper.findobject(self._idp, path)
356 Get object from Transient Store for the given location
359 - path : Location of object in Transient Store
360 - retrieve (bool) True : retrieve versus find
361 - disable on-demand (bool) False : temporary disable 'on-demand' actions
363 >>> svc = ... ## get the service
364 >>> path = ... ## get the path
366 >>> data = svc.getObject ( path , False ) ## find object in Transient Store
368 ## find object in Transient Store
369 # load form tape or use 'on-demand' action for missing objects :
370 >>> data = svc.getObject ( path , True )
372 ## find object in Transient Store
373 # load from tape or for missing objects, disable 'on-demand'-actions
374 >>> data = svc.getObject ( path , True , True )
377 if not self._idp :
raise IndexError(
'C++ service %s does not exist' % self.__dict__[
'_name'])
378 return Helper.getobject(self._idp, path, *args )
381 if not self._idp :
raise IndexError(
'C++ service %s does not exist' % self.__dict__[
'_name'])
382 return Helper.dataobject(self._idp, path)
384 if not self._idp :
raise IndexError(
'C++ service %s does not exist' % self.__dict__[
'_name'])
385 return self._idp.registerObject(path,obj)
387 if not self._idp :
raise IndexError(
'C++ service %s does not exist' % self.__dict__[
'_name'])
388 return self._idp.unregisterObject(path)
391 ll = gbl.std.vector(
'IRegistry*')()
394 if self._idm.objectLeaves(node, ll).isSuccess() :
return ll
398 if root : node = root.registry()
400 print node.identifier()
403 def getList(self, node=None, lst=[], rootFID=None) :
407 node = root.registry()
408 rootFID = node.address().
par()
412 Helper.dataobject( self._idp, node.identifier() )
414 lst.append( node.identifier() )
415 for l
in self.
leaves(node) :
416 if l.address()
and l.address().
par() == rootFID :
425 node = root.registry()
429 Helper.dataobject( self._idp, node.identifier() )
431 lst.append( node.identifier() )
432 for l
in self.
leaves(node) :
439 if not self._idm :
raise IndexError(
'C++ service %s does not exist' % self.__dict__[
'_name'])
440 return self._idm.setRoot(name,obj)
442 if not self._idm :
raise IndexError(
'C++ service %s does not exist' % self.__dict__[
'_name'])
443 return self._idm.clearStore()
449 self.__dict__[
'_ihs'] =
InterfaceCast(gbl.IHistogramSvc)(ihs)
450 iDataSvc.__init__(self, name, ihs)
452 return Helper.histo1D(self._ihs, path)
454 return Helper.histo2D(self._ihs, path)
456 return Helper.histo3D(self._ihs, path)
458 return Helper.profile1D(self._ihs, path)
460 return Helper.profile2D(self._ihs, path)
463 Retrieve AIDA histogram or AIDA profile histogram by path in Histogram Transient Store
465 >>> histo = svc.retrieve ( 'path/to/my/histogram' )
475 Book the histograms(1D,2D&3D) , see IHistogramSvc::book
477 >>> histo = svc.book( .... )
479 return apply(self._ihs.book,args)
482 Book the profile(1D&2D) histograms, see IHistogramSvc::bookProf
484 >>> histo = svc.bookProf( .... )
486 return apply(self._ihs.bookProf,args)
489 Retrieve the object from Histogram Transient Store (by path)
490 The reference to AIDA histogram is returned (if possible)
492 >>> histo = svc['path/to/my/histogram']
496 return iDataSvc.__getitem__( self , path )
499 Retrieve the histogram from Histogram Transient Store (by path)
500 The reference to AIDA histogram is returned (if possible)
502 >>> histo = svc.getAsAIDA ( 'path/to/my/histogram' )
507 Retrieve the histogram from Histogram Transient Store (by path)
508 The Underlying native ROOT object is returned (if possible)
510 >>> histo = svc.getAsROOT ( 'path/to/my/histogram' )
512 fun=gbl.Gaudi.Utils.Aida2ROOT.aida2root
521 iDataSvc.__init__(self, name, ints)
523 return apply(self._ints.book, args)
525 """ Defines the mapping between logical names and the output file
527 defineOutput({'LUN1':'MyFile1.root', 'LUN2':'Myfile2.root'}, svc='Gaudi::RootCnvSvc')
529 import Persistency
as prs
530 helper = prs.get(typ)
531 helper.configure(
AppMgr())
532 self.
Output = [helper.formatOutput(files[lun], lun=lun)
for lun
in files]
533 if AppMgr().HistogramPersistency ==
'NONE':
534 AppMgr().HistogramPersistency =
"ROOT"
536 return iDataSvc.__getitem__( self , path )
543 iService.__init__(self, name, its)
545 sol = _gaudi.OutputLevel
547 if name.rfind(
'.') == -1 :
548 itool = Helper.tool(self._its,
'', name,
None,
False )
549 elif name[0:8] ==
'ToolSvc.' :
550 itool = Helper.tool(self._its,
'', name[8:],
None,
False )
551 elif name.count(
'.') > 1 :
552 ptool = self.
_retrieve(name[:name.rfind(
'.')])
553 itool = Helper.tool(self._its,
'', name[name.rfind(
'.')+1:], ptool,
False )
555 prop = _gaudi.property(name[:name.rfind(
'.')])
556 itool = Helper.tool(self._its,
'', name[name.rfind(
'.')+1:], prop._ip,
False )
561 def create(self, typ, name=None, parent=None, interface=None) :
562 if not name : name = typ
563 itool = Helper.tool(self._its, typ, name, parent,
True )
569 if type(itool)
is iAlgTool :
570 self._its.releaseTool(itool._itool)
575 Python-image of C++ class IJobOptionsSvc
580 self.__dict__[
'_optsvc'] =
InterfaceCast(gbl.IJobOptionsSvc)(svc)
581 return iService.__init__( self , name , svc )
584 Extract *ALL* properties of the given component
586 >>> jos = gaudi.optSvc()
587 >>> props = jos.getProperties( 'Name' )
589 props = self._optsvc.getProperties( component )
591 if not props :
return prps
593 prop = p.name().upper()
595 value = eval( p.value() , {} , {} )
596 except: value = p.value()
597 prps [ prop ] = value
602 Get a certain property of the certain component
605 >>> extServices = jos.getProperty( 'ApplicationMgr', 'ExtSvc' )
609 return all.get( name.upper() ,
None )
614 iService.__init__(self,
'EventSelector', Helper.service(gbl.Gaudi.svcLocator(),
'EventSelector'))
615 self.__dict__[
'g'] =
AppMgr()
616 def open(self, stream, typ = 'Gaudi::RootCnvSvc
', **kwargs):
617 import Persistency
as prs
618 helper = prs.get(typ)
619 helper.configure(self.g)
620 self.
Input = helper.formatInput(stream, **kwargs)
631 newobj = object.__new__( cls )
632 cls.__init__(newobj, *args, **kwargs)
640 self._evtpro.release()
641 self._svcloc.release()
642 self._appmgr.release()
648 def __init__(self, outputlevel = -1, joboptions = None, selfoptions = {},
649 dllname =
None, factname =
None) :
653 self.__dict__[
'_exit_called'] =
False
655 self.__dict__[
'_gaudi_ns'] = Gaudi
657 from GaudiKernel.Proxy.Configurable
import expandvars
660 expandvars =
lambda data : data
661 if dllname
and factname:
662 self.__dict__[
'_appmgr'] = gbl.Gaudi.createApplicationMgr(dllname,factname)
664 self.__dict__[
'_appmgr'] = gbl.Gaudi.createApplicationMgr(dllname)
666 self.__dict__[
'_appmgr'] = gbl.Gaudi.createApplicationMgr()
667 self.__dict__[
'_svcloc'] = gbl.Gaudi.svcLocator()
668 self.__dict__[
'_algmgr'] =
InterfaceCast(gbl.IAlgManager)(self._appmgr)
669 self.__dict__[
'_evtpro'] =
InterfaceCast(gbl.IEventProcessor)(self._appmgr)
670 self.__dict__[
'_svcmgr'] =
InterfaceCast(gbl.ISvcManager)(self._appmgr)
671 self.__dict__[
'pyalgorithms'] = []
672 iService.__init__(self,
'ApplicationMgr', self._appmgr )
674 if self.
FSMState() < Gaudi.StateMachine.CONFIGURED :
680 import GaudiKernel.Proxy.Configurable
681 if hasattr(GaudiKernel.Proxy.Configurable,
"applyConfigurableUsers"):
682 GaudiKernel.Proxy.Configurable.applyConfigurableUsers()
685 selfprops = Configurable.allConfigurables.get(
'ApplicationMgr',{})
686 if selfprops : selfprops =
expandvars(selfprops.getValuedProperties())
687 for p,v
in selfprops.items() : setattr(self, p, v)
688 for p,v
in selfoptions.items() : setattr(self, p, v)
690 if outputlevel != -1 : self.
OutputLevel = outputlevel
693 ms = self.
service(
'MessageSvc')
694 if 'MessageSvc' in Configurable.allConfigurables:
695 msprops = Configurable.allConfigurables[
'MessageSvc']
696 ms = self.
service(
'MessageSvc')
697 if hasattr(msprops,
"getValuedProperties"):
698 msprops =
expandvars(msprops.getValuedProperties())
699 for p,v
in msprops.items():
701 if outputlevel != -1 : ms.OutputLevel = outputlevel
703 self.__dict__[
'_optsvc'] =
InterfaceCast(gbl.IJobOptionsSvc)(Helper.service(self._svcloc,
'JobOptionsSvc'))
706 c = Configurable.allConfigurables[n]
707 if n
in [
'ApplicationMgr',
'MessageSvc'] :
continue
708 for p, v
in c.getValuedProperties().items() :
711 if hasattr(Configurable,
"PropertyReference")
and type(v) == Configurable.PropertyReference:
715 if type(v) == str : v =
'"%s"' % v
716 elif type(v) == long: v =
'%d' % v
718 if hasattr(Configurable,
"_configurationLocked"):
719 Configurable._configurationLocked =
True
723 atexit.register(self.
exit)
727 root_handler_installed =
False
728 for h
in atexit._exithandlers:
730 if hasattr(func,
"__module__")
and func.__module__ ==
"ROOT":
731 root_handler_installed =
True
737 if not root_handler_installed:
738 orig_register = atexit.register
739 def register(func, *targs, **kargs):
740 orig_register(func, *targs, **kargs)
741 if hasattr(func,
"__module__")
and func.__module__ ==
"ROOT":
742 orig_register(self.
exit)
745 register.__doc__ = (orig_register.__doc__ +
746 "\nNote: version hacked by GaudiPython to work " +
747 "around a problem with the ROOT exit handler")
748 atexit.register = register
750 def state(self) :
return self._isvc.FSMState()
756 svc = Helper.service( self._svcloc, name )
762 self._svcmgr.declareSvcType(svcname, svctype)
764 return Helper.service( self._svcloc, name,
True )
766 l = self._svcloc.getServices()
769 for i
in range(l.size()) :
770 s.append(nl.front().
name())
774 alg = Helper.algorithm( self._algmgr, name , createIf )
775 if not alg :
return iAlgorithm ( name , alg )
776 else :
return iAlgorithm ( alg.name() , alg )
778 l = self._algmgr.getAlgorithms()
781 for i
in range(l.size()) :
782 s.append(nl.front().
name())
793 svc = Helper.service( self._svcloc, name )
796 return self.
datasvc(
'EventDataSvc')
798 return self.
datasvc(
'DetectorDataSvc')
800 return self.
datasvc(
'FileRecordDataSvc')
803 if not hasattr(self,
'_evtsel') : self.__dict__[
'_evtsel'] =
iEventSelector()
806 svc = Helper.service( self._svcloc, name )
809 if name
not in self.ExtSvc : self.ExtSvc += [name]
811 svc = Helper.service( self._svcloc, name,
True )
815 svc = Helper.service( self._svcloc,
'ParticlePropertySvc' )
818 svc = Helper.service( self._svcloc, name,
True )
820 def optSvc (self, name='JobOptionsSvc') :
821 svc = Helper.service( self._svcloc, name,
True )
824 return self._optsvc.readOptions(file)
826 """ Add an Algorithm to the list of Top algorithms. It can be either a instance of
827 an Algorithm class or it name """
828 if type(alg)
is str :
831 self.pyalgorithms.append(alg)
837 self.
topAlg += [alg.name()]
839 """ Set the list of Top Algorithms.
840 It can be an individual of a list of algorithms names or instances """
841 if type(algs)
is not list : algs = [algs]
844 if type(alg)
is str : names.append(alg)
846 self.pyalgorithms.append(alg)
851 names.append(alg.name())
854 """ Remove an Algorithm to the list of Top algorithms. It can be either a instance of
855 an Algorithm class or it name """
857 if type(alg)
is str :
860 tmp.remove(alg.name())
861 self.pyalgorithms.remove(alg)
866 Simple utility to perform the configuration of Gaudi application.
867 It reads the set of input job-options files, and set few
868 additional parameters 'options' through the usage of temporary *.opts file
870 gaudi.config( files = [ '$GAUSSOPTS/Gauss.opts' ,
871 '$DECFILESROOT/options/10022_010.0GeV.opts' ] ,
872 options = [ 'EventSelector.PrintFreq = 5 ' ] )
874 files = args.get(
'files',[])
878 raise RuntimeError ,
' Unable to read file "' + file +
'" '
879 options = args.get(
'options',
None)
882 tmpfilename = tempfile.mktemp()
883 tmpfile = open( tmpfilename,
'w' )
884 tmpfile.write (
'#pragma print on \n' )
885 tmpfile.write (
'/// File "' + tmpfilename+
'" generated by GaudiPython \n\n' )
887 if type(options)
is dict :
888 tmpfile.write(
' \t ' + opt +
' = '+ options[opt]+
' ; // added by GaudiPython \n' )
890 tmpfile.write(
' \t ' + opt +
' ; // added by GaudiPython \n' )
891 tmpfile.write (
'/// End of file "' + tmpfilename+
'" generated by GaudiPython \n\n' )
895 raise RuntimeError ,
' Unable to read file "' + tmpfilename +
'" '
896 os.remove( tmpfilename )
898 if self.
FSMState() != Gaudi.StateMachine.OFFLINE :
904 _dlls = jos.getProperty ( self.
name() ,
'DLLs' )
907 libs = [ l
for l
in _dlls
if not l
in self.DLLs ]
908 if libs : self.DLLs += libs
911 _svcs = jos.getProperty ( self.
name() ,
'ExtSvc' )
914 svcs = [ s
for s
in _svcs
if not s
in self.ExtSvc ]
915 if svcs : self.ExtSvc += svcs
918 props = jos.getProperties ( self.
name() )
921 if 'DLLS' == key
or 'EXTSVC' == key :
continue
925 return self._appmgr.configure()
927 return self._appmgr.start()
929 if self.
FSMState() == Gaudi.StateMachine.CONFIGURED :
931 if sc.isFailure()
or self.ReturnCode != 0:
933 if self.
FSMState() == Gaudi.StateMachine.INITIALIZED :
935 if sc.isFailure()
or self.ReturnCode != 0:
937 return self._evtpro.executeRun(n)
939 return self._evtpro.executeEvent()
941 return self._evtpro.executeEvent()
943 if self.
FSMState() == Gaudi.StateMachine.CONFIGURED :
945 if sc.isFailure():
return sc
946 if self.
FSMState() == Gaudi.StateMachine.INITIALIZED :
948 if sc.isFailure():
return sc
950 if not hasattr(self,
'_perssvc'): self.__dict__[
'_perssvc'] = self.
service(
'EventPersistencySvc',
'IAddressCreator')
951 if not hasattr(self,
'_filecat'): self.__dict__[
'_filecat'] = self.
service(
'FileCatalog',
'Gaudi::IFileCatalog')
952 if not hasattr(self,
'_evtmgr'): self.__dict__[
'_evtmgr'] = self.
service(
'EventDataSvc',
'IDataManagerSvc')
954 if pfn.find(
'PFN:') == 0: pfn = pfn[4:]
957 if not self._filecat.existsFID(fid) : self._filecat.registerPFN(fid, pfn,
'')
959 if type(events)
is not list : events = (events,)
962 gadd = gbl.GenericAddress(0x02, 1, fid,
'/Event', 0, evt)
964 self._perssvc.createAddress(gadd.svcType(),gadd.clID(),gadd.par(),gadd.ipar(),oadd)
966 self._evtmgr.clearStore()
967 self._evtmgr.setRoot(
'/Event',oadd)
968 self._evtpro.executeEvent()
971 if not self._exit_called:
972 self.__dict__[
'_exit_called'] =
True
973 Gaudi = self._gaudi_ns
974 if self.
FSMState() == Gaudi.StateMachine.RUNNING:
975 self._appmgr.stop().ignore()
976 if self.
FSMState() == Gaudi.StateMachine.INITIALIZED:
977 self._appmgr.finalize().ignore()
978 if self.
FSMState() == Gaudi.StateMachine.CONFIGURED:
979 self._appmgr.terminate()
986 ntupleSvc = ntuplesvc
994 tfile = gbl.TFile.Open(pfn)
995 if not tfile :
raise 'Cannot open ROOT file ', pfn
996 tree = tfile.Get(
'##Params')
998 text = tree.db_string
999 if 'NAME=FID' in text :
1000 fid = text[text.rfind(
'VALUE=')+6:-1]
1001 nevt = tfile.Get(
'_Event').GetEntries()
1007 """ Get all the properties of a component as a Python dictionary.
1008 The component is instantiated using the component library
1011 if name ==
'GaudiCoreSvc' :
1012 if Helper.loadDynamicLib(name) != 1 :
1013 raise ImportError,
'Error loading component library '+ name
1014 factorylist = gbl.FactoryTable.instance().getEntries()
1016 g =
AppMgr(outputlevel=7)
1018 g =
AppMgr(outputlevel=7)
1019 if Helper.loadDynamicLib(name) != 1 :
1020 raise ImportError,
'Error loading component library '+ name
1021 factorylist = gbl.FactoryTable.instance().getEntries()
1023 svcloc = gbl.Gaudi.svcLocator()
1024 dummysvc = gbl.Service(
'DummySvc',svcloc)
1025 for factory
in factories :
1026 if InterfaceCast(gbl.IAlgFactory)(factory) : ctype =
'Algorithm'
1027 elif InterfaceCast(gbl.ISvcFactory)(factory) : ctype =
'Service'
1028 elif InterfaceCast(gbl.IToolFactory)(factory) : ctype =
'AlgTool'
1029 elif factory.ident() ==
'ApplicationMgr' : ctype =
'ApplicationMgr'
1030 else : ctype =
'Unknown'
1031 cname = factory.ident().split()[-1]
1032 if ctype
in (
'Algorithm',
'Service',
'AlgTool',
'ApplicationMgr') :
1034 if ctype ==
'AlgTool' :
1035 obj = factory.instantiate(dummysvc)
1037 obj = factory.instantiate(svcloc)
1038 except RuntimeError, text :
1039 print 'Error instantiating', cname,
' from ', name
1043 properties[cname] = [ctype, prop.properties()]
1050 for i
in range(factories.size()) :
1051 factory = factories.front()
1052 result.append(factory)
1053 factories.pop_front()
1054 for factory
in result :
1055 factories.push_back(factory)
1060 _CallbackStreamBufBase = gbl.GaudiPython.CallbackStreamBuf
1063 _CallbackStreamBufBase.__init__(self, self)
1066 if not string :
return 0
1072 _PyAlgorithm = gbl.GaudiPython.PyAlgorithm
1075 if not name : name = self.__class__.__name__
1076 _PyAlgorithm.__init__(self, self, name)
1079 sc = self._algmgr.addAlgorithm(self)
1080 if sc.isFailure() :
raise RuntimeError,
'Unable to add Algorithm'
1082 sc = self._algmgr.removeAlgorithm(self)
1083 if sc.isFailure() :
pass
1094 import rlcompleter, readline
1095 readline.parse_and_bind(
"tab: complete")