The Gaudi Framework  v36r9p1 (5c15b2bb)
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 330 of file Main.py.

Constructor & Destructor Documentation

◆ __init__()

def Gaudi.Main.gaudimain.__init__ (   self)

Definition at line 331 of file Main.py.

331  def __init__(self):
332  from Configurables import ApplicationMgr
333 
334  appMgr = ApplicationMgr()
335  if os.environ.get("GAUDIAPPNAME"):
336  appMgr.AppName = str(os.environ["GAUDIAPPNAME"])
337  if os.environ.get("GAUDIAPPVERSION"):
338  appMgr.AppVersion = str(os.environ["GAUDIAPPVERSION"])
339  self.log = logging.getLogger(__name__)
340  self.printsequence = False
341  self.application = "Gaudi::Application"
342 

Member Function Documentation

◆ _writepickle()

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

Definition at line 407 of file Main.py.

407  def _writepickle(self, filename):
408  # --- Lets take the first file input file as the name of the pickle file
409  import pickle
410 
411  output = open(filename, "wb")
412  # Dump only the the configurables that make sense to dump (not User ones)
413  from GaudiKernel.Proxy.Configurable import getNeededConfigurables
414 
415  to_dump = {}
416  for n in getNeededConfigurables():
417  to_dump[n] = Configuration.allConfigurables[n]
418  pickle.dump(to_dump, output, -1)
419  output.close()
420 

◆ generateOptsOutput()

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

Definition at line 400 of file Main.py.

400  def generateOptsOutput(self, all=False):
401  opts = getAllOpts(all)
402  keys = sorted(opts)
403  return "\n".join(
404  "{} = {};".format(key, toOpt(parseOpt(opts[key]))) for key in keys
405  )
406 

◆ generatePyOutput()

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

Definition at line 381 of file Main.py.

381  def generatePyOutput(self, all=False):
382  from collections import defaultdict
383  from pprint import pformat
384 
385  optDict = defaultdict(dict)
386  allOpts = getAllOpts(all)
387  for key in allOpts:
388  c, p = key.rsplit(".", 1)
389  optDict[c][p] = parseOpt(allOpts[key])
390  formatted = pformat(dict(optDict))
391  # Python 2 compatibility
392  if six.PY2:
393  return formatted
394  else:
395  # undo splitting of strings on multiple lines
396  import re
397 
398  return re.sub(r'"\n +"', "", formatted, flags=re.MULTILINE)
399 

◆ hookDebugger()

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

Definition at line 479 of file Main.py.

479  def hookDebugger(self, debugger="gdb"):
480  import os
481 
482  self.log.info("attaching debugger to PID " + str(os.getpid()))
483  pid = os.spawnvp(
484  os.P_NOWAIT, debugger, [debugger, "-q", "python", str(os.getpid())]
485  )
486 
487  # give debugger some time to attach to the python process
488  import time
489 
490  time.sleep(5)
491 
492  # verify the process' existence (will raise OSError if failed)
493  os.waitpid(pid, os.WNOHANG)
494  os.kill(pid, 0)
495  return
496 

◆ printconfig()

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

Definition at line 421 of file Main.py.

421  def printconfig(self, old_format=False, all=False):
422  msg = "Dumping all configurables and properties"
423  if not all:
424  msg += " (different from default)"
425  log.info(msg)
426  if old_format:
427  print(self.generateOptsOutput(all))
428  else:
429  print(self.generatePyOutput(all))
430  sys.stdout.flush()
431 

◆ run()

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

Definition at line 470 of file Main.py.

470  def run(self, attach_debugger, ncpus=None):
471  if not ncpus:
472  # Standard sequential mode
473  result = self.runSerial(attach_debugger)
474  else:
475  # Otherwise, run with the specified number of cpus
476  result = self.runParallel(ncpus)
477  return result
478 

◆ runParallel()

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

Definition at line 539 of file Main.py.

539  def runParallel(self, ncpus):
540  self.setupParallelLogging()
541  import GaudiMP.GMPBase as gpp
542  from Gaudi.Configuration import Configurable
543 
544  c = Configurable.allConfigurables
545  self.log.info("-" * 80)
546  self.log.info("%s: Parallel Mode : %i ", __name__, ncpus)
547  for name, value in [
548  ("platform", " ".join(os.uname())),
549  ("config", os.environ.get("BINARY_TAG") or os.environ.get("CMTCONFIG")),
550  ("app. name", os.environ.get("GAUDIAPPNAME")),
551  ("app. version", os.environ.get("GAUDIAPPVERSION")),
552  ]:
553  self.log.info("%s: %30s : %s ", __name__, name, value or "Undefined")
554  try:
555  events = str(c["ApplicationMgr"].EvtMax)
556  except:
557  events = "Undetermined"
558  self.log.info("%s: Events Specified : %s ", __name__, events)
559  self.log.info("-" * 80)
560  # Parall = gpp.Coordinator(ncpus, shared, c, self.log)
561  Parall = gpp.Coord(ncpus, c, self.log)
562  sysStart = time()
563  sc = Parall.Go()
564  self.log.info("MAIN.PY : received %s from Coordinator" % (sc))
565  if sc.isFailure():
566  return 1
567  sysTime = time() - sysStart
568  self.log.name = "Gaudi/Main.py Logger"
569  self.log.info("-" * 80)
570  self.log.info(
571  "%s: parallel system finished, time taken: %5.4fs", __name__, sysTime
572  )
573  self.log.info("-" * 80)
574  return 0

