The Gaudi Framework  v33r1 (b1225454)
GaudiPython.Bindings Namespace Reference

Classes

class  AppMgr
 
class  CallbackStreamBuf
 
class  iAlgorithm
 
class  iAlgTool
 
class  iDataSvc
 
class  iEventSelector
 
class  iHistogramSvc
 
class  iJobOptSvc
 
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

list __all__
 
 long = int
 
 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, True)
 
 FAILURE = gbl.StatusCode(gbl.StatusCode.FAILURE, True)
 
 nullptr = gbl.nullptr
 
 ROOT = cppyy.libPyROOT
 
 makeNullPointer = cppyy.libPyROOT.MakeNullPointer
 
 setOwnership = cppyy.libPyROOT.SetOwnership
 
 _CallbackStreamBufBase = gbl.GaudiPython.CallbackStreamBuf
 
 _PyAlgorithm = gbl.GaudiPython.PyAlgorithm
 

Function Documentation

◆ _copyFactoriesFromList()

def GaudiPython.Bindings._copyFactoriesFromList (   factories)
private

Definition at line 1500 of file Bindings.py.

1500 def _copyFactoriesFromList(factories):
1501  result = []
1502  for i in range(factories.size()):
1503  factory = factories.front()
1504  result.append(factory)
1505  factories.pop_front()
1506  for factory in result:
1507  factories.push_back(factory)
1508  return result
1509 
1510 
1511 # ----CallbackStreamBuf--------------------------------------------------------
1512 # Used for redirecting C++ messages to python
def _copyFactoriesFromList(factories)
Definition: Bindings.py:1500
decltype(auto) range(Args &&... args)
Zips multiple containers together to form a single range.

◆ _getFIDandEvents()

def GaudiPython.Bindings._getFIDandEvents (   pfn)
private

Definition at line 1433 of file Bindings.py.

1433 def _getFIDandEvents(pfn):
1434  tfile = gbl.TFile.Open(pfn)
1435  if not tfile:
1436  raise IOError('Cannot open ROOT file {0}'.format(pfn))
1437  tree = tfile.Get('##Params')
1438  tree.GetEvent(0)
1439  text = tree.db_string
1440  if 'NAME=FID' in text:
1441  fid = text[text.rfind('VALUE=') + 6:-1]
1442  nevt = tfile.Get('_Event').GetEntries()
1443  tfile.Close()
1444  return fid, nevt
1445 
1446 
1447 # -----------------------------------------------------------------------------
1448 
1449 
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
def _getFIDandEvents(pfn)
Definition: Bindings.py:1433

◆ deprecation()

def GaudiPython.Bindings.deprecation (   message)

Definition at line 106 of file Bindings.py.

106 def deprecation(message):
107  warnings.warn('GaudiPython: ' + message, DeprecationWarning, stacklevel=3)
108 
109 
110 # ----InterfaceCast class -----------------------------------------------------
111 
112 
def deprecation(message)
Definition: Bindings.py:106

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

171 def getClass(name, libs=[]):
172  """
173  Function to retrieve a certain C++ class by name and to load dictionary if requested
174 
175  Usage:
176 
177  from gaudimodule import getClass
178  # one knows that class is already loaded
179  AppMgr = getClass( 'ApplicationMgr' )
180  # one knows where to look for class, if not loaded yet
181  MCParticle = getClass( 'MCParticle' , 'EventDict' )
182  # one knows where to look for class, if not loaded yet
183  Vertex = getClass( 'Vertex' , ['EventDict', 'PhysEventDict'] )
184  """
185  # see if class is already loaded
186  if hasattr(gbl, name):
187  return getattr(gbl, name)
188  # try to load dictionaries and look for the required class
189  if type(libs) is not list:
190  libs = [libs]
191  for lib in libs:
192  loaddict(lib)
193  if hasattr(gbl, name):
194  return getattr(gbl, name)
195  # return None ( or raise exception? I do not know... )
196  return None
197 
198 
199 # ----PropertyEntry class------------------------------------------------------
200 
201 
def getClass(name, libs=[])
Definition: Bindings.py:171
def loaddict(dict)
Definition: Bindings.py:157

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

