def configurationDict(all=False): """Return a dictionary representing the configuration. The dictionary contains one entry per configurable which is a dictionary with one entry per property. The optional argument "all" is used to decide if to include only values different from the default or all of them. """ from GaudiKernel.Proxy.Configurable import getNeededConfigurables catalog = allConfigurables keys = getNeededConfigurables() # use only interesting configurables conf_dict = {} if all: for n in keys : if n not in conf_dict: conf_dict[n] = {} for p, v in catalog[n].getDefaultProperties().items() : conf_dict[n][p] = v for n in keys : if n not in conf_dict: conf_dict[n] = {} for p, v in catalog[n].getValuedProperties().items() : conf_dict[n][p] = v # purge empty configurables keys = conf_dict.keys() for n in keys: if not conf_dict[n]: del conf_dict[n] return conf_dict
def _writepickle(self, filename) : #--- Lets take the first file input file as the name of the pickle file import pickle output = open(filename, 'wb') # Dump only the the configurables that make sense to dump (not User ones) from GaudiKernel.Proxy.Configurable import getNeededConfigurables to_dump = {} for n in getNeededConfigurables(): to_dump[n] = Configuration.allConfigurables[n] pickle.dump(to_dump, output, -1) output.close()
def __init__(self, outputlevel = -1, joboptions = None, selfoptions = {}, dllname = None, factname = None) : global _gaudi if _gaudi : return # Protection against multiple calls to exit() if the finalization fails self.__dict__['_exit_called'] = False # keep the Gaudi namespace around (so it is still available during atexit shutdown)... self.__dict__['_gaudi_ns'] = Gaudi try: from GaudiKernel.Proxy.Configurable import expandvars except ImportError: # pass-through implementation if expandvars is not defined (AthenaCommon) expandvars = lambda data : data if dllname and factname: self.__dict__['_appmgr'] = gbl.Gaudi.createApplicationMgr(dllname,factname) elif dllname: self.__dict__['_appmgr'] = gbl.Gaudi.createApplicationMgr(dllname) else: self.__dict__['_appmgr'] = gbl.Gaudi.createApplicationMgr() self.__dict__['_svcloc'] = gbl.Gaudi.svcLocator() self.__dict__['_algmgr'] = InterfaceCast(gbl.IAlgManager)(self._appmgr) self.__dict__['_evtpro'] = InterfaceCast(gbl.IEventProcessor)(self._appmgr) self.__dict__['_svcmgr'] = InterfaceCast(gbl.ISvcManager)(self._appmgr) self.__dict__['pyalgorithms'] = [] iService.__init__(self, 'ApplicationMgr', self._appmgr ) #------python specific initialization------------------------------------- if self.FSMState() < Gaudi.StateMachine.CONFIGURED : # Not yet configured self.JobOptionsType = 'NONE' if joboptions : from GaudiKernel.ProcessJobOptions import importOptions importOptions(joboptions) # Ensure that the ConfigurableUser instances have been applied import GaudiKernel.Proxy.Configurable if hasattr(GaudiKernel.Proxy.Configurable, "applyConfigurableUsers"): GaudiKernel.Proxy.Configurable.applyConfigurableUsers() # This is the default and could be overridden with "selfopts" self.OutputLevel = 3 selfprops = Configurable.allConfigurables.get('ApplicationMgr',{}) if selfprops : selfprops = expandvars(selfprops.getValuedProperties()) for p,v in selfprops.items() : setattr(self, p, v) for p,v in selfoptions.items() : setattr(self, p, v) # Override job options if outputlevel != -1 : self.OutputLevel = outputlevel self.configure() #---MessageSvc------------------------------------------------------------ ms = self.service('MessageSvc') if 'MessageSvc' in Configurable.allConfigurables: msprops = Configurable.allConfigurables['MessageSvc'] ms = self.service('MessageSvc') if hasattr(msprops,"getValuedProperties"): msprops = expandvars(msprops.getValuedProperties()) for p,v in msprops.items(): setattr(ms, p, v) if outputlevel != -1 : ms.OutputLevel = outputlevel #---JobOptions------------------------------------------------------------ self.__dict__['_optsvc'] = InterfaceCast(gbl.IJobOptionsSvc)(Helper.service(self._svcloc,'JobOptionsSvc')) #------Configurables initialization (part2)------------------------------- for n in getNeededConfigurables(): c = Configurable.allConfigurables[n] if n in ['ApplicationMgr','MessageSvc'] : continue # These are already done--- for p, v in c.getValuedProperties().items() : v = expandvars(v) # Note: AthenaCommon.Configurable does not have Configurable.PropertyReference if hasattr(Configurable,"PropertyReference") and type(v) == Configurable.PropertyReference: # this is done in "getFullName", but the exception is ignored, # so we do it again to get it v = v.__resolve__() if type(v) == str : v = '"%s"' % v # need double quotes elif type(v) == long: v = '%d' % v # prevent pending 'L' self._optsvc.addPropertyToCatalogue(n, StringProperty(p,str(v))) if hasattr(Configurable,"_configurationLocked"): Configurable._configurationLocked = True # Ensure that the exit method is called when exiting from Python import atexit atexit.register(self.exit) #---Hack to avoid bad interactions with the ROOT exit handler # Look for an exit handler installed by ROOT root_handler_installed = False for h in atexit._exithandlers: func = h[0] if hasattr(func, "__module__") and func.__module__ == "ROOT": root_handler_installed = True break # If the handler is not yet installed, let's install our private version # that detects that the ROOT exit handler is installed and add our own # after it to ensure it is called before. if not root_handler_installed: orig_register = atexit.register def register(func, *targs, **kargs): orig_register(func, *targs, **kargs) if hasattr(func, "__module__") and func.__module__ == "ROOT": orig_register(self.exit) # we do not need to remove out handler from the list because # it can be safely called more than once register.__doc__ = (orig_register.__doc__ + "\nNote: version hacked by GaudiPython to work " + "around a problem with the ROOT exit handler") atexit.register = register