Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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  global cfgDb
27 
28  nFiles = loadConfigurableDb()
29  cfgDb.msg.info( "Read module info for %d configurables from %d genConfDb files",
30  len(cfgDb), nFiles )
31 
32  if 0 < len( cfgDb.duplicates() ):
33  cfgDb.msg.warning( "Found %d duplicates among the %d genConfDb files :",
34  len(cfgDb.duplicates()), nFiles )
35  cfgDb.msg.warning( "--------------------------------------------------" )
36  cfgDb.msg.warning( " -%s: %s - %s",
37  "<component name>", "<module>", "[ <duplicates> ]" )
38  cfgDb.msg.warning( "--------------------------------------------------" )
39 
40  dups = cfgDb.duplicates()
41  for cfgName in dups.keys():
42  cfgDb.msg.warning( " -%s: %s - %s",
43  cfgName,
44  cfgDb[cfgName]['module'],
45  str([ d['module'] for d in dups[cfgName]]) )
46  del dups
47 
48  else:
49  cfgDb.msg.info( "No duplicates have been found: that's good !" )
50 
51 

◆ getConfigurable()

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

Definition at line 208 of file ConfigurableDb.py.

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

◆ loadConfigurableDb()

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

Definition at line 136 of file ConfigurableDb.py.

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

◆ 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 181 of file ConfigurableDb.py.

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

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 268 of file ConfigurableDb.py.

◆ cfgDb

python.ConfigurableDb.cfgDb = CfgDb()

Definition at line 269 of file ConfigurableDb.py.

◆ conf

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

Definition at line 282 of file ConfigurableDb.py.

python.ConfigurableDb.getConfigurable
def getConfigurable(className, requester='', assumeCxxClass=True)
Definition: ConfigurableDb.py:208
python.ConfigurableDb.unloadConfigurableDb
def unloadConfigurableDb()
function to UNload all ConfigurableDb informations --------------------—
Definition: ConfigurableDb.py:181
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:127
python.ConfigurableDb.loadConfigurableDb
def loadConfigurableDb()
Definition: ConfigurableDb.py:136
str
Definition: BTagTrackIpAccessor.cxx:11
python.ConfigurableDb._fillConfDict
def _fillConfDict()
helpers ---------------------------------------------------------------—
Definition: ConfigurableDb.py:25
Trk::split
@ split
Definition: LayerMaterialProperties.h:38