| The Gaudi Framework v29r1 (5cd95fa2)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | List of all members
Gaudi.Main.gaudimain Class Reference
Inheritance diagram for Gaudi.Main.gaudimain:
[legend]
Collaboration diagram for Gaudi.Main.gaudimain:
[legend]

## Public Member Functions
def | __init__ (self)
def | setupParallelLogging (self)
def | generatePyOutput (self, all=False)
def | generateOptsOutput (self, all=False)
def | printconfig (self, old_format=False, all=False)
def | writeconfig (self, filename, all=False)
def | run (self, attach_debugger, ncpus=None)
def | hookDebugger (self, debugger='gdb')
def | basicInit (self)
def | gaudiPythonInit (self)
def | runSerial (self, attach_debugger)
def | runParallel (self, ncpus)

## Public Attributes
| log
| printsequence
| ip
| g

## Static Public Attributes
| mainLoop = None

## Private Member Functions
def | _writepickle (self, filename)

## Detailed Description

Definition at line 163 of file Main.py.

## Constructor & Destructor Documentation

def Gaudi.Main.gaudimain.__init__ | ( |  | self | ) |

Definition at line 167 of file Main.py.

167 def __init__(self):
168 from Configurables import ApplicationMgr
169 appMgr = ApplicationMgr()
170 if "GAUDIAPPNAME" in os.environ:
171 appMgr.AppName = str(os.environ["GAUDIAPPNAME"])
172 if "GAUDIAPPVERSION" in os.environ:
173 appMgr.AppVersion = str(os.environ["GAUDIAPPVERSION"])
174 self.log = logging.getLogger(__name__)
175 self.printsequence = False
176
Gaudi.Main.gaudimain.log
log
Definition: Main.py:174
Gaudi.Main.gaudimain.printsequence
printsequence
Definition: Main.py:175
ApplicationMgr
The Application Manager class.
Definition: ApplicationMgr.h:47
Gaudi.Main.gaudimain.__init__
def __init__(self)
Definition: Main.py:167

## Member Function Documentation

def Gaudi.Main.gaudimain._writepickle | ( |  | self,
|  |  | filename
| ) |  |
| private

Definition at line 230 of file Main.py.

230 def _writepickle(self, filename):
231 #--- Lets take the first file input file as the name of the pickle file
232 import pickle
233 output = open(filename, 'wb')
234 # Dump only the the configurables that make sense to dump (not User ones)
235 from GaudiKernel.Proxy.Configurable import getNeededConfigurables
236 to_dump = {}
237 for n in getNeededConfigurables():
238 to_dump[n] = Configuration.allConfigurables[n]
239 pickle.dump(to_dump, output, -1)
240 output.close()
241
Gaudi.Main.gaudimain._writepickle
def _writepickle(self, filename)
Definition: Main.py:230
GaudiKernel.Proxy.getNeededConfigurables
getNeededConfigurables
Definition: Proxy.py:20

def Gaudi.Main.gaudimain.basicInit | ( |  | self | ) |

    Bootstrap the application with minimal use of Python bindings.

Definition at line 293 of file Main.py.

