Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v36r13 (995e4364)
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 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  log.warning("Fix your cmt/requirements file !!")
67  pass
68  else:
69  log.debug("No duplicates have been found: that's good !")
70  pass
71  return
72 
73 
74 # fill the configurable dictionary at module load
76 
77 
78 def importConfiguration(conf, local=locals()):
79  local[conf] = confDbGetConfigurable(conf)
80 
81 
82 def configurationDict(all=False):
83  """Return a dictionary representing the configuration.
84  The dictionary contains one entry per configurable which is a dictionary
85  with one entry per property.
86  The optional argument "all" is used to decide if to include only values
87  different from the default or all of them.
88  """
89  from GaudiKernel.Proxy.Configurable import getNeededConfigurables
90 
91  catalog = allConfigurables
92  keys = getNeededConfigurables() # use only interesting configurables
93  conf_dict = {}
94  if all:
95  for n in keys:
96  if n not in conf_dict:
97  conf_dict[n] = {}
98  for p, v in catalog[n].getDefaultProperties().items():
99  conf_dict[n][p] = v
100 
101  for n in keys:
102  if n not in conf_dict:
103  conf_dict[n] = {}
104  for p, v in catalog[n].getValuedProperties().items():
105  conf_dict[n][p] = v
106  # purge empty configurables
107  keys = conf_dict.keys()
108  ret_dict = {}
109  for n in keys:
110  if conf_dict[n]:
111  ret_dict[n] = conf_dict[n]
112  return ret_dict
113 
114 
115 def getConfigurable(name, defaultType=None):
116  """Helper function to get a configurable with the given name regardless
117  for the type.
118  If defaultType can be a class derived from configurable or a string. If not
119  specified, the tool name is used as type."""
120  if name in allConfigurables:
121  return allConfigurables[name]
122  else:
123  # if the configurable is not found, we need to instantiate it
124  if defaultType is None:
125  # try to use the name of the configurable as default type
126  defaultType = name
127  if type(defaultType) is str:
128  # we need to convert from string to actual class
129  if defaultType in globals():
130  # We the type is defined in the global namespace
131  defaultType = globals()[defaultType]
132  else:
133  # otherwise we try to get it from the Configurables database
134  import Configurables
135 
136  defaultType = getattr(Configurables, defaultType)
137  return defaultType(name)
Gaudi.CommonGaudiConfigurables
Definition: CommonGaudiConfigurables.py:1
Gaudi.Configuration.configurationDict
def configurationDict(all=False)
Definition: Configuration.py:82
GaudiKernel.Constants
Definition: Constants.py:1
GaudiKernel.Proxy.getNeededConfigurables
getNeededConfigurables
Definition: Proxy.py:30
GaudiKernel.ConfigurableDb.loadConfigurableDb
def loadConfigurableDb()
Definition: ConfigurableDb.py:120
Gaudi.Configuration.importConfiguration
def importConfiguration(conf, local=locals())
Definition: Configuration.py:78
GaudiKernel.ProcessJobOptions
Definition: ProcessJobOptions.py:1
GaudiKernel.Configurable
Definition: Configurable.py:1
Gaudi.Configuration.getConfigurable
def getConfigurable(name, defaultType=None)
Definition: Configuration.py:115
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