The Gaudi Framework  v38r0 (2143aa4c)
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-2023 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 1413 of file Bindings.py.

1413 def _copyFactoriesFromList(factories):
1414  result = []
1415  for i in range(factories.size()):
1416  factory = factories.front()
1417  result.append(factory)
1418  factories.pop_front()
1419  for factory in result:
1420  factories.push_back(factory)
1421  return result
1422 
1423 
1424 # ----CallbackStreamBuf--------------------------------------------------------
1425 # Used for redirecting C++ messages to python

◆ _getFIDandEvents()

def GaudiPython.Bindings._getFIDandEvents (   pfn)
private

Definition at line 1346 of file Bindings.py.

1346 def _getFIDandEvents(pfn):
1347  tfile = gbl.TFile.Open(pfn)
1348  if not tfile:
1349  raise IOError("Cannot open ROOT file {0}".format(pfn))
1350  tree = tfile.Get("##Params")
1351  tree.GetEvent(0)
1352  text = tree.db_string
1353  if "NAME=FID" in text:
1354  fid = text[text.rfind("VALUE=") + 6 : -1]
1355  nevt = tfile.Get("_Event").GetEntries()
1356  tfile.Close()
1357  return fid, nevt
1358 
1359 
1360 # -----------------------------------------------------------------------------
1361 
1362 

◆ 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 type(libs) is not 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 1363 of file Bindings.py.

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

◆ 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-2023 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 1426 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 1443 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:40
GaudiPython.Bindings._copyFactoriesFromList
def _copyFactoriesFromList(factories)
Definition: Bindings.py:1413
GaudiPython.Bindings.loaddict
def loaddict(dict)
Definition: Bindings.py:191
GaudiPartProp.Service.InterfaceCast
InterfaceCast
Definition: Service.py:39
GaudiPython.Bindings.getComponentProperties
def getComponentProperties(name)
Definition: Bindings.py:1363
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:1346
gaudirun.type
type
Definition: gaudirun.py:160
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:98