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