The Gaudi Framework  v32r2 (46d42edc)
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)
 
 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 1489 of file Bindings.py.

1489 def _copyFactoriesFromList(factories):
1490  result = []
1491  for i in range(factories.size()):
1492  factory = factories.front()
1493  result.append(factory)
1494  factories.pop_front()
1495  for factory in result:
1496  factories.push_back(factory)
1497  return result
1498 
1499 
1500 # ----CallbackStreamBuf--------------------------------------------------------
1501 # Used for redirecting C++ messages to python
def _copyFactoriesFromList(factories)
Definition: Bindings.py:1489
decltype(auto) range(Args &&... args)
Zips multiple containers together to form a single range.

◆ _getFIDandEvents()

def GaudiPython.Bindings._getFIDandEvents (   pfn)
private

Definition at line 1422 of file Bindings.py.

1422 def _getFIDandEvents(pfn):
1423  tfile = gbl.TFile.Open(pfn)
1424  if not tfile:
1425  raise IOError('Cannot open ROOT file {0}'.format(pfn))
1426  tree = tfile.Get('##Params')
1427  tree.GetEvent(0)
1428  text = tree.db_string
1429  if 'NAME=FID' in text:
1430  fid = text[text.rfind('VALUE=') + 6:-1]
1431  nevt = tfile.Get('_Event').GetEntries()
1432  tfile.Close()
1433  return fid, nevt
1434 
1435 
1436 # -----------------------------------------------------------------------------
1437 
1438 
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:109
def _getFIDandEvents(pfn)
Definition: Bindings.py:1422

◆ deprecation()

def GaudiPython.Bindings.deprecation (   message)

Definition at line 95 of file Bindings.py.

95 def deprecation(message):
96  warnings.warn('GaudiPython: ' + message, DeprecationWarning, stacklevel=3)
97 
98 
99 # ----InterfaceCast class -----------------------------------------------------
100 
101 
def deprecation(message)
Definition: Bindings.py:95

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

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

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

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

◆ loaddict()

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

Definition at line 146 of file Bindings.py.

146 def loaddict(dict):
147  """ Load a LCG dictionary using various mechanisms"""
148  if Helper.loadDynamicLib(dict) == 1:
149  return
150  else:
151  try:
152  cppyy.loadDict(dict)
153  except:
154  raise ImportError('Error loading dictionary library')
155 
156 
157 # ---get a class (by loading modules if needed)--------------------------------
158 
159 
def loaddict(dict)
Definition: Bindings.py:146

◆ toArray()

def GaudiPython.Bindings.toArray (   typ)

Definition at line 81 of file Bindings.py.

81  def toArray(typ):
82  return getattr(Helper, "toArray")
83 else:
def toArray(typ)
Definition: Bindings.py:81

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

◆ _CallbackStreamBufBase

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

Definition at line 1502 of file Bindings.py.

◆ _gaudi

GaudiPython.Bindings._gaudi = None
private

Definition at line 51 of file Bindings.py.

◆ _PyAlgorithm

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

Definition at line 1519 of file Bindings.py.

◆ DataObject

GaudiPython.Bindings.DataObject = gbl.DataObject

Definition at line 60 of file Bindings.py.

◆ FAILURE

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

Definition at line 62 of file Bindings.py.

◆ Gaudi

GaudiPython.Bindings.Gaudi = gbl.Gaudi

Definition at line 49 of file Bindings.py.

◆ GaudiHandleArrayProperty

GaudiPython.Bindings.GaudiHandleArrayProperty = gbl.GaudiHandleArrayProperty

Definition at line 59 of file Bindings.py.

◆ GaudiHandleProperty

GaudiPython.Bindings.GaudiHandleProperty = gbl.GaudiHandleProperty

Definition at line 58 of file Bindings.py.

◆ gbl

GaudiPython.Bindings.gbl = cppyy.gbl

Definition at line 48 of file Bindings.py.

◆ Helper

GaudiPython.Bindings.Helper = gbl.GaudiPython.Helper

Definition at line 55 of file Bindings.py.

◆ long

GaudiPython.Bindings.long = int

Definition at line 34 of file Bindings.py.

◆ makeNullPointer

GaudiPython.Bindings.makeNullPointer = cppyy.libPyROOT.MakeNullPointer

Definition at line 91 of file Bindings.py.

◆ ROOT

GaudiPython.Bindings.ROOT = cppyy.libPyROOT

Definition at line 90 of file Bindings.py.

◆ setOwnership

GaudiPython.Bindings.setOwnership = cppyy.libPyROOT.SetOwnership

Definition at line 92 of file Bindings.py.

◆ StringProperty

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

Definition at line 56 of file Bindings.py.

◆ StringPropertyRef

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

Definition at line 57 of file Bindings.py.

◆ SUCCESS

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

Definition at line 61 of file Bindings.py.