Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 
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
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 def setCustomMainLoop(runner):
114  '''
115  Replace the default main execution loop with the specified callable object.
116 
117  @param runner: a callable that accepts an initialized instance of GaudiPython.AppMgr
118  and the number of events to process and returns a StatusCode or a boolean
119  (True means success)
120  '''
121  # change the mainLoop function
122  from Gaudi.Main import gaudimain
123  gaudimain.mainLoop = lambda _self, app, nevt: runner(app, nevt)
124 
125 
127  """Configurable to enable ROOT-based persistency.
128 
129  Note: it requires Gaudi::RootCnvSvc (package RootCnv).
130  """
131  __slots__ = {}
132 
134  """Apply low-level configuration"""
135  from Configurables import (
136  ApplicationMgr,
137  PersistencySvc,
138  FileRecordDataSvc,
139  EventPersistencySvc,
140  )
141  # aliased names
142  from Configurables import (
143  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(), RootCnvSvc()]
153  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.
def setCustomMainLoop(runner)
A FileRecordDataSvc is the base class for event services.
The Application Manager class.