The Gaudi Framework  v33r1 (b1225454)
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 282 of file Main.py.

Constructor & Destructor Documentation

◆ __init__()

def Gaudi.Main.gaudimain.__init__ (   self)

Definition at line 283 of file Main.py.

283  def __init__(self):
284  from Configurables import ApplicationMgr
285  appMgr = ApplicationMgr()
286  if "GAUDIAPPNAME" in os.environ:
287  appMgr.AppName = str(os.environ["GAUDIAPPNAME"])
288  if "GAUDIAPPVERSION" in os.environ:
289  appMgr.AppVersion = str(os.environ["GAUDIAPPVERSION"])
290  self.log = logging.getLogger(__name__)
291  self.printsequence = False
292  self.application = 'Gaudi::Application'
293 
The Application Manager class.

Member Function Documentation

◆ _writepickle()

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

Definition at line 352 of file Main.py.

352  def _writepickle(self, filename):
353  # --- Lets take the first file input file as the name of the pickle file
354  import pickle
355  output = open(filename, 'wb')
356  # Dump only the the configurables that make sense to dump (not User ones)
357  from GaudiKernel.Proxy.Configurable import getNeededConfigurables
358  to_dump = {}
359  for n in getNeededConfigurables():
360  to_dump[n] = Configuration.allConfigurables[n]
361  pickle.dump(to_dump, output, -1)
362  output.close()
363 
getNeededConfigurables
Definition: Proxy.py:31

◆ generateOptsOutput()

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

Definition at line 346 of file Main.py.

346  def generateOptsOutput(self, all=False):
347  opts = getAllOpts(all)
348  keys = sorted(opts)
349  return '\n'.join(
350  '{} = {};'.format(key, toOpt(parseOpt(opts[key]))) for key in keys)
351 
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
def toOpt(value)
Definition: Main.py:229
def parseOpt(s)
Definition: Main.py:252
def getAllOpts(explicit_defaults=False)
Definition: Main.py:169

◆ generatePyOutput()

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

Definition at line 329 of file Main.py.

329  def generatePyOutput(self, all=False):
330  from pprint import pformat
331  from collections import defaultdict
332  optDict = defaultdict(dict)
333  allOpts = getAllOpts(all)
334  for key in allOpts:
335  c, p = key.rsplit('.', 1)
336  optDict[c][p] = parseOpt(allOpts[key])
337  formatted = pformat(dict(optDict))
338  # Python 2 compatibility
339  if six.PY2:
340  return formatted
341  else:
342  # undo splitting of strings on multiple lines
343  import re
344  return re.sub(r'"\n +"', '', formatted, flags=re.MULTILINE)
345 
def parseOpt(s)
Definition: Main.py:252
def getAllOpts(explicit_defaults=False)
Definition: Main.py:169

◆ hookDebugger()

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

Definition at line 400 of file Main.py.

400  def hookDebugger(self, debugger='gdb'):
401  import os
402  self.log.info('attaching debugger to PID ' + str(os.getpid()))
403  pid = os.spawnvp(os.P_NOWAIT, debugger,
404  [debugger, '-q', 'python',
405  str(os.getpid())])
406 
407  # give debugger some time to attach to the python process
408  import time
409  time.sleep(5)
410 
411  # verify the process' existence (will raise OSError if failed)
412  os.waitpid(pid, os.WNOHANG)
413  os.kill(pid, 0)
414  return
415 

◆ printconfig()

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

Definition at line 364 of file Main.py.

364  def printconfig(self, old_format=False, all=False):
365  msg = 'Dumping all configurables and properties'
366  if not all:
367  msg += ' (different from default)'
368  log.info(msg)
369  if old_format:
370  print(self.generateOptsOutput(all))
371  else:
372  print(self.generatePyOutput(all))
373  sys.stdout.flush()
374 

◆ run()

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

Definition at line 391 of file Main.py.

391  def run(self, attach_debugger, ncpus=None):
392  if not ncpus:
393  # Standard sequential mode
394  result = self.runSerial(attach_debugger)
395  else:
396  # Otherwise, run with the specified number of cpus
397  result = self.runParallel(ncpus)
398  return result
399 

◆ runParallel()

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

Definition at line 456 of file Main.py.

456  def runParallel(self, ncpus):
457  self.setupParallelLogging()
458  from Gaudi.Configuration import Configurable
459  import GaudiMP.GMPBase as gpp
460  c = Configurable.allConfigurables
461  self.log.info('-' * 80)
462  self.log.info('%s: Parallel Mode : %i ', __name__, ncpus)
463  for name, value in [
464  ('platrofm', ' '.join(os.uname())),
465  ('config', os.environ.get('BINARY_TAG')
466  or os.environ.get('CMTCONFIG')),
467  ('app. name', os.environ.get('GAUDIAPPNAME')),
468  ('app. version', os.environ.get('GAUDIAPPVERSION')),
469  ]:
470  self.log.info('%s: %30s : %s ', __name__, name, value
471  or 'Undefined')
472  try:
473  events = str(c['ApplicationMgr'].EvtMax)
474  except:
475  events = "Undetermined"
476  self.log.info('%s: Events Specified : %s ', __name__, events)
477  self.log.info('-' * 80)
478  # Parall = gpp.Coordinator(ncpus, shared, c, self.log)
479  Parall = gpp.Coord(ncpus, c, self.log)
480  sysStart = time()
481  sc = Parall.Go()
482  self.log.info('MAIN.PY : received %s from Coordinator' % (sc))
483  if sc.isFailure():
484  return 1
485  sysTime = time() - sysStart
486  self.log.name = 'Gaudi/Main.py Logger'
487  self.log.info('-' * 80)
488  self.log.info('%s: parallel system finished, time taken: %5.4fs',
489  __name__, sysTime)
490  self.log.info('-' * 80)
491  return 0

