ATLAS Offline Software
Classes | Functions | Variables
python.ConfigurableDb Namespace Reference

Classes

class  _CfgDb
 singleton holding configurable and loadable information ---------------— More...
 
class  _Singleton
 create configurable DB, and pre-fill it, then clean-up remnants -------— More...
 

Functions

def _fillConfDict ()
 helpers ---------------------------------------------------------------— More...
 
def loadConfigurableDb ()
 
def unloadConfigurableDb ()
 function to UNload all ConfigurableDb informations --------------------— More...
 
def getConfigurable (className, requester='', assumeCxxClass=True)
 

Variables

string __version__ = '3.0.0'
 data ------------------------------------------------------------------— More...
 
string __author__ = 'Sebastien Binet (binet@cern.ch)'
 
list __all__
 
 _transtable = str.maketrans('<>&*,: ().', '__rp__s___')
 
 CfgDb = _Singleton()
 
 cfgDb = CfgDb()
 
def conf = getConfigurable( 'StoreGateSvc' )
 

Function Documentation

◆ _fillConfDict()

def python.ConfigurableDb._fillConfDict ( )
private

helpers ---------------------------------------------------------------—

Definition at line 25 of file ConfigurableDb.py.

25 def _fillConfDict():
26  nFiles = loadConfigurableDb()
27  cfgDb.msg.info( "Read module info for %d configurables from %d genConfDb files",
28  len(cfgDb), nFiles )
29 
30  if 0 < len( cfgDb.duplicates() ):
31  cfgDb.msg.warning( "Found %d duplicates among the %d genConfDb files :",
32  len(cfgDb.duplicates()), nFiles )
33  cfgDb.msg.warning( "--------------------------------------------------" )
34  cfgDb.msg.warning( " -%s: %s - %s",
35  "<component name>", "<module>", "[ <duplicates> ]" )
36  cfgDb.msg.warning( "--------------------------------------------------" )
37 
38  dups = cfgDb.duplicates()
39  for cfgName in dups.keys():
40  cfgDb.msg.warning( " -%s: %s - %s",
41  cfgName,
42  cfgDb[cfgName]['module'],
43  str([ d['module'] for d in dups[cfgName]]) )
44  del dups
45 
46  else:
47  cfgDb.msg.info( "No duplicates have been found: that's good !" )
48 
49 

◆ getConfigurable()

def python.ConfigurableDb.getConfigurable (   className,
  requester = '',
  assumeCxxClass = True 
)
Localize and load a Configurable class based on the (C++) class name.

Definition at line 202 of file ConfigurableDb.py.

202 def getConfigurable( className, requester = '', assumeCxxClass = True ):
203  """Localize and load a Configurable class based on the (C++) class name.
204  """
205 
206  # fill the configurable dict, first time only
207  try:
208  global _fillConfDict
209  _fillConfDict()
210  del _fillConfDict
211  except NameError:
212  pass
213 
214  confClass = className
215  if assumeCxxClass:
216  # assume className is C++: --> translate to python
217  confClass = str.translate( confClass, _transtable )
218 
219  # attempt to retrieve existing information
220  confClassInfo = cfgDb.get( confClass )
221 
222  # get the python module, if info available
223  confMod = confClassInfo and confClassInfo.get( 'module' )
224  if not confMod:
225  cfgDb.msg.warning( "%s: Class %s not in database", requester, className )
226  return None
227 
228  # load the module
229  try:
230  mod = __import__( confMod, globals(), locals(), confClass, level=0 )
231  except ImportError:
232  cfgDb.msg.warning( "%s: Module %s not found (needed for configurable %s)",
233  requester, confMod, className )
234  return None
235 
236  # localize class
237  try:
238  confClass = getattr( mod, confClass )
239  except AttributeError:
240  cfgDb.msg.warning( "%s: Configurable %s not found in module %s",
241  requester, confClass, confMod )
242  return None
243 
244  # got this far, assume confClass to be valid
245  cfgDb.msg.debug( "%s: Found configurable %s in module %s",
246  requester, confClass, confMod )
247 
248  return confClass
249 
250 

◆ loadConfigurableDb()

def python.ConfigurableDb.loadConfigurableDb ( )
Load all ConfigurableDb files (modules) holding informations about
Configurables available in the release

Definition at line 134 of file ConfigurableDb.py.

