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