The Gaudi Framework  v32r2 (46d42edc)
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 from __future__ import absolute_import
4 
5 from GaudiKernel.Constants import *
6 from GaudiKernel.Configurable import *
7 from GaudiKernel.ConfigurableDb import loadConfigurableDb, cfgDb
8 from GaudiKernel.ConfigurableDb import getConfigurable as confDbGetConfigurable
10 from GaudiKernel.ProcessJobOptions import importOptions, importUnits
11 from GaudiKernel.ProcessJobOptions import InstallRootLoggingHandler as _InstallRootLoggingHandler
12 
13 import logging
14 log = logging.getLogger(__name__)
15 # Ensure that a root logging handler is always present.
16 _InstallRootLoggingHandler()
17 
18 allConfigurables = Configurable.allConfigurables
19 
20 
22  nFiles = loadConfigurableDb()
23  log = logging.getLogger('PropertyProxy')
24  log.debug("Read module info for %d configurables from %d genConfDb files",
25  len(cfgDb), nFiles)
26  if len(cfgDb.duplicates()) > 0:
27  log.warning("Found %d duplicates among the %d genConfDb files :",
28  len(cfgDb.duplicates()), nFiles)
29  log.warning("--------------------------------------------------")
30  log.warning(" -%s: %s - %s", "<component name>", "<module>",
31  "[ <duplicates> ]")
32  log.warning("--------------------------------------------------")
33  dups = cfgDb.duplicates()
34  for cfgName in dups.keys():
35  log.warning(" -%s: %s - %s", cfgName, 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 
47 # fill the configurable dictionary at module load
49 
50 import os
51 import sys
52 
53 
54 def importConfiguration(conf, local=locals()):
55  local[conf] = confDbGetConfigurable(conf)
56 
57 
58 def configurationDict(all=False):
59  """Return a dictionary representing the configuration.
60  The dictionary contains one entry per configurable which is a dictionary
61  with one entry per property.
62  The optional argument "all" is used to decide if to include only values
63  different from the default or all of them.
64  """
65  from GaudiKernel.Proxy.Configurable import getNeededConfigurables
66 
67  catalog = allConfigurables
68  keys = getNeededConfigurables() # use only interesting configurables
69  conf_dict = {}
70  if all:
71  for n in keys:
72  if n not in conf_dict:
73  conf_dict[n] = {}
74  for p, v in catalog[n].getDefaultProperties().items():
75  conf_dict[n][p] = v
76 
77  for n in keys:
78  if n not in conf_dict:
79  conf_dict[n] = {}
80  for p, v in catalog[n].getValuedProperties().items():
81  conf_dict[n][p] = v
82  # purge empty configurables
83  keys = conf_dict.keys()
84  ret_dict = {}
85  for n in keys:
86  if conf_dict[n]:
87  ret_dict[n] = conf_dict[n]
88  return ret_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 
116  """Configurable to enable ROOT-based persistency.
117 
118  Note: it requires Gaudi::RootCnvSvc (package RootCnv).
119  """
120  __slots__ = {}
121 
123  """Apply low-level configuration"""
124  from Configurables import (
125  ApplicationMgr,
126  PersistencySvc,
127  FileRecordDataSvc,
128  EventPersistencySvc,
129  )
130  # aliased names
131  from Configurables import (
132  RootCnvSvc,
133  RootEvtSelector,
134  IODataManager,
135  FileCatalog,
136  )
137  cnvSvcs = [RootCnvSvc()]
138  EventPersistencySvc().CnvServices += cnvSvcs
139  PersistencySvc("FileRecordPersistencySvc").CnvServices += cnvSvcs
140  app = ApplicationMgr()
141  app.SvcOptMapping += [FileCatalog(), IODataManager(), RootCnvSvc()]
142  app.ExtSvc += [FileRecordDataSvc()]
def getConfigurable(name, defaultType=None)
getNeededConfigurables
Definition: Proxy.py:21
Description:
Definition: RootCnvSvc.h:52
def importConfiguration(conf, local=locals())
def configurationDict(all=False)
PersistencySvc class implementation definition.
A FileRecordDataSvc is the base class for event services.
The Application Manager class.