The Gaudi Framework  v36r10 (fc05264c)
Bindings.py
Go to the documentation of this file.
1 
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.
17 """
18 from __future__ import absolute_import, print_function
19 
20 __all__ = [
21  "gbl",
22  "InterfaceCast",
23  "Interface",
24  "PropertyEntry",
25  "AppMgr",
26  "PyAlgorithm",
27  "CallbackStreamBuf",
28  "iAlgorithm",
29  "iDataSvc",
30  "iHistogramSvc",
31  "iNTupleSvc",
32  "iService",
33  "iAlgTool",
34  "Helper",
35  "SUCCESS",
36  "FAILURE",
37  "toArray",
38  "ROOT",
39  "makeNullPointer",
40  "setOwnership",
41  "getClass",
42  "loaddict",
43  "deprecation",
44 ]
45 
46 import os
47 import re
48 import string
49 import sys
50 import warnings
51 
52 from GaudiKernel import ROOT6WorkAroundEnabled
53 
54 # Workaround for ROOT-10769
55 with warnings.catch_warnings():
56  warnings.simplefilter("ignore")
57  import cppyy
58 
59 if sys.version_info >= (3,):
60  # Python 2 compatibility
61  long = int
62 
63 if ROOT6WorkAroundEnabled("ROOT-5478"):
64  # Trigger the loading of GaudiKernelDict
65  cppyy.gbl.DataObject
66  # Trigger the loading of GaudiPythonDict
67  cppyy.gbl.Chrono
68 
69 # Import Configurable from AthenaCommon or GaudiKernel if the first is not
70 # available.
71 from GaudiKernel.Proxy.Configurable import Configurable, getNeededConfigurables
72 
73 from . import Pythonizations
74 
75 # namespaces
76 gbl = cppyy.gbl
77 Gaudi = gbl.Gaudi
78 
79 _gaudi = None
80 
81 # ---- Useful shortcuts for classes -------------------------------------------
82 gbl.gInterpreter.Declare('#include "Gaudi/Property.h"')
83 Helper = gbl.GaudiPython.Helper
84 StringProperty = gbl.Gaudi.Property("std::string")
85 StringPropertyRef = gbl.Gaudi.Property("std::string&")
86 GaudiHandleProperty = gbl.GaudiHandleProperty
87 GaudiHandleArrayProperty = gbl.GaudiHandleArrayProperty
88 DataObject = gbl.DataObject
89 SUCCESS = gbl.StatusCode(gbl.StatusCode.SUCCESS)
90 FAILURE = gbl.StatusCode(gbl.StatusCode.FAILURE)
91 # Workaround for ROOT-10770
92 if hasattr(cppyy, "nullptr"):
93  nullptr = cppyy.nullptr
94 elif hasattr(gbl, "nullptr"):
95  nullptr = gbl.nullptr
96 else:
97  nullptr = None
98 # Helper to create a StringProperty
99 cppyy.gbl.gInterpreter.Declare(
100  """
101 #include <stdexcept>
102 namespace GaudiPython { namespace Helpers {
103  void setProperty(ISvcLocator* svcLoc, std::string key, std::string value) {
104  if ( !svcLoc ) throw std::runtime_error( "invalid ISvcLocator pointer" );
105  svcLoc->getOptsSvc().set(key, value);
106  }
107 }}
108 """
109 )
110 
111 # toIntArray, toShortArray, etc.
112 for l in [l for l in dir(Helper) if re.match("^to.*Array$", l)]:
113  exec("%s = Helper.%s" % (l, l))
114  __all__.append(l)
115 
116 # FIXME: (MCl) Hack to handle ROOT 5.18 and ROOT >= 5.20
117 if hasattr(Helper, "toArray"):
118  # This is not backward compatible, but allows to use the same signature
119  # with all the versions of ROOT.
120  def toArray(typ):
121  return getattr(Helper, "toArray")
122 
123 else:
124  # forward to the actual implementation of GaudiPython::Helper::toArray<T>
125  def toArray(typ):
126  return getattr(Helper, "toArray<%s>" % typ)
127 
128 
129 # ----Convenient accessors to PyROOT functionality ----------------------------
130 # See https://sft.its.cern.ch/jira/browse/ROOT-10771
131 if hasattr(cppyy, "libPyROOT"):
132  ROOT = cppyy.libPyROOT
133 else:
134  import ROOT
135 makeNullPointer = ROOT.MakeNullPointer
136 setOwnership = ROOT.SetOwnership
137 
138 
139 def deprecation(message):
140  warnings.warn("GaudiPython: " + message, DeprecationWarning, stacklevel=3)
141 
142 
143 # ----InterfaceCast class -----------------------------------------------------
144 
145 
146 class InterfaceCast(object):
147  """Helper class to obtain the adequate interface from a component
148  by using the Gaudi queryInterface() mechanism"""
149 
150  def __init__(self, t):
151  if type(t) is str:
152  t = getattr(gbl, t)
153  self.type = t
154 
155  def __call__(self, obj):
156  if obj:
157  ip = makeNullPointer(self.type)
158  try:
159  if obj.queryInterface(self.type.interfaceID(), ip).isSuccess():
160  return ip
161  else:
162  print(
163  "ERROR: queryInterface failed for", obj, "interface:", self.type
164  )
165  except Exception as e:
166  print(
167  "ERROR: exception",
168  e,
169  "caught when retrieving interface",
170  self.type,
171  "for object",
172  obj,
173  )
174  import traceback
175 
176  traceback.print_stack()
177  return cppyy.nullptr
178 
179  cast = __call__
180 
181 
182 # ---Interface class (for backward compatibility)------------------------------
183 
184 
186  def __init__(self, t):
187  deprecation("Use InterfaceCast class instead")
188  InterfaceCast.__init__(self, t)
189 
190  def cast(self, obj):
191  return self(obj)
192 
193 
194 # ----load dictionary function using Gaudi function----------------------------
195 
196 
197 def loaddict(dict):
198  """Load an LCG dictionary"""
199  loadlib_return_code = Helper.loadDynamicLib(dict)
200  if loadlib_return_code == 1:
201  return
202  raise RuntimeError(
203  f"Failed to load dictionary library {dict} (return code {loadlib_return_code})"
204  )
205 
206 
207 # ---get a class (by loading modules if needed)--------------------------------
208 
209 
210 def getClass(name, libs=[]):
211  """
212  Function to retrieve a certain C++ class by name and to load dictionary if requested
213 
214  Usage:
215 
216  from gaudimodule import getClass
217  # one knows that class is already loaded
218  AppMgr = getClass( 'ApplicationMgr' )
219  # one knows where to look for class, if not loaded yet
220  MCParticle = getClass( 'MCParticle' , 'EventDict' )
221  # one knows where to look for class, if not loaded yet
222  Vertex = getClass( 'Vertex' , ['EventDict', 'PhysEventDict'] )
223  """
224  # see if class is already loaded
225  if hasattr(gbl, name):
226  return getattr(gbl, name)
227  # try to load dictionaries and look for the required class
228  if type(libs) is not list:
229  libs = [libs]
230  for lib in libs:
231  loaddict(lib)
232  if hasattr(gbl, name):
233  return getattr(gbl, name)
234  # return None ( or raise exception? I do not know... )
235  return None
236 
237 
238 # ----PropertyEntry class------------------------------------------------------
239 
240 
241 class PropertyEntry(object):
242  """holds the value and the documentation string of a property"""
243 
244  def __init__(self, prop):
245  self._type = type(prop).__name__
246  self.__doc__ = " --- Property type is " + self.ptype()
247 
248  if issubclass(type(prop), GaudiHandleProperty):
249  self._value = prop.value() # do nothing for ATLAS' handles
250  elif issubclass(type(prop), GaudiHandleArrayProperty):
251  self._value = prop.value() # do nothing for ATLAS' handles
252  else:
253  # for all other types try to extract the native python type
254  try:
255  self._value = eval(prop.toString(), {}, {})
256  except:
257  if hasattr(prop, "value"):
258  self._value = prop.value()
259  else:
260  self._value = prop.toString()
261 
262  self.__doc__ += " --- Default value = " + str(self._value) + " --- "
263  if prop.documentation() != "none":
264  self.__doc__ = prop.documentation() + "\\n" + self.__doc__
265  # keep the original property
266  self._property = prop # property itself
267 
268  def value(self):
269  return self._value
270 
271  def ptype(self):
272  return self._type
273 
274  def property(self):
275  "Return the underlying property itself"
276  return self._property
277 
278  def documentation(self):
279  return self.__doc__
280 
281  def hasDoc(self):
282  return len(self.__doc__) > 0 and self.__doc__ != "none"
283 
284 
285 # ----iProperty class----------------------------------------------------------
286 
287 
288 class iProperty(object):
289  """Python equivalent to the C++ Property interface"""
290 
291  def __init__(self, name, ip=cppyy.nullptr):
292  self.__dict__["_ip"] = InterfaceCast(gbl.IProperty)(ip)
293  self.__dict__["_svcloc"] = gbl.Gaudi.svcLocator()
294  self.__dict__["_name"] = name
295 
296  def getInterface(self):
297  if not self._ip:
298  self.retrieveInterface()
299  return self._ip
300 
301  def retrieveInterface(self):
302  pass
303 
304  def __call_interface_method__(self, ifname, method, *args):
305  if not getattr(self, ifname):
306  self.retrieveInterface()
307  return getattr(getattr(self, ifname), method)(*args)
308 
309  def __setattr__(self, name, value):
310  """
311  The method which is used for setting the property from the given value.
312  - In the case of the valid instance it sets the property through IProperty interface
313  - In the case of placeholder the property is added to JobOptionsCatalogue
314  """
315  if hasattr(value, "toStringProperty"):
316  # user defined behaviour
317  value = str(value.toStringProperty())
318  elif hasattr(value, "toString"):
319  value = str(value.toString())
320  elif type(value) == long:
321  value = "%d" % value # prevent pending 'L'
322  else:
323  value = str(value)
324 
325  ip = self.getInterface()
326  if ip:
327  if not gbl.Gaudi.Utils.hasProperty(ip, name):
328  raise AttributeError("property %s does not exist" % name)
329  ip.setPropertyRepr(name, value)
330  else:
331  gbl.GaudiPython.Helpers.setProperty(
332  self._svcloc, ".".join([self._name, name]), value
333  )
334 
335  def __getattr__(self, name):
336  """
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
340  """
341  ip = self.getInterface()
342  if ip:
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):
347  return prop.value()
348  elif StringPropertyRef == type(prop):
349  return prop.value()
350  try:
351  return eval(prop.toString(), {}, {})
352  except:
353  return prop.value()
354  else:
355  opts = self._svcloc.getOptsSvc()
356  if opts.has("{}.{}".format(self._name, name)):
357  # from JobOptionsSvc we always have only strings
358  return eval(opts.get("{}.{}".format(self._name, name)), {}, {})
359  raise AttributeError("property %s does not exist" % name)
360 
361  def properties(self):
362  dct = {}
363  props = None
364  ip = self.getInterface()
365  if ip:
366  props = ip.getProperties()
367  propsFrom = self._name # "interface"
368  else:
369  raise NotImplementedError("rely on IJobOptionsSvc")
370  props = self._optsvc.getProperties(self._name)
371  propsFrom = "jobOptionsSvc"
372  if props:
373  for p in props:
374  try:
375  dct[p.name()] = PropertyEntry(p)
376  except (ValueError, TypeError) as e:
377  raise ValueError(
378  "gaudimodule.iProperty.properties(): %s%s processing property %s.%s = %s"
379  % (e.__class__.__name__, e.args, propsFrom, p.name(), p.value())
380  )
381  return dct
382 
383  def name(self):
384  return self._name
385 
386 
387 # ----iService class-----------------------------------------------------------
388 
389 
391  """Python equivalent to IProperty interface"""
392 
393  def __init__(self, name, isvc=cppyy.nullptr):
394  iProperty.__init__(self, name, isvc)
395  self.__dict__["_isvc"] = InterfaceCast(gbl.IService)(isvc)
396 
397  def retrieveInterface(self):
398  isvc = Helper.service(self._svcloc, self._name)
399  if isvc:
400  iService.__init__(self, self._name, isvc)
401 
402  def initialize(self):
403  return self.__call_interface_method__("_isvc", "initialize")
404 
405  def start(self):
406  return self.__call_interface_method__("_isvc", "start")
407 
408  def stop(self):
409  return self.__call_interface_method__("_isvc", "stop")
410 
411  def finalize(self):
412  return self.__call_interface_method__("_isvc", "finalize")
413 
414  def reinitialize(self):
415  return self.__call_interface_method__("_isvc", "reinitialize")
416 
417  def restart(self):
418  return self.__call_interface_method__("_isvc", "restart")
419 
420  def isValid(self):
421  if self._isvc:
422  return True
423  else:
424  return False
425 
426 
427 # ----iAlgorithm class---------------------------------------------------------
428 
429 
431  """Python equivalent to IAlgorithm interface"""
432 
433  def __init__(self, name, ialg=cppyy.nullptr):
434  iProperty.__init__(self, name, ialg)
435  self.__dict__["_ialg"] = InterfaceCast(gbl.IAlgorithm)(ialg)
436 
437  def retrieveInterface(self):
438  ialg = Helper.algorithm(
439  InterfaceCast(gbl.IAlgManager)(self._svcloc), self._name
440  )
441  if ialg:
442  iAlgorithm.__init__(self, self._name, ialg)
443 
444  def initialize(self):
445  return self.__call_interface_method__("_ialg", "initialize")
446 
447  def start(self):
448  return self.__call_interface_method__("_ialg", "start")
449 
450  def execute(self):
451  return self.__call_interface_method__("_ialg", "execute")
452 
453  def stop(self):
454  return self.__call_interface_method__("_ialg", "stop")
455 
456  def finalize(self):
457  return self.__call_interface_method__("_ialg", "finalize")
458 
459  def reinitialize(self):
460  return self.__call_interface_method__("_ialg", "reinitialize")
461 
462  def restart(self):
463  return self.__call_interface_method__("_ialg", "restart")
464 
465  def sysInitialize(self):
466  return self.__call_interface_method__("_ialg", "sysInitialize")
467 
468  def sysStart(self):
469  return self.__call_interface_method__("_ialg", "sysStart")
470 
471  def sysExecute(self):
472  return self.__call_interface_method__("_ialg", "sysExecute")
473 
474  def sysStop(self):
475  return self.__call_interface_method__("_ialg", "sysStop")
476 
477  def sysFinalize(self):
478  return self.__call_interface_method__("_ialg", "sysFinalize")
479 
480  def sysReinitialize(self):
481  return self.__call_interface_method__("_ialg", "sysReinitialize")
482 
483  def sysRestart(self):
484  return self.__call_interface_method__("_ialg", "sysRestart")
485 
486 
487 # ----iAlgTool class-----------------------------------------------------------
488 
489 
491  """Python equivalent to IAlgTool interface (not completed yet)"""
492 
493  def __init__(self, name, itool=cppyy.nullptr):
494  iProperty.__init__(self, name, itool)
495  self.__dict__["_itool"] = itool
496  svc = Helper.service(self._svcloc, "ToolSvc", True)
497  self.__dict__["_toolsvc"] = iToolSvc("ToolSvc", svc)
498 
499  def retrieveInterface(self):
500  itool = self._toolsvc._retrieve(self._name)
501  if itool:
502  iAlgTool.__init__(self, self._name, itool)
503 
504  def start(self):
505  return self.__call_interface_method__("_itool", "start")
506 
507  def stop(self):
508  return self.__call_interface_method__("_itool", "stop")
509 
510  def type(self):
511  return self.__call_interface_method__("_itool", "type")
512 
513  def name(self):
514  if self._itool:
515  return self._itool.name()
516  else:
517  return self._name
518 
519 
520 # ----iDataSvc class-----------------------------------------------------------
521 
522 
524  def __init__(self, name, idp):
525  iService.__init__(self, name, idp)
526  self.__dict__["_idp"] = InterfaceCast(gbl.IDataProviderSvc)(idp)
527  self.__dict__["_idm"] = InterfaceCast(gbl.IDataManagerSvc)(idp)
528 
529  def registerObject(self, path, obj):
530  if not self._idp:
531  raise AttributeError(
532  "C++ service %s does not exist" % self.__dict__["_name"]
533  )
534  return Helper.registerObject(self._idp, path, obj)
535 
536  def unregisterObject(self, path):
537  if not self._idp:
538  raise AttributeError(
539  "C++ service %s does not exist" % self.__dict__["_name"]
540  )
541  return Helper.unregisterObject(self._idp, path)
542 
543  def retrieveObject(self, path):
544  if not self._idp:
545  return cppyy.nullptr
546  return Helper.dataobject(self._idp, path)
547 
548  # get object from TES
549 
550  def findObject(self, path):
551  """
552 
553  Get the existing object in TransientStore for the given location
554 
555  - loading of object from persistency is NOT triggered
556  - 'data-on-demand' action is NOT triggered
557 
558  >>> svc = ... ## get the service
559  >>> path = ... ## get the path in Transient Store
560  >>> data = svc.findObject ( path ) ## use the method
561 
562  """
563  if not self._idp:
564  raise IndexError("C++ service %s does not exist" % self.__dict__["_name"])
565  return Helper.findobject(self._idp, path)
566 
567  # get or retrieve object, possible switch-off 'on-demand' actions
568  def getObject(self, path, *args):
569  """
570  Get object from Transient Store for the given location
571 
572  arguments :
573  - path : Location of object in Transient Store
574  - retrieve (bool) True : retrieve versus find
575  - disable on-demand (bool) False : temporary disable 'on-demand' actions
576 
577  >>> svc = ... ## get the service
578  >>> path = ... ## get the path
579 
580  >>> data = svc.getObject ( path , False ) ## find object in Transient Store
581 
582  ## find object in Transient Store
583  # load form tape or use 'on-demand' action for missing objects :
584  >>> data = svc.getObject ( path , True )
585 
586  ## find object in Transient Store
587  # load from tape or for missing objects, disable 'on-demand'-actions
588  >>> data = svc.getObject ( path , True , True )
589 
590  """
591  if not self._idp:
592  raise IndexError("C++ service %s does not exist" % self.__dict__["_name"])
593  return Helper.getobject(self._idp, path, *args)
594 
595  def __getitem__(self, path):
596  if not self._idp:
597  raise IndexError("C++ service %s does not exist" % self.__dict__["_name"])
598  return Helper.dataobject(self._idp, path)
599 
600  def __setitem__(self, path, obj):
601  if not self._idp:
602  raise IndexError("C++ service %s does not exist" % self.__dict__["_name"])
603  return self.registerObject(path, obj)
604 
605  def __delitem__(self, path):
606  if not self._idp:
607  raise IndexError("C++ service %s does not exist" % self.__dict__["_name"])
608  return self.unregisterObject(path)
609 
610  def leaves(self, node=cppyy.nullptr):
611  if node == cppyy.nullptr:
612  node = self.retrieveObject("")
613  ll = gbl.std.vector("IRegistry*")()
614  if type(node) is str:
615  obj = self.retrieveObject(node)
616  else:
617  obj = node
618  if self._idm.objectLeaves(node, ll).isSuccess():
619  return ll
620 
621  def dump(self, node=cppyy.nullptr):
622  if node == cppyy.nullptr:
623  root = self.retrieveObject("")
624  if root:
625  node = root.registry()
626  else:
627  return
628  print(node.identifier())
629  if node.object():
630  for l in self.leaves(node):
631  self.dump(l)
632 
633  def getList(self, node=cppyy.nullptr, lst=[], rootFID=None):
634  if node == cppyy.nullptr:
635  root = self.retrieveObject("")
636  if root:
637  node = root.registry()
638  rootFID = node.address().par()
639  lst = []
640  else:
641  return
642  Helper.dataobject(self._idp, node.identifier())
643  if node.object():
644  lst.append(node.identifier())
645  for l in self.leaves(node):
646  if l.address() and l.address().par() == rootFID:
647  self.getList(l, lst, rootFID)
648  else:
649  continue
650  return lst
651 
652  def getHistoNames(self, node=cppyy.nullptr, lst=[]):
653  if node == cppyy.nullptr:
654  root = self.retrieveObject("")
655  if root:
656  node = root.registry()
657  # rootFID = node.address().par()
658  lst = []
659  else:
660  return
661  Helper.dataobject(self._idp, node.identifier())
662  if node.object():
663  lst.append(node.identifier())
664  for l in self.leaves(node):
665  if l.name(): # and l.address().par() == rootFID :
666  self.getHistoNames(l, lst)
667  else:
668  continue
669  return lst
670 
671  def setRoot(self, name, obj):
672  if not self._idm:
673  raise IndexError("C++ service %s does not exist" % self.__dict__["_name"])
674  return self._idm.setRoot(name, obj)
675 
676  def clearStore(self):
677  if not self._idm:
678  raise IndexError("C++ service %s does not exist" % self.__dict__["_name"])
679  return self._idm.clearStore()
680 
681 
682 # ----iHistogramSvc class------------------------------------------------------
684  def __init__(self, name, ihs):
685  self.__dict__["_ihs"] = InterfaceCast(gbl.IHistogramSvc)(ihs)
686  iDataSvc.__init__(self, name, ihs)
687 
688  def retrieve1D(self, path):
689  return Helper.histo1D(self._ihs, path)
690 
691  def retrieve2D(self, path):
692  return Helper.histo2D(self._ihs, path)
693 
694  def retrieve3D(self, path):
695  return Helper.histo3D(self._ihs, path)
696 
697  def retrieveProfile1D(self, path):
698  return Helper.profile1D(self._ihs, path)
699 
700  def retrieveProfile2D(self, path):
701  return Helper.profile2D(self._ihs, path)
702 
703  def retrieve(self, path):
704  """
705  Retrieve AIDA histogram or AIDA profile histogram by path in Histogram Transient Store
706  >>> svc = ...
707  >>> histo = svc.retrieve ( 'path/to/my/histogram' )
708  """
709  h = self.retrieve1D(path)
710  if not h:
711  h = self.retrieve2D(path)
712  if not h:
713  h = self.retrieve3D(path)
714  if not h:
715  h = self.retrieveProfile1D(path)
716  if not h:
717  h = self.retrieveProfile2D(path)
718  return h
719 
720  def book(self, *args):
721  """
722  Book the histograms(1D,2D&3D) , see IHistogramSvc::book
723  >>> svc = ...
724  >>> histo = svc.book( .... )
725  """
726  return self._ihs.book(*args)
727 
728  def bookProf(self, *args):
729  """
730  Book the profile(1D&2D) histograms, see IHistogramSvc::bookProf
731  >>> svc = ...
732  >>> histo = svc.bookProf( .... )
733  """
734  return self._ihs.bookProf(*args)
735 
736  def __getitem__(self, path):
737  """
738  Retrieve the object from Histogram Transient Store (by path)
739  The reference to AIDA histogram is returned (if possible)
740  >>> svc = ...
741  >>> histo = svc['path/to/my/histogram']
742  """
743  h = self.retrieve(path)
744  if h:
745  return h
746  return iDataSvc.__getitem__(self, path)
747 
748  def getAsAIDA(self, path):
749  """
750  Retrieve the histogram from Histogram Transient Store (by path)
751  The reference to AIDA histogram is returned (if possible)
752  >>> svc = ...
753  >>> histo = svc.getAsAIDA ( 'path/to/my/histogram' )
754  """
755  return self.__getitem__(path)
756 
757  def getAsROOT(self, path):
758  """
759  Retrieve the histogram from Histogram Transient Store (by path)
760  The Underlying native ROOT object is returned (if possible)
761  >>> svc = ...
762  >>> histo = svc.getAsROOT ( 'path/to/my/histogram' )
763  """
764  fun = gbl.Gaudi.Utils.Aida2ROOT.aida2root
765  return fun(self.getAsAIDA(path))
766 
767 
768 # ----iNTupleSvc class---------------------------------------------------------
769 
770 
772  RowWiseTuple = 42
773  ColumnWiseTuple = 43
774 
775  def __init__(self, name, ints):
776  self.__dict__["_ints"] = InterfaceCast(gbl.INTupleSvc)(ints)
777  iDataSvc.__init__(self, name, ints)
778 
779  def book(self, *args):
780  return self._ints.book(*args)
781 
782  def defineOutput(self, files, typ="Gaudi::RootCnvSvc"):
783  """Defines the mapping between logical names and the output file
784  Usage:
785  defineOutput({'LUN1':'MyFile1.root', 'LUN2':'Myfile2.root'}, svc='Gaudi::RootCnvSvc')
786  """
787  from . import Persistency as prs
788 
789  helper = prs.get(typ)
790  helper.configure(AppMgr())
791  self.Output = [helper.formatOutput(files[lun], lun=lun) for lun in files]
792  if AppMgr().HistogramPersistency == "NONE":
793  AppMgr().HistogramPersistency = "ROOT"
794 
795  def __getitem__(self, path):
796  return iDataSvc.__getitem__(self, path)
797 
798 
799 # ----iToolSvc class-----------------------------------------------------------
801  def __init__(self, name, its):
802  self.__dict__["_its"] = InterfaceCast(gbl.IToolSvc)(its)
803  iService.__init__(self, name, its)
804 
805  def _retrieve(self, name, quiet=True):
806  sol = _gaudi.OutputLevel
807  if quiet:
808  self.OutputLevel = 6
809  if name.rfind(".") == -1:
810  itool = Helper.tool(self._its, "", name, nullptr, False)
811  elif name[0:8] == "ToolSvc.":
812  itool = Helper.tool(self._its, "", name[8:], nullptr, False)
813  elif name.count(".") > 1:
814  ptool = self._retrieve(name[: name.rfind(".")])
815  itool = Helper.tool(
816  self._its, "", name[name.rfind(".") + 1 :], ptool, False
817  )
818  elif _gaudi:
819  prop = _gaudi.property(name[: name.rfind(".")])
820  itool = Helper.tool(
821  self._its, "", name[name.rfind(".") + 1 :], prop._ip, False
822  )
823  if quiet:
824  self.OutputLevel = sol
825  return itool
826 
827  def retrieve(self, name):
828  return iAlgTool(name, self._retrieve(name, quiet=False))
829 
830  def create(self, typ, name=None, parent=nullptr, interface=None):
831  if not name:
832  name = typ
833  itool = Helper.tool(self._its, typ, name, parent, True)
834  if interface:
835  return InterfaceCast(interface)(itool)
836  else:
837  return iAlgTool(name, itool)
838 
839  def release(self, itool):
840  if type(itool) is iAlgTool:
841  self._its.releaseTool(itool._itool)
842 
843 
844 # ----iEventSelector class-----------------------------------------------------
845 
846 
848  def __init__(self):
849  iService.__init__(
850  self,
851  "EventSelector",
852  Helper.service(gbl.Gaudi.svcLocator(), "EventSelector"),
853  )
854  self.__dict__["g"] = AppMgr()
855 
856  def open(self, stream, typ="Gaudi::RootCnvSvc", **kwargs):
857  from . import Persistency as prs
858 
859  helper = prs.get(typ)
860  helper.configure(self.g)
861  self.Input = helper.formatInput(stream, **kwargs)
862  self.reinitialize()
863 
864  def rewind(self):
865  # It is not possible to reinitialize EventSelector only
866  self.g.service("EventLoopMgr").reinitialize()
867 
868 
869 # ----AppMgr class-------------------------------------------------------------
870 
871 
873  def __new__(cls, *args, **kwargs):
874  global _gaudi
875  if not _gaudi:
876  newobj = object.__new__(cls)
877  cls.__init__(newobj, *args, **kwargs)
878  _gaudi = newobj
879  return _gaudi
880 
881  def __reset__(self):
882  global _gaudi
883  # Stop, Finalize and Terminate the current AppMgr
884  self.exit()
885  # release interfaces
886  self._evtpro.release()
887  self._svcloc.release()
888  self._appmgr.release()
889  # Reset the C++ globals
890  gbl.Gaudi.setInstance(makeNullPointer("ISvcLocator"))
891  gbl.Gaudi.setInstance(makeNullPointer("IAppMgrUI"))
892  # Reset the Python global
893  _gaudi = None
894 
895  def __init__(
896  self,
897  outputlevel=-1,
898  joboptions=None,
899  selfoptions={},
900  dllname=None,
901  factname=None,
902  ):
903  global _gaudi
904  if _gaudi:
905  return
906  # Make sure the python stdout buffer is flushed before c++ runs
907  sys.stdout.flush()
908  # Protection against multiple calls to exit() if the finalization fails
909  self.__dict__["_exit_called"] = False
910  # keep the Gaudi namespace around (so it is still available during atexit shutdown)...
911  self.__dict__["_gaudi_ns"] = Gaudi
912  try:
913  from GaudiKernel.Proxy.Configurable import expandvars
914  except ImportError:
915  # pass-through implementation if expandvars is not defined (AthenaCommon)
916  def expandvars(data):
917  return data
918 
919  if dllname and factname:
920  self.__dict__["_appmgr"] = gbl.Gaudi.createApplicationMgr(dllname, factname)
921  elif dllname:
922  self.__dict__["_appmgr"] = gbl.Gaudi.createApplicationMgr(dllname)
923  else:
924  self.__dict__["_appmgr"] = gbl.Gaudi.createApplicationMgr()
925  self.__dict__["_svcloc"] = gbl.Gaudi.svcLocator()
926  self.__dict__["_algmgr"] = InterfaceCast(gbl.IAlgManager)(self._appmgr)
927  self.__dict__["_evtpro"] = InterfaceCast(gbl.IEventProcessor)(self._appmgr)
928  self.__dict__["_svcmgr"] = InterfaceCast(gbl.ISvcManager)(self._appmgr)
929  self.__dict__["pyalgorithms"] = []
930  iService.__init__(self, "ApplicationMgr", self._appmgr)
931  # ------python specific initialization-------------------------------------
932  if self.FSMState() < Gaudi.StateMachine.CONFIGURED: # Not yet configured
933  self.JobOptionsType = "NONE"
934  if joboptions:
935  from GaudiKernel.ProcessJobOptions import importOptions
936 
937  importOptions(joboptions)
938  # Ensure that the ConfigurableUser instances have been applied
939  import GaudiKernel.Proxy.Configurable
940 
941  if hasattr(GaudiKernel.Proxy.Configurable, "applyConfigurableUsers"):
942  GaudiKernel.Proxy.Configurable.applyConfigurableUsers()
943  # This is the default and could be overridden with "selfopts"
944  self.OutputLevel = 3
945  try:
946  appMgr = Configurable.allConfigurables["ApplicationMgr"]
947  selfprops = expandvars(appMgr.getValuedProperties())
948  except KeyError:
949  selfprops = {}
950  for p, v in selfprops.items():
951  setattr(self, p, v)
952  for p, v in selfoptions.items():
953  setattr(self, p, v)
954  # Override job options
955  if outputlevel != -1:
956  self.OutputLevel = outputlevel
957  self.configure()
958  # ---MessageSvc------------------------------------------------------------
959  ms = self.service("MessageSvc")
960  if "MessageSvc" in Configurable.allConfigurables:
961  msprops = Configurable.allConfigurables["MessageSvc"]
962  ms = self.service("MessageSvc")
963  if hasattr(msprops, "getValuedProperties"):
964  msprops = expandvars(msprops.getValuedProperties())
965  for p, v in msprops.items():
966  setattr(ms, p, v)
967  if outputlevel != -1:
968  ms.OutputLevel = outputlevel
969  # ------Configurables initialization (part2)-------------------------------
970  for n in getNeededConfigurables():
971  c = Configurable.allConfigurables[n]
972  if n in ["ApplicationMgr", "MessageSvc"]:
973  continue # These are already done---
974  for p, v in c.getValuedProperties().items():
975  v = expandvars(v)
976  # Note: AthenaCommon.Configurable does not have Configurable.PropertyReference
977  if (
978  hasattr(Configurable, "PropertyReference")
979  and type(v) == Configurable.PropertyReference
980  ):
981  # this is done in "getFullName", but the exception is ignored,
982  # so we do it again to get it
983  v = v.__resolve__()
984  if type(v) == str:
985  v = repr(v) # need double quotes
986  if type(v) == long:
987  v = "%d" % v # prevent pending 'L'
988  gbl.GaudiPython.Helpers.setProperty(
989  self._svcloc, ".".join([n, p]), str(v)
990  )
991  if hasattr(Configurable, "_configurationLocked"):
992  Configurable._configurationLocked = True
993 
994  # Ensure that the exit method is called when exiting from Python
995  import atexit
996 
997  atexit.register(self.exit)
998 
999  # ---Hack to avoid bad interactions with the ROOT exit handler
1000  # let's install a private version of atexit.register that detects when
1001  # the ROOT exit handler is installed and adds our own after it to ensure
1002  # it is called before.
1003  orig_register = atexit.register
1004 
1005  def register(func, *targs, **kargs):
1006  orig_register(func, *targs, **kargs)
1007  if hasattr(func, "__module__") and func.__module__ == "ROOT":
1008  orig_register(self.exit)
1009  # we do not need to remove out handler from the list because
1010  # it can be safely called more than once
1011 
1012  register.__doc__ = (
1013  orig_register.__doc__
1014  + "\nNote: version hacked by GaudiPython to work "
1015  + "around a problem with the ROOT exit handler"
1016  )
1017  atexit.register = register
1018 
1019  @property
1020  def opts(self):
1021  if "_svcloc" in self.__dict__:
1022  return self._svcloc.getOptsSvc()
1023  return None
1024 
1025  def state(self):
1026  return self._isvc.FSMState()
1027 
1028  def FSMState(self):
1029  return self._isvc.FSMState()
1030 
1031  def targetFSMState(self):
1032  return self._isvc.targetFSMState()
1033 
1034  def service(self, name, interface=None):
1035  svc = Helper.service(self._svcloc, name)
1036  if interface:
1037  return InterfaceCast(interface)(svc)
1038  else:
1039  return iService(name, svc)
1040 
1041  def declSvcType(self, svcname, svctype):
1042  self._svcmgr.declareSvcType(svcname, svctype)
1043 
1044  def createSvc(self, name):
1045  return Helper.service(self._svcloc, name, True)
1046 
1047  def services(self):
1048  l = self._svcloc.getServices()
1049  return [s.name() for s in l]
1050 
1051  def algorithm(self, name, createIf=False):
1052  alg = Helper.algorithm(self._algmgr, name, createIf)
1053  if not alg:
1054  return iAlgorithm(name, alg)
1055  else:
1056  return iAlgorithm(alg.name(), alg)
1057 
1058  def algorithms(self):
1059  l = self._algmgr.getAlgorithms()
1060  return [a.name() for a in l]
1061 
1062  def tool(self, name):
1063  return iAlgTool(name)
1064 
1065  def property(self, name):
1066  if name in self.algorithms():
1067  return self.algorithm(name)
1068  elif name in self.services():
1069  return self.service(name)
1070  else:
1071  return iProperty(name)
1072 
1073  def datasvc(self, name):
1074  if self.state() == Gaudi.StateMachine.CONFIGURED:
1075  self.initialize()
1076  svc = Helper.service(self._svcloc, name)
1077  return iDataSvc(name, svc)
1078 
1079  def evtsvc(self):
1080  return self.datasvc("EventDataSvc")
1081 
1082  def detsvc(self):
1083  return self.datasvc("DetectorDataSvc")
1084 
1085  def filerecordsvc(self):
1086  return self.datasvc("FileRecordDataSvc")
1087 
1088  def evtsel(self):
1089  if self.state() == Gaudi.StateMachine.CONFIGURED:
1090  self.initialize()
1091  if not hasattr(self, "_evtsel"):
1092  self.__dict__["_evtsel"] = iEventSelector()
1093  return self._evtsel
1094 
1095  def histsvc(self, name="HistogramDataSvc"):
1096  svc = Helper.service(self._svcloc, name)
1097  return iHistogramSvc(name, svc)
1098 
1099  def ntuplesvc(self, name="NTupleSvc"):
1100  if name not in self.ExtSvc:
1101  self.ExtSvc += [name]
1102  # if self.HistogramPersistency == 'NONE' : self.HistogramPersistency = 'ROOT'
1103  svc = Helper.service(self._svcloc, name, True)
1104  return iNTupleSvc(name, svc)
1105 
1106  def partsvc(self):
1107  if self.FSMState() == Gaudi.StateMachine.CONFIGURED:
1108  self.initialize()
1109  svc = Helper.service(self._svcloc, "ParticlePropertySvc")
1110  return InterfaceCast(gbl.IParticlePropertySvc)(svc)
1111 
1112  def toolsvc(self, name="ToolSvc"):
1113  svc = Helper.service(self._svcloc, name, True)
1114  return iToolSvc(name, svc)
1115 
1116  def readOptions(self, file):
1117  return self.opts.readOptions(file)
1118 
1119  def addAlgorithm(self, alg):
1120  """Add an Algorithm to the list of Top algorithms. It can be either a instance of
1121  an Algorithm class or it name"""
1122  if type(alg) is str:
1123  self.topAlg += [alg]
1124  else:
1125  self.pyalgorithms.append(alg)
1126  setOwnership(alg, 0)
1127  if self.targetFSMState() >= Gaudi.StateMachine.INITIALIZED:
1128  alg.sysInitialize()
1129  if self.targetFSMState() == Gaudi.StateMachine.RUNNING:
1130  alg.sysStart()
1131  self.topAlg += [alg.name()]
1132 
1133  def setAlgorithms(self, algs):
1134  """Set the list of Top Algorithms.
1135  It can be an individual of a list of algorithms names or instances"""
1136  if type(algs) is not list:
1137  algs = [algs]
1138  names = []
1139  for alg in algs:
1140  if type(alg) is str:
1141  names.append(alg)
1142  else:
1143  self.pyalgorithms.append(alg)
1144  if self.targetFSMState() >= Gaudi.StateMachine.INITIALIZED:
1145  alg.sysInitialize()
1146  if self.targetFSMState() == Gaudi.StateMachine.RUNNING:
1147  alg.sysStart()
1148  names.append(alg.name())
1149  self.topAlg = names
1150 
1151  def removeAlgorithm(self, alg):
1152  """Remove an Algorithm to the list of Top algorithms. It can be either a instance of
1153  an Algorithm class or it name"""
1154  tmp = self.topAlg
1155  if type(alg) is str:
1156  tmp.remove(alg)
1157  else:
1158  tmp.remove(alg.name())
1159  self.pyalgorithms.remove(alg)
1160  setOwnership(alg, 1)
1161  self.topAlg = tmp
1162 
1164  """
1165  Print the sequence of Algorithms.
1166  """
1167 
1168  def printAlgo(algName, appMgr, prefix=" "):
1169  print(prefix + algName)
1170  alg = appMgr.algorithm(algName.split("/")[-1])
1171  prop = alg.properties()
1172  if "Members" in prop:
1173  subs = prop["Members"].value()
1174  for i in subs:
1175  printAlgo(i.strip('"'), appMgr, prefix + " ")
1176 
1177  mp = self.properties()
1178  prefix = "ApplicationMgr SUCCESS "
1179  print(
1180  prefix
1181  + "****************************** Algorithm Sequence ****************************"
1182  )
1183  for i in mp["TopAlg"].value():
1184  printAlgo(i, self, prefix)
1185  print(
1186  prefix
1187  + "******************************************************************************"
1188  )
1189 
1190  def config(self, **args):
1191  """
1192  Simple utility to perform the configuration of Gaudi application.
1193  It reads the set of input job-options files, and set few
1194  additional parameters 'options' through the usage of temporary *.opts file
1195  Usage:
1196  gaudi.config( files = [ '$GAUSSOPTS/Gauss.opts' ,
1197  '$DECFILESROOT/options/10022_010.0GeV.opts' ] ,
1198  options = [ 'EventSelector.PrintFreq = 5 ' ] )
1199  """
1200  files = args.get("files", [])
1201  for file in files:
1202  sc = self.readOptions(file)
1203  if sc.isFailure():
1204  raise RuntimeError(' Unable to read file "' + file + '" ')
1205  options = args.get("options", None)
1206  if options:
1207  import tempfile
1208 
1209  tmpfilename = tempfile.mktemp()
1210  tmpfile = open(tmpfilename, "w")
1211  tmpfile.write("#pragma print on \n")
1212  tmpfile.write(
1213  '/// File "' + tmpfilename + '" generated by GaudiPython \n\n'
1214  )
1215  for opt in options:
1216  if type(options) is dict:
1217  tmpfile.write(
1218  " \t "
1219  + opt
1220  + " = "
1221  + options[opt]
1222  + " ; // added by GaudiPython \n"
1223  )
1224  else:
1225  tmpfile.write(" \t " + opt + " ; // added by GaudiPython \n")
1226  tmpfile.write(
1227  '/// End of file "' + tmpfilename + '" generated by GaudiPython \n\n'
1228  )
1229  tmpfile.close()
1230  sc = self.readOptions(tmpfilename)
1231  if sc.isFailure():
1232  raise RuntimeError(' Unable to read file "' + tmpfilename + '" ')
1233  os.remove(tmpfilename)
1234 
1235  return SUCCESS
1236 
1237  def configure(self):
1238  return self._appmgr.configure()
1239 
1240  def start(self):
1241  return self._appmgr.start()
1242 
1243  def terminate(self):
1244  return self._appmgr.terminate()
1245 
1246  def run(self, n):
1247  if self.FSMState() == Gaudi.StateMachine.CONFIGURED:
1248  sc = self.initialize()
1249  if sc.isFailure() or self.ReturnCode != 0:
1250  return sc
1251  if self.FSMState() == Gaudi.StateMachine.INITIALIZED:
1252  sc = self.start()
1253  if sc.isFailure() or self.ReturnCode != 0:
1254  return sc
1255  return self._evtpro.executeRun(n)
1256 
1257  def executeEvent(self):
1258  return self._evtpro.executeEvent()
1259 
1260  def execute(self):
1261  return self._evtpro.executeEvent()
1262 
1263  def runSelectedEvents(self, pfn, events):
1264  if self.FSMState() == Gaudi.StateMachine.CONFIGURED:
1265  sc = self.initialize()
1266  if sc.isFailure():
1267  return sc
1268  if self.FSMState() == Gaudi.StateMachine.INITIALIZED:
1269  sc = self.start()
1270  if sc.isFailure():
1271  return sc
1272  # --- Access a number of services ----
1273  if not hasattr(self, "_perssvc"):
1274  self.__dict__["_perssvc"] = self.service(
1275  "EventPersistencySvc", "IAddressCreator"
1276  )
1277  if not hasattr(self, "_filecat"):
1278  self.__dict__["_filecat"] = self.service(
1279  "FileCatalog", "Gaudi::IFileCatalog"
1280  )
1281  if not hasattr(self, "_evtmgr"):
1282  self.__dict__["_evtmgr"] = self.service("EventDataSvc", "IDataManagerSvc")
1283  # --- Get FID from PFN and number of events in file
1284  if pfn.find("PFN:") == 0:
1285  pfn = pfn[4:]
1286  fid, maxevt = _getFIDandEvents(pfn)
1287  # --- Add FID into catalog if needed ---
1288  if not self._filecat.existsFID(fid):
1289  self._filecat.registerPFN(fid, pfn, "")
1290  # --- Loop over events
1291  if type(events) is not list:
1292  events = (events,)
1293  for evt in events:
1294  # --- Create POOL Address from Generic Address
1295  gadd = gbl.GenericAddress(0x02, 1, fid, "/Event", 0, evt)
1296  oadd = makeNullPointer("IOpaqueAddress")
1297  self._perssvc.createAddress(
1298  gadd.svcType(), gadd.clID(), gadd.par(), gadd.ipar(), oadd
1299  )
1300  # --- Clear TES, set root and run all algorithms
1301  self._evtmgr.clearStore()
1302  self._evtmgr.setRoot("/Event", oadd)
1303  self._evtpro.executeEvent()
1304 
1305  def exit(self):
1306  # Protection against multiple calls to exit() if the finalization fails
1307  if not self._exit_called:
1308  self.__dict__["_exit_called"] = True
1309  Gaudi = self._gaudi_ns
1310  if self.FSMState() == Gaudi.StateMachine.RUNNING:
1311  self._appmgr.stop().ignore()
1312  if self.FSMState() == Gaudi.StateMachine.INITIALIZED:
1313  self._appmgr.finalize().ignore()
1314  if self.FSMState() == Gaudi.StateMachine.CONFIGURED:
1315  self._appmgr.terminate()
1316  return SUCCESS
1317 
1318  # Custom destructor to ensure that the application is correctly finalized when exiting from python.
1319 
1320  def __del__(self):
1321  self.exit()
1322 
1323  evtSvc = evtsvc
1324  histSvc = histsvc
1325  ntupleSvc = ntuplesvc
1326  evtSel = evtsel
1327  detSvc = detsvc
1328  toolSvc = toolsvc
1329  partSvc = partsvc
1330 
1331 
1332 # -----------------------------------------------------------------------------
1333 
1334 
1336  tfile = gbl.TFile.Open(pfn)
1337  if not tfile:
1338  raise IOError("Cannot open ROOT file {0}".format(pfn))
1339  tree = tfile.Get("##Params")
1340  tree.GetEvent(0)
1341  text = tree.db_string
1342  if "NAME=FID" in text:
1343  fid = text[text.rfind("VALUE=") + 6 : -1]
1344  nevt = tfile.Get("_Event").GetEntries()
1345  tfile.Close()
1346  return fid, nevt
1347 
1348 
1349 # -----------------------------------------------------------------------------
1350 
1351 
1353  """Get all the properties of a component as a Python dictionary.
1354  The component is instantiated using the component library
1355  """
1356  properties = {}
1357  if name == "GaudiCoreSvc":
1358  if Helper.loadDynamicLib(name) != 1:
1359  raise ImportError("Error loading component library " + name)
1360  factorylist = gbl.FactoryTable.instance().getEntries()
1361  factories = _copyFactoriesFromList(factorylist)
1362  g = AppMgr(outputlevel=7)
1363  else:
1364  g = AppMgr(outputlevel=7)
1365  if Helper.loadDynamicLib(name) != 1:
1366  raise ImportError("Error loading component library " + name)
1367  factorylist = gbl.FactoryTable.instance().getEntries()
1368  factories = _copyFactoriesFromList(factorylist)
1369  svcloc = gbl.Gaudi.svcLocator()
1370  dummysvc = gbl.Service("DummySvc", svcloc)
1371  for factory in factories:
1372  if InterfaceCast(gbl.IAlgFactory)(factory):
1373  ctype = "Algorithm"
1374  elif InterfaceCast(gbl.ISvcFactory)(factory):
1375  ctype = "Service"
1376  elif InterfaceCast(gbl.IToolFactory)(factory):
1377  ctype = "AlgTool"
1378  elif factory.ident() == "ApplicationMgr":
1379  ctype = "ApplicationMgr"
1380  else:
1381  ctype = "Unknown"
1382  cname = factory.ident().split()[-1]
1383  if ctype in ("Algorithm", "Service", "AlgTool", "ApplicationMgr"):
1384  try:
1385  if ctype == "AlgTool":
1386  obj = factory.instantiate(dummysvc)
1387  else:
1388  obj = factory.instantiate(svcloc)
1389  except RuntimeError as text:
1390  print("Error instantiating", cname, " from ", name)
1391  print(text)
1392  continue
1393  prop = iProperty("dummy", obj)
1394  properties[cname] = [ctype, prop.properties()]
1395  try:
1396  obj.release()
1397  except:
1398  pass
1399  return properties
1400 
1401 
1402 def _copyFactoriesFromList(factories):
1403  result = []
1404  for i in range(factories.size()):
1405  factory = factories.front()
1406  result.append(factory)
1407  factories.pop_front()
1408  for factory in result:
1409  factories.push_back(factory)
1410  return result
1411 
1412 
1413 # ----CallbackStreamBuf--------------------------------------------------------
1414 # Used for redirecting C++ messages to python
1415 _CallbackStreamBufBase = gbl.GaudiPython.CallbackStreamBuf
1416 
1417 
1419  def __init__(self, callback):
1420  _CallbackStreamBufBase.__init__(self, self)
1421  self.callback = callback
1422 
1423  def _sync(self, string=None):
1424  if not string:
1425  return 0
1426  self.callback(string)
1427  return 0
1428 
1429 
1430 # ----PyAlgorithm--------------------------------------------------------------
1431 # Used to implement Algorithms in Python
1432 _PyAlgorithm = gbl.GaudiPython.PyAlgorithm
1433 
1434 
1436  def __init__(self, name=None):
1437  if not name:
1438  name = self.__class__.__name__
1439  _PyAlgorithm.__init__(self, self, name)
1440  self._svcloc = gbl.Gaudi.svcLocator()
1441  self._algmgr = InterfaceCast(gbl.IAlgManager)(self._svcloc)
1442  sc = self._algmgr.addAlgorithm(self)
1443  if sc.isFailure():
1444  raise RuntimeError("Unable to add Algorithm")
1445 
1446  def __del__(self):
1447  sc = self._algmgr.removeAlgorithm(self)
1448  if sc.isFailure():
1449  pass
1450 
1451  def initialize(self):
1452  return 1
1453 
1454  def start(self):
1455  return 1
1456 
1457  def execute(self):
1458  return 1
1459 
1460  def stop(self):
1461  return 1
1462 
1463  def finalize(self):
1464  return 1
1465 
1466 
1467 # ----Enable tab completion----------------------------------------------------
1468 try:
1469  import readline
1470  import rlcompleter
1471 
1472  readline.parse_and_bind("tab: complete")
1473 except:
1474  pass
GaudiPython.Bindings.AppMgr.start
def start(self)
Definition: Bindings.py:1240
GaudiPython.Bindings.makeNullPointer
makeNullPointer
Definition: Bindings.py:135
GaudiPython.Bindings.iService.reinitialize
def reinitialize(self)
Definition: Bindings.py:414
GaudiPython.Bindings.iProperty.__setattr__
def __setattr__(self, name, value)
Definition: Bindings.py:309
GaudiPython.Bindings.AppMgr.histsvc
def histsvc(self, name="HistogramDataSvc")
Definition: Bindings.py:1095
GaudiPython.Bindings.iAlgorithm.sysExecute
def sysExecute(self)
Definition: Bindings.py:471
GaudiPython.Bindings.AppMgr.removeAlgorithm
def removeAlgorithm(self, alg)
Definition: Bindings.py:1151
GaudiPython.Bindings.iAlgTool.start
def start(self)
Definition: Bindings.py:504
GaudiPython.Bindings.iDataSvc
Definition: Bindings.py:523
GaudiPython.Bindings.iAlgorithm.__init__
def __init__(self, name, ialg=cppyy.nullptr)
Definition: Bindings.py:433
GaudiPython.Bindings.iToolSvc.create
def create(self, typ, name=None, parent=nullptr, interface=None)
Definition: Bindings.py:830
GaudiPython.Bindings.InterfaceCast.__init__
def __init__(self, t)
Definition: Bindings.py:150
GaudiPython.Bindings.AppMgr.__reset__
def __reset__(self)
Definition: Bindings.py:881
GaudiPython.Bindings.PyAlgorithm.__init__
def __init__(self, name=None)
Definition: Bindings.py:1436
GaudiPython.Bindings.iNTupleSvc.book
def book(self, *args)
Definition: Bindings.py:779
GaudiPython.Bindings.AppMgr.readOptions
def readOptions(self, file)
Definition: Bindings.py:1116
GaudiPython.Bindings.iProperty.retrieveInterface
def retrieveInterface(self)
Definition: Bindings.py:301
GaudiPython.Bindings.iHistogramSvc.getAsAIDA
def getAsAIDA(self, path)
Definition: Bindings.py:748
GaudiPython.Bindings.iEventSelector.rewind
def rewind(self)
Definition: Bindings.py:864
GaudiPython.Bindings.AppMgr.ntuplesvc
def ntuplesvc(self, name="NTupleSvc")
Definition: Bindings.py:1099
GaudiPython.Bindings.iHistogramSvc.retrieve1D
def retrieve1D(self, path)
Definition: Bindings.py:688
GaudiPython.Bindings.iHistogramSvc.retrieve
def retrieve(self, path)
Definition: Bindings.py:703
GaudiPython.Bindings.iToolSvc.retrieve
def retrieve(self, name)
Definition: Bindings.py:827
GaudiPython.Bindings.AppMgr.tool
def tool(self, name)
Definition: Bindings.py:1062
GaudiPython.Bindings.iDataSvc.__init__
def __init__(self, name, idp)
Definition: Bindings.py:524
GaudiPython.Bindings.iAlgTool.stop
def stop(self)
Definition: Bindings.py:507
GaudiPython.Bindings.AppMgr.__new__
def __new__(cls, *args, **kwargs)
Definition: Bindings.py:873
GaudiPython.Bindings._copyFactoriesFromList
def _copyFactoriesFromList(factories)
Definition: Bindings.py:1402
GaudiPython.Bindings.iAlgorithm.sysStop
def sysStop(self)
Definition: Bindings.py:474
GaudiPython.Bindings.PyAlgorithm.execute
def execute(self)
Definition: Bindings.py:1457
GaudiPython.Bindings.AppMgr.addAlgorithm
def addAlgorithm(self, alg)
Definition: Bindings.py:1119
GaudiPython.Bindings.AppMgr.runSelectedEvents
def runSelectedEvents(self, pfn, events)
Definition: Bindings.py:1263
GaudiPython.Bindings.AppMgr.datasvc
def datasvc(self, name)
Definition: Bindings.py:1073
GaudiPython.Bindings.PropertyEntry.property
def property(self)
Definition: Bindings.py:274
GaudiPython.Bindings.iToolSvc._retrieve
def _retrieve(self, name, quiet=True)
Definition: Bindings.py:805
GaudiPython.Bindings.AppMgr.service
def service(self, name, interface=None)
Definition: Bindings.py:1034
GaudiPython.Bindings.iDataSvc.registerObject
def registerObject(self, path, obj)
Definition: Bindings.py:529
GaudiPython.Bindings.iAlgTool.retrieveInterface
def retrieveInterface(self)
Definition: Bindings.py:499
GaudiKernel.ROOT6WorkAroundEnabled
def ROOT6WorkAroundEnabled(id=None)
Definition: __init__.py:14
GaudiPython.Bindings.iHistogramSvc.__getitem__
def __getitem__(self, path)
Definition: Bindings.py:736
GaudiPython.Bindings.iToolSvc.OutputLevel
OutputLevel
Definition: Bindings.py:808
GaudiPython.Bindings.loaddict
def loaddict(dict)
Definition: Bindings.py:197
GaudiPython.Bindings.iDataSvc.retrieveObject
def retrieveObject(self, path)
Definition: Bindings.py:543
GaudiPython.Bindings.AppMgr
Definition: Bindings.py:872
GaudiPython.Bindings.iAlgorithm
Definition: Bindings.py:430
conf.release
string release
Definition: conf.py:27
GaudiPython.Bindings.getComponentProperties
def getComponentProperties(name)
Definition: Bindings.py:1352
GaudiPython.Bindings.iHistogramSvc.bookProf
def bookProf(self, *args)
Definition: Bindings.py:728
GaudiPython.Bindings.AppMgr.opts
def opts(self)
Definition: Bindings.py:1020
GaudiPython.Bindings.iDataSvc.leaves
def leaves(self, node=cppyy.nullptr)
Definition: Bindings.py:610
GaudiPython.Bindings.iDataSvc.__setitem__
def __setitem__(self, path, obj)
Definition: Bindings.py:600
GaudiPython.Bindings.iDataSvc.clearStore
def clearStore(self)
Definition: Bindings.py:676
GaudiPython.Bindings.setOwnership
setOwnership
Definition: Bindings.py:136
GaudiPython.Bindings.iAlgorithm.restart
def restart(self)
Definition: Bindings.py:462
GaudiPython.Bindings.iService.__init__
def __init__(self, name, isvc=cppyy.nullptr)
Definition: Bindings.py:393
GaudiPython.Bindings.iService.stop
def stop(self)
Definition: Bindings.py:408
GaudiPython.Bindings.iEventSelector.Input
Input
Definition: Bindings.py:861
GaudiPython.Bindings.iProperty
Definition: Bindings.py:288
GaudiPython.Bindings.iDataSvc.setRoot
def setRoot(self, name, obj)
Definition: Bindings.py:671
GaudiPython.Bindings.iToolSvc.release
def release(self, itool)
Definition: Bindings.py:839
GaudiPython.Bindings.iAlgorithm.retrieveInterface
def retrieveInterface(self)
Definition: Bindings.py:437
GaudiPython.Bindings.iHistogramSvc.retrieveProfile1D
def retrieveProfile1D(self, path)
Definition: Bindings.py:697
GaudiPython.Bindings.iService.retrieveInterface
def retrieveInterface(self)
Definition: Bindings.py:397
GaudiPython.Bindings.iNTupleSvc.Output
Output
Definition: Bindings.py:791
GaudiPython.Bindings.AppMgr.property
def property(self, name)
Definition: Bindings.py:1065
GaudiPython.Bindings.PyAlgorithm.finalize
def finalize(self)
Definition: Bindings.py:1463
GaudiKernel.Proxy.getNeededConfigurables
getNeededConfigurables
Definition: Proxy.py:30
GaudiPython.Bindings.toArray
def toArray(typ)
Definition: Bindings.py:120
GaudiPython.Bindings.PyAlgorithm
Definition: Bindings.py:1435
compareOutputFiles.par
string par
Definition: compareOutputFiles.py:483
GaudiPython.Bindings.iEventSelector.__init__
def __init__(self)
Definition: Bindings.py:848
GaudiPython.Bindings.iAlgTool.type
def type(self)
Definition: Bindings.py:510
GaudiPython.Bindings.PyAlgorithm.__del__
def __del__(self)
Definition: Bindings.py:1446
GaudiPython.Bindings.iDataSvc.getHistoNames
def getHistoNames(self, node=cppyy.nullptr, lst=[])
Definition: Bindings.py:652
GaudiPython.Bindings.AppMgr.printAlgsSequences
def printAlgsSequences(self)
Definition: Bindings.py:1163
GaudiPython.Bindings.iEventSelector.open
def open(self, stream, typ="Gaudi::RootCnvSvc", **kwargs)
Definition: Bindings.py:856
GaudiPython.Bindings.iHistogramSvc.getAsROOT
def getAsROOT(self, path)
Definition: Bindings.py:757
GaudiPython.Bindings.InterfaceCast.__call__
def __call__(self, obj)
Definition: Bindings.py:155
GaudiPython.Bindings.CallbackStreamBuf
Definition: Bindings.py:1418
GaudiPython.Bindings.deprecation
def deprecation(message)
Definition: Bindings.py:139
GaudiPython.Bindings.iAlgorithm.execute
def execute(self)
Definition: Bindings.py:450
GaudiPython.Bindings.iProperty.__call_interface_method__
def __call_interface_method__(self, ifname, method, *args)
Definition: Bindings.py:304
GaudiPython.Bindings.InterfaceCast.cast
def cast
Definition: Bindings.py:179
GaudiPython.Pythonizations.self
self
Definition: Pythonizations.py:588
GaudiPython.Bindings.iHistogramSvc.retrieve2D
def retrieve2D(self, path)
Definition: Bindings.py:691
GaudiPython.Bindings.iAlgorithm.stop
def stop(self)
Definition: Bindings.py:453
GaudiPython.Bindings.AppMgr.topAlg
topAlg
Definition: Bindings.py:1149
GaudiKernel.ProcessJobOptions
Definition: ProcessJobOptions.py:1
GaudiPython.Bindings.iHistogramSvc.__init__
def __init__(self, name, ihs)
Definition: Bindings.py:684
GaudiPython.Bindings.PyAlgorithm.stop
def stop(self)
Definition: Bindings.py:1460
GaudiPython.Bindings.PyAlgorithm.initialize
def initialize(self)
Definition: Bindings.py:1451
GaudiPython.Bindings.iService.start
def start(self)
Definition: Bindings.py:405
GaudiPython.Bindings.iDataSvc.unregisterObject
def unregisterObject(self, path)
Definition: Bindings.py:536
GaudiPython.Bindings.iAlgorithm.reinitialize
def reinitialize(self)
Definition: Bindings.py:459
GaudiPython.Bindings.AppMgr.executeEvent
def executeEvent(self)
Definition: Bindings.py:1257
GaudiPython.Bindings.CallbackStreamBuf._sync
def _sync(self, string=None)
Definition: Bindings.py:1423
GaudiPython.Bindings.iService.isValid
def isValid(self)
Definition: Bindings.py:420
GaudiPython.Bindings.AppMgr.toolsvc
def toolsvc(self, name="ToolSvc")
Definition: Bindings.py:1112
GaudiPython.Bindings.iDataSvc.dump
def dump(self, node=cppyy.nullptr)
Definition: Bindings.py:621
GaudiPython.Bindings.CallbackStreamBuf.__init__
def __init__(self, callback)
Definition: Bindings.py:1419
GaudiPython.Bindings.AppMgr.createSvc
def createSvc(self, name)
Definition: Bindings.py:1044
GaudiPython.Bindings.InterfaceCast.type
type
Definition: Bindings.py:153
GaudiPython.Bindings.iNTupleSvc.__getitem__
def __getitem__(self, path)
Definition: Bindings.py:795
GaudiPython.Bindings.iHistogramSvc.book
def book(self, *args)
Definition: Bindings.py:720
GaudiPython.Bindings.iNTupleSvc.__init__
def __init__(self, name, ints)
Definition: Bindings.py:775
GaudiPython.Bindings.iAlgTool.__init__
def __init__(self, name, itool=cppyy.nullptr)
Definition: Bindings.py:493
GaudiPython.Bindings.iAlgorithm.sysReinitialize
def sysReinitialize(self)
Definition: Bindings.py:480
GaudiPython.Bindings.iDataSvc.getObject
def getObject(self, path, *args)
Definition: Bindings.py:568
GaudiPython.Bindings.AppMgr.execute
def execute(self)
Definition: Bindings.py:1260
GaudiPython.Bindings.AppMgr.__init__
def __init__(self, outputlevel=-1, joboptions=None, selfoptions={}, dllname=None, factname=None)
Definition: Bindings.py:895
GaudiPython.Bindings.iHistogramSvc.retrieveProfile2D
def retrieveProfile2D(self, path)
Definition: Bindings.py:700
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
GaudiPython.Bindings.AppMgr.run
def run(self, n)
Definition: Bindings.py:1246
GaudiKernel.ProcessJobOptions.importOptions
def importOptions(optsfile)
Definition: ProcessJobOptions.py:541
GaudiPython.Bindings.AppMgr.setAlgorithms
def setAlgorithms(self, algs)
Definition: Bindings.py:1133
GaudiPython.Bindings.AppMgr.algorithm
def algorithm(self, name, createIf=False)
Definition: Bindings.py:1051
GaudiPython.Bindings.PropertyEntry.ptype
def ptype(self)
Definition: Bindings.py:271
GaudiPython.Bindings.PropertyEntry
Definition: Bindings.py:241
GaudiPython.Bindings.iService
Definition: Bindings.py:390
GaudiPython.Bindings.PropertyEntry.documentation
def documentation(self)
Definition: Bindings.py:278
GaudiPython.Bindings.iDataSvc.getList
def getList(self, node=cppyy.nullptr, lst=[], rootFID=None)
Definition: Bindings.py:633
GaudiPython.Bindings.PropertyEntry.value
def value(self)
Definition: Bindings.py:268
GaudiPython.Bindings.AppMgr.state
def state(self)
Definition: Bindings.py:1025
GaudiPython.Bindings.AppMgr.config
def config(self, **args)
Definition: Bindings.py:1190
GaudiPython.Bindings.iHistogramSvc
Definition: Bindings.py:683
GaudiPython.Bindings._getFIDandEvents
def _getFIDandEvents(pfn)
Definition: Bindings.py:1335
GaudiPython.Bindings._CallbackStreamBufBase
_CallbackStreamBufBase
Definition: Bindings.py:1415
GaudiPython.Bindings.iProperty.getInterface
def getInterface(self)
Definition: Bindings.py:296
gaudirun.type
type
Definition: gaudirun.py:160
GaudiPython.Bindings.iService.restart
def restart(self)
Definition: Bindings.py:417
GaudiPython.Bindings.iNTupleSvc
Definition: Bindings.py:771
GaudiPython.Bindings.AppMgr.exit
def exit(self)
Definition: Bindings.py:1305
GaudiPython.Bindings.AppMgr.detsvc
def detsvc(self)
Definition: Bindings.py:1082
GaudiPython.Bindings.iDataSvc.__getitem__
def __getitem__(self, path)
Definition: Bindings.py:595
GaudiPython.Bindings.PropertyEntry.__doc__
__doc__
Definition: Bindings.py:246
GaudiPython.Bindings.AppMgr.FSMState
def FSMState(self)
Definition: Bindings.py:1028
GaudiPython.Bindings.iDataSvc.findObject
def findObject(self, path)
Definition: Bindings.py:550
GaudiPython.Bindings.Interface
Definition: Bindings.py:185
GaudiPython.Bindings.AppMgr.terminate
def terminate(self)
Definition: Bindings.py:1243
GaudiPython.Bindings.AppMgr.targetFSMState
def targetFSMState(self)
Definition: Bindings.py:1031
GaudiPython.Bindings.InterfaceCast
Definition: Bindings.py:146
GaudiPython.Bindings.iProperty.__getattr__
def __getattr__(self, name)
Definition: Bindings.py:335
GaudiPython.Bindings.getClass
def getClass(name, libs=[])
Definition: Bindings.py:210
GaudiPython.Bindings.CallbackStreamBuf.callback
callback
Definition: Bindings.py:1421
GaudiPython.Bindings.AppMgr.OutputLevel
OutputLevel
Definition: Bindings.py:937
GaudiPython.Bindings.PyAlgorithm._algmgr
_algmgr
Definition: Bindings.py:1441
GaudiPython.Bindings.iAlgorithm.start
def start(self)
Definition: Bindings.py:447
GaudiPython.Bindings.iService.initialize
def initialize(self)
Definition: Bindings.py:402
GaudiPython.Bindings.AppMgr.algorithms
def algorithms(self)
Definition: Bindings.py:1058
GaudiPython.Bindings.PropertyEntry._type
_type
Definition: Bindings.py:245
GaudiPython.Bindings.AppMgr.declSvcType
def declSvcType(self, svcname, svctype)
Definition: Bindings.py:1041
GaudiPython.Bindings.PropertyEntry.__init__
def __init__(self, prop)
Definition: Bindings.py:244
GaudiPython.Bindings.iEventSelector
Definition: Bindings.py:847
GaudiPython.Bindings.iProperty.properties
def properties(self)
Definition: Bindings.py:361
GaudiPython.Bindings.AppMgr.evtsel
def evtsel(self)
Definition: Bindings.py:1088
GaudiPython.Bindings.AppMgr.services
def services(self)
Definition: Bindings.py:1047
GaudiPython.Bindings.iAlgTool.name
def name(self)
Definition: Bindings.py:513
GaudiPython.Bindings.PyAlgorithm._svcloc
_svcloc
Definition: Bindings.py:1440
GaudiPython.Bindings.PropertyEntry._property
_property
Definition: Bindings.py:266
GaudiPython.Bindings.AppMgr.__del__
def __del__(self)
Definition: Bindings.py:1320
GaudiPython.Bindings.iAlgorithm.sysRestart
def sysRestart(self)
Definition: Bindings.py:483
GaudiPython.Bindings.iHistogramSvc.retrieve3D
def retrieve3D(self, path)
Definition: Bindings.py:694
GaudiPython.Bindings.iProperty.__init__
def __init__(self, name, ip=cppyy.nullptr)
Definition: Bindings.py:291
GaudiPython.Bindings.iAlgorithm.sysInitialize
def sysInitialize(self)
Definition: Bindings.py:465
GaudiPython.Bindings.iAlgorithm.finalize
def finalize(self)
Definition: Bindings.py:456
GaudiPython.Bindings.iAlgorithm.initialize
def initialize(self)
Definition: Bindings.py:444
GaudiPython.Bindings.PropertyEntry._value
_value
Definition: Bindings.py:249
GaudiPython.Bindings.AppMgr.configure
def configure(self)
Definition: Bindings.py:1237
GaudiPython.Bindings.iAlgorithm.sysStart
def sysStart(self)
Definition: Bindings.py:468
GaudiPython.Bindings.iAlgorithm.sysFinalize
def sysFinalize(self)
Definition: Bindings.py:477
GaudiPython.Bindings.Interface.__init__
def __init__(self, t)
Definition: Bindings.py:186
GaudiPython.Bindings.iDataSvc.__delitem__
def __delitem__(self, path)
Definition: Bindings.py:605
GaudiPython.Bindings.PyAlgorithm.start
def start(self)
Definition: Bindings.py:1454
GaudiPython.Bindings.PropertyEntry.hasDoc
def hasDoc(self)
Definition: Bindings.py:281
GaudiPython.Bindings.iToolSvc.__init__
def __init__(self, name, its)
Definition: Bindings.py:801
GaudiPython.Bindings._PyAlgorithm
_PyAlgorithm
Definition: Bindings.py:1432
GaudiPython.Bindings.iNTupleSvc.defineOutput
def defineOutput(self, files, typ="Gaudi::RootCnvSvc")
Definition: Bindings.py:782
GaudiKernel.Configurable.expandvars
def expandvars(data)
Definition: Configurable.py:73
GaudiPython.Bindings.AppMgr.partsvc
def partsvc(self)
Definition: Bindings.py:1106
GaudiPython.Bindings.AppMgr.evtsvc
def evtsvc(self)
Definition: Bindings.py:1079
GaudiPython.Bindings.AppMgr.filerecordsvc
def filerecordsvc(self)
Definition: Bindings.py:1085
GaudiPython.Bindings.iService.finalize
def finalize(self)
Definition: Bindings.py:411
GaudiPython.Bindings.iToolSvc
Definition: Bindings.py:800
Gaudi::Functional::details::zip::range
decltype(auto) range(Args &&... args)
Zips multiple containers together to form a single range.
Definition: FunctionalDetails.h:102
GaudiPython.Bindings.AppMgr.JobOptionsType
JobOptionsType
Definition: Bindings.py:926
GaudiPython.Bindings.iProperty.name
def name(self)
Definition: Bindings.py:383
GaudiPython.Bindings.iAlgTool
Definition: Bindings.py:490
GaudiPython.Pythonizations.items
items
Definition: Pythonizations.py:546