◆ runSerial()

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

Definition at line 497 of file Main.py.

497  def runSerial(self, attach_debugger):
498  try:
499  from GaudiKernel.Proxy.Configurable import expandvars
500  except ImportError:
501  # pass-through implementation if expandvars is not defined (AthenaCommon)
502  def expandvars(data):
503  return data
504 
505  from GaudiKernel.Proxy.Configurable import Configurable
506 
507  self.log.debug("runSerial: apply options")
508  conf_dict = expandvars(getAllOpts())
509  conf_dict["ApplicationMgr.JobOptionsType"] = '"NONE"'
510 
511  if self.printsequence:
512  conf_dict["ApplicationMgr.PrintAlgsSequence"] = "true"
513 
514  if hasattr(Configurable, "_configurationLocked"):
515  Configurable._configurationLocked = True
516 
517  if attach_debugger:
518  self.hookDebugger()
519 
520  self.log.debug("-" * 80)
521  self.log.debug("%s: running in serial mode", __name__)
522  self.log.debug("-" * 80)
523  sysStart = time()
524 
525  import Gaudi
526 
527  app = Gaudi.Application.create(self.application, conf_dict)
528  retcode = app.run()
529 
530  sysTime = time() - sysStart
531  self.log.debug("-" * 80)
532  self.log.debug(
533  "%s: serial system finished, time taken: %5.4fs", __name__, sysTime
534  )
535  self.log.debug("-" * 80)
536 
537  return retcode
538 

◆ setupParallelLogging()

def Gaudi.Main.gaudimain.setupParallelLogging (   self)

Definition at line 343 of file Main.py.

343  def setupParallelLogging(self):
344  # ---------------------------------------------------
345  # set up Logging
346  # ----------------
347  # from multiprocessing import enableLogging, getLogger
348  import multiprocessing
349 
350  # preliminaries for handlers/output files, etc.
351  from time import ctime
352 
353  datetime = ctime()
354  datetime = datetime.replace(" ", "_")
355  outfile = open("gaudirun-%s.log" % (datetime), "w")
356  # two handlers, one for a log file, one for terminal
357  streamhandler = logging.StreamHandler(stream=outfile)
358  console = logging.StreamHandler()
359  # create formatter : the params in parentheses are variable names available via logging
360  formatter = logging.Formatter(
361  "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
362  )
363  # add formatter to Handler
364  streamhandler.setFormatter(formatter)
365  console.setFormatter(formatter)
366  # now, configure the logger
367  # enableLogging( level=0 )
368  # self.log = getLogger()
369  self.log = multiprocessing.log_to_stderr()
370  self.log.setLevel(logging.INFO)
371  self.log.name = "Gaudi/Main.py Logger"
372  self.log.handlers = []
373  # add handlers to logger : one for output to a file, one for console output
374  self.log.addHandler(streamhandler)
375  self.log.addHandler(console)
376  self.log.removeHandler(console)
377  # set level!!
378  self.log.setLevel = logging.INFO
379  # ---------------------------------------------------
380 

◆ writeconfig()

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

Definition at line 432 of file Main.py.

432  def writeconfig(self, filename, all=False):
433  import json
434 
435  write = {
436  ".pkl": lambda filename, all: self._writepickle(filename),
437  ".py": lambda filename, all: open(filename, "w").write(
438  self.generatePyOutput(all) + "\n"
439  ),
440  ".opts": lambda filename, all: open(filename, "w").write(
441  self.generateOptsOutput(all) + "\n"
442  ),
443  ".json": lambda filename, all: json.dump(
444  getAllOpts(all), open(filename, "w"), indent=2, sort_keys=True
445  ),
446  }
447  try:
448  import yaml
449 
450  write[".yaml"] = lambda filename, all: yaml.safe_dump(
451  getAllOpts(all), open(filename, "w")
452  )
453  write[".yml"] = write[".yaml"]
454  except ImportError:
455  pass # yaml support is optional
456 
457  from os.path import splitext
458 
459  ext = splitext(filename)[1]
460  if ext in write:
461  write[ext](filename, all)
462  else:
463  log.error(
464  "Unknown file type '%s'. Must be any of %r.", ext, sorted(write.keys())
465  )
466  sys.exit(1)
467 

Member Data Documentation

◆ application

Gaudi.Main.gaudimain.application

Definition at line 341 of file Main.py.

◆ log

Gaudi.Main.gaudimain.log

Definition at line 339 of file Main.py.

◆ printsequence

Gaudi.Main.gaudimain.printsequence

Definition at line 340 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:112
GaudiMP.GMPBase
Definition: GMPBase.py:1
GaudiKernel.Proxy.getNeededConfigurables
getNeededConfigurables
Definition: Proxy.py:30
plotSpeedupsPyRoot.time
def time
Definition: plotSpeedupsPyRoot.py:175
Gaudi.Main.parseOpt
def parseOpt(s)
Definition: Main.py:299
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:275
Gaudi.Main.getAllOpts
def getAllOpts(explicit_defaults=False)
Definition: Main.py:237
GaudiKernel.Configurable.expandvars
def expandvars(data)
Definition: Configurable.py:73