The Gaudi Framework  v37r1 (a7f61348)
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

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

Variables

 __all__
 
 gbl
 
 Gaudi
 
 _gaudi
 
 Helper
 
 StringProperty
 
 StringPropertyRef
 
 GaudiHandleProperty
 
 GaudiHandleArrayProperty
 
 DataObject
 
 SUCCESS
 
 FAILURE
 
 nullptr
 
 ROOT
 
 makeNullPointer
 
 setOwnership
 
 _CallbackStreamBufBase
 
 _PyAlgorithm
 

Function Documentation

◆ _copyFactoriesFromList()

def GaudiPython.Bindings._copyFactoriesFromList (   factories)
private

Definition at line 1390 of file Bindings.py.

1390 def _copyFactoriesFromList(factories):
1391  result = []
1392  for i in range(factories.size()):
1393  factory = factories.front()
1394  result.append(factory)
1395  factories.pop_front()
1396  for factory in result:
1397  factories.push_back(factory)
1398  return result
1399 
1400 
1401 # ----CallbackStreamBuf--------------------------------------------------------
1402 # Used for redirecting C++ messages to python

◆ _getFIDandEvents()

def GaudiPython.Bindings._getFIDandEvents (   pfn)
private

Definition at line 1323 of file Bindings.py.

1323 def _getFIDandEvents(pfn):
1324  tfile = gbl.TFile.Open(pfn)
1325  if not tfile:
1326  raise IOError("Cannot open ROOT file {0}".format(pfn))
1327  tree = tfile.Get("##Params")
1328  tree.GetEvent(0)
1329  text = tree.db_string
1330  if "NAME=FID" in text:
1331  fid = text[text.rfind("VALUE=") + 6 : -1]
1332  nevt = tfile.Get("_Event").GetEntries()
1333  tfile.Close()
1334  return fid, nevt
1335 
1336 
1337 # -----------------------------------------------------------------------------
1338 
1339 

◆ deprecation()

def GaudiPython.Bindings.deprecation (   message)

Definition at line 134 of file Bindings.py.

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

◆ getClass()

def 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 205 of file Bindings.py.

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

◆ getComponentProperties()

def 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 1340 of file Bindings.py.

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

◆ loaddict()

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

Definition at line 192 of file Bindings.py.

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

◆ toArray()

def GaudiPython.Bindings.toArray (   typ)

Definition at line 115 of file Bindings.py.

115  def toArray(typ):
116  return getattr(Helper, "toArray")
117 
118 else:

Variable Documentation

◆ __all__

GaudiPython.Bindings.__all__
private

Definition at line 20 of file Bindings.py.

◆ _CallbackStreamBufBase

GaudiPython.Bindings._CallbackStreamBufBase
private

Definition at line 1403 of file Bindings.py.

◆ _gaudi

GaudiPython.Bindings._gaudi
private

Definition at line 74 of file Bindings.py.

◆ _PyAlgorithm

GaudiPython.Bindings._PyAlgorithm
private

Definition at line 1420 of file Bindings.py.

◆ DataObject

GaudiPython.Bindings.DataObject

Definition at line 83 of file Bindings.py.

◆ FAILURE

GaudiPython.Bindings.FAILURE

Definition at line 85 of file Bindings.py.

◆ Gaudi

GaudiPython.Bindings.Gaudi

Definition at line 72 of file Bindings.py.

◆ GaudiHandleArrayProperty

GaudiPython.Bindings.GaudiHandleArrayProperty

Definition at line 82 of file Bindings.py.

◆ GaudiHandleProperty

GaudiPython.Bindings.GaudiHandleProperty

Definition at line 81 of file Bindings.py.

◆ gbl

GaudiPython.Bindings.gbl

Definition at line 71 of file Bindings.py.

◆ Helper

GaudiPython.Bindings.Helper

Definition at line 78 of file Bindings.py.

◆ makeNullPointer

GaudiPython.Bindings.makeNullPointer

Definition at line 130 of file Bindings.py.

◆ nullptr

GaudiPython.Bindings.nullptr

Definition at line 88 of file Bindings.py.

◆ ROOT

GaudiPython.Bindings.ROOT

Definition at line 127 of file Bindings.py.

◆ setOwnership

GaudiPython.Bindings.setOwnership

Definition at line 131 of file Bindings.py.

◆ StringProperty

GaudiPython.Bindings.StringProperty

Definition at line 79 of file Bindings.py.

◆ StringPropertyRef

GaudiPython.Bindings.StringPropertyRef

Definition at line 80 of file Bindings.py.

◆ SUCCESS

GaudiPython.Bindings.SUCCESS

Definition at line 84 of file Bindings.py.

GaudiPython.Bindings._copyFactoriesFromList
def _copyFactoriesFromList(factories)
Definition: Bindings.py:1390
GaudiPython.Bindings.loaddict
def loaddict(dict)
Definition: Bindings.py:192
GaudiPython.Bindings.getComponentProperties
def getComponentProperties(name)
Definition: Bindings.py:1340
GaudiPython.Bindings.toArray
def toArray(typ)
Definition: Bindings.py:115
GaudiPython.Bindings.deprecation
def deprecation(message)
Definition: Bindings.py:134
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
GaudiPython.Bindings._getFIDandEvents
def _getFIDandEvents(pfn)
Definition: Bindings.py:1323
gaudirun.type
type
Definition: gaudirun.py:162
GaudiPython.Bindings.getClass
def getClass(name, libs=[])
Definition: Bindings.py:205
Gaudi::Functional::details::zip::range
decltype(auto) range(Args &&... args)
Zips multiple containers together to form a single range.
Definition: details.h:98