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