The Gaudi Framework  v33r2 (a6f0ec87)
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 = cppyy.nullptr
 
 ROOT = cppyy.libPyROOT
 
 makeNullPointer = ROOT.MakeNullPointer
 
 setOwnership = ROOT.SetOwnership
 
 _CallbackStreamBufBase = gbl.GaudiPython.CallbackStreamBuf
 
 _PyAlgorithm = gbl.GaudiPython.PyAlgorithm
 

Function Documentation

◆ _copyFactoriesFromList()

def GaudiPython.Bindings._copyFactoriesFromList (   factories)
private

Definition at line 1509 of file Bindings.py.

1509 def _copyFactoriesFromList(factories):
1510  result = []
1511  for i in range(factories.size()):
1512  factory = factories.front()
1513  result.append(factory)
1514  factories.pop_front()
1515  for factory in result:
1516  factories.push_back(factory)
1517  return result
1518 
1519 
1520 # ----CallbackStreamBuf--------------------------------------------------------
1521 # Used for redirecting C++ messages to python
def _copyFactoriesFromList(factories)
Definition: Bindings.py:1509
decltype(auto) range(Args &&... args)
Zips multiple containers together to form a single range.

◆ _getFIDandEvents()

def GaudiPython.Bindings._getFIDandEvents (   pfn)
private

Definition at line 1442 of file Bindings.py.

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

◆ deprecation()

def GaudiPython.Bindings.deprecation (   message)

Definition at line 115 of file Bindings.py.

115 def deprecation(message):
116  warnings.warn('GaudiPython: ' + message, DeprecationWarning, stacklevel=3)
117 
118 
119 # ----InterfaceCast class -----------------------------------------------------
120 
121 
def deprecation(message)
Definition: Bindings.py:115

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

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

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

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

◆ loaddict()

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

Definition at line 166 of file Bindings.py.

166 def loaddict(dict):
167  """ Load a LCG dictionary using various mechanisms"""
168  if Helper.loadDynamicLib(dict) == 1:
169  return
170  else:
171  try:
172  cppyy.loadDict(dict)
173  except:
174  raise ImportError('Error loading dictionary library')
175 
176 
177 # ---get a class (by loading modules if needed)--------------------------------
178 
179 
def loaddict(dict)
Definition: Bindings.py:166

◆ toArray()

def GaudiPython.Bindings.toArray (   typ)

Definition at line 97 of file Bindings.py.

97  def toArray(typ):
98  return getattr(Helper, "toArray")
99 else:
def toArray(typ)
Definition: Bindings.py:97

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

◆ _gaudi

GaudiPython.Bindings._gaudi = None
private

Definition at line 60 of file Bindings.py.

◆ _PyAlgorithm

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

Definition at line 1539 of file Bindings.py.

◆ DataObject

GaudiPython.Bindings.DataObject = gbl.DataObject

Definition at line 69 of file Bindings.py.

◆ FAILURE

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

Definition at line 71 of file Bindings.py.

◆ Gaudi

GaudiPython.Bindings.Gaudi = gbl.Gaudi

Definition at line 58 of file Bindings.py.

◆ GaudiHandleArrayProperty

GaudiPython.Bindings.GaudiHandleArrayProperty = gbl.GaudiHandleArrayProperty

Definition at line 68 of file Bindings.py.

◆ GaudiHandleProperty

GaudiPython.Bindings.GaudiHandleProperty = gbl.GaudiHandleProperty

Definition at line 67 of file Bindings.py.

◆ gbl

GaudiPython.Bindings.gbl = cppyy.gbl

Definition at line 57 of file Bindings.py.

◆ Helper

GaudiPython.Bindings.Helper = gbl.GaudiPython.Helper

Definition at line 64 of file Bindings.py.

◆ long

GaudiPython.Bindings.long = int

Definition at line 43 of file Bindings.py.

◆ makeNullPointer

GaudiPython.Bindings.makeNullPointer = ROOT.MakeNullPointer

Definition at line 111 of file Bindings.py.

◆ nullptr

GaudiPython.Bindings.nullptr = cppyy.nullptr

Definition at line 74 of file Bindings.py.

◆ ROOT

GaudiPython.Bindings.ROOT = cppyy.libPyROOT

Definition at line 108 of file Bindings.py.

◆ setOwnership

GaudiPython.Bindings.setOwnership = ROOT.SetOwnership

Definition at line 112 of file Bindings.py.

◆ StringProperty

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

Definition at line 65 of file Bindings.py.

◆ StringPropertyRef

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

Definition at line 66 of file Bindings.py.

◆ SUCCESS

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

Definition at line 70 of file Bindings.py.