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