3 from Gaudi
import Configuration
6 log = logging.getLogger(__name__)
13 from Configurables
import ApplicationMgr
15 if "GAUDIAPPNAME" in os.environ:
16 appMgr.AppName = str(os.environ[
"GAUDIAPPNAME"])
17 if "GAUDIAPPVERSION" in os.environ:
18 appMgr.AppVersion = str(os.environ[
"GAUDIAPPVERSION"])
19 self.
log = logging.getLogger(__name__)
27 import multiprocessing
29 from time
import ctime
31 datetime = datetime.replace(
' ',
'_')
32 outfile = open(
'gaudirun-%s.log'%(datetime),
'w' )
34 streamhandler = logging.StreamHandler(strm=outfile)
35 console = logging.StreamHandler()
37 formatter = logging.Formatter(
"%(asctime)s - %(name)s - %(levelname)s - %(message)s" )
39 streamhandler.setFormatter(formatter)
40 console.setFormatter(formatter)
44 self.
log = multiprocessing.log_to_stderr()
45 self.log.setLevel( logging.INFO )
46 self.log.name =
'Gaudi/Main.py Logger'
47 self.log.handlers = []
49 self.log.addHandler(streamhandler)
50 self.log.addHandler(console)
51 self.log.removeHandler(console)
53 self.log.setLevel = logging.INFO
57 from pprint
import pformat
58 conf_dict = Configuration.configurationDict(all)
59 return pformat(conf_dict)
62 from pprint
import pformat
63 conf_dict = Configuration.configurationDict(all)
65 names = conf_dict.keys()
68 props = conf_dict[n].keys()
71 out.append(
'%s.%s = %s;' % (n,p, repr(conf_dict[n][p])))
77 output = open(filename,
'wb')
79 from GaudiKernel.Proxy.Configurable
import getNeededConfigurables
82 to_dump[n] = Configuration.allConfigurables[n]
83 pickle.dump(to_dump, output, -1)
87 msg =
'Dumping all configurables and properties'
89 msg +=
' (different from default)'
91 conf_dict = Configuration.configurationDict(all)
98 write = {
".pkl" :
lambda filename, all: self.
_writepickle(filename),
99 ".py" :
lambda filename, all: open(filename,
"w").write(self.
generatePyOutput(all) +
"\n"),
100 ".opts":
lambda filename, all: open(filename,
"w").write(self.
generateOptsOutput(all) +
"\n"),
102 from os.path
import splitext
103 ext = splitext(filename)[1]
105 write[ext](filename, all)
107 log.error(
"Unknown file type '%s'. Must be any of %r.", ext, write.keys())
115 def printAlgo( algName, appMgr, prefix = ' ') :
116 print prefix + algName
117 alg = appMgr.algorithm( algName.split(
"/" )[ -1 ] )
118 prop = alg.properties()
119 if prop.has_key(
"Members" ) :
120 subs = prop[
"Members" ].
value()
121 for i
in subs : printAlgo( i.strip(
'"' ), appMgr, prefix +
" " )
122 elif prop.has_key(
"DetectorList" ) :
123 subs = prop[
"DetectorList" ].
value()
124 for i
in subs : printAlgo( algName.split(
"/" )[ -1 ] + i.strip(
'"' ) +
"Seq", appMgr, prefix +
" ")
126 mp = self.g.properties()
127 print "\n ****************************** Algorithm Sequence **************************** \n"
128 for i
in mp[
"TopAlg"].
value(): printAlgo( i, self.
g )
129 print "\n ****************************************************************************** \n"
133 def run(self, ncpus = None):
146 self.log.debug(
'-'*80)
147 self.log.debug(
'%s: running in serial mode', __name__)
148 self.log.debug(
'-'*80)
152 runner = self.
mainLoop or (
lambda app, nevt: app.run(nevt))
154 statuscode = runner(self.
g, self.g.EvtMax)
157 self.g.ReturnCode = 128 + 11
161 self.g.ReturnCode = 1
163 if hasattr(statuscode,
"isSuccess"):
164 success = statuscode.isSuccess()
167 success = self.g.exit().isSuccess()
and success
168 if not success
and self.g.ReturnCode == 0:
170 self.g.ReturnCode = 1
171 sysTime = time()-sysStart
172 self.log.debug(
'-'*80)
173 self.log.debug(
'%s: serial system finished, time taken: %5.4fs', __name__, sysTime)
174 self.log.debug(
'-'*80)
175 return self.g.ReturnCode
179 self.log.fatal(
"Cannot use custom main loop in multi-process mode, check your options")
184 c = Configurable.allConfigurables
185 self.log.info(
'-'*80)
186 self.log.info(
'%s: Parallel Mode : %i '%(__name__, ncpus))
187 from commands
import getstatusoutput
as gso
188 metadataCommands = [
'uname -a',
190 'echo $GAUDIAPPNAME',
191 'echo $GAUDIAPPVERSION']
192 for comm
in metadataCommands :
196 string =
'%s: %30s : %s '%(__name__, comm, o)
197 self.log.info( string )
199 events = str(c[
'ApplicationMgr'].EvtMax)
201 events =
"Undetermined"
202 self.log.info(
'%s: Events Specified : %s '%(__name__,events))
203 self.log.info(
'-'*80)
205 Parall = gpp.Coord( ncpus, c, self.
log )
208 self.log.info(
'MAIN.PY : received %s from Coordinator'%(sc))
211 sysTime = time()-sysStart
212 self.log.name =
'Gaudi/Main.py Logger'
213 self.log.info(
'-'*80)
214 self.log.info(
'%s: parallel system finished, time taken: %5.4fs', __name__, sysTime)
215 self.log.info(
'-'*80)
def getNeededConfigurables
The Application Manager class.
def run
Instantiate and run the application.