The Gaudi Framework  v33r0 (d5ea422b)
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 1499 of file Bindings.py.

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

◆ _getFIDandEvents()

def GaudiPython.Bindings._getFIDandEvents (   pfn)
private

Definition at line 1432 of file Bindings.py.

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

◆ deprecation()

def GaudiPython.Bindings.deprecation (   message)

Definition at line 105 of file Bindings.py.

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

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

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

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

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

◆ loaddict()

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

Definition at line 156 of file Bindings.py.

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

◆ toArray()

def GaudiPython.Bindings.toArray (   typ)

Definition at line 91 of file Bindings.py.

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

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 1512 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 1529 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 101 of file Bindings.py.

◆ ROOT

GaudiPython.Bindings.ROOT = cppyy.libPyROOT

Definition at line 100 of file Bindings.py.

◆ setOwnership

GaudiPython.Bindings.setOwnership = cppyy.libPyROOT.SetOwnership

Definition at line 102 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.