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

Classes

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

Functions

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

Variables

list __all__
 (c) Copyright 1998-2024 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()

GaudiPython.Bindings._copyFactoriesFromList ( factories)
protected

Definition at line 1416 of file Bindings.py.

1416def _copyFactoriesFromList(factories):
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

◆ _getFIDandEvents()

GaudiPython.Bindings._getFIDandEvents ( pfn)
protected

Definition at line 1349 of file Bindings.py.

1349def _getFIDandEvents(pfn):
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
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition MsgStream.cpp:93

◆ deprecation()

GaudiPython.Bindings.deprecation ( message)

Definition at line 133 of file Bindings.py.

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

◆ getClass()

GaudiPython.Bindings.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 204 of file Bindings.py.

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

◆ getComponentProperties()

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

Definition at line 1366 of file Bindings.py.

1366def getComponentProperties(name):
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

◆ loaddict()

GaudiPython.Bindings.loaddict ( dict)
Load an LCG dictionary

Definition at line 191 of file Bindings.py.

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

◆ toArray()

GaudiPython.Bindings.toArray ( typ)

Definition at line 114 of file Bindings.py.

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

Variable Documentation

◆ __all__

list GaudiPython.Bindings.__all__
private
Initial value:
1= [
2 "gbl",
3 "InterfaceCast",
4 "Interface",
5 "PropertyEntry",
6 "AppMgr",
7 "PyAlgorithm",
8 "CallbackStreamBuf",
9 "iAlgorithm",
10 "iDataSvc",
11 "iHistogramSvc",
12 "iNTupleSvc",
13 "iService",
14 "iAlgTool",
15 "Helper",
16 "SUCCESS",
17 "FAILURE",
18 "toArray",
19 "ROOT",
20 "makeNullPointer",
21 "setOwnership",
22 "getClass",
23 "loaddict",
24 "deprecation",
25]

(c) Copyright 1998-2024 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 1429 of file Bindings.py.

◆ _gaudi

GaudiPython.Bindings._gaudi = None
protected

Definition at line 73 of file Bindings.py.

◆ _PyAlgorithm

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

Definition at line 1446 of file Bindings.py.

◆ DataObject

GaudiPython.Bindings.DataObject = gbl.DataObject

Definition at line 82 of file Bindings.py.

◆ FAILURE

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

Definition at line 84 of file Bindings.py.

◆ Gaudi

GaudiPython.Bindings.Gaudi = gbl.Gaudi

Definition at line 71 of file Bindings.py.

◆ GaudiHandleArrayProperty

GaudiPython.Bindings.GaudiHandleArrayProperty = gbl.GaudiHandleArrayProperty

Definition at line 81 of file Bindings.py.

◆ GaudiHandleProperty

GaudiPython.Bindings.GaudiHandleProperty = gbl.GaudiHandleProperty

Definition at line 80 of file Bindings.py.

◆ gbl

GaudiPython.Bindings.gbl = cppyy.gbl

Definition at line 70 of file Bindings.py.

◆ Helper

GaudiPython.Bindings.Helper = gbl.GaudiPython.Helper

Definition at line 77 of file Bindings.py.

◆ makeNullPointer

GaudiPython.Bindings.makeNullPointer = ROOT.MakeNullPointer

Definition at line 129 of file Bindings.py.

◆ nullptr

GaudiPython.Bindings.nullptr = cppyy.nullptr

Definition at line 87 of file Bindings.py.

◆ ROOT

GaudiPython.Bindings.ROOT = cppyy.libPyROOT

Definition at line 126 of file Bindings.py.

◆ setOwnership

GaudiPython.Bindings.setOwnership = ROOT.SetOwnership

Definition at line 130 of file Bindings.py.

◆ StringProperty

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

Definition at line 78 of file Bindings.py.

◆ StringPropertyRef

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

Definition at line 79 of file Bindings.py.

◆ SUCCESS

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

Definition at line 83 of file Bindings.py.