1450 def getComponentProperties(name):
1451  """ Get all the properties of a component as a Python dictionary.
1452  The component is instantiated using the component library
1453  """
1454  properties = {}
1455  if name == 'GaudiCoreSvc':
1456  if Helper.loadDynamicLib(name) != 1:
1457  raise ImportError('Error loading component library ' + name)
1458  factorylist = gbl.FactoryTable.instance().getEntries()
1459  factories = _copyFactoriesFromList(factorylist)
1460  g = AppMgr(outputlevel=7)
1461  else:
1462  g = AppMgr(outputlevel=7)
1463  if Helper.loadDynamicLib(name) != 1:
1464  raise ImportError('Error loading component library ' + name)
1465  factorylist = gbl.FactoryTable.instance().getEntries()
1466  factories = _copyFactoriesFromList(factorylist)
1467  svcloc = gbl.Gaudi.svcLocator()
1468  dummysvc = gbl.Service('DummySvc', svcloc)
1469  for factory in factories:
1470  if InterfaceCast(gbl.IAlgFactory)(factory):
1471  ctype = 'Algorithm'
1472  elif InterfaceCast(gbl.ISvcFactory)(factory):
1473  ctype = 'Service'
1474  elif InterfaceCast(gbl.IToolFactory)(factory):
1475  ctype = 'AlgTool'
1476  elif factory.ident() == 'ApplicationMgr':
1477  ctype = 'ApplicationMgr'
1478  else:
1479  ctype = 'Unknown'
1480  cname = factory.ident().split()[-1]
1481  if ctype in ('Algorithm', 'Service', 'AlgTool', 'ApplicationMgr'):
1482  try:
1483  if ctype == 'AlgTool':
1484  obj = factory.instantiate(dummysvc)
1485  else:
1486  obj = factory.instantiate(svcloc)
1487  except RuntimeError as text:
1488  print('Error instantiating', cname, ' from ', name)
1489  print(text)
1490  continue
1491  prop = iProperty('dummy', obj)
1492  properties[cname] = [ctype, prop.properties()]
1493  try:
1494  obj.release()
1495  except:
1496  pass
1497  return properties
1498 
1499 
def _copyFactoriesFromList(factories)
Definition: Bindings.py:1500
def getComponentProperties(name)
Definition: Bindings.py:1450

◆ loaddict()

def GaudiPython.Bindings.loaddict (   dict)
Load a LCG dictionary using various mechanisms

Definition at line 157 of file Bindings.py.

157 def loaddict(dict):
158  """ Load a LCG dictionary using various mechanisms"""
159  if Helper.loadDynamicLib(dict) == 1:
160  return
161  else:
162  try:
163  cppyy.loadDict(dict)
164  except:
165  raise ImportError('Error loading dictionary library')
166 
167 
168 # ---get a class (by loading modules if needed)--------------------------------
169 
170 
def loaddict(dict)
Definition: Bindings.py:157

◆ toArray()

def GaudiPython.Bindings.toArray (   typ)

Definition at line 92 of file Bindings.py.

92  def toArray(typ):
93  return getattr(Helper, "toArray")
94 else:
def toArray(typ)
Definition: Bindings.py:92

Variable Documentation

◆ __all__

list GaudiPython.Bindings.__all__
private
Initial value:
1 = [
2  'gbl', 'InterfaceCast', 'Interface', 'PropertyEntry', 'AppMgr',
3  'PyAlgorithm', 'CallbackStreamBuf', 'iAlgorithm', 'iDataSvc',
4  'iHistogramSvc', 'iNTupleSvc', 'iService', 'iAlgTool', 'Helper', 'SUCCESS',
5  'FAILURE', 'toArray', 'ROOT', 'makeNullPointer', 'setOwnership',
6  'getClass', 'loaddict', 'deprecation'
7 ]

Definition at line 20 of file Bindings.py.

◆ _CallbackStreamBufBase

GaudiPython.Bindings._CallbackStreamBufBase = gbl.GaudiPython.CallbackStreamBuf
private

Definition at line 1513 of file Bindings.py.

◆ _gaudi

GaudiPython.Bindings._gaudi = None
private

Definition at line 61 of file Bindings.py.

◆ _PyAlgorithm

GaudiPython.Bindings._PyAlgorithm = gbl.GaudiPython.PyAlgorithm
private

Definition at line 1530 of file Bindings.py.

◆ DataObject

GaudiPython.Bindings.DataObject = gbl.DataObject

Definition at line 70 of file Bindings.py.

◆ FAILURE

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

Definition at line 72 of file Bindings.py.

◆ Gaudi

GaudiPython.Bindings.Gaudi = gbl.Gaudi

Definition at line 59 of file Bindings.py.

◆ GaudiHandleArrayProperty

GaudiPython.Bindings.GaudiHandleArrayProperty = gbl.GaudiHandleArrayProperty

Definition at line 69 of file Bindings.py.

◆ GaudiHandleProperty

GaudiPython.Bindings.GaudiHandleProperty = gbl.GaudiHandleProperty

Definition at line 68 of file Bindings.py.

◆ gbl

GaudiPython.Bindings.gbl = cppyy.gbl

Definition at line 58 of file Bindings.py.

◆ Helper

GaudiPython.Bindings.Helper = gbl.GaudiPython.Helper

Definition at line 65 of file Bindings.py.

◆ long

GaudiPython.Bindings.long = int

Definition at line 44 of file Bindings.py.

◆ makeNullPointer

GaudiPython.Bindings.makeNullPointer = cppyy.libPyROOT.MakeNullPointer

Definition at line 102 of file Bindings.py.

◆ nullptr

GaudiPython.Bindings.nullptr = gbl.nullptr

Definition at line 73 of file Bindings.py.

◆ ROOT

GaudiPython.Bindings.ROOT = cppyy.libPyROOT

Definition at line 101 of file Bindings.py.

◆ setOwnership

GaudiPython.Bindings.setOwnership = cppyy.libPyROOT.SetOwnership

Definition at line 103 of file Bindings.py.

◆ StringProperty

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

Definition at line 66 of file Bindings.py.

◆ StringPropertyRef

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

Definition at line 67 of file Bindings.py.

◆ SUCCESS

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

Definition at line 71 of file Bindings.py.