The Gaudi Framework  v36r16 (ea80daf8)
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 326 of file Main.py.

Constructor & Destructor Documentation

◆ __init__()

def Gaudi.Main.gaudimain.__init__ (   self)

Definition at line 327 of file Main.py.

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

Member Function Documentation

◆ _writepickle()

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

Definition at line 403 of file Main.py.

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

◆ generateOptsOutput()

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

Definition at line 396 of file Main.py.

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

◆ generatePyOutput()

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

Definition at line 377 of file Main.py.

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

◆ hookDebugger()

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

Definition at line 475 of file Main.py.

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

◆ printconfig()

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

Definition at line 417 of file Main.py.

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

◆ run()

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

Definition at line 466 of file Main.py.

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

◆ runParallel()

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

Definition at line 535 of file Main.py.

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

◆ runSerial()

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

Definition at line 493 of file Main.py.

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

◆ setupParallelLogging()

def Gaudi.Main.gaudimain.setupParallelLogging (   self)

Definition at line 339 of file Main.py.

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

◆ writeconfig()

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

Definition at line 428 of file Main.py.

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

Member Data Documentation

◆ application

Gaudi.Main.gaudimain.application

Definition at line 337 of file Main.py.

◆ log

Gaudi.Main.gaudimain.log

Definition at line 335 of file Main.py.

◆ printsequence

Gaudi.Main.gaudimain.printsequence

Definition at line 336 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:295
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:271
Gaudi.Main.getAllOpts
def getAllOpts(explicit_defaults=False)
Definition: Main.py:233
GaudiKernel.Configurable.expandvars
def expandvars(data)
Definition: Configurable.py:78