13 """ GaudiPython.Bindings module. 14 This module provides the basic bindings of the main Gaudi 15 components to Python. It is itself based on the ROOT cppyy 16 Python extension module. 18 from __future__
import absolute_import, print_function
21 'gbl',
'InterfaceCast',
'Interface',
'PropertyEntry',
'AppMgr',
22 'PyAlgorithm',
'CallbackStreamBuf',
'iAlgorithm',
'iDataSvc',
23 'iHistogramSvc',
'iNTupleSvc',
'iService',
'iAlgTool',
'Helper',
'SUCCESS',
24 'FAILURE',
'toArray',
'ROOT',
'makeNullPointer',
'setOwnership',
25 'getClass',
'loaddict',
'deprecation' 28 from GaudiKernel
import ROOT6WorkAroundEnabled
39 print(
"# WARNING: using PyCintex as cppyy implementation")
40 import PyCintex
as cppyy
42 if sys.version_info >= (3, ):
52 from .
import Pythonizations
55 from GaudiKernel.Proxy.Configurable
import Configurable, getNeededConfigurables
64 gbl.gInterpreter.Declare(
'#include "GaudiKernel/Property.h"')
65 Helper = gbl.GaudiPython.Helper
66 StringProperty = gbl.Gaudi.Property(
'std::string')
67 StringPropertyRef = gbl.Gaudi.Property(
'std::string&')
68 GaudiHandleProperty = gbl.GaudiHandleProperty
69 GaudiHandleArrayProperty = gbl.GaudiHandleArrayProperty
70 DataObject = gbl.DataObject
71 SUCCESS = gbl.StatusCode(gbl.StatusCode.SUCCESS,
True)
72 FAILURE = gbl.StatusCode(gbl.StatusCode.FAILURE,
True)
74 cppyy.gbl.gInterpreter.Declare(
''' 75 namespace GaudiPython { namespace Helpers { 76 Gaudi::Property<std::string> mkStringProperty(const std::string &name, 77 const std::string &value) { 78 return Gaudi::Property<std::string>{name, value}; 83 for l
in [l
for l
in dir(Helper)
if re.match(
"^to.*Array$", l)]:
84 exec (
"%s = Helper.%s" % (l, l))
88 if hasattr(Helper,
"toArray"):
92 return getattr(Helper,
"toArray")
96 return getattr(Helper,
"toArray<%s>" % typ)
100 ROOT = cppyy.libPyROOT
101 makeNullPointer = cppyy.libPyROOT.MakeNullPointer
102 setOwnership = cppyy.libPyROOT.SetOwnership
106 warnings.warn(
'GaudiPython: ' + message, DeprecationWarning, stacklevel=3)
113 """ Helper class to obtain the adequate interface from a component 114 by using the Gaudi queryInterface() mechanism """ 125 if obj.queryInterface(self.
type.interfaceID(), ip).isSuccess():
128 print(
"ERROR: queryInterface failed for", obj,
129 "interface:", self.
type)
130 except Exception
as e:
131 print(
"ERROR: exception", e,
132 "caught when retrieving interface", self.
type,
135 traceback.print_stack()
147 InterfaceCast.__init__(self, t)
157 """ Load a LCG dictionary using various mechanisms""" 158 if Helper.loadDynamicLib(dict) == 1:
164 raise ImportError(
'Error loading dictionary library')
172 Function to retrieve a certain C++ class by name and to load dictionary if requested 176 from gaudimodule import getClass 177 # one knows that class is already loaded 178 AppMgr = getClass( 'ApplicationMgr' ) 179 # one knows where to look for class, if not loaded yet 180 MCParticle = getClass( 'MCParticle' , 'EventDict' ) 181 # one knows where to look for class, if not loaded yet 182 Vertex = getClass( 'Vertex' , ['EventDict', 'PhysEventDict'] ) 185 if hasattr(gbl, name):
186 return getattr(gbl, name)
188 if type(libs)
is not list:
192 if hasattr(gbl, name):
193 return getattr(gbl, name)
202 """ holds the value and the documentation string of a property """ 208 if issubclass(
type(prop), GaudiHandleProperty):
210 elif issubclass(
type(prop), GaudiHandleArrayProperty):
211 self.
_value = prop.value()
215 self.
_value = eval(prop.toString(), {}, {})
217 if hasattr(prop,
'value'):
218 self.
_value = prop.value()
220 self.
_value = prop.toString()
222 self.
__doc__ +=
" --- Default value = " + str(self.
_value) +
" --- " 223 if prop.documentation() !=
'none':
235 "Return the underlying property itself " 249 """ Python equivalent to the C++ Property interface """ 255 self.__dict__[
'_ip'] =
None 256 self.__dict__[
'_svcloc'] = gbl.Gaudi.svcLocator()
257 optsvc = Helper.service(self._svcloc,
'JobOptionsSvc')
260 gbl.IJobOptionsSvc)(optsvc)
262 self.__dict__[
'_optsvc'] =
None 263 self.__dict__[
'_name'] = name
274 if not getattr(self, ifname):
275 self.retrieveInterface()
276 return getattr(getattr(self, ifname), method)(*args)
280 The method which is used for setting the property from the given value. 281 - In the case of the valid instance it sets the property through IProperty interface 282 - In the case of placeholder the property is added to JobOptionsCatalogue 284 if hasattr(value,
'toStringProperty'):
286 value =
'%s' % value.toStringProperty()
289 if not gbl.Gaudi.Utils.hasProperty(ip, name):
290 raise AttributeError(
'property %s does not exist' % name)
291 prop = ip.getProperty(name)
294 canSetValue = (hasattr(prop,
'value')
295 and 'const&[' not in prop.value.func_doc
296 and type(value) ==
type(prop.value()))
298 canSetValue = (hasattr(prop,
'value')
299 and type(value) ==
type(prop.value()))
302 if not prop.setValue(value):
303 raise AttributeError(
304 'property %s could not be set from %s' % (name, value))
306 if tuple ==
type(value):
308 elif hasattr(value,
'toString'):
309 value = value.toString()
310 elif not long ==
type(value):
315 sc = cppyy.gbl.GaudiPython.Helper.setPropertyFromString(
318 sc = prop.fromString(value)
320 raise AttributeError(
321 'property %s could not be set from %s' % (name, value))
323 if type(value) == str:
324 value =
'"%s"' % value
325 elif type(value) == tuple:
327 elif hasattr(value,
'toString'):
328 value = value.toString()
329 elif type(value) == long:
331 sp = gbl.GaudiPython.Helpers.mkStringProperty(name, str(value))
336 The method which returns the value for the given property 337 - In the case of the valid instance it returns the valid property value through IProperty interface 338 - In the case of placeholder the property value is retrieved from JobOptionsCatalogue 342 if not gbl.Gaudi.Utils.hasProperty(ip, name):
343 raise AttributeError(
'property %s does not exist' % name)
344 prop = ip.getProperty(name)
345 if StringProperty ==
type(prop):
347 elif StringPropertyRef ==
type(prop):
350 return eval(prop.toString(), {}, {})
354 props = self._optsvc.getProperties(self._name)
356 if not p.name() == name:
360 return eval(p.value(), {}, {})
363 raise AttributeError(
'property %s does not exist' % name)
370 props = ip.getProperties()
371 propsFrom = self._name
373 props = self._optsvc.getProperties(self._name)
374 propsFrom =
"jobOptionsSvc" 379 except (ValueError, TypeError)
as e:
380 raise ValueError(
"gaudimodule.iProperty.properties(): %s%s processing property %s.%s = %s" % \
381 (e.__class__.__name__, e.args,
382 propsFrom, p.name(), p.value()))
393 """ Python equivalent to IProperty interface """ 396 iProperty.__init__(self, name, isvc)
400 self.__dict__[
'_isvc'] =
None 403 isvc = Helper.service(self._svcloc, self._name)
405 iService.__init__(self, self._name, isvc)
436 """ Python equivalent to IAlgorithm interface """ 439 iProperty.__init__(self, name, ialg)
443 self.__dict__[
'_ialg'] =
None 446 ialg = Helper.algorithm(
449 iAlgorithm.__init__(self, self._name, ialg)
498 """ Python equivalent to IAlgTool interface (not completed yet) """ 501 iProperty.__init__(self, name, itool)
503 self.__dict__[
'_itool'] = itool
505 self.__dict__[
'_itool'] =
None 506 svc = Helper.service(self._svcloc,
'ToolSvc',
True)
507 self.__dict__[
'_toolsvc'] =
iToolSvc(
'ToolSvc', svc)
510 itool = self._toolsvc._retrieve(self._name)
512 iAlgTool.__init__(self, self._name, itool)
525 return self._itool.
name()
535 iService.__init__(self, name, idp)
536 self.__dict__[
'_idp'] =
InterfaceCast(gbl.IDataProviderSvc)(idp)
537 self.__dict__[
'_idm'] =
InterfaceCast(gbl.IDataManagerSvc)(idp)
541 raise AttributeError(
542 'C++ service %s does not exist' % self.__dict__[
'_name'])
543 return Helper.registerObject(self._idp, path, obj)
547 raise AttributeError(
548 'C++ service %s does not exist' % self.__dict__[
'_name'])
549 return Helper.unregisterObject(self._idp, path)
554 return Helper.dataobject(self._idp, path)
561 Get the existing object in TransientStore for the given location 563 - loading of object from persistency is NOT triggered 564 - 'data-on-demand' action is NOT triggered 566 >>> svc = ... ## get the service 567 >>> path = ... ## get the path in Transient Store 568 >>> data = svc.findObject ( path ) ## use the method 573 'C++ service %s does not exist' % self.__dict__[
'_name'])
574 return Helper.findobject(self._idp, path)
579 Get object from Transient Store for the given location 582 - path : Location of object in Transient Store 583 - retrieve (bool) True : retrieve versus find 584 - disable on-demand (bool) False : temporary disable 'on-demand' actions 586 >>> svc = ... ## get the service 587 >>> path = ... ## get the path 589 >>> data = svc.getObject ( path , False ) ## find object in Transient Store 591 ## find object in Transient Store 592 # load form tape or use 'on-demand' action for missing objects : 593 >>> data = svc.getObject ( path , True ) 595 ## find object in Transient Store 596 # load from tape or for missing objects, disable 'on-demand'-actions 597 >>> data = svc.getObject ( path , True , True ) 602 'C++ service %s does not exist' % self.__dict__[
'_name'])
603 return Helper.getobject(self._idp, path, *args)
608 'C++ service %s does not exist' % self.__dict__[
'_name'])
609 return Helper.dataobject(self._idp, path)
614 'C++ service %s does not exist' % self.__dict__[
'_name'])
620 'C++ service %s does not exist' % self.__dict__[
'_name'])
626 ll = gbl.std.vector(
'IRegistry*')()
627 if type(node)
is str:
631 if self._idm.objectLeaves(node, ll).isSuccess():
638 node = root.registry()
641 print(node.identifier())
643 for l
in self.
leaves(node):
646 def getList(self, node=None, lst=[], rootFID=None):
650 node = root.registry()
651 rootFID = node.address().
par()
655 Helper.dataobject(self._idp, node.identifier())
657 lst.append(node.identifier())
658 for l
in self.
leaves(node):
659 if l.address()
and l.address().
par() == rootFID:
669 node = root.registry()
674 Helper.dataobject(self._idp, node.identifier())
676 lst.append(node.identifier())
677 for l
in self.
leaves(node):
687 'C++ service %s does not exist' % self.__dict__[
'_name'])
688 return self._idm.
setRoot(name, obj)
693 'C++ service %s does not exist' % self.__dict__[
'_name'])
700 self.__dict__[
'_ihs'] =
InterfaceCast(gbl.IHistogramSvc)(ihs)
701 iDataSvc.__init__(self, name, ihs)
704 return Helper.histo1D(self._ihs, path)
707 return Helper.histo2D(self._ihs, path)
710 return Helper.histo3D(self._ihs, path)
713 return Helper.profile1D(self._ihs, path)
716 return Helper.profile2D(self._ihs, path)
720 Retrieve AIDA histogram or AIDA profile histogram by path in Histogram Transient Store 722 >>> histo = svc.retrieve ( 'path/to/my/histogram' ) 737 Book the histograms(1D,2D&3D) , see IHistogramSvc::book 739 >>> histo = svc.book( .... ) 741 return self._ihs.
book(*args)
745 Book the profile(1D&2D) histograms, see IHistogramSvc::bookProf 747 >>> histo = svc.bookProf( .... ) 753 Retrieve the object from Histogram Transient Store (by path) 754 The reference to AIDA histogram is returned (if possible) 756 >>> histo = svc['path/to/my/histogram'] 761 return iDataSvc.__getitem__(self, path)
765 Retrieve the histogram from Histogram Transient Store (by path) 766 The reference to AIDA histogram is returned (if possible) 768 >>> histo = svc.getAsAIDA ( 'path/to/my/histogram' ) 774 Retrieve the histogram from Histogram Transient Store (by path) 775 The Underlying native ROOT object is returned (if possible) 777 >>> histo = svc.getAsROOT ( 'path/to/my/histogram' ) 779 fun = gbl.Gaudi.Utils.Aida2ROOT.aida2root
792 iDataSvc.__init__(self, name, ints)
795 return self._ints.
book(*args)
798 """ Defines the mapping between logical names and the output file 800 defineOutput({'LUN1':'MyFile1.root', 'LUN2':'Myfile2.root'}, svc='Gaudi::RootCnvSvc') 802 from .
import Persistency
as prs
803 helper = prs.get(typ)
804 helper.configure(
AppMgr())
806 helper.formatOutput(files[lun], lun=lun)
for lun
in files
808 if AppMgr().HistogramPersistency ==
'NONE':
809 AppMgr().HistogramPersistency =
"ROOT" 812 return iDataSvc.__getitem__(self, path)
819 iService.__init__(self, name, its)
822 sol = _gaudi.OutputLevel
825 if name.rfind(
'.') == -1:
826 itool = Helper.tool(self._its,
'', name,
None,
False)
827 elif name[0:8] ==
'ToolSvc.':
828 itool = Helper.tool(self._its,
'', name[8:],
None,
False)
829 elif name.count(
'.') > 1:
830 ptool = self.
_retrieve(name[:name.rfind(
'.')])
831 itool = Helper.tool(self._its,
'', name[name.rfind(
'.') + 1:],
834 prop = _gaudi.property(name[:name.rfind(
'.')])
835 itool = Helper.tool(self._its,
'', name[name.rfind(
'.') + 1:],
844 def create(self, typ, name=None, parent=None, interface=None):
847 itool = Helper.tool(self._its, typ, name, parent,
True)
854 if type(itool)
is iAlgTool:
855 self._its.releaseTool(itool._itool)
863 Python-image of C++ class IJobOptionsSvc 870 self.__dict__[
'_optsvc'] =
InterfaceCast(gbl.IJobOptionsSvc)(svc)
871 return iService.__init__(self, name, svc)
875 Extract *ALL* properties of the given component 877 >>> jos = gaudi.optSvc() 878 >>> props = jos.getProperties( 'Name' ) 885 prop = p.name().upper()
887 value = eval(p.value(), {}, {})
896 Get a certain property of the certain component 899 >>> extServices = jos.getProperty( 'ApplicationMgr', 'ExtSvc' ) 903 return all.get(name.upper(),
None)
912 self,
'EventSelector',
913 Helper.service(gbl.Gaudi.svcLocator(),
'EventSelector'))
914 self.__dict__[
'g'] =
AppMgr()
916 def open(self, stream, typ='Gaudi::RootCnvSvc
', **kwargs): 917 from .
import Persistency
as prs
918 helper = prs.get(typ)
919 helper.configure(self.g)
920 self.
Input = helper.formatInput(stream, **kwargs)
935 newobj = object.__new__(cls)
936 cls.
__init__(newobj, *args, **kwargs)
945 self._evtpro.release()
946 self._svcloc.release()
947 self._appmgr.release()
966 self.__dict__[
'_exit_called'] =
False 968 self.__dict__[
'_gaudi_ns'] = Gaudi
970 from GaudiKernel.Proxy.Configurable
import expandvars
976 if dllname
and factname:
977 self.__dict__[
'_appmgr'] = gbl.Gaudi.createApplicationMgr(
980 self.__dict__[
'_appmgr'] = gbl.Gaudi.createApplicationMgr(dllname)
982 self.__dict__[
'_appmgr'] = gbl.Gaudi.createApplicationMgr()
983 self.__dict__[
'_svcloc'] = gbl.Gaudi.svcLocator()
984 self.__dict__[
'_algmgr'] =
InterfaceCast(gbl.IAlgManager)(self._appmgr)
985 self.__dict__[
'_evtpro'] =
InterfaceCast(gbl.IEventProcessor)(
987 self.__dict__[
'_svcmgr'] =
InterfaceCast(gbl.ISvcManager)(self._appmgr)
988 self.__dict__[
'pyalgorithms'] = []
989 iService.__init__(self,
'ApplicationMgr', self._appmgr)
992 ) < Gaudi.StateMachine.CONFIGURED:
998 import GaudiKernel.Proxy.Configurable
999 if hasattr(GaudiKernel.Proxy.Configurable,
1000 "applyConfigurableUsers"):
1001 GaudiKernel.Proxy.Configurable.applyConfigurableUsers()
1005 appMgr = Configurable.allConfigurables[
'ApplicationMgr']
1006 selfprops =
expandvars(appMgr.getValuedProperties())
1009 for p, v
in selfprops.items():
1011 for p, v
in selfoptions.items():
1014 if outputlevel != -1:
1018 ms = self.
service(
'MessageSvc')
1019 if 'MessageSvc' in Configurable.allConfigurables:
1020 msprops = Configurable.allConfigurables[
'MessageSvc']
1021 ms = self.
service(
'MessageSvc')
1022 if hasattr(msprops,
"getValuedProperties"):
1023 msprops =
expandvars(msprops.getValuedProperties())
1024 for p, v
in msprops.items():
1026 if outputlevel != -1:
1027 ms.OutputLevel = outputlevel
1029 self.__dict__[
'_optsvc'] =
InterfaceCast(gbl.IJobOptionsSvc)(
1030 Helper.service(self._svcloc,
'JobOptionsSvc'))
1032 mkStringProperty = gbl.GaudiPython.Helpers.mkStringProperty
1034 c = Configurable.allConfigurables[n]
1035 if n
in [
'ApplicationMgr',
'MessageSvc']:
1037 for p, v
in c.getValuedProperties().
items():
1040 if hasattr(Configurable,
"PropertyReference")
and type(
1041 v) == Configurable.PropertyReference:
1047 elif type(v) == long:
1050 n, mkStringProperty(p, str(v)))
1051 if hasattr(Configurable,
"_configurationLocked"):
1052 Configurable._configurationLocked =
True 1057 """Ensure that the exit method is called when exiting from Python, and 1058 try to ensure that ROOT doesn't intefere too much.""" 1060 atexit.register(self.
exit)
1063 exit_handlers = atexit._exithandlers
1064 except AttributeError:
1071 root_handler_installed =
False 1072 for h
in exit_handlers:
1074 if hasattr(func,
"__module__")
and func.__module__ ==
"ROOT":
1075 root_handler_installed =
True 1081 if not root_handler_installed:
1082 orig_register = atexit.register
1084 def register(func, *targs, **kargs):
1085 orig_register(func, *targs, **kargs)
1086 if hasattr(func,
"__module__")
and func.__module__ ==
"ROOT":
1087 orig_register(self.
exit)
1091 register.__doc__ = (
1092 orig_register.__doc__ +
1093 "\nNote: version hacked by GaudiPython to work " +
1094 "around a problem with the ROOT exit handler")
1095 atexit.register = register
1107 svc = Helper.service(self._svcloc, name)
1114 self._svcmgr.declareSvcType(svcname, svctype)
1117 return Helper.service(self._svcloc, name,
True)
1120 l = self._svcloc.getServices()
1121 return [s.name()
for s
in l]
1124 alg = Helper.algorithm(self._algmgr, name, createIf)
1131 l = self._algmgr.getAlgorithms()
1132 return [a.name()
for a
in l]
1146 if self.
state() == Gaudi.StateMachine.CONFIGURED:
1148 svc = Helper.service(self._svcloc, name)
1152 return self.
datasvc(
'EventDataSvc')
1155 return self.
datasvc(
'DetectorDataSvc')
1158 return self.
datasvc(
'FileRecordDataSvc')
1161 if self.
state() == Gaudi.StateMachine.CONFIGURED:
1163 if not hasattr(self,
'_evtsel'):
1168 svc = Helper.service(self._svcloc, name)
1172 if name
not in self.ExtSvc:
1173 self.ExtSvc += [name]
1175 svc = Helper.service(self._svcloc, name,
True)
1179 if self.
FSMState() == Gaudi.StateMachine.CONFIGURED:
1181 svc = Helper.service(self._svcloc,
'ParticlePropertySvc')
1185 svc = Helper.service(self._svcloc, name,
True)
1189 svc = Helper.service(self._svcloc, name,
True)
1196 """ Add an Algorithm to the list of Top algorithms. It can be either a instance of 1197 an Algorithm class or it name """ 1198 if type(alg)
is str:
1201 self.pyalgorithms.append(alg)
1207 self.
topAlg += [alg.name()]
1210 """ Set the list of Top Algorithms. 1211 It can be an individual of a list of algorithms names or instances """ 1212 if type(algs)
is not list:
1216 if type(alg)
is str:
1219 self.pyalgorithms.append(alg)
1224 names.append(alg.name())
1228 """ Remove an Algorithm to the list of Top algorithms. It can be either a instance of 1229 an Algorithm class or it name """ 1231 if type(alg)
is str:
1234 tmp.remove(alg.name())
1235 self.pyalgorithms.remove(alg)
1241 Print the sequence of Algorithms. 1244 def printAlgo(algName, appMgr, prefix=' '):
1245 print(prefix + algName)
1246 alg = appMgr.algorithm(algName.split(
"/")[-1])
1247 prop = alg.properties()
1248 if "Members" in prop:
1249 subs = prop[
"Members"].value()
1251 printAlgo(i.strip(
'"'), appMgr, prefix +
" ")
1254 prefix =
'ApplicationMgr SUCCESS ' 1257 "****************************** Algorithm Sequence ****************************" 1259 for i
in mp[
"TopAlg"].value():
1260 printAlgo(i, self, prefix)
1263 "******************************************************************************" 1268 Simple utility to perform the configuration of Gaudi application. 1269 It reads the set of input job-options files, and set few 1270 additional parameters 'options' through the usage of temporary *.opts file 1272 gaudi.config( files = [ '$GAUSSOPTS/Gauss.opts' , 1273 '$DECFILESROOT/options/10022_010.0GeV.opts' ] , 1274 options = [ 'EventSelector.PrintFreq = 5 ' ] ) 1276 files = args.get(
'files', [])
1280 raise RuntimeError(
' Unable to read file "' + file +
'" ')
1281 options = args.get(
'options',
None)
1284 tmpfilename = tempfile.mktemp()
1285 tmpfile = open(tmpfilename,
'w')
1286 tmpfile.write(
'#pragma print on \n')
1287 tmpfile.write(
'/// File "' + tmpfilename +
1288 '" generated by GaudiPython \n\n')
1290 if type(options)
is dict:
1291 tmpfile.write(
' \t ' + opt +
' = ' + options[opt] +
1292 ' ; // added by GaudiPython \n')
1294 tmpfile.write(
' \t ' + opt +
1295 ' ; // added by GaudiPython \n')
1296 tmpfile.write(
'/// End of file "' + tmpfilename +
1297 '" generated by GaudiPython \n\n')
1301 raise RuntimeError(
' Unable to read file "' + tmpfilename +
1303 os.remove(tmpfilename)
1306 if self.
FSMState() != Gaudi.StateMachine.OFFLINE:
1312 _dlls = jos.getProperty(self.
name(),
'DLLs')
1315 libs = [l
for l
in _dlls
if not l
in self.DLLs]
1320 _svcs = jos.getProperty(self.
name(),
'ExtSvc')
1323 svcs = [s
for s
in _svcs
if not s
in self.ExtSvc]
1328 props = jos.getProperties(self.
name())
1331 if 'DLLS' == key
or 'EXTSVC' == key:
1340 return self._appmgr.
start()
1346 if self.
FSMState() == Gaudi.StateMachine.CONFIGURED:
1348 if sc.isFailure()
or self.ReturnCode != 0:
1350 if self.
FSMState() == Gaudi.StateMachine.INITIALIZED:
1352 if sc.isFailure()
or self.ReturnCode != 0:
1363 if self.
FSMState() == Gaudi.StateMachine.CONFIGURED:
1367 if self.
FSMState() == Gaudi.StateMachine.INITIALIZED:
1372 if not hasattr(self,
'_perssvc'):
1373 self.__dict__[
'_perssvc'] = self.
service(
'EventPersistencySvc',
1375 if not hasattr(self,
'_filecat'):
1376 self.__dict__[
'_filecat'] = self.
service(
'FileCatalog',
1377 'Gaudi::IFileCatalog')
1378 if not hasattr(self,
'_evtmgr'):
1379 self.__dict__[
'_evtmgr'] = self.
service(
'EventDataSvc',
1382 if pfn.find(
'PFN:') == 0:
1386 if not self._filecat.existsFID(fid):
1387 self._filecat.registerPFN(fid, pfn,
'')
1389 if type(events)
is not list:
1393 gadd = gbl.GenericAddress(0x02, 1, fid,
'/Event', 0, evt)
1395 self._perssvc.createAddress(gadd.svcType(), gadd.clID(),
1396 gadd.par(), gadd.ipar(), oadd)
1398 self._evtmgr.clearStore()
1399 self._evtmgr.setRoot(
'/Event', oadd)
1404 if not self._exit_called:
1405 self.__dict__[
'_exit_called'] =
True 1406 Gaudi = self._gaudi_ns
1407 if self.
FSMState() == Gaudi.StateMachine.RUNNING:
1408 self._appmgr.
stop().ignore()
1409 if self.
FSMState() == Gaudi.StateMachine.INITIALIZED:
1411 if self.
FSMState() == Gaudi.StateMachine.CONFIGURED:
1422 ntupleSvc = ntuplesvc
1433 tfile = gbl.TFile.Open(pfn)
1435 raise IOError(
'Cannot open ROOT file {0}'.
format(pfn))
1436 tree = tfile.Get(
'##Params')
1438 text = tree.db_string
1439 if 'NAME=FID' in text:
1440 fid = text[text.rfind(
'VALUE=') + 6:-1]
1441 nevt = tfile.Get(
'_Event').GetEntries()
1450 """ Get all the properties of a component as a Python dictionary. 1451 The component is instantiated using the component library 1454 if name ==
'GaudiCoreSvc':
1455 if Helper.loadDynamicLib(name) != 1:
1456 raise ImportError(
'Error loading component library ' + name)
1457 factorylist = gbl.FactoryTable.instance().getEntries()
1459 g =
AppMgr(outputlevel=7)
1461 g =
AppMgr(outputlevel=7)
1462 if Helper.loadDynamicLib(name) != 1:
1463 raise ImportError(
'Error loading component library ' + name)
1464 factorylist = gbl.FactoryTable.instance().getEntries()
1466 svcloc = gbl.Gaudi.svcLocator()
1467 dummysvc = gbl.Service(
'DummySvc', svcloc)
1468 for factory
in factories:
1475 elif factory.ident() ==
'ApplicationMgr':
1476 ctype =
'ApplicationMgr' 1479 cname = factory.ident().split()[-1]
1480 if ctype
in (
'Algorithm',
'Service',
'AlgTool',
'ApplicationMgr'):
1482 if ctype ==
'AlgTool':
1483 obj = factory.instantiate(dummysvc)
1485 obj = factory.instantiate(svcloc)
1486 except RuntimeError
as text:
1487 print(
'Error instantiating', cname,
' from ', name)
1491 properties[cname] = [ctype, prop.properties()]
1501 for i
in range(factories.size()):
1502 factory = factories.front()
1503 result.append(factory)
1504 factories.pop_front()
1505 for factory
in result:
1506 factories.push_back(factory)
1512 _CallbackStreamBufBase = gbl.GaudiPython.CallbackStreamBuf
1517 _CallbackStreamBufBase.__init__(self, self)
1529 _PyAlgorithm = gbl.GaudiPython.PyAlgorithm
1535 name = self.__class__.__name__
1536 _PyAlgorithm.__init__(self, self, name)
1539 sc = self.
_algmgr.addAlgorithm(self)
1541 raise RuntimeError(
'Unable to add Algorithm')
1544 sc = self.
_algmgr.removeAlgorithm(self)
1568 readline.parse_and_bind(
"tab: complete")
def declSvcType(self, svcname, svctype)
def getHistoNames(self, node=None, lst=[])
def setAlgorithms(self, algs)
def printAlgsSequences(self)
def createSvc(self, name)
def histsvc(self, name='HistogramDataSvc')
def __init__(self, name, ints)
def __init__(self, name, isvc=None)
def retrieveInterface(self)
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
def runSelectedEvents(self, pfn, events)
def __getitem__(self, path)
def findObject(self, path)
def unregisterObject(self, path)
def getClass(name, libs=[])
def _install_exit_handlers(self)
bool PyHelper() addPropertyToCatalogue(IInterface *p, char *comp, char *name, char *value)
def retrieveProfile1D(self, path)
def getAsAIDA(self, path)
def getProperties(self, component)
def _getFIDandEvents(pfn)
def __init__(self, name, ialg=None)
def toolsvc(self, name='ToolSvc')
def __getitem__(self, path)
def __init__(self, name, ip=None)
def ROOT6WorkAroundEnabled(id=None)
def service(self, name, interface=None)
def __init__(self, callback)
def retrieveInterface(self)
def algorithm(self, name, createIf=False)
def retrieve1D(self, path)
def retrieve3D(self, path)
def __init__(self, name, svc)
def open(self, stream, typ='Gaudi::RootCnvSvc', **kwargs)
def sysReinitialize(self)
def _sync(self, string=None)
def removeAlgorithm(self, alg)
def __init__(self, name, idp)
def importOptions(optsfile)
def __delitem__(self, path)
def defineOutput(self, files, typ="Gaudi::RootCnvSvc")
def addAlgorithm(self, alg)
def retrieveProfile2D(self, path)
def retrieve2D(self, path)
def __call_interface_method__(self, ifname, method, *args)
def __new__(cls, *args, **kwargs)
def getProperty(self, component, name)
def __setitem__(self, path, obj)
def retrieveInterface(self)
def __init__(self, outputlevel=-1, joboptions=None, selfoptions={}, dllname=None, factname=None)
def __init__(self, name, ihs)
def ntuplesvc(self, name='NTupleSvc')
def bookProf(self, *args)
def getAsROOT(self, path)
def dump(self, node=None)
def retrieveObject(self, path)
def __getitem__(self, path)
def _copyFactoriesFromList(factories)
def setRoot(self, name, obj)
def __init__(self, name=None)
decltype(auto) range(Args &&... args)
Zips multiple containers together to form a single range.
def registerObject(self, path, obj)
def optSvc(self, name='JobOptionsSvc')
return ep &&ep executeRun(maxevt).isSuccess()
def getComponentProperties(name)
def getObject(self, path, *args)
def leaves(self, node=None)
def __getattr__(self, name)
def getList(self, node=None, lst=[], rootFID=None)
def readOptions(self, file)
def __setattr__(self, name, value)