CommonGaudiConfigurables.py
Go to the documentation of this file.
1 # File: Gaudi/CommonGaudiConfigurables.py
2 # Author: Pere Mato (pere.mato@cern.ch)
3 
4 """
5  This module would scan all known Gaudi configurable modules for
6  'Configurable' classes and fill __all__ such that it can be imported
7  by any module requiring it.
8 """
9 
10 from GaudiKernel.Configurable import Configurable
11 from GaudiKernel.ConfigurableMeta import ConfigurableMeta
12 __all__ = []
13 
14 packages = ['GaudiCoreSvc', 'GaudiCommonSvc', 'GaudiSvc', 'GaudiAlg',
15  'GaudiAud', 'GaudiPoolDb', 'RootHistCnv', 'GaudiUtils',
16  'RootCnv']
17 
18 #--Loop open all listed packages and populate __all__ with the names and
19 # the local scope with the Configurable classes
20 for package in packages :
21  try:
22  mod = __import__( '%s.%sConf'%(package,package), globals(), locals(), ['%sConf'%package] )
23  for nam in dir(mod) :
24  cls = getattr(mod, nam)
25  if type(cls) is ConfigurableMeta and issubclass(cls, Configurable) :
26  globals()[nam] = cls
27  __all__.append(nam)
28  except ImportError:
29  # ignore the configurables from missing packages.
30  pass
31 
32 #--Fix some of the name idiosyncrasies in Gaudi
33 aliases = {
34  'EventDataSvc': 'EvtDataSvc',
35  'DetectorDataSvc': 'DetDataSvc',
36  'HistogramDataSvc': 'HistogramSvc',
37  'HbookHistSvc': 'HbookCnv__PersSvc',
38  'RootHistSvc': 'RootHistCnv__PersSvc',
39  'EventPersistencySvc': 'EvtPersistencySvc',
40  'DetectorPersistencySvc': 'DetPersistencySvc',
41  'HistogramPersistencySvc': 'HistogramPersistencySvc',
42  'FileRecordPersistencySvc': 'PersistencySvc',
43 
44  'FileCatalog': 'Gaudi__MultiFileCatalog',
45  'IODataManager': 'Gaudi__IODataManager',
46 
47  'RootCnvSvc': 'Gaudi__RootCnvSvc',
48  'RootEvtSelector': 'Gaudi__RootEvtSelector',
49  }
50 
51 _gbl = globals() # optimization
52 # This would be nicer with dict comprehension (http://www.python.org/dev/peps/pep-0274)
53 # but it is available only in Python 2.7
54 aliases = dict([(new, _gbl[old])
55  for new, old in aliases.items()
56  if old in _gbl]) # do the aliasing only if the original is available
57 # change the default name
58 for new in aliases:
59  aliases[new].DefaultedName = new
60 # update globals and __all__
61 _gbl.update(aliases)
62 __all__.extend(aliases)
63 # remove temporaries
64 del _gbl, new