The Gaudi Framework  v31r0 (aeb156f0)
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 = string.maketrans('<>&*,: ().', '__rp__s___')
 
 log = logging.getLogger('ConfigurableDb')
 
 CfgDb = _Singleton()
 
 cfgDb = CfgDb()
 

Function Documentation

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

Definition at line 151 of file ConfigurableDb.py.

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

Definition at line 105 of file ConfigurableDb.py.

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

Variable Documentation

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

Definition at line 9 of file ConfigurableDb.py.

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

Definition at line 12 of file ConfigurableDb.py.

GaudiKernel.ConfigurableDb.CfgDb = _Singleton()

Definition at line 93 of file ConfigurableDb.py.

GaudiKernel.ConfigurableDb.cfgDb = CfgDb()

Definition at line 100 of file ConfigurableDb.py.

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

Definition at line 15 of file ConfigurableDb.py.