Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v36r16 (ea80daf8)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 type(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 (
975  hasattr(Configurable, "PropertyReference")
976  and type(v) == Configurable.PropertyReference
977  ):
978  # this is done in "getFullName", but the exception is ignored,
979  # so we do it again to get it
980  v = v.__resolve__()
981  if type(v) == str:
982  v = repr(v) # need double quotes
983  if type(v) == long:
984  v = "%d" % v # prevent pending 'L'
985  gbl.GaudiPython.Helpers.setProperty(
986  self._svcloc, ".".join([n, p]), str(v)
987  )
988  if hasattr(Configurable, "_configurationLocked"):
989  Configurable._configurationLocked = True
990 
991  # Ensure that the exit method is called when exiting from Python
992  import atexit
993 
994  atexit.register(self.exit)
995 
996  # ---Hack to avoid bad interactions with the ROOT exit handler
997  # let's install a private version of atexit.register that detects when
998  # the ROOT exit handler is installed and adds our own after it to ensure
999  # it is called before.
1000  orig_register = atexit.register
1001 
1002  def register(func, *targs, **kargs):
1003  orig_register(func, *targs, **kargs)
1004  if hasattr(func, "__module__") and func.__module__ == "ROOT":
1005  orig_register(self.exit)
1006  # we do not need to remove out handler from the list because
1007  # it can be safely called more than once
1008 
1009  register.__doc__ = (
1010  orig_register.__doc__
1011  + "\nNote: version hacked by GaudiPython to work "
1012  + "around a problem with the ROOT exit handler"
1013  )
1014  atexit.register = register
1015 
1016  @property
1017  def opts(self):
1018  if "_svcloc" in self.__dict__:
1019  return self._svcloc.getOptsSvc()
1020  return None
1021 
1022  def state(self):
1023  return self._isvc.FSMState()
1024 
1025  def FSMState(self):
1026  return self._isvc.FSMState()
1027 
1028  def targetFSMState(self):
1029  return self._isvc.targetFSMState()
1030 
1031  def service(self, name, interface=None):
1032  svc = Helper.service(self._svcloc, name)
1033  if interface:
1034  return InterfaceCast(interface)(svc)
1035  else:
1036  return iService(name, svc)
1037 
1038  def declSvcType(self, svcname, svctype):
1039  self._svcmgr.declareSvcType(svcname, svctype)
1040 
1041  def createSvc(self, name):
1042  return Helper.service(self._svcloc, name, True)
1043 
1044  def services(self):
1045  l = self._svcloc.getServices()
1046  return [s.name() for s in l]
1047 
1048  def algorithm(self, name, createIf=False):
1049  alg = Helper.algorithm(self._algmgr, name, createIf)
1050  if not alg:
1051  return iAlgorithm(name, alg)
1052  else:
1053  return iAlgorithm(alg.name(), alg)
1054 
1055  def algorithms(self):
1056  l = self._algmgr.getAlgorithms()
1057  return [a.name() for a in l]
1058 
1059  def tool(self, name):
1060  return iAlgTool(name)
1061 
1062  def property(self, name):
1063  if name in self.algorithms():
1064  return self.algorithm(name)
1065  elif name in self.services():
1066  return self.service(name)
1067  else:
1068  return iProperty(name)
1069 
1070  def datasvc(self, name):
1071  if self.state() == Gaudi.StateMachine.CONFIGURED:
1072  self.initialize()
1073  svc = Helper.service(self._svcloc, name)
1074  return iDataSvc(name, svc)
1075 
1076  def evtsvc(self):
1077  return self.datasvc("EventDataSvc")
1078 
1079  def detsvc(self):
1080  return self.datasvc("DetectorDataSvc")
1081 
1082  def filerecordsvc(self):
1083  return self.datasvc("FileRecordDataSvc")
1084 
1085  def evtsel(self):
1086  if self.state() == Gaudi.StateMachine.CONFIGURED:
1087  self.initialize()
1088  if not hasattr(self, "_evtsel"):
1089  self.__dict__["_evtsel"] = iEventSelector()
1090  return self._evtsel
1091 
1092  def histsvc(self, name="HistogramDataSvc"):
1093  svc = Helper.service(self._svcloc, name)
1094  return iHistogramSvc(name, svc)
1095 
1096  def ntuplesvc(self, name="NTupleSvc"):
1097  if name not in self.ExtSvc:
1098  self.ExtSvc += [name]
1099  # if self.HistogramPersistency == 'NONE' : self.HistogramPersistency = 'ROOT'
1100  svc = Helper.service(self._svcloc, name, True)
1101  return iNTupleSvc(name, svc)
1102 
1103  def partsvc(self):
1104  if self.FSMState() == Gaudi.StateMachine.CONFIGURED:
1105  self.initialize()
1106  svc = Helper.service(self._svcloc, "ParticlePropertySvc")
1107  return InterfaceCast(gbl.IParticlePropertySvc)(svc)
1108 
1109  def toolsvc(self, name="ToolSvc"):
1110  svc = Helper.service(self._svcloc, name, True)
1111  return iToolSvc(name, svc)
1112 
1113  def readOptions(self, file):
1114  return self.opts.readOptions(file)
1115 
1116  def addAlgorithm(self, alg):
1117  """Add an Algorithm to the list of Top algorithms. It can be either a instance of
1118  an Algorithm class or it name"""
1119  if type(alg) is str:
1120  self.topAlg += [alg]
1121  else:
1122  self.pyalgorithms.append(alg)
1123  setOwnership(alg, 0)
1124  if self.targetFSMState() >= Gaudi.StateMachine.INITIALIZED:
1125  alg.sysInitialize()
1126  if self.targetFSMState() == Gaudi.StateMachine.RUNNING:
1127  alg.sysStart()
1128  self.topAlg += [alg.name()]
1129 
1130  def setAlgorithms(self, algs):
1131  """Set the list of Top Algorithms.
1132  It can be an individual of a list of algorithms names or instances"""
1133  if type(algs) is not list:
1134  algs = [algs]
1135  names = []
1136  for alg in algs:
1137  if type(alg) is str:
1138  names.append(alg)
1139  else:
1140  self.pyalgorithms.append(alg)
1141  if self.targetFSMState() >= Gaudi.StateMachine.INITIALIZED:
1142  alg.sysInitialize()
1143  if self.targetFSMState() == Gaudi.StateMachine.RUNNING:
1144  alg.sysStart()
1145  names.append(alg.name())
1146  self.topAlg = names
1147 
1148  def removeAlgorithm(self, alg):
1149  """Remove an Algorithm to the list of Top algorithms. It can be either a instance of
1150  an Algorithm class or it name"""
1151  tmp = self.topAlg
1152  if type(alg) is str:
1153  tmp.remove(alg)
1154  else:
1155  tmp.remove(alg.name())
1156  self.pyalgorithms.remove(alg)
1157  setOwnership(alg, 1)
1158  self.topAlg = tmp
1159 
1161  """
1162  Print the sequence of Algorithms.
1163  """
1164 
1165  def printAlgo(algName, appMgr, prefix=" "):
1166  print(prefix + algName)
1167  alg = appMgr.algorithm(algName.split("/")[-1])
1168  prop = alg.properties()
1169  if "Members" in prop:
1170  subs = prop["Members"].value()
1171  for i in subs:
1172  printAlgo(i.strip('"'), appMgr, prefix + " ")
1173 
1174  mp = self.properties()
1175  prefix = "ApplicationMgr SUCCESS "
1176  print(
1177  prefix
1178  + "****************************** Algorithm Sequence ****************************"
1179  )
1180  for i in mp["TopAlg"].value():
1181  printAlgo(i, self, prefix)
1182  print(
1183  prefix
1184  + "******************************************************************************"
1185  )
1186 
1187  def config(self, **args):
1188  """
1189  Simple utility to perform the configuration of Gaudi application.
1190  It reads the set of input job-options files, and set few
1191  additional parameters 'options' through the usage of temporary *.opts file
1192  Usage:
1193  gaudi.config( files = [ '$GAUSSOPTS/Gauss.opts' ,
1194  '$DECFILESROOT/options/10022_010.0GeV.opts' ] ,
1195  options = [ 'EventSelector.PrintFreq = 5 ' ] )
1196  """
1197  files = args.get("files", [])
1198  for file in files:
1199  sc = self.readOptions(file)
1200  if sc.isFailure():
1201  raise RuntimeError(' Unable to read file "' + file + '" ')
1202  options = args.get("options", None)
1203  if options:
1204  import tempfile
1205 
1206  tmpfilename = tempfile.mktemp()
1207  tmpfile = open(tmpfilename, "w")
1208  tmpfile.write("#pragma print on \n")
1209  tmpfile.write(
1210  '/// File "' + tmpfilename + '" generated by GaudiPython \n\n'
1211  )
1212  for opt in options:
1213  if type(options) is dict:
1214  tmpfile.write(
1215  " \t "
1216  + opt
1217  + " = "
1218  + options[opt]
1219  + " ; // added by GaudiPython \n"
1220  )
1221  else:
1222  tmpfile.write(" \t " + opt + " ; // added by GaudiPython \n")
1223  tmpfile.write(
1224  '/// End of file "' + tmpfilename + '" generated by GaudiPython \n\n'
1225  )
1226  tmpfile.close()
1227  sc = self.readOptions(tmpfilename)
1228  if sc.isFailure():
1229  raise RuntimeError(' Unable to read file "' + tmpfilename + '" ')
1230  os.remove(tmpfilename)
1231 
1232  return SUCCESS
1233 
1234  def configure(self):
1235  return self._appmgr.configure()
1236 
1237  def start(self):
1238  return self._appmgr.start()
1239 
1240  def terminate(self):
1241  return self._appmgr.terminate()
1242 
1243  def run(self, n):
1244  if self.FSMState() == Gaudi.StateMachine.CONFIGURED:
1245  sc = self.initialize()
1246  if sc.isFailure() or self.ReturnCode != 0:
1247  return sc
1248  if self.FSMState() == Gaudi.StateMachine.INITIALIZED:
1249  sc = self.start()
1250  if sc.isFailure() or self.ReturnCode != 0:
1251  return sc
1252  return self._evtpro.executeRun(n)
1253 
1254  def executeEvent(self):
1255  return self._evtpro.executeEvent()
1256 
1257  def execute(self):
1258  return self._evtpro.executeEvent()
1259 
1260  def runSelectedEvents(self, pfn, events):
1261  if self.FSMState() == Gaudi.StateMachine.CONFIGURED:
1262  sc = self.initialize()
1263  if sc.isFailure():
1264  return sc
1265  if self.FSMState() == Gaudi.StateMachine.INITIALIZED:
1266  sc = self.start()
1267  if sc.isFailure():
1268  return sc
1269  # --- Access a number of services ----
1270  if not hasattr(self, "_perssvc"):
1271  self.__dict__["_perssvc"] = self.service(
1272  "EventPersistencySvc", "IAddressCreator"
1273  )
1274  if not hasattr(self, "_filecat"):
1275  self.__dict__["_filecat"] = self.service(
1276  "FileCatalog", "Gaudi::IFileCatalog"
1277  )
1278  if not hasattr(self, "_evtmgr"):
1279  self.__dict__["_evtmgr"] = self.service("EventDataSvc", "IDataManagerSvc")
1280  # --- Get FID from PFN and number of events in file
1281  if pfn.find("PFN:") == 0:
1282  pfn = pfn[4:]
1283  fid, maxevt = _getFIDandEvents(pfn)
1284  # --- Add FID into catalog if needed ---
1285  if not self._filecat.existsFID(fid):
1286  self._filecat.registerPFN(fid, pfn, "")
1287  # --- Loop over events
1288  if type(events) is not list:
1289  events = (events,)
1290  for evt in events:
1291  # --- Create POOL Address from Generic Address
1292  gadd = gbl.GenericAddress(0x02, 1, fid, "/Event", 0, evt)
1293  oadd = makeNullPointer("IOpaqueAddress")
1294  self._perssvc.createAddress(
1295  gadd.svcType(), gadd.clID(), gadd.par(), gadd.ipar(), oadd
1296  )
1297  # --- Clear TES, set root and run all algorithms
1298  self._evtmgr.clearStore()
1299  self._evtmgr.setRoot("/Event", oadd)
1300  self._evtpro.executeEvent()
1301 
1302  def exit(self):
1303  # Protection against multiple calls to exit() if the finalization fails
1304  if not self._exit_called:
1305  self.__dict__["_exit_called"] = True
1306  Gaudi = self._gaudi_ns
1307  if self.FSMState() == Gaudi.StateMachine.RUNNING:
1308  self._appmgr.stop().ignore()
1309  if self.FSMState() == Gaudi.StateMachine.INITIALIZED:
1310  self._appmgr.finalize().ignore()
1311  if self.FSMState() == Gaudi.StateMachine.CONFIGURED:
1312  self._appmgr.terminate()
1313  return SUCCESS
1314 
1315  # Custom destructor to ensure that the application is correctly finalized when exiting from python.
1316 
1317  def __del__(self):
1318  self.exit()
1319 
1320  evtSvc = evtsvc
1321  histSvc = histsvc
1322  ntupleSvc = ntuplesvc
1323  evtSel = evtsel
1324  detSvc = detsvc
1325  toolSvc = toolsvc
1326  partSvc = partsvc
1327 
1328 
1329 # -----------------------------------------------------------------------------
1330 
1331 
1333  tfile = gbl.TFile.Open(pfn)
1334  if not tfile:
1335  raise IOError("Cannot open ROOT file {0}".format(pfn))
1336  tree = tfile.Get("##Params")
1337  tree.GetEvent(0)
1338  text = tree.db_string
1339  if "NAME=FID" in text:
1340  fid = text[text.rfind("VALUE=") + 6 : -1]
1341  nevt = tfile.Get("_Event").GetEntries()
1342  tfile.Close()
1343  return fid, nevt
1344 
1345 
1346 # -----------------------------------------------------------------------------
1347 
1348 
1350  """Get all the properties of a component as a Python dictionary.
1351  The component is instantiated using the component library
1352  """
1353  properties = {}
1354  if name == "GaudiCoreSvc":
1355  if Helper.loadDynamicLib(name) != 1:
1356  raise ImportError("Error loading component library " + name)
1357  factorylist = gbl.FactoryTable.instance().getEntries()
1358  factories = _copyFactoriesFromList(factorylist)
1359  _ = AppMgr(outputlevel=7)
1360  else:
1361  _ = AppMgr(outputlevel=7)
1362  if Helper.loadDynamicLib(name) != 1:
1363  raise ImportError("Error loading component library " + name)
1364  factorylist = gbl.FactoryTable.instance().getEntries()
1365  factories = _copyFactoriesFromList(factorylist)
1366  svcloc = gbl.Gaudi.svcLocator()
1367  dummysvc = gbl.Service("DummySvc", svcloc)
1368  for factory in factories:
1369  if InterfaceCast(gbl.IAlgFactory)(factory):
1370  ctype = "Algorithm"
1371  elif InterfaceCast(gbl.ISvcFactory)(factory):
1372  ctype = "Service"
1373  elif InterfaceCast(gbl.IToolFactory)(factory):
1374  ctype = "AlgTool"
1375  elif factory.ident() == "ApplicationMgr":
1376  ctype = "ApplicationMgr"
1377  else:
1378  ctype = "Unknown"
1379  cname = factory.ident().split()[-1]
1380  if ctype in ("Algorithm", "Service", "AlgTool", "ApplicationMgr"):
1381  try:
1382  if ctype == "AlgTool":
1383  obj = factory.instantiate(dummysvc)
1384  else:
1385  obj = factory.instantiate(svcloc)
1386  except RuntimeError as text:
1387  print("Error instantiating", cname, " from ", name)
1388  print(text)
1389  continue
1390  prop = iProperty("dummy", obj)
1391  properties[cname] = [ctype, prop.properties()]
1392  try:
1393  obj.release()
1394  except Exception:
1395  pass
1396  return properties
1397 
1398 
1399 def _copyFactoriesFromList(factories):
1400  result = []
1401  for i in range(factories.size()):
1402  factory = factories.front()
1403  result.append(factory)
1404  factories.pop_front()
1405  for factory in result:
1406  factories.push_back(factory)
1407  return result
1408 
1409 
1410 # ----CallbackStreamBuf--------------------------------------------------------
1411 # Used for redirecting C++ messages to python
1412 _CallbackStreamBufBase = gbl.GaudiPython.CallbackStreamBuf
1413 
1414 
1416  def __init__(self, callback):
1417  _CallbackStreamBufBase.__init__(self, self)
1418  self.callback = callback
1419 
1420  def _sync(self, string=None):
1421  if not string:
1422  return 0
1423  self.callback(string)
1424  return 0
1425 
1426 
1427 # ----PyAlgorithm--------------------------------------------------------------
1428 # Used to implement Algorithms in Python
1429 _PyAlgorithm = gbl.GaudiPython.PyAlgorithm
1430 
1431 
1433  def __init__(self, name=None):
1434  if not name:
1435  name = self.__class__.__name__
1436  _PyAlgorithm.__init__(self, self, name)
1437  self._svcloc = gbl.Gaudi.svcLocator()
1438  self._algmgr = InterfaceCast(gbl.IAlgManager)(self._svcloc)
1439  sc = self._algmgr.addAlgorithm(self)
1440  if sc.isFailure():
1441  raise RuntimeError("Unable to add Algorithm")
1442 
1443  def __del__(self):
1444  sc = self._algmgr.removeAlgorithm(self)
1445  if sc.isFailure():
1446  pass
1447 
1448  def initialize(self):
1449  return 1
1450 
1451  def start(self):
1452  return 1
1453 
1454  def execute(self):
1455  return 1
1456 
1457  def stop(self):
1458  return 1
1459 
1460  def finalize(self):
1461  return 1
1462 
1463 
1464 # ----Enable tab completion----------------------------------------------------
1465 try:
1466  import readline
1467  import rlcompleter # noqa: F401
1468 
1469  readline.parse_and_bind("tab: complete")
1470 except Exception:
1471  pass
GaudiPython.Bindings.AppMgr.start
def start(self)
Definition: Bindings.py:1237
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:1092
GaudiPython.Bindings.iAlgorithm.sysExecute
def sysExecute(self)
Definition: Bindings.py:470
GaudiPython.Bindings.AppMgr.removeAlgorithm
def removeAlgorithm(self, alg)
Definition: Bindings.py:1148
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:1433
GaudiPython.Bindings.iNTupleSvc.book
def book(self, *args)
Definition: Bindings.py:776
GaudiPython.Bindings.AppMgr.readOptions
def readOptions(self, file)
Definition: Bindings.py:1113
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:1096
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:1059
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:1399
GaudiPython.Bindings.iAlgorithm.sysStop
def sysStop(self)
Definition: Bindings.py:473
GaudiPython.Bindings.PyAlgorithm.execute
def execute(self)
Definition: Bindings.py:1454
GaudiPython.Bindings.AppMgr.addAlgorithm
def addAlgorithm(self, alg)
Definition: Bindings.py:1116
GaudiPython.Bindings.AppMgr.runSelectedEvents
def runSelectedEvents(self, pfn, events)
Definition: Bindings.py:1260
GaudiPython.Bindings.AppMgr.datasvc
def datasvc(self, name)
Definition: Bindings.py:1070
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:1031
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:1349
GaudiPython.Bindings.iHistogramSvc.bookProf
def bookProf(self, *args)
Definition: Bindings.py:725
GaudiPython.Bindings.AppMgr.opts
def opts(self)
Definition: Bindings.py:1017
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:1062
GaudiPython.Bindings.PyAlgorithm.finalize
def finalize(self)
Definition: Bindings.py:1460
GaudiKernel.Proxy.getNeededConfigurables
getNeededConfigurables
Definition: Proxy.py:30
GaudiPython.Bindings.toArray
def toArray(typ)
Definition: Bindings.py:119
GaudiPython.Bindings.PyAlgorithm
Definition: Bindings.py:1432
compareOutputFiles.par
par
Definition: compareOutputFiles.py:486
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:1443
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:1160
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:1415
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:1146
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:1457
GaudiPython.Bindings.PyAlgorithm.initialize
def initialize(self)
Definition: Bindings.py:1448
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:1254
GaudiPython.Bindings.CallbackStreamBuf._sync
def _sync(self, string=None)
Definition: Bindings.py:1420
GaudiPython.Bindings.iService.isValid
def isValid(self)
Definition: Bindings.py:419
GaudiPython.Bindings.AppMgr.toolsvc
def toolsvc(self, name="ToolSvc")
Definition: Bindings.py:1109
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:1416
GaudiPython.Bindings.AppMgr.createSvc
def createSvc(self, name)
Definition: Bindings.py:1041
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:1257
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:1243
GaudiKernel.ProcessJobOptions.importOptions
def importOptions(optsfile)
Definition: ProcessJobOptions.py:541
GaudiPython.Bindings.AppMgr.setAlgorithms
def setAlgorithms(self, algs)
Definition: Bindings.py:1130
GaudiPython.Bindings.AppMgr.algorithm
def algorithm(self, name, createIf=False)
Definition: Bindings.py:1048
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:1022
GaudiPython.Bindings.AppMgr.config
def config(self, **args)
Definition: Bindings.py:1187
GaudiPython.Bindings.iHistogramSvc
Definition: Bindings.py:680
GaudiPython.Bindings._getFIDandEvents
def _getFIDandEvents(pfn)
Definition: Bindings.py:1332
GaudiPython.Bindings._CallbackStreamBufBase
_CallbackStreamBufBase
Definition: Bindings.py:1412
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:1302
GaudiPython.Bindings.AppMgr.detsvc
def detsvc(self)
Definition: Bindings.py:1079
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:1025
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:1240
GaudiPython.Bindings.AppMgr.targetFSMState
def targetFSMState(self)
Definition: Bindings.py:1028
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:1418
GaudiPython.Bindings.AppMgr.OutputLevel
OutputLevel
Definition: Bindings.py:934
GaudiPython.Bindings.PyAlgorithm._algmgr
_algmgr
Definition: Bindings.py:1438
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:1055
GaudiPython.Bindings.PropertyEntry._type
_type
Definition: Bindings.py:244
GaudiPython.Bindings.AppMgr.declSvcType
def declSvcType(self, svcname, svctype)
Definition: Bindings.py:1038
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:1085
GaudiPython.Bindings.AppMgr.services
def services(self)
Definition: Bindings.py:1044
GaudiPython.Bindings.iAlgTool.name
def name(self)
Definition: Bindings.py:512
GaudiPython.Bindings.PyAlgorithm._svcloc
_svcloc
Definition: Bindings.py:1437
GaudiPython.Bindings.PropertyEntry._property
_property
Definition: Bindings.py:265
GaudiPython.Bindings.AppMgr.__del__
def __del__(self)
Definition: Bindings.py:1317
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:1234
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:1451
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:1429
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:1103
GaudiPython.Bindings.AppMgr.evtsvc
def evtsvc(self)
Definition: Bindings.py:1076
GaudiPython.Bindings.AppMgr.filerecordsvc
def filerecordsvc(self)
Definition: Bindings.py:1082
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: FunctionalDetails.h:102
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