| The Gaudi Framework v28r2-patches (bc4ad17a)

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