The Gaudi Framework  v36r2 (27905625)
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 441 of file Main.py.

441  def hookDebugger(self, debugger='gdb'):
442  import os
443  self.log.info('attaching debugger to PID ' + str(os.getpid()))
444  pid = os.spawnvp(os.P_NOWAIT, debugger,
445  [debugger, '-q', 'python',
446  str(os.getpid())])
447 
448  # give debugger some time to attach to the python process
449  import time
450  time.sleep(5)
451 
452  # verify the process' existence (will raise OSError if failed)
453  os.waitpid(pid, os.WNOHANG)
454  os.kill(pid, 0)
455  return
456 

◆ 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 432 of file Main.py.

432  def run(self, attach_debugger, ncpus=None):
433  if not ncpus:
434  # Standard sequential mode
435  result = self.runSerial(attach_debugger)
436  else:
437  # Otherwise, run with the specified number of cpus
438  result = self.runParallel(ncpus)
439  return result
440 

◆ runParallel()

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

Definition at line 497 of file Main.py.

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

◆ runSerial()

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

Definition at line 457 of file Main.py.

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

◆ 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  import json
409  write = {".pkl": lambda filename, all: self._writepickle(filename),
410  ".py": lambda filename, all: open(filename, "w").write(self.generatePyOutput(all) + "\n"),
411  ".opts": lambda filename, all: open(filename, "w").write(self.generateOptsOutput(all) + "\n"),
412  ".json": lambda filename, all: json.dump(getAllOpts(all), open(filename, "w"), indent=2, sort_keys=True),
413  }
414  try:
415  import yaml
416  write[".yaml"] = lambda filename, all: yaml.safe_dump(getAllOpts(all), open(filename, "w"))
417  write[".yml"] = write[".yaml"]
418  except ImportError:
419  pass # yaml support is optional
420 
421  from os.path import splitext
422  ext = splitext(filename)[1]
423  if ext in write:
424  write[ext](filename, all)
425  else:
426  log.error("Unknown file type '%s'. Must be any of %r.", ext,
427  sorted(write.keys()))
428  sys.exit(1)
429 

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