The Gaudi Framework  master (6507eef1)
Loading...
Searching...
No Matches
GaudiPython.Bindings Namespace Reference

Classes

class  InterfaceCast
class  Interface
class  PropertyEntry
class  iProperty
class  iService
class  iAlgorithm
class  iAlgTool
class  iDataSvc
class  iHistogramSvc
class  iNTupleSvc
class  iToolSvc
class  iEventSelector
class  AppMgr
class  CallbackStreamBuf
class  PyAlgorithm

Functions

 toArray (typ)
 deprecation (message)
 loaddict (dict)
 getClass (name, libs=[])
 _getFIDandEvents (pfn)
 getComponentProperties (name)
 _copyFactoriesFromList (factories)

Variables

list __all__
 (c) Copyright 1998-2026 CERN for the benefit of the LHCb and ATLAS collaborations # # This software is distributed under the terms of the Apache version 2 licence, # copied verbatim in the file "LICENSE".
 gbl = cppyy.gbl
 Gaudi = gbl.Gaudi
 _gaudi = None
 Helper = gbl.GaudiPython.Helper
 StringProperty = gbl.Gaudi.Property("std::string")
 StringPropertyRef = gbl.Gaudi.Property("std::string&")
 GaudiHandleProperty = gbl.GaudiHandleProperty
 GaudiHandleArrayProperty = gbl.GaudiHandleArrayProperty
 DataObject = gbl.DataObject
 SUCCESS = gbl.StatusCode(gbl.StatusCode.SUCCESS)
 FAILURE = gbl.StatusCode(gbl.StatusCode.FAILURE)
 nullptr = cppyy.nullptr
 ROOT = cppyy.libPyROOT
 makeNullPointer = ROOT.MakeNullPointer
 setOwnership = ROOT.SetOwnership
 _CallbackStreamBufBase = gbl.GaudiPython.CallbackStreamBuf
 _PyAlgorithm = gbl.GaudiPython.PyAlgorithm

Function Documentation

◆ _copyFactoriesFromList()

_copyFactoriesFromList ( factories)
protected

Definition at line 1380 of file Bindings.py.

1380def _copyFactoriesFromList(factories):
1381 result = []
1382 for i in range(factories.size()):
1383 factory = factories.front()
1384 result.append(factory)
1385 factories.pop_front()
1386 for factory in result:
1387 factories.push_back(factory)
1388 return result
1389
1390
1391# ----CallbackStreamBuf--------------------------------------------------------
1392# Used for redirecting C++ messages to python

◆ _getFIDandEvents()

_getFIDandEvents ( pfn)
protected

Definition at line 1313 of file Bindings.py.

1313def _getFIDandEvents(pfn):
1314 tfile = gbl.TFile.Open(pfn)
1315 if not tfile:
1316 raise OSError(f"Cannot open ROOT file {pfn}")
1317 tree = tfile.Get("##Params")
1318 tree.GetEvent(0)
1319 text = tree.db_string
1320 if "NAME=FID" in text:
1321 fid = text[text.rfind("VALUE=") + 6 : -1]
1322 nevt = tfile.Get("_Event").GetEntries()
1323 tfile.Close()
1324 return fid, nevt
1325
1326
1327# -----------------------------------------------------------------------------
1328
1329

◆ deprecation()

deprecation ( message)

Definition at line 132 of file Bindings.py.

132def deprecation(message):
133 warnings.warn("GaudiPython: " + message, DeprecationWarning, stacklevel=3)
134
135
136# ----InterfaceCast class -----------------------------------------------------
137
138

◆ getClass()

getClass ( name,
libs = [] )
Function to retrieve a certain C++ class by name and to load dictionary if requested

Usage:

from gaudimodule import getClass
# one knows that class is already loaded
AppMgr     = getClass( 'ApplicationMgr'           )
# one knows where to look for class, if not loaded yet
MCParticle = getClass( 'MCParticle' , 'EventDict' )
# one knows where to look for class, if not loaded yet
Vertex     = getClass( 'Vertex' , ['EventDict', 'PhysEventDict'] )