293 def basicInit(self):
294 '''
295 Bootstrap the application with minimal use of Python bindings.
296 '''
297 try:
298 from GaudiKernel.Proxy.Configurable import expandvars
299 except ImportError:
300 # pass-through implementation if expandvars is not defined (AthenaCommon)
301 def expandvars(data): return data
302
303 from GaudiKernel.Proxy.Configurable import Configurable, getNeededConfigurables
304
305 global _bootstrap
306 if _bootstrap is None:
307 _bootstrap = BootstrapHelper()
308
309 self.log.debug('basicInit: instantiate ApplicationMgr')
310 self.ip = self.g = _bootstrap.createApplicationMgr()
311
312 self.log.debug('basicInit: apply options')
313
314 # set ApplicationMgr properties
315 comp = 'ApplicationMgr'
316 props = Configurable.allConfigurables.get(comp, {})
317 if props:
318 props = expandvars(props.getValuedProperties())
319 for p, v in props.items() + [('JobOptionsType', 'NONE')]:
320 if not self.g.setProperty(p, str(v)):
321 self.log.error('Cannot set property %s.%s to %s', comp, p, v)
322 sys.exit(10)
323 # issue with missing dictionary with ROOT < 6.2.7
324 if _bootstrap.ROOT_VERSION < (6, 2, 7):
325 # we need to load GaudiPython
326 import GaudiPython
327
328 self.g.configure()
329
330 # set MessageSvc properties
331 comp = 'MessageSvc'
332 msp = self.g.getService(comp)
333 if not msp:
334 self.log.error('Cannot get service %s', comp)
335 sys.exit(10)
336 props = Configurable.allConfigurables.get(comp, {})
337 if props:
338 props = expandvars(props.getValuedProperties())
339 for p, v in props.items():
340 if not _bootstrap.setProperty(msp, p, str(v)):
341 self.log.error('Cannot set property %s.%s to %s', comp, p, v)
342 sys.exit(10)
343
344 # feed JobOptionsSvc
345 comp = 'JobOptionsSvc'
346 jos = self.g.getService(comp)
347 if not jos:
348 self.log.error('Cannot get service %s', comp)
349 sys.exit(10)
350 for n in getNeededConfigurables():
351 c = Configurable.allConfigurables[n]
352 if n in ['ApplicationMgr', 'MessageSvc']:
353 continue # These are already done
354 for p, v in c.getValuedProperties().items():
355 v = expandvars(v)
356 # Note: AthenaCommon.Configurable does not have Configurable.PropertyReference
357 if hasattr(Configurable, "PropertyReference") and type(v) == Configurable.PropertyReference:
358 # this is done in "getFullName", but the exception is ignored,
359 # so we do it again to get it
360 v = v.__resolve__()
361 if type(v) == str:
362 v = '"%s"' % v # need double quotes
363 elif type(v) == long:
364 v = '%d' % v # prevent pending 'L'
365 _bootstrap.addPropertyToCatalogue(jos, n, p, str(v))
366 if hasattr(Configurable, "_configurationLocked"):
367 Configurable._configurationLocked = True
368 self.log.debug('basicInit: done')
369
Gaudi.Main.gaudimain.g
g
Definition: Main.py:310
Gaudi.Main.gaudimain.basicInit
def basicInit(self)
Definition: Main.py:293
GaudiKernel.Proxy.getNeededConfigurables
getNeededConfigurables
Definition: Proxy.py:20
Gaudi.Main.BootstrapHelper
Definition: Main.py:10
gaudirun.type
type
Definition: gaudirun.py:133
GaudiKernel.Configurable.expandvars
def expandvars(data)
Definition: Configurable.py:38
Gaudi.Main.gaudimain.ip
ip
Definition: Main.py:310

def Gaudi.Main.gaudimain.gaudiPythonInit | ( |  | self | ) |

    Initialize the application with full Python bindings.

Definition at line 370 of file Main.py.

370 def gaudiPythonInit(self):
371 '''
372 Initialize the application with full Python bindings.
373 '''
374 self.log.debug('gaudiPythonInit: import GaudiPython')
375 import GaudiPython
376 self.log.debug('gaudiPythonInit: instantiate ApplicationMgr')
377 self.g = GaudiPython.AppMgr()
378 self.ip = self.g._ip
379 self.log.debug('gaudiPythonInit: done')
380
Gaudi.Main.gaudimain.g
g
Definition: Main.py:310
Gaudi.Main.gaudimain.gaudiPythonInit
def gaudiPythonInit(self)
Definition: Main.py:370
Gaudi.Main.gaudimain.ip
ip
Definition: Main.py:310
GaudiPython.Bindings.AppMgr
Definition: Bindings.py:883

def Gaudi.Main.gaudimain.generateOptsOutput | ( |  | self,
|  |  | all = `False`
| ) |  |

Definition at line 217 of file Main.py.

217 def generateOptsOutput(self, all=False):
218 from pprint import pformat
219 conf_dict = Configuration.configurationDict(all)
220 out = []
221 names = conf_dict.keys()
222 names.sort()
223 for n in names:
224 props = conf_dict[n].keys()
225 props.sort()
226 for p in props:
227 out.append('%s.%s = %s;' % (n, p, toOpt(conf_dict[n][p])))
228 return "\n".join(out)
229
Gaudi.Main.toOpt
def toOpt(value)
Definition: Main.py:140
Gaudi.Main.gaudimain.generateOptsOutput
def generateOptsOutput(self, all=False)
Definition: Main.py:217

