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