The Gaudi Framework  v36r1 (3e2fb5a8)
Gaudi.Main.gaudimain Class Reference
Inheritance diagram for Gaudi.Main.gaudimain:
Collaboration diagram for Gaudi.Main.gaudimain:

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 runSerial (self, attach_debugger)
 
def runParallel (self, ncpus)
 

Public Attributes

 log
 
 printsequence
 
 application
 

Private Member Functions

def _writepickle (self, filename)
 

Detailed Description

Definition at line 314 of file Main.py.

Constructor & Destructor Documentation

◆ __init__()

def Gaudi.Main.gaudimain.__init__ (   self)

Definition at line 315 of file Main.py.

315  def __init__(self):
316  from Configurables import ApplicationMgr
317  appMgr = ApplicationMgr()
318  if "GAUDIAPPNAME" in os.environ:
319  appMgr.AppName = str(os.environ["GAUDIAPPNAME"])
320  if "GAUDIAPPVERSION" in os.environ:
321  appMgr.AppVersion = str(os.environ["GAUDIAPPVERSION"])
322  self.log = logging.getLogger(__name__)
323  self.printsequence = False
324  self.application = 'Gaudi::Application'
325 

Member Function Documentation

◆ _writepickle()

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

Definition at line 384 of file Main.py.

384  def _writepickle(self, filename):
385  # --- Lets take the first file input file as the name of the pickle file
386  import pickle
387  output = open(filename, 'wb')
388  # Dump only the the configurables that make sense to dump (not User ones)
389  from GaudiKernel.Proxy.Configurable import getNeededConfigurables
390  to_dump = {}
391  for n in getNeededConfigurables():
392  to_dump[n] = Configuration.allConfigurables[n]
393  pickle.dump(to_dump, output, -1)
394  output.close()
395 

◆ generateOptsOutput()

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

Definition at line 378 of file Main.py.

378  def generateOptsOutput(self, all=False):
379  opts = getAllOpts(all)
380  keys = sorted(opts)
381  return '\n'.join(
382  '{} = {};'.format(key, toOpt(parseOpt(opts[key]))) for key in keys)
383 

◆ generatePyOutput()

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

Definition at line 361 of file Main.py.

361  def generatePyOutput(self, all=False):
362  from pprint import pformat
363  from collections import defaultdict
364  optDict = defaultdict(dict)
365  allOpts = getAllOpts(all)
366  for key in allOpts:
367  c, p = key.rsplit('.', 1)
368  optDict[c][p] = parseOpt(allOpts[key])
369  formatted = pformat(dict(optDict))
370  # Python 2 compatibility
371  if six.PY2:
372  return formatted
373  else:
374  # undo splitting of strings on multiple lines
375  import re
376  return re.sub(r'"\n +"', '', formatted, flags=re.MULTILINE)
377 

◆ hookDebugger()

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

Definition at line 432 of file Main.py.

432  def hookDebugger(self, debugger='gdb'):
433  import os
434  self.log.info('attaching debugger to PID ' + str(os.getpid()))
435  pid = os.spawnvp(os.P_NOWAIT, debugger,
436  [debugger, '-q', 'python',
437  str(os.getpid())])
438 
439  # give debugger some time to attach to the python process
440  import time
441  time.sleep(5)
442 
443  # verify the process' existence (will raise OSError if failed)
444  os.waitpid(pid, os.WNOHANG)
445  os.kill(pid, 0)
446  return
447 

◆ printconfig()

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

Definition at line 396 of file Main.py.

396  def printconfig(self, old_format=False, all=False):
397  msg = 'Dumping all configurables and properties'
398  if not all:
399  msg += ' (different from default)'
400  log.info(msg)
401  if old_format:
402  print(self.generateOptsOutput(all))
403  else:
404  print(self.generatePyOutput(all))
405  sys.stdout.flush()
406 

◆ run()

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

Definition at line 423 of file Main.py.

423  def run(self, attach_debugger, ncpus=None):
424  if not ncpus:
425  # Standard sequential mode
426  result = self.runSerial(attach_debugger)
427  else:
428  # Otherwise, run with the specified number of cpus
429  result = self.runParallel(ncpus)
430  return result
431 

◆ runParallel()

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

Definition at line 488 of file Main.py.

488  def runParallel(self, ncpus):
489  self.setupParallelLogging()
490  from Gaudi.Configuration import Configurable
491  import GaudiMP.GMPBase as gpp
492  c = Configurable.allConfigurables
493  self.log.info('-' * 80)
494  self.log.info('%s: Parallel Mode : %i ', __name__, ncpus)
495  for name, value in [
496  ('platform', ' '.join(os.uname())),
497  ('config', os.environ.get('BINARY_TAG')
498  or os.environ.get('CMTCONFIG')),
499  ('app. name', os.environ.get('GAUDIAPPNAME')),
500  ('app. version', os.environ.get('GAUDIAPPVERSION')),
501  ]:
502  self.log.info('%s: %30s : %s ', __name__, name, value
503  or 'Undefined')
504  try:
505  events = str(c['ApplicationMgr'].EvtMax)
506  except:
507  events = "Undetermined"
508  self.log.info('%s: Events Specified : %s ', __name__, events)
509  self.log.info('-' * 80)
510  # Parall = gpp.Coordinator(ncpus, shared, c, self.log)
511  Parall = gpp.Coord(ncpus, c, self.log)
512  sysStart = time()
513  sc = Parall.Go()
514  self.log.info('MAIN.PY : received %s from Coordinator' % (sc))
515  if sc.isFailure():
516  return 1
517  sysTime = time() - sysStart
518  self.log.name = 'Gaudi/Main.py Logger'
519  self.log.info('-' * 80)
520  self.log.info('%s: parallel system finished, time taken: %5.4fs',
521  __name__, sysTime)
522  self.log.info('-' * 80)
523  return 0