def Gaudi.Main.gaudimain.generatePyOutput | ( |  | self,
|  |  | all = `False`
| ) |  |

Definition at line 212 of file Main.py.

212 def generatePyOutput(self, all=False):
213 from pprint import pformat
214 conf_dict = Configuration.configurationDict(all)
215 return pformat(conf_dict)
216
Gaudi.Main.gaudimain.generatePyOutput
def generatePyOutput(self, all=False)
Definition: Main.py:212

def Gaudi.Main.gaudimain.hookDebugger | ( |  | self,
|  |  | debugger = `'gdb'`
| ) |  |

Definition at line 278 of file Main.py.

278 def hookDebugger(self, debugger='gdb'):
279 import os
280 self.log.info('attaching debugger to PID ' + str(os.getpid()))
281 pid = os.spawnvp(os.P_NOWAIT,
282 debugger, [debugger, '-q', 'python', str(os.getpid())])
283
284 # give debugger some time to attach to the python process
285 import time
286 time.sleep(5)
287
288 # verify the process' existence (will raise OSError if failed)
289 os.waitpid(pid, os.WNOHANG)
290 os.kill(pid, 0)
291 return
292
Gaudi.Main.gaudimain.hookDebugger
def hookDebugger(self, debugger='gdb')
Definition: Main.py:278

def Gaudi.Main.gaudimain.printconfig | ( |  | self,
|  |  | old_format = `False`,
|  |  | all = `False`
| ) |  |

Definition at line 242 of file Main.py.

242 def printconfig(self, old_format=False, all=False):
243 msg = 'Dumping all configurables and properties'
244 if not all:
245 msg += ' (different from default)'
246 log.info(msg)
247 conf_dict = Configuration.configurationDict(all)
248 if old_format:
249 print self.generateOptsOutput(all)
250 else:
251 print self.generatePyOutput(all)
252
Gaudi.Main.gaudimain.generateOptsOutput
def generateOptsOutput(self, all=False)
Definition: Main.py:217
Gaudi.Main.gaudimain.generatePyOutput
def generatePyOutput(self, all=False)
Definition: Main.py:212
Gaudi.Main.gaudimain.printconfig
def printconfig(self, old_format=False, all=False)
Definition: Main.py:242

def Gaudi.Main.gaudimain.run | ( |  | self,
|  |  | attach_debugger,
|  |  | ncpus = `None`
| ) |  |

Definition at line 269 of file Main.py.

269 def run(self, attach_debugger, ncpus=None):
270 if not ncpus:
271 # Standard sequential mode
272 result = self.runSerial(attach_debugger)
273 else:
274 # Otherwise, run with the specified number of cpus
275 result = self.runParallel(ncpus)
276 return result
277
Gaudi.Main.gaudimain.run
def run(self, attach_debugger, ncpus=None)
Definition: Main.py:269
Gaudi.Main.gaudimain.runParallel
def runParallel(self, ncpus)
Definition: Main.py:452
Gaudi.Main.gaudimain.runSerial
def runSerial(self, attach_debugger)
Definition: Main.py:381

def Gaudi.Main.gaudimain.runParallel | ( |  | self,
|  |  | ncpus
| ) |  |

Definition at line 452 of file Main.py.

