The Gaudi Framework  master (594c33fa)
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 323 of file Main.py.

Constructor & Destructor Documentation

◆ __init__()

def Gaudi.Main.gaudimain.__init__ (   self)

Definition at line 324 of file Main.py.

324  def __init__(self):
325  from Configurables import ApplicationMgr
326 
327  appMgr = ApplicationMgr()
328  if os.environ.get("GAUDIAPPNAME"):
329  appMgr.AppName = str(os.environ["GAUDIAPPNAME"])
330  if os.environ.get("GAUDIAPPVERSION"):
331  appMgr.AppVersion = str(os.environ["GAUDIAPPVERSION"])
332  self.log = logging.getLogger(__name__)
333  self.printsequence = False
334  self.application = "Gaudi::Application"
335 

Member Function Documentation

◆ _writepickle()

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

Definition at line 396 of file Main.py.

396  def _writepickle(self, filename):
397  # --- Lets take the first file input file as the name of the pickle file
398  import pickle
399 
400  output = open(filename, "wb")
401  # Dump only the the configurables that make sense to dump (not User ones)
402  from GaudiKernel.Proxy.Configurable import getNeededConfigurables
403 
404  to_dump = {}
405  for n in getNeededConfigurables():
406  to_dump[n] = Configuration.allConfigurables[n]
407  pickle.dump(to_dump, output, -1)
408  output.close()
409 

◆ generateOptsOutput()

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

Definition at line 389 of file Main.py.

389  def generateOptsOutput(self, all=False):
390  opts = getAllOpts(all)
391  keys = sorted(opts)
392  return "\n".join(
393  "{} = {};".format(key, toOpt(parseOpt(opts[key]))) for key in keys
394  )
395 

◆ generatePyOutput()

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

Definition at line 374 of file Main.py.

374  def generatePyOutput(self, all=False):
375  import re
376  from collections import defaultdict
377  from pprint import pformat
378 
379  optDict = defaultdict(dict)
380  allOpts = getAllOpts(all)
381  for key in allOpts:
382  c, p = key.rsplit(".", 1)
383  optDict[c][p] = parseOpt(allOpts[key])
384  formatted = pformat(dict(optDict))
385  # undo splitting of strings on multiple lines
386 
387  return re.sub(r'"\n +"', "", formatted, flags=re.MULTILINE)
388 

◆ hookDebugger()

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

Definition at line 468 of file Main.py.

468  def hookDebugger(self, debugger="gdb"):
469  import os
470 
471  self.log.info("attaching debugger to PID " + str(os.getpid()))
472  pid = os.spawnvp(
473  os.P_NOWAIT, debugger, [debugger, "-q", "python", str(os.getpid())]
474  )
475 
476  # give debugger some time to attach to the python process
477  import time
478 
479  time.sleep(5)
480 
481  # verify the process' existence (will raise OSError if failed)
482  os.waitpid(pid, os.WNOHANG)
483  os.kill(pid, 0)
484  return
485 

◆ printconfig()

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

Definition at line 410 of file Main.py.

410  def printconfig(self, old_format=False, all=False):
411  msg = "Dumping all configurables and properties"
412  if not all:
413  msg += " (different from default)"
414  log.info(msg)
415  if old_format:
416  print(self.generateOptsOutput(all))
417  else:
418  print(self.generatePyOutput(all))
419  sys.stdout.flush()
420 

◆ run()

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

Definition at line 459 of file Main.py.

459  def run(self, attach_debugger, ncpus=None):
460  if not ncpus:
461  # Standard sequential mode
462  result = self.runSerial(attach_debugger)
463  else:
464  # Otherwise, run with the specified number of cpus
465  result = self.runParallel(ncpus)
466  return result
467 

◆ runParallel()

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

Definition at line 528 of file Main.py.

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

◆ runSerial()

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

Definition at line 486 of file Main.py.

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

◆ setupParallelLogging()

def Gaudi.Main.gaudimain.setupParallelLogging (   self)

Definition at line 336 of file Main.py.

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

◆ writeconfig()

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

Definition at line 421 of file Main.py.

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

Member Data Documentation

◆ application

Gaudi.Main.gaudimain.application

Definition at line 334 of file Main.py.

◆ log

Gaudi.Main.gaudimain.log

Definition at line 332 of file Main.py.

◆ printsequence

Gaudi.Main.gaudimain.printsequence

Definition at line 333 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:127
GaudiMP.GMPBase
Definition: GMPBase.py:1
GaudiKernel.Proxy.getNeededConfigurables
getNeededConfigurables
Definition: Proxy.py:30
Gaudi.Main.parseOpt
def parseOpt(s)
Definition: Main.py:292
Gaudi.Configuration
Definition: Configuration.py:1
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
plotSpeedupsPyRoot.time
time
Definition: plotSpeedupsPyRoot.py:180
ApplicationMgr
Definition: ApplicationMgr.h:57
Gaudi.Main.toOpt
def toOpt(value)
Definition: Main.py:268
Gaudi.Main.getAllOpts
def getAllOpts(explicit_defaults=False)
Definition: Main.py:230
GaudiKernel.Configurable.expandvars
def expandvars(data)
Definition: Configurable.py:77