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