452 def runParallel(self, ncpus):
453 if self.mainLoop:
454 self.log.fatal(
455 "Cannot use custom main loop in multi-process mode, check your options")
456 return 1
457 self.setupParallelLogging()
458 from Gaudi.Configuration import Configurable
459 import GaudiMP.GMPBase as gpp
460 c = Configurable.allConfigurables
461 self.log.info('-' * 80)
462 self.log.info('%s: Parallel Mode : %i ', __name__, ncpus)
463 for name, value in [('platrofm', ' '.join(os.uname())),
464 ('config', os.environ.get('BINARY_TAG') or
465 os.environ.get('CMTCONFIG')),
466 ('app. name', os.environ.get('GAUDIAPPNAME')),
467 ('app. version', os.environ.get('GAUDIAPPVERSION')),
468 ]:
469 self.log.info('%s: %30s : %s ', __name__,
470 name, value or 'Undefined')
471 try:
472 events = str(c['ApplicationMgr'].EvtMax)
473 except:
474 events = "Undetermined"
475 self.log.info('%s: Events Specified : %s ', __name__, events)
476 self.log.info('-' * 80)
477 # Parall = gpp.Coordinator(ncpus, shared, c, self.log)
478 Parall = gpp.Coord(ncpus, c, self.log)
479 sysStart = time()
480 sc = Parall.Go()
481 self.log.info('MAIN.PY : received %s from Coordinator' % (sc))
482 if sc.isFailure():
483 return 1
484 sysTime = time() - sysStart
485 self.log.name = 'Gaudi/Main.py Logger'
486 self.log.info('-' * 80)
487 self.log.info(
488 '%s: parallel system finished, time taken: %5.4fs', __name__, sysTime)
489 self.log.info('-' * 80)
490 return 0
491
Gaudi.Main.gaudimain.setupParallelLogging
def setupParallelLogging(self)
Definition: Main.py:177
Gaudi.Main.gaudimain.log
log
Definition: Main.py:174
plotSpeedupsPyRoot.time
time
Definition: plotSpeedupsPyRoot.py:154
Gaudi.Configuration
Definition: Configuration.py:1
Gaudi.Main.gaudimain.runParallel
def runParallel(self, ncpus)
Definition: Main.py:452
GaudiMP.GMPBase
Definition: GMPBase.py:1
Gaudi.Main.gaudimain.mainLoop
mainLoop
Definition: Main.py:165

def Gaudi.Main.gaudimain.runSerial | ( |  | self,
|  |  | attach_debugger
| ) |  |

Definition at line 381 of file Main.py.

381 def runSerial(self, attach_debugger):
382 #--- Instantiate the ApplicationMgr------------------------------
383 if (self.mainLoop or
384 os.environ.get('GAUDIRUN_USE_GAUDIPYTHON')):
385 self.gaudiPythonInit()
386 else:
387 self.basicInit()
388
389 self.log.debug('-' * 80)
390 self.log.debug('%s: running in serial mode', __name__)
391 self.log.debug('-' * 80)
392 sysStart = time()
393
394 if self.mainLoop:
395 runner = self.mainLoop
396 else:
397 def runner(app, nevt):
398 self.log.debug('initialize')
399 sc = app.initialize()
400 if sc.isSuccess():
401 if self.printsequence:
402 app.printAlgsSequences()
403 self.log.debug('start')
404 sc = app.start()
405 if sc.isSuccess():
406 self.log.debug('run(%d)', nevt)
407 sc = app.run(nevt)
408 self.log.debug('stop')
409 app.stop().ignore()
410 self.log.debug('finalize')
411 app.finalize().ignore()
412 self.log.debug('terminate')
413 sc1 = app.terminate()
414 if sc.isSuccess():
415 sc = sc1
416 else:
417 sc1.ignore()
418 self.log.debug('status code: %s',
419 'SUCCESS' if sc.isSuccess() else 'FAILURE')
420 return sc
421
422 if (attach_debugger == True):
423 self.hookDebugger()
424
425 try:
426 statuscode = runner(self.g, int(
427 self.ip.getProperty('EvtMax').toString()))
428 except SystemError:
429 # It may not be 100% correct, but usually it means a segfault in C++
430 self.ip.setProperty('ReturnCode', str(128 + 11))
431 statuscode = False
432 except Exception, x:
433 print 'Exception:', x
434 # for other exceptions, just set a generic error code
435 self.ip.setProperty('ReturnCode', '1')
436 statuscode = False
437 if hasattr(statuscode, "isSuccess"):
438 success = statuscode.isSuccess()
439 else:
440 success = statuscode
441 #success = self.g.exit().isSuccess() and success
442 if not success and self.ip.getProperty('ReturnCode').toString() == '0':
443 # ensure that the return code is correctly set
444 self.ip.setProperty('ReturnCode', '1')
445 sysTime = time() - sysStart
446 self.log.debug('-' * 80)
447 self.log.debug(
448 '%s: serial system finished, time taken: %5.4fs', __name__, sysTime)
449 self.log.debug('-' * 80)
450 return int(self.ip.getProperty('ReturnCode').toString())
451
Gaudi.Main.gaudimain.g
g
Definition: Main.py:310
Gaudi.Main.gaudimain.basicInit
def basicInit(self)
Definition: Main.py:293
Gaudi.Main.gaudimain.gaudiPythonInit
def gaudiPythonInit(self)
Definition: Main.py:370
plotSpeedupsPyRoot.time
time
Definition: plotSpeedupsPyRoot.py:154
Gaudi.Main.gaudimain.hookDebugger
def hookDebugger(self, debugger='gdb')
Definition: Main.py:278
Gaudi.Main.gaudimain.printsequence
printsequence
Definition: Main.py:175
GaudiMath::Interpolation::toString
std::string toString(const Type &)
Definition: Interpolation.cpp:42
Gaudi.Main.gaudimain.runSerial
def runSerial(self, attach_debugger)
Definition: Main.py:381
Gaudi.Main.gaudimain.mainLoop
mainLoop
Definition: Main.py:165