◆ runSerial()

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

Definition at line 416 of file Main.py.

416  def runSerial(self, attach_debugger):
417  try:
418  from GaudiKernel.Proxy.Configurable import expandvars
419  except ImportError:
420  # pass-through implementation if expandvars is not defined (AthenaCommon)
421  def expandvars(data):
422  return data
423 
424  from GaudiKernel.Proxy.Configurable import Configurable
425 
426  self.log.debug('runSerial: apply options')
427  conf_dict = expandvars(getAllOpts())
428  conf_dict['ApplicationMgr.JobOptionsType'] = '"NONE"'
429 
430  if self.printsequence:
431  conf_dict['ApplicationMgr.PrintAlgsSequence'] = 'true'
432 
433  if hasattr(Configurable, "_configurationLocked"):
434  Configurable._configurationLocked = True
435 
436  if attach_debugger:
437  self.hookDebugger()
438 
439  self.log.debug('-' * 80)
440  self.log.debug('%s: running in serial mode', __name__)
441  self.log.debug('-' * 80)
442  sysStart = time()
443 
444  import Gaudi
445  app = Gaudi.Application.create(self.application, conf_dict)
446  retcode = app.run()
447 
448  sysTime = time() - sysStart
449  self.log.debug('-' * 80)
450  self.log.debug('%s: serial system finished, time taken: %5.4fs',
451  __name__, sysTime)
452  self.log.debug('-' * 80)
453 
454  return retcode
455 
def create(cls, appType, opts)
Definition: __init__.py:105
def getAllOpts(explicit_defaults=False)
Definition: Main.py:169

◆ setupParallelLogging()

def Gaudi.Main.gaudimain.setupParallelLogging (   self)

Definition at line 294 of file Main.py.

294  def setupParallelLogging(self):
295  # ---------------------------------------------------
296  # set up Logging
297  # ----------------
298  # from multiprocessing import enableLogging, getLogger
299  import multiprocessing
300  # preliminaries for handlers/output files, etc.
301  from time import ctime
302  datetime = ctime()
303  datetime = datetime.replace(' ', '_')
304  outfile = open('gaudirun-%s.log' % (datetime), 'w')
305  # two handlers, one for a log file, one for terminal
306  streamhandler = logging.StreamHandler(stream=outfile)
307  console = logging.StreamHandler()
308  # create formatter : the params in parentheses are variable names available via logging
309  formatter = logging.Formatter(
310  "%(asctime)s - %(name)s - %(levelname)s - %(message)s")
311  # add formatter to Handler
312  streamhandler.setFormatter(formatter)
313  console.setFormatter(formatter)
314  # now, configure the logger
315  # enableLogging( level=0 )
316  # self.log = getLogger()
317  self.log = multiprocessing.log_to_stderr()
318  self.log.setLevel(logging.INFO)
319  self.log.name = 'Gaudi/Main.py Logger'
320  self.log.handlers = []
321  # add handlers to logger : one for output to a file, one for console output
322  self.log.addHandler(streamhandler)
323  self.log.addHandler(console)
324  self.log.removeHandler(console)
325  # set level!!
326  self.log.setLevel = logging.INFO
327  # ---------------------------------------------------
328 

◆ writeconfig()

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

Definition at line 375 of file Main.py.

375  def writeconfig(self, filename, all=False):
376  write = {".pkl": lambda filename, all: self._writepickle(filename),
377  ".py": lambda filename, all: open(filename, "w").write(self.generatePyOutput(all) + "\n"),
378  ".opts": lambda filename, all: open(filename, "w").write(self.generateOptsOutput(all) + "\n"),
379  }
380  from os.path import splitext
381  ext = splitext(filename)[1]
382  if ext in write:
383  write[ext](filename, all)
384  else:
385  log.error("Unknown file type '%s'. Must be any of %r.", ext,
386  write.keys())
387  sys.exit(1)
388 

Member Data Documentation

◆ application

Gaudi.Main.gaudimain.application

Definition at line 292 of file Main.py.

◆ log

Gaudi.Main.gaudimain.log

Definition at line 290 of file Main.py.

◆ printsequence

Gaudi.Main.gaudimain.printsequence

Definition at line 291 of file Main.py.


The documentation for this class was generated from the following file: