Gaudi Framework, version v21r4

Home   Generated: 7 Sep 2009

Main.py

Go to the documentation of this file.
00001 import sys, os
00002 from Gaudi import Configuration
00003 from GaudiKernel.ConfigurableDb import cfgDb, loadConfigurableDb, getConfigurable
00004 import logging
00005 
00006 log = logging.getLogger(__name__)
00007 
00008 class gaudimain(object) :
00009     def __init__(self) :
00010         from Configurables import ApplicationMgr
00011         appMgr = ApplicationMgr()
00012         if "GAUDIAPPNAME" in os.environ:
00013             appMgr.AppName = str(os.environ["GAUDIAPPNAME"])
00014         if "GAUDIAPPVERSION" in os.environ:
00015             appMgr.AppVersion = str(os.environ["GAUDIAPPVERSION"])
00016     
00017     def generatePyOutput(self, all = False):
00018         from pprint import pformat
00019         conf_dict = Configuration.configurationDict(all)
00020         return pformat(conf_dict)
00021 
00022     def generateOptsOutput(self, all = False):
00023         from pprint import pformat
00024         conf_dict = Configuration.configurationDict(all)
00025         out = []
00026         names = conf_dict.keys()
00027         names.sort()
00028         for n in names:
00029             props = conf_dict[n].keys()
00030             props.sort()
00031             for p in props:
00032                 out.append('%s.%s = %s;' % (n,p, repr(conf_dict[n][p])))
00033         return "\n".join(out)
00034 
00035     def _writepickle(self, filename) :
00036         #--- Lets take the first file input file as the name of the pickle file
00037         import pickle
00038         output = open(filename, 'wb')
00039         # Dump only the the configurables that make sense to dump (not User ones)
00040         from GaudiKernel.Proxy.Configurable import getNeededConfigurables
00041         to_dump = {}
00042         for n in getNeededConfigurables():
00043             to_dump[n] = Configuration.allConfigurables[n]
00044         pickle.dump(to_dump, output, -1)
00045         output.close()
00046 
00047     def printconfig(self, old_format = False, all = False) :
00048         msg = 'Dumping all configurables and properties'
00049         if not all:
00050             msg += ' (different from default)'
00051         log.info(msg)
00052         conf_dict = Configuration.configurationDict(all)
00053         if old_format:
00054             print self.generateOptsOutput(all)
00055         else:
00056             print self.generatePyOutput(all)
00057 
00058     def writeconfig(self, filename, all = False):
00059         write = { ".pkl" : lambda filename, all: self._writepickle(filename),
00060                   ".py"  : lambda filename, all: open(filename,"w").write(self.generatePyOutput(all) + "\n"),
00061                   ".opts": lambda filename, all: open(filename,"w").write(self.generateOptsOutput(all) + "\n"),
00062                 }
00063         from os.path import splitext
00064         ext = splitext(filename)[1]
00065         if ext in write:
00066             write[ext](filename, all)
00067         else:
00068             log.error("Unknown file type '%s'. Must be any of %r.", ext, write.keys())
00069             sys.exit(1)
00070 
00071     def printsequence(self):
00072         def printAlgo( algName, appMgr, prefix = ' ') :
00073             print prefix + algName
00074             alg = appMgr.algorithm( algName.split( "/" )[ -1 ] )
00075             prop = alg.properties()
00076             if prop.has_key( "Members" ) :
00077                 subs = prop[ "Members" ].value()
00078                 for i in subs : printAlgo( i.strip( '"' ), appMgr, prefix + "     " )
00079             elif prop.has_key( "DetectorList" ) :
00080                 subs = prop[ "DetectorList" ].value()
00081                 for i in subs : printAlgo( algName.split( "/" )[ -1 ] + i.strip( '"' ) + "Seq", appMgr, prefix + "     ")
00082         import GaudiPython
00083         self.g = GaudiPython.AppMgr()
00084         mp = self.g.properties()
00085         print "\n ****************************** Algorithm Sequence **************************** \n"
00086         for i in mp["TopAlg"].value(): printAlgo( i, self.g )
00087         print "\n ****************************************************************************** \n"
00088  
00089     def run(self) :
00090         #--- Instantiate the ApplicationMgr------------------------------
00091         import GaudiPython
00092         self.g = GaudiPython.AppMgr()
00093         success = self.g.run(self.g.EvtMax).isSuccess()
00094         success = self.g.exit().isSuccess() and success
00095         if not success:
00096             return 1
00097         return 0

Generated at Mon Sep 7 18:05:34 2009 for Gaudi Framework, version v21r4 by Doxygen version 1.5.6 written by Dimitri van Heesch, © 1997-2004