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)
75 cppyy.gbl.gInterpreter.Declare(
''' 76 namespace GaudiPython { namespace Helpers { 77 Gaudi::Property<std::string> mkStringProperty(const std::string &name, 78 const std::string &value) { 79 return Gaudi::Property<std::string>{name, value}; 84 for l
in [l
for l
in dir(Helper)
if re.match(
"^to.*Array$", l)]:
85 exec (
"%s = Helper.%s" % (l, l))
89 if hasattr(Helper,
"toArray"):
93 return getattr(Helper,
"toArray")
97 return getattr(Helper,
"toArray<%s>" % typ)
101 ROOT = cppyy.libPyROOT
102 makeNullPointer = cppyy.libPyROOT.MakeNullPointer
103 setOwnership = cppyy.libPyROOT.SetOwnership
107 warnings.warn(
'GaudiPython: ' + message, DeprecationWarning, stacklevel=3)
114 """ Helper class to obtain the adequate interface from a component 115 by using the Gaudi queryInterface() mechanism """ 126 if obj.queryInterface(self.
type.interfaceID(), ip).isSuccess():
129 print(
"ERROR: queryInterface failed for", obj,
130 "interface:", self.
type)
131 except Exception
as e:
132 print(
"ERROR: exception", e,
133 "caught when retrieving interface", self.
type,
136 traceback.print_stack()
148 InterfaceCast.__init__(self, t)
158 """ Load a LCG dictionary using various mechanisms""" 159 if Helper.loadDynamicLib(dict) == 1:
165 raise ImportError(
'Error loading dictionary library')
173 Function to retrieve a certain C++ class by name and to load dictionary if requested 177 from gaudimodule import getClass 178 # one knows that class is already loaded 179 AppMgr = getClass( 'ApplicationMgr' ) 180 # one knows where to look for class, if not loaded yet 181 MCParticle = getClass( 'MCParticle' , 'EventDict' ) 182 # one knows where to look for class, if not loaded yet 183 Vertex = getClass( 'Vertex' , ['EventDict', 'PhysEventDict'] ) 186 if hasattr(gbl, name):
187 return getattr(gbl, name)
189 if type(libs)
is not list:
193 if hasattr(gbl, name):
194 return getattr(gbl, name)
203 """ holds the value and the documentation string of a property """ 209 if issubclass(
type(prop), GaudiHandleProperty):
211 elif issubclass(
type(prop), GaudiHandleArrayProperty):
212 self.
_value = prop.value()
216 self.
_value = eval(prop.toString(), {}, {})
218 if hasattr(prop,
'value'):
219 self.
_value = prop.value()
221 self.
_value = prop.toString()
223 self.
__doc__ +=
" --- Default value = " + str(self.
_value) +
" --- " 224 if prop.documentation() !=
'none':
236 "Return the underlying property itself " 250 """ Python equivalent to the C++ Property interface """ 256 self.__dict__[
'_ip'] =
None 257 self.__dict__[
'_svcloc'] = gbl.Gaudi.svcLocator()
258 optsvc = Helper.service(self._svcloc,
'JobOptionsSvc')
261 gbl.IJobOptionsSvc)(optsvc)
263 self.__dict__[
'_optsvc'] =
None 264 self.__dict__[
'_name'] = name
275 if not getattr(self, ifname):
276 self.retrieveInterface()
277 return getattr(getattr(self, ifname), method)(*args)
281 The method which is used for setting the property from the given value. 282 - In the case of the valid instance it sets the property through IProperty interface 283 - In the case of placeholder the property is added to JobOptionsCatalogue 285 if hasattr(value,
'toStringProperty'):
287 value =
'%s' % value.toStringProperty()
290 if not gbl.Gaudi.Utils.hasProperty(ip, name):
291 raise AttributeError(
'property %s does not exist' % name)
292 prop = ip.getProperty(name)
295 canSetValue = (hasattr(prop,
'value')
296 and 'const&[' not in prop.value.func_doc
297 and type(value) ==
type(prop.value()))
299 canSetValue = (hasattr(prop,
'value')
300 and type(value) ==
type(prop.value()))
303 if not prop.setValue(value):
304 raise AttributeError(
305 'property %s could not be set from %s' % (name, value))
307 if tuple ==
type(value):
309 elif hasattr(value,
'toString'):
310 value = value.toString()
311 elif not long ==
type(value):
316 sc = cppyy.gbl.GaudiPython.Helper.setPropertyFromString(
319 sc = prop.fromString(value)
321 raise AttributeError(
322 'property %s could not be set from %s' % (name, value))
324 if type(value) == str:
325 value =
'"%s"' % value
326 elif type(value) == tuple:
328 elif hasattr(value,
'toString'):
329 value = value.toString()
330 elif type(value) == long:
332 sp = gbl.GaudiPython.Helpers.mkStringProperty(name, str(value))
337 The method which returns the value for the given property 338 - In the case of the valid instance it returns the valid property value through IProperty interface 339 - In the case of placeholder the property value is retrieved from JobOptionsCatalogue 343 if not gbl.Gaudi.Utils.hasProperty(ip, name):
344 raise AttributeError(
'property %s does not exist' % name)
345 prop = ip.getProperty(name)
346 if StringProperty ==
type(prop):
348 elif StringPropertyRef ==
type(prop):
351 return eval(prop.toString(), {}, {})
355 props = self._optsvc.getProperties(self._name)
357 if not p.name() == name:
361 return eval(p.value(), {}, {})
364 raise AttributeError(
'property %s does not exist' % name)
371 props = ip.getProperties()
372 propsFrom = self._name
374 props = self._optsvc.getProperties(self._name)
375 propsFrom =
"jobOptionsSvc" 380 except (ValueError, TypeError)
as e:
381 raise ValueError(
"gaudimodule.iProperty.properties(): %s%s processing property %s.%s = %s" % \
382 (e.__class__.__name__, e.args,
383 propsFrom, p.name(), p.value()))
394 """ Python equivalent to IProperty interface """ 397 iProperty.__init__(self, name, isvc)
401 self.__dict__[
'_isvc'] =
None 404 isvc = Helper.service(self._svcloc, self._name)
406 iService.__init__(self, self._name, isvc)
437 """ Python equivalent to IAlgorithm interface """ 440 iProperty.__init__(self, name, ialg)
444 self.__dict__[
'_ialg'] =
None 447 ialg = Helper.algorithm(
450 iAlgorithm.__init__(self, self._name, ialg)
499 """ Python equivalent to IAlgTool interface (not completed yet) """ 502 iProperty.__init__(self, name, itool)
504 self.__dict__[
'_itool'] = itool
506 self.__dict__[
'_itool'] =
None 507 svc = Helper.service(self._svcloc,
'ToolSvc',
True)
508 self.__dict__[
'_toolsvc'] =
iToolSvc(
'ToolSvc', svc)
511 itool = self._toolsvc._retrieve(self._name)
513 iAlgTool.__init__(self, self._name, itool)
526 return self._itool.
name()
536 iService.__init__(self, name, idp)
537 self.__dict__[
'_idp'] =
InterfaceCast(gbl.IDataProviderSvc)(idp)
538 self.__dict__[
'_idm'] =
InterfaceCast(gbl.IDataManagerSvc)(idp)
542 raise AttributeError(
543 'C++ service %s does not exist' % self.__dict__[
'_name'])
544 return Helper.registerObject(self._idp, path, obj)
548 raise AttributeError(
549 'C++ service %s does not exist' % self.__dict__[
'_name'])
550 return Helper.unregisterObject(self._idp, path)
555 return Helper.dataobject(self._idp, path)
562 Get the existing object in TransientStore for the given location 564 - loading of object from persistency is NOT triggered 565 - 'data-on-demand' action is NOT triggered 567 >>> svc = ... ## get the service 568 >>> path = ... ## get the path in Transient Store 569 >>> data = svc.findObject ( path ) ## use the method 574 'C++ service %s does not exist' % self.__dict__[
'_name'])
575 return Helper.findobject(self._idp, path)
580 Get object from Transient Store for the given location 583 - path : Location of object in Transient Store 584 - retrieve (bool) True : retrieve versus find 585 - disable on-demand (bool) False : temporary disable 'on-demand' actions 587 >>> svc = ... ## get the service 588 >>> path = ... ## get the path 590 >>> data = svc.getObject ( path , False ) ## find object in Transient Store 592 ## find object in Transient Store 593 # load form tape or use 'on-demand' action for missing objects : 594 >>> data = svc.getObject ( path , True ) 596 ## find object in Transient Store 597 # load from tape or for missing objects, disable 'on-demand'-actions 598 >>> data = svc.getObject ( path , True , True ) 603 'C++ service %s does not exist' % self.__dict__[
'_name'])
604 return Helper.getobject(self._idp, path, *args)
609 'C++ service %s does not exist' % self.__dict__[
'_name'])
610 return Helper.dataobject(self._idp, path)
615 'C++ service %s does not exist' % self.__dict__[
'_name'])
621 'C++ service %s does not exist' % self.__dict__[
'_name'])
627 ll = gbl.std.vector(
'IRegistry*')()
628 if type(node)
is str:
632 if self._idm.objectLeaves(node, ll).isSuccess():
639 node = root.registry()
642 print(node.identifier())
644 for l
in self.
leaves(node):
647 def getList(self, node=None, lst=[], rootFID=None):
651 node = root.registry()
652 rootFID = node.address().
par()
656 Helper.dataobject(self._idp, node.identifier())
658 lst.append(node.identifier())
659 for l
in self.
leaves(node):
660 if l.address()
and l.address().
par() == rootFID:
670 node = root.registry()
675 Helper.dataobject(self._idp, node.identifier())
677 lst.append(node.identifier())
678 for l
in self.
leaves(node):
688 'C++ service %s does not exist' % self.__dict__[
'_name'])
689 return self._idm.
setRoot(name, obj)
694 'C++ service %s does not exist' % self.__dict__[
'_name'])
701 self.__dict__[
'_ihs'] =
InterfaceCast(gbl.IHistogramSvc)(ihs)
702 iDataSvc.__init__(self, name, ihs)
705 return Helper.histo1D(self._ihs, path)
708 return Helper.histo2D(self._ihs, path)
711 return Helper.histo3D(self._ihs, path)
714 return Helper.profile1D(self._ihs, path)
717 return Helper.profile2D(self._ihs, path)
721 Retrieve AIDA histogram or AIDA profile histogram by path in Histogram Transient Store 723 >>> histo = svc.retrieve ( 'path/to/my/histogram' ) 738 Book the histograms(1D,2D&3D) , see IHistogramSvc::book 740 >>> histo = svc.book( .... ) 742 return self._ihs.
book(*args)
746 Book the profile(1D&2D) histograms, see IHistogramSvc::bookProf 748 >>> histo = svc.bookProf( .... ) 754 Retrieve the object from Histogram Transient Store (by path) 755 The reference to AIDA histogram is returned (if possible) 757 >>> histo = svc['path/to/my/histogram'] 762 return iDataSvc.__getitem__(self, path)
766 Retrieve the histogram from Histogram Transient Store (by path) 767 The reference to AIDA histogram is returned (if possible) 769 >>> histo = svc.getAsAIDA ( 'path/to/my/histogram' ) 775 Retrieve the histogram from Histogram Transient Store (by path) 776 The Underlying native ROOT object is returned (if possible) 778 >>> histo = svc.getAsROOT ( 'path/to/my/histogram' ) 780 fun = gbl.Gaudi.Utils.Aida2ROOT.aida2root
793 iDataSvc.__init__(self, name, ints)
796 return self._ints.
book(*args)
799 """ Defines the mapping between logical names and the output file 801 defineOutput({'LUN1':'MyFile1.root', 'LUN2':'Myfile2.root'}, svc='Gaudi::RootCnvSvc') 803 from .
import Persistency
as prs
804 helper = prs.get(typ)
805 helper.configure(
AppMgr())
807 helper.formatOutput(files[lun], lun=lun)
for lun
in files
809 if AppMgr().HistogramPersistency ==
'NONE':
810 AppMgr().HistogramPersistency =
"ROOT" 813 return iDataSvc.__getitem__(self, path)
820 iService.__init__(self, name, its)
823 sol = _gaudi.OutputLevel
826 if name.rfind(
'.') == -1:
827 itool = Helper.tool(self._its,
'', name, nullptr,
False)
828 elif name[0:8] ==
'ToolSvc.':
829 itool = Helper.tool(self._its,
'', name[8:], nullptr,
False)
830 elif name.count(
'.') > 1:
831 ptool = self.
_retrieve(name[:name.rfind(
'.')])
832 itool = Helper.tool(self._its,
'', name[name.rfind(
'.') + 1:],
835 prop = _gaudi.property(name[:name.rfind(
'.')])
836 itool = Helper.tool(self._its,
'', name[name.rfind(
'.') + 1:],
845 def create(self, typ, name=None, parent=nullptr, interface=None):
848 itool = Helper.tool(self._its, typ, name, parent,
True)
855 if type(itool)
is iAlgTool:
856 self._its.releaseTool(itool._itool)
864 Python-image of C++ class IJobOptionsSvc 871 self.__dict__[
'_optsvc'] =
InterfaceCast(gbl.IJobOptionsSvc)(svc)
872 return iService.__init__(self, name, svc)
876 Extract *ALL* properties of the given component 878 >>> jos = gaudi.optSvc() 879 >>> props = jos.getProperties( 'Name' ) 886 prop = p.name().upper()
888 value = eval(p.value(), {}, {})
897 Get a certain property of the certain component 900 >>> extServices = jos.getProperty( 'ApplicationMgr', 'ExtSvc' ) 904 return all.get(name.upper(),
None)
913 self,
'EventSelector',
914 Helper.service(gbl.Gaudi.svcLocator(),
'EventSelector'))
915 self.__dict__[
'g'] =
AppMgr()
917 def open(self, stream, typ='Gaudi::RootCnvSvc
', **kwargs): 918 from .
import Persistency
as prs
919 helper = prs.get(typ)
920 helper.configure(self.g)
921 self.
Input = helper.formatInput(stream, **kwargs)
936 newobj = object.__new__(cls)
937 cls.
__init__(newobj, *args, **kwargs)
946 self._evtpro.release()
947 self._svcloc.release()
948 self._appmgr.release()
967 self.__dict__[
'_exit_called'] =
False 969 self.__dict__[
'_gaudi_ns'] = Gaudi
971 from GaudiKernel.Proxy.Configurable
import expandvars
977 if dllname
and factname:
978 self.__dict__[
'_appmgr'] = gbl.Gaudi.createApplicationMgr(
981 self.__dict__[
'_appmgr'] = gbl.Gaudi.createApplicationMgr(dllname)
983 self.__dict__[
'_appmgr'] = gbl.Gaudi.createApplicationMgr()
984 self.__dict__[
'_svcloc'] = gbl.Gaudi.svcLocator()
985 self.__dict__[
'_algmgr'] =
InterfaceCast(gbl.IAlgManager)(self._appmgr)
986 self.__dict__[
'_evtpro'] =
InterfaceCast(gbl.IEventProcessor)(
988 self.__dict__[
'_svcmgr'] =
InterfaceCast(gbl.ISvcManager)(self._appmgr)
989 self.__dict__[
'pyalgorithms'] = []
990 iService.__init__(self,
'ApplicationMgr', self._appmgr)
993 ) < Gaudi.StateMachine.CONFIGURED:
999 import GaudiKernel.Proxy.Configurable
1000 if hasattr(GaudiKernel.Proxy.Configurable,
1001 "applyConfigurableUsers"):
1002 GaudiKernel.Proxy.Configurable.applyConfigurableUsers()
1006 appMgr = Configurable.allConfigurables[
'ApplicationMgr']
1007 selfprops =
expandvars(appMgr.getValuedProperties())
1010 for p, v
in selfprops.items():
1012 for p, v
in selfoptions.items():
1015 if outputlevel != -1:
1019 ms = self.
service(
'MessageSvc')
1020 if 'MessageSvc' in Configurable.allConfigurables:
1021 msprops = Configurable.allConfigurables[
'MessageSvc']
1022 ms = self.
service(
'MessageSvc')
1023 if hasattr(msprops,
"getValuedProperties"):
1024 msprops =
expandvars(msprops.getValuedProperties())
1025 for p, v
in msprops.items():
1027 if outputlevel != -1:
1028 ms.OutputLevel = outputlevel
1030 self.__dict__[
'_optsvc'] =
InterfaceCast(gbl.IJobOptionsSvc)(
1031 Helper.service(self._svcloc,
'JobOptionsSvc'))
1033 mkStringProperty = gbl.GaudiPython.Helpers.mkStringProperty
1035 c = Configurable.allConfigurables[n]
1036 if n
in [
'ApplicationMgr',
'MessageSvc']:
1038 for p, v
in c.getValuedProperties().
items():
1041 if hasattr(Configurable,
"PropertyReference")
and type(
1042 v) == Configurable.PropertyReference:
1048 elif type(v) == long:
1051 n, mkStringProperty(p, str(v)))
1052 if hasattr(Configurable,
"_configurationLocked"):
1053 Configurable._configurationLocked =
True 1058 """Ensure that the exit method is called when exiting from Python, and 1059 try to ensure that ROOT doesn't intefere too much.""" 1061 atexit.register(self.
exit)
1064 exit_handlers = atexit._exithandlers
1065 except AttributeError:
1072 root_handler_installed =
False 1073 for h
in exit_handlers:
1075 if hasattr(func,
"__module__")
and func.__module__ ==
"ROOT":
1076 root_handler_installed =
True 1082 if not root_handler_installed:
1083 orig_register = atexit.register
1085 def register(func, *targs, **kargs):
1086 orig_register(func, *targs, **kargs)
1087 if hasattr(func,
"__module__")
and func.__module__ ==
"ROOT":
1088 orig_register(self.
exit)
1092 register.__doc__ = (
1093 orig_register.__doc__ +
1094 "\nNote: version hacked by GaudiPython to work " +
1095 "around a problem with the ROOT exit handler")
1096 atexit.register = register
1108 svc = Helper.service(self._svcloc, name)
1115 self._svcmgr.declareSvcType(svcname, svctype)
1118 return Helper.service(self._svcloc, name,
True)
1121 l = self._svcloc.getServices()
1122 return [s.name()
for s
in l]
1125 alg = Helper.algorithm(self._algmgr, name, createIf)
1132 l = self._algmgr.getAlgorithms()
1133 return [a.name()
for a
in l]
1147 if self.
state() == Gaudi.StateMachine.CONFIGURED:
1149 svc = Helper.service(self._svcloc, name)
1153 return self.
datasvc(
'EventDataSvc')
1156 return self.
datasvc(
'DetectorDataSvc')
1159 return self.
datasvc(
'FileRecordDataSvc')
1162 if self.
state() == Gaudi.StateMachine.CONFIGURED:
1164 if not hasattr(self,
'_evtsel'):
1169 svc = Helper.service(self._svcloc, name)
1173 if name
not in self.ExtSvc:
1174 self.ExtSvc += [name]
1176 svc = Helper.service(self._svcloc, name,
True)
1180 if self.
FSMState() == Gaudi.StateMachine.CONFIGURED:
1182 svc = Helper.service(self._svcloc,
'ParticlePropertySvc')
1186 svc = Helper.service(self._svcloc, name,
True)
1190 svc = Helper.service(self._svcloc, name,
True)
1197 """ Add an Algorithm to the list of Top algorithms. It can be either a instance of 1198 an Algorithm class or it name """ 1199 if type(alg)
is str:
1202 self.pyalgorithms.append(alg)
1208 self.
topAlg += [alg.name()]
1211 """ Set the list of Top Algorithms. 1212 It can be an individual of a list of algorithms names or instances """ 1213 if type(algs)
is not list:
1217 if type(alg)
is str:
1220 self.pyalgorithms.append(alg)
1225 names.append(alg.name())
1229 """ Remove an Algorithm to the list of Top algorithms. It can be either a instance of 1230 an Algorithm class or it name """ 1232 if type(alg)
is str:
1235 tmp.remove(alg.name())
1236 self.pyalgorithms.remove(alg)
1242 Print the sequence of Algorithms. 1245 def printAlgo(algName, appMgr, prefix=' '):
1246 print(prefix + algName)
1247 alg = appMgr.algorithm(algName.split(
"/")[-1])
1248 prop = alg.properties()
1249 if "Members" in prop:
1250 subs = prop[
"Members"].value()
1252 printAlgo(i.strip(
'"'), appMgr, prefix +
" ")
1255 prefix =
'ApplicationMgr SUCCESS ' 1258 "****************************** Algorithm Sequence ****************************" 1260 for i
in mp[
"TopAlg"].value():
1261 printAlgo(i, self, prefix)
1264 "******************************************************************************" 1269 Simple utility to perform the configuration of Gaudi application. 1270 It reads the set of input job-options files, and set few 1271 additional parameters 'options' through the usage of temporary *.opts file 1273 gaudi.config( files = [ '$GAUSSOPTS/Gauss.opts' , 1274 '$DECFILESROOT/options/10022_010.0GeV.opts' ] , 1275 options = [ 'EventSelector.PrintFreq = 5 ' ] ) 1277 files = args.get(
'files', [])
1281 raise RuntimeError(
' Unable to read file "' + file +
'" ')
1282 options = args.get(
'options',
None)
1285 tmpfilename = tempfile.mktemp()
1286 tmpfile = open(tmpfilename,
'w')
1287 tmpfile.write(
'#pragma print on \n')
1288 tmpfile.write(
'/// File "' + tmpfilename +
1289 '" generated by GaudiPython \n\n')
1291 if type(options)
is dict:
1292 tmpfile.write(
' \t ' + opt +
' = ' + options[opt] +
1293 ' ; // added by GaudiPython \n')
1295 tmpfile.write(
' \t ' + opt +
1296 ' ; // added by GaudiPython \n')
1297 tmpfile.write(
'/// End of file "' + tmpfilename +
1298 '" generated by GaudiPython \n\n')
1302 raise RuntimeError(
' Unable to read file "' + tmpfilename +
1304 os.remove(tmpfilename)
1307 if self.
FSMState() != Gaudi.StateMachine.OFFLINE:
1313 _dlls = jos.getProperty(self.
name(),
'DLLs')
1316 libs = [l
for l
in _dlls
if not l
in self.DLLs]
1321 _svcs = jos.getProperty(self.
name(),
'ExtSvc')
1324 svcs = [s
for s
in _svcs
if not s
in self.ExtSvc]
1329 props = jos.getProperties(self.
name())
1332 if 'DLLS' == key
or 'EXTSVC' == key:
1341 return self._appmgr.
start()
1347 if self.
FSMState() == Gaudi.StateMachine.CONFIGURED:
1349 if sc.isFailure()
or self.ReturnCode != 0:
1351 if self.
FSMState() == Gaudi.StateMachine.INITIALIZED:
1353 if sc.isFailure()
or self.ReturnCode != 0:
1364 if self.
FSMState() == Gaudi.StateMachine.CONFIGURED:
1368 if self.
FSMState() == Gaudi.StateMachine.INITIALIZED:
1373 if not hasattr(self,
'_perssvc'):
1374 self.__dict__[
'_perssvc'] = self.
service(
'EventPersistencySvc',
1376 if not hasattr(self,
'_filecat'):
1377 self.__dict__[
'_filecat'] = self.
service(
'FileCatalog',
1378 'Gaudi::IFileCatalog')
1379 if not hasattr(self,
'_evtmgr'):
1380 self.__dict__[
'_evtmgr'] = self.
service(
'EventDataSvc',
1383 if pfn.find(
'PFN:') == 0:
1387 if not self._filecat.existsFID(fid):
1388 self._filecat.registerPFN(fid, pfn,
'')
1390 if type(events)
is not list:
1394 gadd = gbl.GenericAddress(0x02, 1, fid,
'/Event', 0, evt)
1396 self._perssvc.createAddress(gadd.svcType(), gadd.clID(),
1397 gadd.par(), gadd.ipar(), oadd)
1399 self._evtmgr.clearStore()
1400 self._evtmgr.setRoot(
'/Event', oadd)
1405 if not self._exit_called:
1406 self.__dict__[
'_exit_called'] =
True 1407 Gaudi = self._gaudi_ns
1408 if self.
FSMState() == Gaudi.StateMachine.RUNNING:
1409 self._appmgr.
stop().ignore()
1410 if self.
FSMState() == Gaudi.StateMachine.INITIALIZED:
1412 if self.
FSMState() == Gaudi.StateMachine.CONFIGURED:
1423 ntupleSvc = ntuplesvc
1434 tfile = gbl.TFile.Open(pfn)
1436 raise IOError(
'Cannot open ROOT file {0}'.
format(pfn))
1437 tree = tfile.Get(
'##Params')
1439 text = tree.db_string
1440 if 'NAME=FID' in text:
1441 fid = text[text.rfind(
'VALUE=') + 6:-1]
1442 nevt = tfile.Get(
'_Event').GetEntries()
1451 """ Get all the properties of a component as a Python dictionary. 1452 The component is instantiated using the component library 1455 if name ==
'GaudiCoreSvc':
1456 if Helper.loadDynamicLib(name) != 1:
1457 raise ImportError(
'Error loading component library ' + name)
1458 factorylist = gbl.FactoryTable.instance().getEntries()
1460 g =
AppMgr(outputlevel=7)
1462 g =
AppMgr(outputlevel=7)
1463 if Helper.loadDynamicLib(name) != 1:
1464 raise ImportError(
'Error loading component library ' + name)
1465 factorylist = gbl.FactoryTable.instance().getEntries()
1467 svcloc = gbl.Gaudi.svcLocator()
1468 dummysvc = gbl.Service(
'DummySvc', svcloc)
1469 for factory
in factories:
1476 elif factory.ident() ==
'ApplicationMgr':
1477 ctype =
'ApplicationMgr' 1480 cname = factory.ident().split()[-1]
1481 if ctype
in (
'Algorithm',
'Service',
'AlgTool',
'ApplicationMgr'):
1483 if ctype ==
'AlgTool':
1484 obj = factory.instantiate(dummysvc)
1486 obj = factory.instantiate(svcloc)
1487 except RuntimeError
as text:
1488 print(
'Error instantiating', cname,
' from ', name)
1492 properties[cname] = [ctype, prop.properties()]
1502 for i
in range(factories.size()):
1503 factory = factories.front()
1504 result.append(factory)
1505 factories.pop_front()
1506 for factory
in result:
1507 factories.push_back(factory)
1513 _CallbackStreamBufBase = gbl.GaudiPython.CallbackStreamBuf
1518 _CallbackStreamBufBase.__init__(self, self)
1530 _PyAlgorithm = gbl.GaudiPython.PyAlgorithm
1536 name = self.__class__.__name__
1537 _PyAlgorithm.__init__(self, self, name)
1540 sc = self.
_algmgr.addAlgorithm(self)
1542 raise RuntimeError(
'Unable to add Algorithm')
1545 sc = self.
_algmgr.removeAlgorithm(self)
1569 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)