The Gaudi Framework  master (ff829712)
Loading...
Searching...
No Matches
Gaudi.Main.gaudimain Class Reference
Inheritance diagram for Gaudi.Main.gaudimain:
Collaboration diagram for Gaudi.Main.gaudimain:

Public Member Functions

 __init__ (self)
 
 setupParallelLogging (self)
 
 generatePyOutput (self, all=False)
 
 generateOptsOutput (self, all=False)
 
 printconfig (self, old_format=False, all=False)
 
 writeconfig (self, filename, all=False)
 
 run (self, attach_debugger, ncpus=None)
 
 hookDebugger (self, debugger="gdb")
 
 runSerial (self, attach_debugger)
 
 runParallel (self, ncpus)
 

Public Attributes

 log = logging.getLogger(__name__)
 
bool printsequence = False
 
str application = "Gaudi::Application"
 

Protected Member Functions

 _writepickle (self, filename)
 

Detailed Description

Definition at line 318 of file Main.py.

Constructor & Destructor Documentation

◆ __init__()

Gaudi.Main.gaudimain.__init__ ( self)

Definition at line 319 of file Main.py.

319 def __init__(self):
320 from Configurables import ApplicationMgr
321
322 appMgr = ApplicationMgr()
323 if os.environ.get("GAUDIAPPNAME"):
324 appMgr.AppName = str(os.environ["GAUDIAPPNAME"])
325 if os.environ.get("GAUDIAPPVERSION"):
326 appMgr.AppVersion = str(os.environ["GAUDIAPPVERSION"])
327 self.log = logging.getLogger(__name__)
328 self.printsequence = False
329 self.application = "Gaudi::Application"
330
The Application Manager class.

Member Function Documentation

◆ _writepickle()

Gaudi.Main.gaudimain._writepickle ( self,
filename )
protected

Definition at line 391 of file Main.py.

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

◆ generateOptsOutput()

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

Definition at line 384 of file Main.py.

384 def generateOptsOutput(self, all=False):
385 opts = getAllOpts(all)
386 keys = sorted(opts)
387 return "\n".join(
388 "{} = {};".format(key, toOpt(parseOpt(opts[key]))) for key in keys
389 )
390
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition MsgStream.cpp:93

◆ generatePyOutput()

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

Definition at line 369 of file Main.py.

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

◆ hookDebugger()

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

Definition at line 463 of file Main.py.

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

◆ printconfig()

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

Definition at line 405 of file Main.py.

405 def printconfig(self, old_format=False, all=False):
406 msg = "Dumping all configurables and properties"
407 if not all:
408 msg += " (different from default)"
409 log.info(msg)
410 if old_format:
411 print(self.generateOptsOutput(all))
412 else:
413 print(self.generatePyOutput(all))
414 sys.stdout.flush()
415

◆ run()

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

Definition at line 454 of file Main.py.

454 def run(self, attach_debugger, ncpus=None):
455 if not ncpus:
456 # Standard sequential mode
457 result = self.runSerial(attach_debugger)
458 else:
459 # Otherwise, run with the specified number of cpus
460 result = self.runParallel(ncpus)
461 return result
462

◆ runParallel()

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

Definition at line 523 of file Main.py.

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

◆ runSerial()

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

Definition at line 481 of file Main.py.

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

◆ setupParallelLogging()

Gaudi.Main.gaudimain.setupParallelLogging ( self)

Definition at line 331 of file Main.py.

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

◆ writeconfig()

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

Definition at line 416 of file Main.py.

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

Member Data Documentation

◆ application

str Gaudi.Main.gaudimain.application = "Gaudi::Application"

Definition at line 329 of file Main.py.

◆ log

Gaudi.Main.gaudimain.log = logging.getLogger(__name__)

Definition at line 327 of file Main.py.

◆ printsequence

bool Gaudi.Main.gaudimain.printsequence = False

Definition at line 328 of file Main.py.


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