The Gaudi Framework  v32r2 (46d42edc)
GaudiKernel.ConfigurableDb Namespace Reference

Classes

class  _CfgDb
 
class  _Singleton
 

Functions

def loadConfigurableDb ()
 
def getConfigurable (className, requester='', assumeCxxClass=True)
 

Variables

list __all__ = ['CfgDb', 'cfgDb', 'loadConfigurableDb', 'getConfigurable']
 
 _transtable = str.maketrans('<>&*,: ().', '__rp__s___')
 
 log = logging.getLogger('ConfigurableDb')
 
 CfgDb = _Singleton()
 
 cfgDb = CfgDb()
 

Function Documentation

◆ getConfigurable()

def GaudiKernel.ConfigurableDb.getConfigurable (   className,
  requester = '',
  assumeCxxClass = True 
)

Definition at line 152 of file ConfigurableDb.py.

152 def getConfigurable(className, requester='', assumeCxxClass=True):
153  confClass = className
154  if assumeCxxClass:
155  # assume className is C++: --> translate to python
156  try:
157  confClass = str.translate(confClass, _transtable)
158  except AttributeError:
159  # Python 2 compatibility
160  confClass = string.translate(confClass, _transtable)
161  # see if I have it in my dictionary
162  confClassInfo = cfgDb.get(confClass)
163  if not confClassInfo:
164  confClassInfo = cfgDb.get(confClass)
165  # get the python module
166  confMod = confClassInfo and confClassInfo.get('module')
167  if not confMod:
168  log.warning("%s: Class %s not in database", requester, className)
169  return None
170  # load the module
171  try:
172  mod = __import__(confMod, globals(), locals(), confClass)
173  except ImportError:
174  log.warning("%s: Module %s not found (needed for configurable %s)",
175  requester, confMod, className)
176  return None
177  # get the class
178  try:
179  confClass = getattr(mod, confClass)
180  except AttributeError:
181  log.warning("%s: Configurable %s not found in module %s", requester,
182  confClass, confMod)
183  return None
184  # Got it!
185  log.debug("%s: Found configurable %s in module %s", requester, confClass,
186  confMod)
187 
188  return confClass
def getConfigurable(className, requester='', assumeCxxClass=True)

◆ loadConfigurableDb()

def GaudiKernel.ConfigurableDb.loadConfigurableDb ( )
Helper function to load all ConfigurableDb files (modules) holding
informations about Configurables

Definition at line 109 of file ConfigurableDb.py.

109 def loadConfigurableDb():
110  """Helper function to load all ConfigurableDb files (modules) holding
111  informations about Configurables
112  """
113  import os
114  import sys
115  from glob import glob
116  from os.path import join as path_join
117  log.debug("loading confDb files...")
118  nFiles = 0 # counter of imported files
119  pathlist = os.getenv("LD_LIBRARY_PATH", "").split(os.pathsep)
120  for path in pathlist:
121  if not os.path.isdir(path):
122  continue
123  log.debug("walking in [%s]...", path)
124  confDbFiles = [
125  f for f in [
126  path_join(path, f) for f in os.listdir(path)
127  if f.endswith('.confdb')
128  ] if os.path.isfile(f)
129  ]
130  # check if we use "*_merged.confdb"
131  mergedConfDbFiles = [
132  f for f in confDbFiles if f.endswith('_merged.confdb')
133  ]
134  if mergedConfDbFiles:
135  # use only the merged ones
136  confDbFiles = mergedConfDbFiles
137 
138  for confDb in confDbFiles:
139  log.debug("\t-loading [%s]...", confDb)
140  try:
141  cfgDb._loadModule(confDb)
142  except Exception as err:
143  log.warning("Could not load file [%s] !", confDb)
144  log.warning("Reason: %s", err)
145  nFiles += 1
146  log.debug("loading confDb files... [DONE]")
147  nPkgs = len(set([k['package'] for k in cfgDb.values()]))
148  log.debug("loaded %i confDb packages", nPkgs)
149  return nFiles
150 
151 

Variable Documentation

◆ __all__

list GaudiKernel.ConfigurableDb.__all__ = ['CfgDb', 'cfgDb', 'loadConfigurableDb', 'getConfigurable']
private

Definition at line 9 of file ConfigurableDb.py.

◆ _transtable

GaudiKernel.ConfigurableDb._transtable = str.maketrans('<>&*,: ().', '__rp__s___')
private

Definition at line 13 of file ConfigurableDb.py.

◆ CfgDb

GaudiKernel.ConfigurableDb.CfgDb = _Singleton()

Definition at line 97 of file ConfigurableDb.py.

◆ cfgDb

GaudiKernel.ConfigurableDb.cfgDb = CfgDb()

Definition at line 104 of file ConfigurableDb.py.

◆ log

GaudiKernel.ConfigurableDb.log = logging.getLogger('ConfigurableDb')

Definition at line 19 of file ConfigurableDb.py.