The Gaudi Framework  v32r2 (46d42edc)
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 185 of file Main.py.

Constructor & Destructor Documentation

◆ __init__()

def Gaudi.Main.gaudimain.__init__ (   self)

Definition at line 186 of file Main.py.

186  def __init__(self):
187  from Configurables import ApplicationMgr
188  appMgr = ApplicationMgr()
189  if "GAUDIAPPNAME" in os.environ:
190  appMgr.AppName = str(os.environ["GAUDIAPPNAME"])
191  if "GAUDIAPPVERSION" in os.environ:
192  appMgr.AppVersion = str(os.environ["GAUDIAPPVERSION"])
193  self.log = logging.getLogger(__name__)
194  self.printsequence = False
195  self.application = 'Gaudi::Application'
196 
The Application Manager class.

Member Function Documentation

◆ _writepickle()

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

Definition at line 256 of file Main.py.

256  def _writepickle(self, filename):
257  # --- Lets take the first file input file as the name of the pickle file
258  import pickle
259  output = open(filename, 'wb')
260  # Dump only the the configurables that make sense to dump (not User ones)
261  from GaudiKernel.Proxy.Configurable import getNeededConfigurables
262  to_dump = {}
263  for n in getNeededConfigurables():
264  to_dump[n] = Configuration.allConfigurables[n]
265  pickle.dump(to_dump, output, -1)
266  output.close()
267 
getNeededConfigurables
Definition: Proxy.py:21

◆ generateOptsOutput()

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

Definition at line 244 of file Main.py.

244  def generateOptsOutput(self, all=False):
245  conf_dict = Configuration.configurationDict(all)
246  out = []
247  names = list(conf_dict.keys())
248  names.sort()
249  for n in names:
250  props = list(conf_dict[n].keys())
251  props.sort()
252  for p in props:
253  out.append('%s.%s = %s;' % (n, p, toOpt(conf_dict[n][p])))
254  return "\n".join(out)
255 
def toOpt(value)
Definition: Main.py:162

◆ generatePyOutput()

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

Definition at line 232 of file Main.py.

232  def generatePyOutput(self, all=False):
233  from pprint import pformat
234  conf_dict = Configuration.configurationDict(all)
235  formatted = pformat(conf_dict)
236  # Python 2 compatibility
237  if six.PY2:
238  return formatted
239  else:
240  # undo splitting of strings on multiple lines
241  import re
242  return re.sub(r'"\n +"', '', formatted, flags=re.MULTILINE)
243 

◆ hookDebugger()

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

Definition at line 305 of file Main.py.

305  def hookDebugger(self, debugger='gdb'):
306  import os
307  self.log.info('attaching debugger to PID ' + str(os.getpid()))
308  pid = os.spawnvp(os.P_NOWAIT, debugger,
309  [debugger, '-q', 'python',
310  str(os.getpid())])
311 
312  # give debugger some time to attach to the python process
313  import time
314  time.sleep(5)
315 
316  # verify the process' existence (will raise OSError if failed)
317  os.waitpid(pid, os.WNOHANG)
318  os.kill(pid, 0)
319  return
320 

◆ printconfig()

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

Definition at line 268 of file Main.py.

268  def printconfig(self, old_format=False, all=False):
269  msg = 'Dumping all configurables and properties'
270  if not all:
271  msg += ' (different from default)'
272  log.info(msg)
273  conf_dict = Configuration.configurationDict(all)
274  if old_format:
275  print(self.generateOptsOutput(all))
276  else:
277  print(self.generatePyOutput(all))
278  sys.stdout.flush()
279 

◆ run()

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

Definition at line 296 of file Main.py.

296  def run(self, attach_debugger, ncpus=None):
297  if not ncpus:
298  # Standard sequential mode
299  result = self.runSerial(attach_debugger)
300  else:
301  # Otherwise, run with the specified number of cpus
302  result = self.runParallel(ncpus)
303  return result
304 

◆ runParallel()

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

Definition at line 384 of file Main.py.

384  def runParallel(self, ncpus):
385  self.setupParallelLogging()
386  from Gaudi.Configuration import Configurable
387  import GaudiMP.GMPBase as gpp
388  c = Configurable.allConfigurables
389  self.log.info('-' * 80)
390  self.log.info('%s: Parallel Mode : %i ', __name__, ncpus)
391  for name, value in [
392  ('platrofm', ' '.join(os.uname())),
393  ('config', os.environ.get('BINARY_TAG')
394  or os.environ.get('CMTCONFIG')),
395  ('app. name', os.environ.get('GAUDIAPPNAME')),
396  ('app. version', os.environ.get('GAUDIAPPVERSION')),
397  ]:
398  self.log.info('%s: %30s : %s ', __name__, name, value
399  or 'Undefined')
400  try:
401  events = str(c['ApplicationMgr'].EvtMax)
402  except:
403  events = "Undetermined"
404  self.log.info('%s: Events Specified : %s ', __name__, events)
405  self.log.info('-' * 80)
406  # Parall = gpp.Coordinator(ncpus, shared, c, self.log)
407  Parall = gpp.Coord(ncpus, c, self.log)
408  sysStart = time()
409  sc = Parall.Go()
410  self.log.info('MAIN.PY : received %s from Coordinator' % (sc))
411  if sc.isFailure():
412  return 1
413  sysTime = time() - sysStart
414  self.log.name = 'Gaudi/Main.py Logger'
415  self.log.info('-' * 80)
416  self.log.info('%s: parallel system finished, time taken: %5.4fs',
417  __name__, sysTime)
418  self.log.info('-' * 80)
419  return 0

