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