134 def loadConfigurableDb():
135  """Load all ConfigurableDb files (modules) holding informations about
136  Configurables available in the release
137  """
138 
139  import os
140  from os.path import join as path_join
141 
142  cfgDb.msg.debug( "loading confDb files..." )
143  nFiles = 0
144  pathlist = os.getenv("LD_LIBRARY_PATH", "").split(os.pathsep)
145  for path in pathlist:
146  if not os.path.isdir(path):
147  continue
148  cfgDb.msg.verbose( "walking in [%s]..." % path )
149  confDbFiles = [f for f in [path_join(path, f) for f in os.listdir(path)
150  if f.endswith('.confdb')]
151  if os.path.isfile(f)]
152 
153  # check if we use "*_merged.confdb"
154  mergedConfDbFiles = [f for f in confDbFiles
155  if f.endswith('_merged.confdb')]
156  if mergedConfDbFiles:
157  # use only the merged ones
158  confDbFiles = mergedConfDbFiles
159 
160  for confDb in confDbFiles:
161  cfgDb.msg.debug( "\t-loading [%s]...", confDb )
162  try:
163  cfgDb._loadModule( confDb )
164  except Exception as err:
165  import traceback
166  traceback.print_exc()
167  cfgDb.msg.warning( "Could not load file [%s] !", confDb )
168  cfgDb.msg.warning( "Reason: %s", err )
169  nFiles += 1
170  cfgDb.msg.debug( "loading confDb files... [DONE]" )
171  nPkgs = len( set([k['package'] for k in cfgDb.values()]) )
172  cfgDb.msg.debug( "loaded %i confDb packages", nPkgs )
173  return nFiles
174 
175 

◆ unloadConfigurableDb()

def python.ConfigurableDb.unloadConfigurableDb ( )

function to UNload all ConfigurableDb informations --------------------—

UNload all ConfigurableDb files (modules) holding informations about
Configurables available in the release:
 - remove imported modules from sys.modules
 - clear the configurable Db

Definition at line 177 of file ConfigurableDb.py.

178  """UNload all ConfigurableDb files (modules) holding informations about
179  Configurables available in the release:
180  - remove imported modules from sys.modules
181  - clear the configurable Db
182  """
183 
184  confModules = set( [ cfgDb.get(k).get('module') for k in cfgDb ] +
185  [ cfgDb.get(k).get('package') for k in cfgDb ] )
186  cfgDb.clear()
187  import sys
188  for m in sys.modules.keys():
189  if m in confModules or \
190  m.count("_merged_confDb") > 0 or \
191  m.count(".GaudiHandles" ) > 0 or \
192  m.count("ConfigurableDb") > 0 or \
193  m.count("AthenaPython") > 0:
194 
195  if hasattr(sys.modules[m], '__dict__'):
196  for i in sys.modules[m].__dict__.keys():
197  del sys.modules[m].__dict__[i]
198  del sys.modules[m]
199  del confModules
200 
201 

Variable Documentation

◆ __all__

list python.ConfigurableDb.__all__
private
Initial value:
1 = [ 'CfgDb', 'cfgDb',
2  'loadConfigurableDb', 'unloadConfigurableDb',
3  'getConfigurable' ]

Definition at line 18 of file ConfigurableDb.py.

◆ __author__

string python.ConfigurableDb.__author__ = 'Sebastien Binet (binet@cern.ch)'
private

Definition at line 16 of file ConfigurableDb.py.

◆ __version__

string python.ConfigurableDb.__version__ = '3.0.0'
private

data ------------------------------------------------------------------—

Definition at line 15 of file ConfigurableDb.py.

◆ _transtable

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

Definition at line 22 of file ConfigurableDb.py.

◆ CfgDb

python.ConfigurableDb.CfgDb = _Singleton()

Definition at line 260 of file ConfigurableDb.py.

◆ cfgDb

python.ConfigurableDb.cfgDb = CfgDb()

Definition at line 261 of file ConfigurableDb.py.

◆ conf

def python.ConfigurableDb.conf = getConfigurable( 'StoreGateSvc' )

Definition at line 274 of file ConfigurableDb.py.

python.ConfigurableDb.getConfigurable
def getConfigurable(className, requester='', assumeCxxClass=True)
Definition: ConfigurableDb.py:202
python.ConfigurableDb.unloadConfigurableDb
def unloadConfigurableDb()
function to UNload all ConfigurableDb informations --------------------—
Definition: ConfigurableDb.py:177
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition: bitmask.h:232
get
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition: hcg.cxx:130
python.ConfigurableDb.loadConfigurableDb
def loadConfigurableDb()
Definition: ConfigurableDb.py:134
str
Definition: BTagTrackIpAccessor.cxx:11
python.ConfigurableDb._fillConfDict
def _fillConfDict()
helpers ---------------------------------------------------------------—
Definition: ConfigurableDb.py:25
Trk::split
@ split
Definition: LayerMaterialProperties.h:38