◆ runSerial()

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

Definition at line 448 of file Main.py.

448  def runSerial(self, attach_debugger):
449  try:
450  from GaudiKernel.Proxy.Configurable import expandvars
451  except ImportError:
452  # pass-through implementation if expandvars is not defined (AthenaCommon)
453  def expandvars(data):
454  return data
455 
456  from GaudiKernel.Proxy.Configurable import Configurable
457 
458  self.log.debug('runSerial: apply options')
459  conf_dict = expandvars(getAllOpts())
460  conf_dict['ApplicationMgr.JobOptionsType'] = '"NONE"'
461 
462  if self.printsequence:
463  conf_dict['ApplicationMgr.PrintAlgsSequence'] = 'true'
464 
465  if hasattr(Configurable, "_configurationLocked"):
466  Configurable._configurationLocked = True
467 
468  if attach_debugger:
469  self.hookDebugger()
470 
471  self.log.debug('-' * 80)
472  self.log.debug('%s: running in serial mode', __name__)
473  self.log.debug('-' * 80)
474  sysStart = time()
475 
476  import Gaudi
477  app = Gaudi.Application.create(self.application, conf_dict)
478  retcode = app.run()
479 
480  sysTime = time() - sysStart
481  self.log.debug('-' * 80)
482  self.log.debug('%s: serial system finished, time taken: %5.4fs',
483  __name__, sysTime)
484  self.log.debug('-' * 80)
485 
486  return retcode
487 

◆ setupParallelLogging()

def Gaudi.Main.gaudimain.setupParallelLogging (   self)

Definition at line 326 of file Main.py.

326  def setupParallelLogging(self):
327  # ---------------------------------------------------
328  # set up Logging
329  # ----------------
330  # from multiprocessing import enableLogging, getLogger
331  import multiprocessing
332  # preliminaries for handlers/output files, etc.
333  from time import ctime
334  datetime = ctime()
335  datetime = datetime.replace(' ', '_')
336  outfile = open('gaudirun-%s.log' % (datetime), 'w')
337  # two handlers, one for a log file, one for terminal
338  streamhandler = logging.StreamHandler(stream=outfile)
339  console = logging.StreamHandler()
340  # create formatter : the params in parentheses are variable names available via logging
341  formatter = logging.Formatter(
342  "%(asctime)s - %(name)s - %(levelname)s - %(message)s")
343  # add formatter to Handler
344  streamhandler.setFormatter(formatter)
345  console.setFormatter(formatter)
346  # now, configure the logger
347  # enableLogging( level=0 )
348  # self.log = getLogger()
349  self.log = multiprocessing.log_to_stderr()
350  self.log.setLevel(logging.INFO)
351  self.log.name = 'Gaudi/Main.py Logger'
352  self.log.handlers = []
353  # add handlers to logger : one for output to a file, one for console output
354  self.log.addHandler(streamhandler)
355  self.log.addHandler(console)
356  self.log.removeHandler(console)
357  # set level!!
358  self.log.setLevel = logging.INFO
359  # ---------------------------------------------------
360 

◆ writeconfig()

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

Definition at line 407 of file Main.py.

407  def writeconfig(self, filename, all=False):
408  write = {".pkl": lambda filename, all: self._writepickle(filename),
409  ".py": lambda filename, all: open(filename, "w").write(self.generatePyOutput(all) + "\n"),
410  ".opts": lambda filename, all: open(filename, "w").write(self.generateOptsOutput(all) + "\n"),
411  }
412  from os.path import splitext
413  ext = splitext(filename)[1]
414  if ext in write:
415  write[ext](filename, all)
416  else:
417  log.error("Unknown file type '%s'. Must be any of %r.", ext,
418  write.keys())
419  sys.exit(1)
420 

Member Data Documentation

◆ application

Gaudi.Main.gaudimain.application

Definition at line 324 of file Main.py.

◆ log

Gaudi.Main.gaudimain.log

Definition at line 322 of file Main.py.

◆ printsequence

Gaudi.Main.gaudimain.printsequence

Definition at line 323 of file Main.py.


The documentation for this class was generated from the following file:
Gaudi.Application.create
def create(cls, appType, opts)
Definition: __init__.py:105
GaudiMP.GMPBase
Definition: GMPBase.py:1
GaudiKernel.Proxy.getNeededConfigurables
getNeededConfigurables
Definition: Proxy.py:31
plotSpeedupsPyRoot.time
def time
Definition: plotSpeedupsPyRoot.py:163
Gaudi.Main.parseOpt
def parseOpt(s)
Definition: Main.py:284
Gaudi.Configuration
Definition: Configuration.py:1
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
ApplicationMgr
Definition: ApplicationMgr.h:57
Gaudi.Main.toOpt
def toOpt(value)
Definition: Main.py:261
Gaudi.Main.getAllOpts
def getAllOpts(explicit_defaults=False)
Definition: Main.py:222
GaudiKernel.Configurable.expandvars
def expandvars(data)
Definition: Configurable.py:47