The Gaudi Framework  v37r0 (b608885e)
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__
 
 long
 
 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 1398 of file Bindings.py.

1398 def _copyFactoriesFromList(factories):
1399  result = []
1400  for i in range(factories.size()):
1401  factory = factories.front()
1402  result.append(factory)
1403  factories.pop_front()
1404  for factory in result:
1405  factories.push_back(factory)
1406  return result
1407 
1408 
1409 # ----CallbackStreamBuf--------------------------------------------------------
1410 # Used for redirecting C++ messages to python

◆ _getFIDandEvents()

def GaudiPython.Bindings._getFIDandEvents (   pfn)
private

Definition at line 1331 of file Bindings.py.

1331 def _getFIDandEvents(pfn):
1332  tfile = gbl.TFile.Open(pfn)
1333  if not tfile:
1334  raise IOError("Cannot open ROOT file {0}".format(pfn))
1335  tree = tfile.Get("##Params")
1336  tree.GetEvent(0)
1337  text = tree.db_string
1338  if "NAME=FID" in text:
1339  fid = text[text.rfind("VALUE=") + 6 : -1]
1340  nevt = tfile.Get("_Event").GetEntries()
1341  tfile.Close()
1342  return fid, nevt
1343 
1344 
1345 # -----------------------------------------------------------------------------
1346 
1347 

◆ deprecation()

def GaudiPython.Bindings.deprecation (   message)

Definition at line 138 of file Bindings.py.

138 def deprecation(message):
139  warnings.warn("GaudiPython: " + message, DeprecationWarning, stacklevel=3)
140 
141 
142 # ----InterfaceCast class -----------------------------------------------------
143 
144 

◆ 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 209 of file Bindings.py.

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

◆ 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 1348 of file Bindings.py.

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

◆ loaddict()

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

Definition at line 196 of file Bindings.py.

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

◆ toArray()

def GaudiPython.Bindings.toArray (   typ)

Definition at line 119 of file Bindings.py.

119  def toArray(typ):
120  return getattr(Helper, "toArray")
121 
122 else:

Variable Documentation

◆ __all__

GaudiPython.Bindings.__all__
private

Definition at line 20 of file Bindings.py.

◆ _CallbackStreamBufBase

GaudiPython.Bindings._CallbackStreamBufBase
private

Definition at line 1411 of file Bindings.py.

◆ _gaudi

GaudiPython.Bindings._gaudi
private

Definition at line 78 of file Bindings.py.

◆ _PyAlgorithm

GaudiPython.Bindings._PyAlgorithm
private

Definition at line 1428 of file Bindings.py.

◆ DataObject

GaudiPython.Bindings.DataObject

Definition at line 87 of file Bindings.py.

◆ FAILURE

GaudiPython.Bindings.FAILURE

Definition at line 89 of file Bindings.py.

◆ Gaudi

GaudiPython.Bindings.Gaudi

Definition at line 76 of file Bindings.py.

◆ GaudiHandleArrayProperty

GaudiPython.Bindings.GaudiHandleArrayProperty

Definition at line 86 of file Bindings.py.

◆ GaudiHandleProperty

GaudiPython.Bindings.GaudiHandleProperty

Definition at line 85 of file Bindings.py.

◆ gbl

GaudiPython.Bindings.gbl

Definition at line 75 of file Bindings.py.

◆ Helper

GaudiPython.Bindings.Helper

Definition at line 82 of file Bindings.py.

◆ long

GaudiPython.Bindings.long

Definition at line 60 of file Bindings.py.

◆ makeNullPointer

GaudiPython.Bindings.makeNullPointer

Definition at line 134 of file Bindings.py.

◆ nullptr

GaudiPython.Bindings.nullptr

Definition at line 92 of file Bindings.py.

◆ ROOT

GaudiPython.Bindings.ROOT

Definition at line 131 of file Bindings.py.

◆ setOwnership

GaudiPython.Bindings.setOwnership

Definition at line 135 of file Bindings.py.

◆ StringProperty

GaudiPython.Bindings.StringProperty

Definition at line 83 of file Bindings.py.

◆ StringPropertyRef

GaudiPython.Bindings.StringPropertyRef

Definition at line 84 of file Bindings.py.

◆ SUCCESS

GaudiPython.Bindings.SUCCESS

Definition at line 88 of file Bindings.py.

GaudiPython.Bindings._copyFactoriesFromList
def _copyFactoriesFromList(factories)
Definition: Bindings.py:1398
GaudiPython.Bindings.loaddict
def loaddict(dict)
Definition: Bindings.py:196
GaudiPython.Bindings.getComponentProperties
def getComponentProperties(name)
Definition: Bindings.py:1348
GaudiPython.Bindings.toArray
def toArray(typ)
Definition: Bindings.py:119
GaudiPython.Bindings.deprecation
def deprecation(message)
Definition: Bindings.py:138
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:1331
gaudirun.type
type
Definition: gaudirun.py:162
GaudiPython.Bindings.getClass
def getClass(name, libs=[])
Definition: Bindings.py:209
Gaudi::Functional::details::zip::range
decltype(auto) range(Args &&... args)
Zips multiple containers together to form a single range.
Definition: details.h:98