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