Definition at line 203 of file Bindings.py.

203def getClass(name, libs=[]):
204 """
205 Function to retrieve a certain C++ class by name and to load dictionary if requested
206
207 Usage:
208
209 from gaudimodule import getClass
210 # one knows that class is already loaded
211 AppMgr = getClass( 'ApplicationMgr' )
212 # one knows where to look for class, if not loaded yet
213 MCParticle = getClass( 'MCParticle' , 'EventDict' )
214 # one knows where to look for class, if not loaded yet
215 Vertex = getClass( 'Vertex' , ['EventDict', 'PhysEventDict'] )
216 """
217 # see if class is already loaded
218 if hasattr(gbl, name):
219 return getattr(gbl, name)
220 # try to load dictionaries and look for the required class
221 if not isinstance(libs, list):
222 libs = [libs]
223 for lib in libs:
224 loaddict(lib)
225 if hasattr(gbl, name):
226 return getattr(gbl, name)
227 # return None ( or raise exception? I do not know... )
228 return None
229
230
231# ----PropertyEntry class------------------------------------------------------
232
233

◆ getComponentProperties()

getComponentProperties ( name)
Get all the properties of a component as a Python dictionary.
The component is instantiated using the component library

Definition at line 1330 of file Bindings.py.

1330def getComponentProperties(name):
1331 """Get all the properties of a component as a Python dictionary.
1332 The component is instantiated using the component library
1333 """
1334 properties = {}
1335 if name == "GaudiCoreSvc":
1336 if Helper.loadDynamicLib(name) != 1:
1337 raise ImportError("Error loading component library " + name)
1338 factorylist = gbl.FactoryTable.instance().getEntries()
1339 factories = _copyFactoriesFromList(factorylist)
1340 _ = AppMgr(outputlevel=7)
1341 else:
1342 _ = AppMgr(outputlevel=7)
1343 if Helper.loadDynamicLib(name) != 1:
1344 raise ImportError("Error loading component library " + name)
1345 factorylist = gbl.FactoryTable.instance().getEntries()
1346 factories = _copyFactoriesFromList(factorylist)
1347 svcloc = gbl.Gaudi.svcLocator()
1348 dummysvc = gbl.Service("DummySvc", svcloc)
1349 for factory in factories:
1350 if InterfaceCast(gbl.IAlgFactory)(factory):
1351 ctype = "Algorithm"
1352 elif InterfaceCast(gbl.ISvcFactory)(factory):
1353 ctype = "Service"
1354 elif InterfaceCast(gbl.IToolFactory)(factory):
1355 ctype = "AlgTool"
1356 elif factory.ident() == "ApplicationMgr":
1357 ctype = "ApplicationMgr"
1358 else:
1359 ctype = "Unknown"
1360 cname = factory.ident().split()[-1]
1361 if ctype in ("Algorithm", "Service", "AlgTool", "ApplicationMgr"):
1362 try:
1363 if ctype == "AlgTool":
1364 obj = factory.instantiate(dummysvc)
1365 else:
1366 obj = factory.instantiate(svcloc)
1367 except RuntimeError as text:
1368 print("Error instantiating", cname, " from ", name)
1369 print(text)
1370 continue
1371 prop = iProperty("dummy", obj)
1372 properties[cname] = [ctype, prop.properties()]
1373 try:
1374 obj.release()
1375 except Exception:
1376 pass
1377 return properties
1378
1379

◆ loaddict()

loaddict ( dict)
Load an LCG dictionary

Definition at line 190 of file Bindings.py.

190def loaddict(dict):
191 """Load an LCG dictionary"""
192 loadlib_return_code = Helper.loadDynamicLib(dict)
193 if loadlib_return_code == 1:
194 return
195 raise RuntimeError(
196 f"Failed to load dictionary library {dict} (return code {loadlib_return_code})"
197 )
198
199
200# ---get a class (by loading modules if needed)--------------------------------
201
202

◆ toArray()

