The Gaudi Framework  v37r1 (a7f61348)
Configuration.py
Go to the documentation of this file.
1 
13 from __future__ import absolute_import
14 
15 import logging
16 
17 # Make these available in our namespace
18 from Gaudi.CommonGaudiConfigurables import * # noqa: F401 F403
19 from GaudiKernel.Configurable import * # noqa: F401 F403
20 from GaudiKernel.Configurable import Configurable
21 from GaudiKernel.ConfigurableDb import cfgDb
22 from GaudiKernel.ConfigurableDb import getConfigurable as confDbGetConfigurable
23 from GaudiKernel.ConfigurableDb import loadConfigurableDb
24 from GaudiKernel.Constants import * # noqa: F401 F403
26  InstallRootLoggingHandler as _InstallRootLoggingHandler,
27 )
28 from GaudiKernel.ProcessJobOptions import importOptions, importUnits # noqa: F401
29 
30 log = logging.getLogger(__name__)
31 # Ensure that a root logging handler is always present.
32 _InstallRootLoggingHandler()
33 
34 allConfigurables = Configurable.allConfigurables
35 
36 
38  nFiles = loadConfigurableDb()
39  log = logging.getLogger("PropertyProxy")
40  log.debug(
41  "Read module info for %d configurables from %d genConfDb files",
42  len(cfgDb),
43  nFiles,
44  )
45  if len(cfgDb.duplicates()) > 0:
46  log.warning(
47  "Found %d duplicates among the %d genConfDb files :",
48  len(cfgDb.duplicates()),
49  nFiles,
50  )
51  log.warning("--------------------------------------------------")
52  log.warning(
53  " -%s: %s - %s", "<component name>", "<module>", "[ <duplicates> ]"
54  )
55  log.warning("--------------------------------------------------")
56  dups = cfgDb.duplicates()
57  for cfgName in dups.keys():
58  log.warning(
59  " -%s: %s - %s",
60  cfgName,
61  cfgDb[cfgName]["module"],
62  str([d["module"] for d in dups[cfgName]]),
63  )
64  pass
65  del dups
66  pass
67  else:
68  log.debug("No duplicates have been found: that's good !")
69  pass
70  return
71 
72 
73 # fill the configurable dictionary at module load
75 
76 
77 def importConfiguration(conf, local=locals()):
78  local[conf] = confDbGetConfigurable(conf)
79 
80 
81 def configurationDict(all=False):
82  """Return a dictionary representing the configuration.
83  The dictionary contains one entry per configurable which is a dictionary
84  with one entry per property.
85  The optional argument "all" is used to decide if to include only values
86  different from the default or all of them.
87  """
88  from GaudiKernel.Proxy.Configurable import getNeededConfigurables
89 
90  catalog = allConfigurables
91  keys = getNeededConfigurables() # use only interesting configurables
92  conf_dict = {}
93  if all:
94  for n in keys:
95  if n not in conf_dict:
96  conf_dict[n] = {}
97  for p, v in catalog[n].getDefaultProperties().items():
98  conf_dict[n][p] = v
99 
100  for n in keys:
101  if n not in conf_dict:
102  conf_dict[n] = {}
103  for p, v in catalog[n].getValuedProperties().items():
104  conf_dict[n][p] = v
105  # purge empty configurables
106  keys = conf_dict.keys()
107  ret_dict = {}
108  for n in keys:
109  if conf_dict[n]:
110  ret_dict[n] = conf_dict[n]
111  return ret_dict
112 
113 
114 def getConfigurable(name, defaultType=None):
115  """Helper function to get a configurable with the given name regardless
116  for the type.
117  If defaultType can be a class derived from configurable or a string. If not
118  specified, the tool name is used as type."""
119  if name in allConfigurables:
120  return allConfigurables[name]
121  else:
122  # if the configurable is not found, we need to instantiate it
123  if defaultType is None:
124  # try to use the name of the configurable as default type
125  defaultType = name
126  if type(defaultType) is str:
127  # we need to convert from string to actual class
128  if defaultType in globals():
129  # We the type is defined in the global namespace
130  defaultType = globals()[defaultType]
131  else:
132  # otherwise we try to get it from the Configurables database
133  import Configurables
134 
135  defaultType = getattr(Configurables, defaultType)
136  return defaultType(name)
Gaudi.CommonGaudiConfigurables
Definition: CommonGaudiConfigurables.py:1
Gaudi.Configuration.configurationDict
def configurationDict(all=False)
Definition: Configuration.py:81
GaudiKernel.Constants
Definition: Constants.py:1
GaudiKernel.Proxy.getNeededConfigurables
getNeededConfigurables
Definition: Proxy.py:30
GaudiKernel.ConfigurableDb.loadConfigurableDb
def loadConfigurableDb()
Definition: ConfigurableDb.py:119
Gaudi.Configuration.importConfiguration
def importConfiguration(conf, local=locals())
Definition: Configuration.py:77
GaudiKernel.ProcessJobOptions
Definition: ProcessJobOptions.py:1
GaudiKernel.Configurable
Definition: Configurable.py:1
Gaudi.Configuration.getConfigurable
def getConfigurable(name, defaultType=None)
Definition: Configuration.py:114
gaudirun.type
type
Definition: gaudirun.py:162
Gaudi.Configuration._fillConfDict
def _fillConfDict()
Definition: Configuration.py:37
GaudiKernel.ConfigurableDb
Definition: ConfigurableDb.py:1
GaudiPython.Pythonizations.items
items
Definition: Pythonizations.py:546