The Gaudi Framework  master (e68eea06)
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)
 
 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)
Hook gdb to the current session. This is done by forking
the current process and replacing the parent with gdb, while
the child continues to run the program.

Definition at line 463 of file Main.py.

463 def hookDebugger(self):
464 """Hook gdb to the current session. This is done by forking
465 the current process and replacing the parent with gdb, while
466 the child continues to run the program.
467 """
468
469 child_pid = os.fork()
470
471 if child_pid == 0:
472 # CHILD PROCESS - runs the actual program
473 return
474 else:
475 # PARENT PROCESS - becomes GDB
476
477 # Replace parent process with GDB
478 args = [arg for arg in sys.argv if arg != "--gdb"]
479 os.execvp(
480 "gdb",
481 [
482 "gdb",
483 "-q",
484 "-p",
485 str(child_pid),
486 "-ex",
487 f"set args {' '.join(args)}",
488 ],
489 )
490

◆ 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 533 of file Main.py.

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

◆ runSerial()

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

Definition at line 491 of file Main.py.

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