toArray ( typ)

Definition at line 113 of file Bindings.py.

113 def toArray(typ):
114 return getattr(Helper, "toArray")
115

Variable Documentation

◆ __all__

list GaudiPython.Bindings.__all__
private
Initial value:
= [
"gbl",
"InterfaceCast",
"Interface",
"PropertyEntry",
"AppMgr",
"PyAlgorithm",
"CallbackStreamBuf",
"iAlgorithm",
"iDataSvc",
"iHistogramSvc",
"iNTupleSvc",
"iService",
"iAlgTool",
"Helper",
"SUCCESS",
"FAILURE",
"toArray",
"ROOT",
"makeNullPointer",
"setOwnership",
"getClass",
"loaddict",
"deprecation",
]

(c) Copyright 1998-2026 CERN for the benefit of the LHCb and ATLAS collaborations # # This software is distributed under the terms of the Apache version 2 licence, # copied verbatim in the file "LICENSE".

# # In applying this licence, CERN does not waive the privileges and immunities # granted to it by virtue of its status as an Intergovernmental Organization # or submit itself to any jurisdiction. #

File: GaudiPython/Bindings.py Author: Pere Mato (pere..nosp@m.mato.nosp@m.@cern.nosp@m..ch)

Definition at line 19 of file Bindings.py.

◆ _CallbackStreamBufBase

GaudiPython.Bindings._CallbackStreamBufBase = gbl.GaudiPython.CallbackStreamBuf
protected

Definition at line 1393 of file Bindings.py.

◆ _gaudi

GaudiPython.Bindings._gaudi = None
protected

Definition at line 72 of file Bindings.py.

◆ _PyAlgorithm

GaudiPython.Bindings._PyAlgorithm = gbl.GaudiPython.PyAlgorithm
protected

Definition at line 1410 of file Bindings.py.

◆ DataObject

GaudiPython.Bindings.DataObject = gbl.DataObject

Definition at line 81 of file Bindings.py.

◆ FAILURE

GaudiPython.Bindings.FAILURE = gbl.StatusCode(gbl.StatusCode.FAILURE)

Definition at line 83 of file Bindings.py.

◆ Gaudi

GaudiPython.Bindings.Gaudi = gbl.Gaudi

Definition at line 70 of file Bindings.py.

◆ GaudiHandleArrayProperty

GaudiPython.Bindings.GaudiHandleArrayProperty = gbl.GaudiHandleArrayProperty

Definition at line 80 of file Bindings.py.

◆ GaudiHandleProperty

GaudiPython.Bindings.GaudiHandleProperty = gbl.GaudiHandleProperty

Definition at line 79 of file Bindings.py.

◆ gbl

GaudiPython.Bindings.gbl = cppyy.gbl

Definition at line 69 of file Bindings.py.

◆ Helper

GaudiPython.Bindings.Helper = gbl.GaudiPython.Helper

Definition at line 76 of file Bindings.py.

◆ makeNullPointer

GaudiPython.Bindings.makeNullPointer = ROOT.MakeNullPointer

Definition at line 128 of file Bindings.py.

◆ nullptr

GaudiPython.Bindings.nullptr = cppyy.nullptr

Definition at line 86 of file Bindings.py.

◆ ROOT

GaudiPython.Bindings.ROOT = cppyy.libPyROOT

Definition at line 125 of file Bindings.py.

◆ setOwnership

GaudiPython.Bindings.setOwnership = ROOT.SetOwnership

Definition at line 129 of file Bindings.py.

◆ StringProperty

GaudiPython.Bindings.StringProperty = gbl.Gaudi.Property("std::string")

Definition at line 77 of file Bindings.py.

◆ StringPropertyRef

GaudiPython.Bindings.StringPropertyRef = gbl.Gaudi.Property("std::string&")

Definition at line 78 of file Bindings.py.

◆ SUCCESS

GaudiPython.Bindings.SUCCESS = gbl.StatusCode(gbl.StatusCode.SUCCESS)

Definition at line 82 of file Bindings.py.