◆ runSerial()

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

Definition at line 321 of file Main.py.

321  def runSerial(self, attach_debugger):
322  try:
323  from GaudiKernel.Proxy.Configurable import expandvars
324  except ImportError:
325  # pass-through implementation if expandvars is not defined (AthenaCommon)
326  def expandvars(data):
327  return data
328 
329  from GaudiKernel.Proxy.Configurable import Configurable, getNeededConfigurables
330 
331  self.log.debug('runSerial: apply options')
332  conf_dict = {'ApplicationMgr.JobOptionsType': '"NONE"'}
333 
334  # FIXME: this is to make sure special properties are correctly
335  # expanded before we fill conf_dict
336  for c in list(Configurable.allConfigurables.values()):
337  if hasattr(c, 'getValuedProperties'):
338  c.getValuedProperties()
339 
340  for n in getNeededConfigurables():
341  c = Configurable.allConfigurables[n]
342  for p, v in c.getValuedProperties().items():
343  v = expandvars(v)
344  # Note: AthenaCommon.Configurable does not have Configurable.PropertyReference
345  if hasattr(Configurable, "PropertyReference") and type(
346  v) == Configurable.PropertyReference:
347  # this is done in "getFullName", but the exception is ignored,
348  # so we do it again to get it
349  v = v.__resolve__()
350  if type(v) == str:
351  # properly escape quotes in the string
352  v = '"%s"' % v.replace('"', '\\"')
353  elif sys.version_info < (
354  3, ) and type(v) == long: # Python 3 compatibility
355  v = '%d' % v # prevent pending 'L'
356  conf_dict['{}.{}'.format(n, p)] = str(v)
357 
358  if self.printsequence:
359  conf_dict['ApplicationMgr.PrintAlgsSequence'] = 'true'
360 
361  if hasattr(Configurable, "_configurationLocked"):
362  Configurable._configurationLocked = True
363 
364  if attach_debugger:
365  self.hookDebugger()
366 
367  self.log.debug('-' * 80)
368  self.log.debug('%s: running in serial mode', __name__)
369  self.log.debug('-' * 80)
370  sysStart = time()
371 
372  import Gaudi
373  app = Gaudi.Application.create(self.application, conf_dict)
374  retcode = app.run()
375 
376  sysTime = time() - sysStart
377  self.log.debug('-' * 80)
378  self.log.debug('%s: serial system finished, time taken: %5.4fs',
379  __name__, sysTime)
380  self.log.debug('-' * 80)
381 
382  return retcode
383 
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:109
getNeededConfigurables
Definition: Proxy.py:21
def create(cls, appType, opts)
Definition: __init__.py:86

◆ setupParallelLogging()

def Gaudi.Main.gaudimain.setupParallelLogging (   self)

Definition at line 197 of file Main.py.

197  def setupParallelLogging(self):
198  # ---------------------------------------------------
199  # set up Logging
200  # ----------------
201  # from multiprocessing import enableLogging, getLogger
202  import multiprocessing
203  # preliminaries for handlers/output files, etc.
204  from time import ctime
205  datetime = ctime()
206  datetime = datetime.replace(' ', '_')
207  outfile = open('gaudirun-%s.log' % (datetime), 'w')
208  # two handlers, one for a log file, one for terminal
209  streamhandler = logging.StreamHandler(stream=outfile)
210  console = logging.StreamHandler()
211  # create formatter : the params in parentheses are variable names available via logging
212  formatter = logging.Formatter(
213  "%(asctime)s - %(name)s - %(levelname)s - %(message)s")
214  # add formatter to Handler
215  streamhandler.setFormatter(formatter)
216  console.setFormatter(formatter)
217  # now, configure the logger
218  # enableLogging( level=0 )
219  # self.log = getLogger()
220  self.log = multiprocessing.log_to_stderr()
221  self.log.setLevel(logging.INFO)
222  self.log.name = 'Gaudi/Main.py Logger'
223  self.log.handlers = []
224  # add handlers to logger : one for output to a file, one for console output
225  self.log.addHandler(streamhandler)
226  self.log.addHandler(console)
227  self.log.removeHandler(console)
228  # set level!!
229  self.log.setLevel = logging.INFO
230  # ---------------------------------------------------
231 

◆ writeconfig()

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

Definition at line 280 of file Main.py.

280  def writeconfig(self, filename, all=False):
281  write = {".pkl": lambda filename, all: self._writepickle(filename),
282  ".py": lambda filename, all: open(filename, "w").write(self.generatePyOutput(all) + "\n"),
283  ".opts": lambda filename, all: open(filename, "w").write(self.generateOptsOutput(all) + "\n"),
284  }
285  from os.path import splitext
286  ext = splitext(filename)[1]
287  if ext in write:
288  write[ext](filename, all)
289  else:
290  log.error("Unknown file type '%s'. Must be any of %r.", ext,
291  write.keys())
292  sys.exit(1)
293 

Member Data Documentation

◆ application

Gaudi.Main.gaudimain.application

Definition at line 195 of file Main.py.

◆ log

Gaudi.Main.gaudimain.log

Definition at line 193 of file Main.py.

◆ printsequence

Gaudi.Main.gaudimain.printsequence

Definition at line 194 of file Main.py.


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