The Gaudi Framework  master (37c0b60a)
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__
 (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". More...
 
 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 1416 of file Bindings.py.

1416 def _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()

def GaudiPython.Bindings._getFIDandEvents (   pfn)
private

Definition at line 1349 of file Bindings.py.

1349 def _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 

◆ deprecation()

def GaudiPython.Bindings.deprecation (   message)

Definition at line 133 of file Bindings.py.

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

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

204 def 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()

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

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

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

Definition at line 191 of file Bindings.py.

191 def 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()

def GaudiPython.Bindings.toArray (   typ)

Definition at line 114 of file Bindings.py.

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

Variable Documentation

◆ __all__

GaudiPython.Bindings.__all__
private

(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
private

Definition at line 1429 of file Bindings.py.

◆ _gaudi

GaudiPython.Bindings._gaudi
private

Definition at line 73 of file Bindings.py.

◆ _PyAlgorithm

GaudiPython.Bindings._PyAlgorithm
private

Definition at line 1446 of file Bindings.py.

◆ DataObject

GaudiPython.Bindings.DataObject

Definition at line 82 of file Bindings.py.

◆ FAILURE

GaudiPython.Bindings.FAILURE

Definition at line 84 of file Bindings.py.

◆ Gaudi

GaudiPython.Bindings.Gaudi

Definition at line 71 of file Bindings.py.

◆ GaudiHandleArrayProperty

GaudiPython.Bindings.GaudiHandleArrayProperty

Definition at line 81 of file Bindings.py.

◆ GaudiHandleProperty

GaudiPython.Bindings.GaudiHandleProperty

Definition at line 80 of file Bindings.py.

◆ gbl

GaudiPython.Bindings.gbl

Definition at line 70 of file Bindings.py.

◆ Helper

GaudiPython.Bindings.Helper

Definition at line 77 of file Bindings.py.

◆ makeNullPointer

GaudiPython.Bindings.makeNullPointer

Definition at line 129 of file Bindings.py.

◆ nullptr

GaudiPython.Bindings.nullptr

Definition at line 87 of file Bindings.py.

◆ ROOT

GaudiPython.Bindings.ROOT

Definition at line 126 of file Bindings.py.

◆ setOwnership

GaudiPython.Bindings.setOwnership

Definition at line 130 of file Bindings.py.

◆ StringProperty

GaudiPython.Bindings.StringProperty

Definition at line 78 of file Bindings.py.

◆ StringPropertyRef

GaudiPython.Bindings.StringPropertyRef

Definition at line 79 of file Bindings.py.

◆ SUCCESS

GaudiPython.Bindings.SUCCESS

Definition at line 83 of file Bindings.py.

GaudiPartProp.Service.AppMgr
AppMgr
Definition: Service.py:41
GaudiPython.Bindings._copyFactoriesFromList
def _copyFactoriesFromList(factories)
Definition: Bindings.py:1416
GaudiPython.Bindings.loaddict
def loaddict(dict)
Definition: Bindings.py:191
GaudiPartProp.Service.InterfaceCast
InterfaceCast
Definition: Service.py:40
GaudiPython.Bindings.getComponentProperties
def getComponentProperties(name)
Definition: Bindings.py:1366
GaudiPython.Bindings.toArray
def toArray(typ)
Definition: Bindings.py:114
GaudiPython.Bindings.deprecation
def deprecation(message)
Definition: Bindings.py:133
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:1349
GaudiPython.Bindings.getClass
def getClass(name, libs=[])
Definition: Bindings.py:204
Gaudi::Functional::details::zip::range
decltype(auto) range(Args &&... args)
Zips multiple containers together to form a single range.
Definition: details.h:97