The Gaudi Framework  v37r1 (a7f61348)
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 325 of file Main.py.

Constructor & Destructor Documentation

◆ __init__()

def Gaudi.Main.gaudimain.__init__ (   self)

Definition at line 326 of file Main.py.

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

Member Function Documentation

◆ _writepickle()

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

Definition at line 402 of file Main.py.

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

◆ generateOptsOutput()

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

Definition at line 395 of file Main.py.

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

◆ generatePyOutput()

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

Definition at line 376 of file Main.py.

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

◆ hookDebugger()

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

Definition at line 474 of file Main.py.

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

◆ printconfig()

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

Definition at line 416 of file Main.py.

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

◆ run()

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

Definition at line 465 of file Main.py.

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

◆ runParallel()

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

Definition at line 534 of file Main.py.

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

◆ runSerial()

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

Definition at line 492 of file Main.py.

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

◆ setupParallelLogging()

def Gaudi.Main.gaudimain.setupParallelLogging (   self)

Definition at line 338 of file Main.py.

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

◆ writeconfig()

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

Definition at line 427 of file Main.py.

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

Member Data Documentation

◆ application

Gaudi.Main.gaudimain.application

Definition at line 336 of file Main.py.

◆ log

Gaudi.Main.gaudimain.log

Definition at line 334 of file Main.py.

◆ printsequence

Gaudi.Main.gaudimain.printsequence

Definition at line 335 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:294
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:270
Gaudi.Main.getAllOpts
def getAllOpts(explicit_defaults=False)
Definition: Main.py:232
GaudiKernel.Configurable.expandvars
def expandvars(data)
Definition: Configurable.py:78