| # Gaudi Framework, version v23r1 |

Home |  | Generated: Wed Feb 29 2012

# Configuration.py

Go to the documentation of this file.

    00001 # File: Gaudi/python/Gaudi/Configuration.py
    00002 # Author: Pere Mato (pere.mato@cern.ch)
    00003
    00004 from GaudiKernel.Constants import *
    00005 from GaudiKernel.Configurable import *
    00006 from GaudiKernel.ConfigurableDb import loadConfigurableDb, cfgDb
    00007 from GaudiKernel.ConfigurableDb import getConfigurable as confDbGetConfigurable
    00008 from CommonGaudiConfigurables import *
    00009 from GaudiKernel.ProcessJobOptions import importOptions, importUnits
    00010 from GaudiKernel.ProcessJobOptions import InstallRootLoggingHandler as _InstallRootLoggingHandler
    00011
    00012 import logging
    00013 log = logging.getLogger(__name__)
    00014 # Ensure that a root logging handler is always present.
    00015 _InstallRootLoggingHandler()
    00016
    00017 allConfigurables = Configurable.allConfigurables
    00018
    00019 def _fillConfDict():
    00020     nFiles = loadConfigurableDb()
    00021     log = logging.getLogger( 'PropertyProxy' )
    00022     log.debug( "Read module info for %d configurables from %d genConfDb files",
    00023               len(cfgDb), nFiles )
    00024     if len(cfgDb.duplicates()) > 0:
    00025         log.warning( "Found %d duplicates among the %d genConfDb files :",
    00026                      len(cfgDb.duplicates()), nFiles )
    00027         log.warning( "--------------------------------------------------" )
    00028         log.warning( "  -%s: %s - %s",
    00029                      "<component name>", "<module>", "[ <duplicates> ]" )
    00030         log.warning( "--------------------------------------------------" )
    00031         dups = cfgDb.duplicates()
    00032         for cfgName in dups.keys():
    00033             log.warning( "  -%s: %s - %s",
    00034                          cfgName,
    00035                          cfgDb[cfgName]['module'],
    00036                          str([ d['module'] for d in dups[cfgName]]) )
    00037             pass
    00038         del dups
    00039         log.warning( "Fix your cmt/requirements file !!" )
    00040         pass
    00041     else:
    00042         log.debug( "No duplicates have been found: that's good !" )
    00043         pass
    00044     return
    00045
    00046 # fill the configurable dictionary at module load
    00047 _fillConfDict()
    00048
    00049 import os, sys
    00050
    00051 def importConfiguration(conf, local=locals()) :
    00052     local[conf] = confDbGetConfigurable(conf)
    00053
    00054 def configurationDict(all=False):
    00055     """Return a dictionary representing the configuration.
    00056     The dictionary contains one entry per configurable which is a dictionary
    00057     with one entry per property.
    00058     The optional argument "all" is used to decide if to include only values
    00059     different from the default or all of them.
    00060     """
    00061     from GaudiKernel.Proxy.Configurable import getNeededConfigurables
    00062
    00063     catalog = allConfigurables
    00064     keys = getNeededConfigurables() # use only interesting configurables
    00065     conf_dict = {}
    00066     if all:
    00067         for n in keys :
    00068             if n not in conf_dict:
    00069                 conf_dict[n] = {}
    00070             for p, v in  catalog[n].getDefaultProperties().items() :
    00071                 conf_dict[n][p] = v
    00072
    00073     for n in keys :
    00074         if n not in conf_dict:
    00075             conf_dict[n] = {}
    00076         for p, v in catalog[n].getValuedProperties().items() :
    00077             conf_dict[n][p] = v
    00078     # purge empty configurables
    00079     keys = conf_dict.keys()
    00080     for n in keys:
    00081         if not conf_dict[n]:
    00082             del conf_dict[n]
    00083     return conf_dict
    00084
    00085 def getConfigurable(name, defaultType = None):
    00086     """Helper function to get a configurable with the given name regardless
    00087     for the type.
    00088     If defaultType can be a class derived from configurable or a string. If not
    00089     specified, the tool name is used as type."""
    00090     if name in allConfigurables:
    00091         return allConfigurables[name]
    00092     else:
    00093         # if the configurable is not found, we need to instantiate it
    00094         if defaultType is None:
    00095             # try to use the name of the configurable as default type
    00096             defaultType = name
    00097         if type(defaultType) is str:
    00098             # we need to convert from string to actual class
    00099             if defaultType in globals():
    00100                 # We the type is defined in the global namespace
    00101                 defaultType = globals()[defaultType]
    00102             else:
    00103                 # otherwise we try to get it from the Configurables database
    00104                 import Configurables
    00105                 defaultType = getattr(Configurables, defaultType)
    00106         return defaultType(name)
    00107
    00108 def setCustomMainLoop(runner):
    00109     '''
    00110     Replace the default main execution loop with the specified callable object.
    00111
    00112     @param runner: a callable that accepts an initialized instance of GaudiPython.AppMgr
    00113                    and the number of events to process and returns a StatusCode or a boolean
    00114                    (True means success)
    00115     '''
    00116     # change the mainLoop function
    00117     from Gaudi.Main import gaudimain
    00118     gaudimain.mainLoop = lambda _self, app, nevt: runner(app, nevt)
    00119
    00120
    00121 class GaudiPersistency(ConfigurableUser):
    00122     """Configurable to enable ROOT-based persistency.
    00123
    00124     Note: it requires Gaudi::RootCnvSvc (package RootCnv).
    00125     """
    00126     __slots__ = {}
    00127     def __apply_configuration__(self):
    00128         """Apply low-level configuration"""
    00129         from Configurables import (ApplicationMgr,
    00130                                    PersistencySvc,
    00131                                    FileRecordDataSvc,
    00132                                    EventPersistencySvc,
    00133                                    )
    00134         # aliased names
    00135         from Configurables import (RootCnvSvc,
    00136                                    RootEvtSelector,
    00137                                    IODataManager,
    00138                                    FileCatalog,
    00139                                    )
    00140         cnvSvcs = [ RootCnvSvc() ]
    00141         EventPersistencySvc().CnvServices += cnvSvcs
    00142         PersistencySvc("FileRecordPersistencySvc").CnvServices += cnvSvcs
    00143         app = ApplicationMgr()
    00144         app.SvcOptMapping += [ FileCatalog(), IODataManager(),
    00145                                RootCnvSvc() ]
    00146         app.ExtSvc += [ FileRecordDataSvc() ]

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines