| The Gaudi Framework v30r0 (c919700c)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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",
30 "<component name>", "<module>", "[ <duplicates> ]")
31 log.warning("--------------------------------------------------")
32 dups = cfgDb.duplicates()
33 for cfgName in dups.keys():
34 log.warning(" -%s: %s - %s",
35 cfgName,
36 cfgDb[cfgName]['module'],
37 str([d['module'] for d in dups[cfgName]]))
38 pass
39 del dups
40 log.warning("Fix your cmt/requirements file !!")
41 pass
42 else:
43 log.debug("No duplicates have been found: that's good !")
44 pass
45 return
46
47
48 # fill the configurable dictionary at module load
49 _fillConfDict()
50
51 import os
52 import sys
53
54
55 def importConfiguration(conf, local=locals()):
56 local[conf] = confDbGetConfigurable(conf)
57
58
59 def configurationDict(all=False):
60 """Return a dictionary representing the configuration.
61 The dictionary contains one entry per configurable which is a dictionary
62 with one entry per property.
63 The optional argument "all" is used to decide if to include only values
64 different from the default or all of them.
65 """
66 from GaudiKernel.Proxy.Configurable import getNeededConfigurables
67
68 catalog = allConfigurables
69 keys = getNeededConfigurables() # use only interesting configurables
70 conf_dict = {}
71 if all:
72 for n in keys:
73 if n not in conf_dict:
74 conf_dict[n] = {}
75 for p, v in catalog[n].getDefaultProperties().items():
76 conf_dict[n][p] = v
77
78 for n in keys:
79 if n not in conf_dict:
80 conf_dict[n] = {}
81 for p, v in catalog[n].getValuedProperties().items():
82 conf_dict[n][p] = v
83 # purge empty configurables
84 keys = conf_dict.keys()
85 for n in keys:
86 if not conf_dict[n]:
87 del conf_dict[n]
88 return conf_dict
89
90
91 def getConfigurable(name, defaultType=None):
92 """Helper function to get a configurable with the given name regardless
93 for the type.
94 If defaultType can be a class derived from configurable or a string. If not
95 specified, the tool name is used as type."""
96 if name in allConfigurables:
97 return allConfigurables[name]
98 else:
99 # if the configurable is not found, we need to instantiate it
100 if defaultType is None:
101 # try to use the name of the configurable as default type
102 defaultType = name
103 if type(defaultType) is str:
104 # we need to convert from string to actual class
105 if defaultType in globals():
106 # We the type is defined in the global namespace
107 defaultType = globals()[defaultType]
108 else:
109 # otherwise we try to get it from the Configurables database
110 import Configurables
111 defaultType = getattr(Configurables, defaultType)
112 return defaultType(name)
113
114
115 def setCustomMainLoop(runner):
116 '''
117 Replace the default main execution loop with the specified callable object.
118
119 @param runner: a callable that accepts an initialized instance of GaudiPython.AppMgr
120 and the number of events to process and returns a StatusCode or a boolean
121 (True means success)
122 '''
123 # change the mainLoop function
124 from Gaudi.Main import gaudimain
125 gaudimain.mainLoop = lambda _self, app, nevt: runner(app, nevt)
126
127
128 class GaudiPersistency(ConfigurableUser):
129 """Configurable to enable ROOT-based persistency.
130
131 Note: it requires Gaudi::RootCnvSvc (package RootCnv).
132 """
133 __slots__ = {}
134
135 def __apply_configuration__(self):
136 """Apply low-level configuration"""
137 from Configurables import (ApplicationMgr,
138 PersistencySvc,
139 FileRecordDataSvc,
140 EventPersistencySvc,
141 )
142 # aliased names
143 from Configurables import (RootCnvSvc,
144 RootEvtSelector,
145 IODataManager,
146 FileCatalog,
147 )
148 cnvSvcs = [RootCnvSvc()]
149 EventPersistencySvc().CnvServices += cnvSvcs
150 PersistencySvc("FileRecordPersistencySvc").CnvServices += cnvSvcs
151 app = ApplicationMgr()
152 app.SvcOptMapping += [FileCatalog(), IODataManager(),
153 RootCnvSvc()]
154 app.ExtSvc += [FileRecordDataSvc()]
GaudiKernel.ConfigurableDb.loadConfigurableDb
def loadConfigurableDb()
Definition: ConfigurableDb.py:110
Gaudi.Configuration.GaudiPersistency.__apply_configuration__
def __apply_configuration__(self)
Definition: Configuration.py:135
Gaudi.Configuration.getConfigurable
def getConfigurable(name, defaultType=None)
Definition: Configuration.py:91
GaudiKernel.Proxy.getNeededConfigurables
getNeededConfigurables
Definition: Proxy.py:20
Gaudi::RootCnvSvc
Description:
Definition: RootCnvSvc.h:53
GaudiKernel.ProcessJobOptions
Definition: ProcessJobOptions.py:1
GaudiKernel.ConfigurableDb
Definition: ConfigurableDb.py:1
Gaudi.Configuration.importConfiguration
def importConfiguration(conf, local=locals())
Definition: Configuration.py:55
Gaudi::IODataManager
Definition: IODataManager.h:30
gaudirun.type
type
Definition: gaudirun.py:133
Gaudi.Configuration.configurationDict
def configurationDict(all=False)
Definition: Configuration.py:59
PersistencySvc
PersistencySvc class implementation definition.
Definition: PersistencySvc.h:50
Gaudi.Main
Definition: Main.py:1
Gaudi.Configuration.GaudiPersistency
Definition: Configuration.py:128
GaudiKernel.Configurable
Definition: Configurable.py:1
GaudiKernel.Constants
Definition: Constants.py:1
Gaudi.Configuration.setCustomMainLoop
def setCustomMainLoop(runner)
Definition: Configuration.py:115
FileRecordDataSvc
A FileRecordDataSvc is the base class for event services.
Definition: FileRecordDataSvc.cpp:38
ApplicationMgr
The Application Manager class.
Definition: ApplicationMgr.h:47
GaudiKernel.Configurable.ConfigurableUser
Definition: Configurable.py:1209
Gaudi.Configuration._fillConfDict
def _fillConfDict()
Definition: Configuration.py:20