def Gaudi.Main.gaudimain.setupParallelLogging | ( |  | self | ) |

Definition at line 177 of file Main.py.

177 def setupParallelLogging(self):
178 # ---------------------------------------------------
179 # set up Logging
180 # ----------------
181 # from multiprocessing import enableLogging, getLogger
182 import multiprocessing
183 # preliminaries for handlers/output files, etc.
184 from time import ctime
185 datetime = ctime()
186 datetime = datetime.replace(' ', '_')
187 outfile = open('gaudirun-%s.log' % (datetime), 'w')
188 # two handlers, one for a log file, one for terminal
189 streamhandler = logging.StreamHandler(stream=outfile)
190 console = logging.StreamHandler()
191 # create formatter : the params in parentheses are variable names available via logging
192 formatter = logging.Formatter(
193 "%(asctime)s - %(name)s - %(levelname)s - %(message)s")
194 # add formatter to Handler
195 streamhandler.setFormatter(formatter)
196 console.setFormatter(formatter)
197 # now, configure the logger
198 # enableLogging( level=0 )
199 # self.log = getLogger()
200 self.log = multiprocessing.log_to_stderr()
201 self.log.setLevel(logging.INFO)
202 self.log.name = 'Gaudi/Main.py Logger'
203 self.log.handlers = []
204 # add handlers to logger : one for output to a file, one for console output
205 self.log.addHandler(streamhandler)
206 self.log.addHandler(console)
207 self.log.removeHandler(console)
208 # set level!!
209 self.log.setLevel = logging.INFO
210 # ---------------------------------------------------
211
Gaudi.Main.gaudimain.setupParallelLogging
def setupParallelLogging(self)
Definition: Main.py:177
Gaudi.Main.gaudimain.log
log
Definition: Main.py:174

def Gaudi.Main.gaudimain.writeconfig | ( |  | self,
|  |  | filename,
|  |  | all = `False`
| ) |  |

Definition at line 253 of file Main.py.

253 def writeconfig(self, filename, all=False):
254 write = {".pkl": lambda filename, all: self._writepickle(filename),
255 ".py": lambda filename, all: open(filename, "w").write(self.generatePyOutput(all) + "\n"),
256 ".opts": lambda filename, all: open(filename, "w").write(self.generateOptsOutput(all) + "\n"),
257 }
258 from os.path import splitext
259 ext = splitext(filename)[1]
260 if ext in write:
261 write[ext](filename, all)
262 else:
263 log.error("Unknown file type '%s'. Must be any of %r.",
264 ext, write.keys())
265 sys.exit(1)
266
Gaudi.Main.gaudimain._writepickle
def _writepickle(self, filename)
Definition: Main.py:230
Gaudi.Main.gaudimain.generateOptsOutput
def generateOptsOutput(self, all=False)
Definition: Main.py:217
Gaudi.Main.gaudimain.generatePyOutput
def generatePyOutput(self, all=False)
Definition: Main.py:212
GaudiPython.GaudiAlgs.write
write
Definition: GaudiAlgs.py:1259
Gaudi.Main.gaudimain.writeconfig
def writeconfig(self, filename, all=False)
Definition: Main.py:253

## Member Data Documentation

Gaudi.Main.gaudimain.g

Definition at line 310 of file Main.py.

Gaudi.Main.gaudimain.ip

Definition at line 310 of file Main.py.

Gaudi.Main.gaudimain.log

Definition at line 174 of file Main.py.

Gaudi.Main.gaudimain.mainLoop = None
| static

Definition at line 165 of file Main.py.

Gaudi.Main.gaudimain.printsequence

Definition at line 175 of file Main.py.

The documentation for this class was generated from the following file:

- Gaudi/python/Gaudi/Main.py