| The Gaudi Framework v32r1 (f65d50dc)

Configuration.py
Go to the documentation of this file.
1 # File: Gaudi/python/Gaudi/Configuration.py
2 # Author: Pere Mato (pere.mato@cern.ch)
3
4 from GaudiKernel.Constants import *
5 from GaudiKernel.Configurable import *
6 from GaudiKernel.ConfigurableDb import loadConfigurableDb, cfgDb
7 from GaudiKernel.ConfigurableDb import getConfigurable as confDbGetConfigurable
8 from CommonGaudiConfigurables import *
9 from GaudiKernel.ProcessJobOptions import importOptions, importUnits
10 from GaudiKernel.ProcessJobOptions import InstallRootLoggingHandler as _InstallRootLoggingHandler
11
12 import logging
13 log = logging.getLogger(__name__)
14 # Ensure that a root logging handler is always present.
15 _InstallRootLoggingHandler()
16
17 allConfigurables = Configurable.allConfigurables
18
19
20 def _fillConfDict():
21 nFiles = loadConfigurableDb()
22 log = logging.getLogger('PropertyProxy')
23 log.debug("Read module info for %d configurables from %d genConfDb files",
24 len(cfgDb), nFiles)
25 if len(cfgDb.duplicates()) > 0:
26 log.warning("Found %d duplicates among the %d genConfDb files :",
27 len(cfgDb.duplicates()), nFiles)
28 log.warning("--------------------------------------------------")
29 log.warning(" -%s: %s - %s", "<component name>", "<module>",
30 "[ <duplicates> ]")
31 log.warning("--------------------------------------------------")
32 dups = cfgDb.duplicates()
33 for cfgName in dups.keys():
34 log.warning(" -%s: %s - %s", cfgName, cfgDb[cfgName]['module'],
35 str([d['module'] for d in dups[cfgName]]))
36 pass
37 del dups
38 log.warning("Fix your cmt/requirements file !!")
39 pass
40 else:
41 log.debug("No duplicates have been found: that's good !")
42 pass
43 return
44
45
46 # fill the configurable dictionary at module load
47 _fillConfDict()
48
49 import os
50 import sys
51
52
53 def importConfiguration(conf, local=locals()):
54 local[conf] = confDbGetConfigurable(conf)
55
56
57 def configurationDict(all=False):
58 """Return a dictionary representing the configuration.
59 The dictionary contains one entry per configurable which is a dictionary
60 with one entry per property.
61 The optional argument "all" is used to decide if to include only values
62 different from the default or all of them.
63 """
64 from GaudiKernel.Proxy.Configurable import getNeededConfigurables
65
66 catalog = allConfigurables
67 keys = getNeededConfigurables() # use only interesting configurables
68 conf_dict = {}
69 if all:
70 for n in keys:
71 if n not in conf_dict:
72 conf_dict[n] = {}
73 for p, v in catalog[n].getDefaultProperties().items():
74 conf_dict[n][p] = v
75
76 for n in keys:
77 if n not in conf_dict:
78 conf_dict[n] = {}
79 for p, v in catalog[n].getValuedProperties().items():
80 conf_dict[n][p] = v
81 # purge empty configurables
82 keys = conf_dict.keys()
83 for n in keys:
84 if not conf_dict[n]:
85 del conf_dict[n]
86 return conf_dict
87
88
89 def getConfigurable(name, defaultType=None):
90 """Helper function to get a configurable with the given name regardless
91 for the type.
92 If defaultType can be a class derived from configurable or a string. If not
93 specified, the tool name is used as type."""
94 if name in allConfigurables:
95 return allConfigurables[name]
96 else:
97 # if the configurable is not found, we need to instantiate it
98 if defaultType is None:
99 # try to use the name of the configurable as default type
100 defaultType = name
101 if type(defaultType) is str:
102 # we need to convert from string to actual class
103 if defaultType in globals():
104 # We the type is defined in the global namespace
105 defaultType = globals()[defaultType]
106 else:
107 # otherwise we try to get it from the Configurables database
108 import Configurables
109 defaultType = getattr(Configurables, defaultType)
110 return defaultType(name)
111
112
113 class GaudiPersistency(ConfigurableUser):
114 """Configurable to enable ROOT-based persistency.
115
116 Note: it requires Gaudi::RootCnvSvc (package RootCnv).
117 """
118 __slots__ = {}
119
120 def __apply_configuration__(self):
121 """Apply low-level configuration"""
122 from Configurables import (
123 ApplicationMgr,
124 PersistencySvc,
125 FileRecordDataSvc,
126 EventPersistencySvc,
127 )
128 # aliased names
129 from Configurables import (
130 RootCnvSvc,
131 RootEvtSelector,
132 IODataManager,
133 FileCatalog,
134 )
135 cnvSvcs = [RootCnvSvc()]
136 EventPersistencySvc().CnvServices += cnvSvcs
137 PersistencySvc("FileRecordPersistencySvc").CnvServices += cnvSvcs
138 app = ApplicationMgr()
139 app.SvcOptMapping += [FileCatalog(), IODataManager(), RootCnvSvc()]
140 app.ExtSvc += [FileRecordDataSvc()]
GaudiKernel.ConfigurableDb.loadConfigurableDb
def loadConfigurableDb()
Definition: ConfigurableDb.py:109
Gaudi.Configuration.GaudiPersistency.__apply_configuration__
def __apply_configuration__(self)
Definition: Configuration.py:120
Gaudi.Configuration.getConfigurable
def getConfigurable(name, defaultType=None)
Definition: Configuration.py:89
GaudiKernel.Proxy.getNeededConfigurables
getNeededConfigurables
Definition: Proxy.py:21
Gaudi::RootCnvSvc
Description:
Definition: RootCnvSvc.h:52
GaudiKernel.ProcessJobOptions
Definition: ProcessJobOptions.py:1
GaudiKernel.ConfigurableDb
Definition: ConfigurableDb.py:1
Gaudi.Configuration.importConfiguration
def importConfiguration(conf, local=locals())
Definition: Configuration.py:53
Gaudi::IODataManager
Definition: IODataManager.h:29
gaudirun.type
type
Definition: gaudirun.py:142
Gaudi.Configuration.configurationDict
def configurationDict(all=False)
Definition: Configuration.py:57
PersistencySvc
PersistencySvc class implementation definition.
Definition: PersistencySvc.h:50
Gaudi.Configuration.GaudiPersistency
Definition: Configuration.py:113
GaudiKernel.Configurable
Definition: Configurable.py:1
GaudiKernel.Constants
Definition: Constants.py:1
FileRecordDataSvc
A FileRecordDataSvc is the base class for event services.
Definition: FileRecordDataSvc.cpp:38
ApplicationMgr
The Application Manager class.
Definition: ApplicationMgr.h:45
GaudiKernel.Configurable.ConfigurableUser
Definition: Configurable.py:1272
Gaudi.Configuration._fillConfDict
def _fillConfDict()
Definition: Configuration.py:20