The Gaudi Framework  master (ff829712)
Loading...
Searching...
No Matches
GaudiKernel.ProcessJobOptions Namespace Reference

Classes

class  _TempSysPath
 
class  ConsoleHandler
 
class  JobOptsParser
 
class  LogFilter
 
class  LogFormatter
 
class  ParserError
 

Functions

 GetConsoleHandler (prefix=None, stream=None, with_time=False)
 
 InstallRootLoggingHandler (prefix=None, level=None, stream=None, with_time=False)
 
 PrintOn (step=1, force=False)
 
 PrintOff (step=1)
 
 _find_file (f)
 
 _to_be_included (f)
 
 _import_python (file)
 
 _import_pickle (file)
 
 _import_opts (file)
 
 _import_dict (data)
 
 _import_json (filename)
 
 _import_yaml (filename)
 
 importOptions (optsfile)
 
 importUnits (unitsfile)
 

Variables

 _log = logging.getLogger(__name__)
 
 _consoleHandler = None
 
 _included_files = set()
 
 _parser = JobOptsParser()
 
dict _import_function_mapping
 

Function Documentation

◆ _find_file()

GaudiKernel.ProcessJobOptions._find_file ( f)
protected

Definition at line 149 of file ProcessJobOptions.py.

149def _find_file(f):
150 # expand environment variables in the filename
151 f = os.path.expandvars(f)
152 if os.path.isfile(f):
153 return os.path.realpath(f)
154
155 path = os.environ.get("JOBOPTSEARCHPATH", "").split(os.pathsep)
156 # find the full path to the option file
157 candidates = [d for d in path if os.path.isfile(os.path.join(d, f))]
158 if not candidates:
159 raise ParserError("Cannot find '%s' in %s" % (f, path))
160 return os.path.realpath(os.path.join(candidates[0], f))
161
162

◆ _import_dict()

GaudiKernel.ProcessJobOptions._import_dict ( data)
protected

Definition at line 499 of file ProcessJobOptions.py.

499def _import_dict(data):
500 from GaudiKernel.Proxy.Configurable import Configurable, ConfigurableGeneric
501
502 for property, value_repr in data.items():
503 component, property = property.rsplit(".", 1)
504 if component in Configurable.allConfigurables:
505 cfg = Configurable.allConfigurables[component]
506 else:
507 cfg = ConfigurableGeneric(component)
508 value = eval(value_repr)
509 setattr(cfg, property, value)
510
511

◆ _import_json()

GaudiKernel.ProcessJobOptions._import_json ( filename)
protected

Definition at line 512 of file ProcessJobOptions.py.

512def _import_json(filename):
513 import json
514
515 with open(filename) as f:
516 _import_dict(json.load(f))
517
518

◆ _import_opts()

GaudiKernel.ProcessJobOptions._import_opts ( file)
protected

Definition at line 495 of file ProcessJobOptions.py.

495def _import_opts(file):
496 _parser.parse(file)
497
498

◆ _import_pickle()

GaudiKernel.ProcessJobOptions._import_pickle ( file)
protected

Definition at line 487 of file ProcessJobOptions.py.

487def _import_pickle(file):
488 import pickle
489
490 input = open(file, "rb")
491 catalog = pickle.load(input)
492 _log.info("Unpickled %d configurables", len(catalog))
493
494

◆ _import_python()

GaudiKernel.ProcessJobOptions._import_python ( file)
protected

Definition at line 481 of file ProcessJobOptions.py.

481def _import_python(file):
482 with open(file) as f:
483 code = compile(f.read(), file, "exec")
484 exec(code, {"__file__": file})
485
486

◆ _import_yaml()

GaudiKernel.ProcessJobOptions._import_yaml ( filename)
protected

Definition at line 529 of file ProcessJobOptions.py.

529 def _import_yaml(filename):
530 with open(filename) as f:
531 _import_dict(yaml.safe_load(f))
532

◆ _to_be_included()

GaudiKernel.ProcessJobOptions._to_be_included ( f)
protected

Definition at line 166 of file ProcessJobOptions.py.

166def _to_be_included(f):
167 if f in _included_files:
168 _log.warning("file '%s' already included, ignored.", f)
169 return False
170 _included_files.add(f)
171 return True
172
173

◆ GetConsoleHandler()

GaudiKernel.ProcessJobOptions.GetConsoleHandler ( prefix = None,
stream = None,
with_time = False )

Definition at line 117 of file ProcessJobOptions.py.

117def GetConsoleHandler(prefix=None, stream=None, with_time=False):
118 global _consoleHandler
119 if _consoleHandler is None:
120 _consoleHandler = ConsoleHandler(
121 prefix=prefix, stream=stream, with_time=with_time
122 )
123 elif prefix is not None:
124 _consoleHandler.setPrefix(prefix)
125 return _consoleHandler
126
127

◆ importOptions()

GaudiKernel.ProcessJobOptions.importOptions ( optsfile)

Definition at line 539 of file ProcessJobOptions.py.

539def importOptions(optsfile):
540 # expand environment variables before checking the extension
541 optsfile = os.path.expandvars(optsfile)
542 # check the file type (extension)
543 dummy, ext = os.path.splitext(optsfile)
544 if ext in _import_function_mapping:
545 # check if the file has been already included
546 optsfile = _find_file(optsfile)
547 if _to_be_included(optsfile):
548 _log.info("--> Including file '%s'", optsfile)
549 # include the file
550 _import_function_mapping[ext](optsfile)
551 _log.info("<-- End of file '%s'", optsfile)
552 else:
553 raise ParserError("Unknown file type '%s' ('%s')" % (ext, optsfile))
554
555
556# Import a file containing declaration of units.
557# It is equivalent to:
558#
559# #units "unitsfile.opts"
560#
561
562

◆ importUnits()

GaudiKernel.ProcessJobOptions.importUnits ( unitsfile)

Definition at line 563 of file ProcessJobOptions.py.

563def importUnits(unitsfile):
564 # expand environment variables
565 unitsfile = os.path.expandvars(unitsfile)
566 # we do not need to check the file type (extension) because it must be a
567 # units file
568 _parser._include(unitsfile, _parser._parse_units)

◆ InstallRootLoggingHandler()

GaudiKernel.ProcessJobOptions.InstallRootLoggingHandler ( prefix = None,
level = None,
stream = None,
with_time = False )

Definition at line 128 of file ProcessJobOptions.py.

128def InstallRootLoggingHandler(prefix=None, level=None, stream=None, with_time=False):
129 root_logger = logging.getLogger()
130 if not root_logger.handlers:
131 root_logger.addHandler(GetConsoleHandler(prefix, stream, with_time))
132 root_logger.setLevel(logging.WARNING)
133 if level is not None:
134 root_logger.setLevel(level)
135
136

◆ PrintOff()

GaudiKernel.ProcessJobOptions.PrintOff ( step = 1)

Definition at line 141 of file ProcessJobOptions.py.

141def PrintOff(step=1):
142 GetConsoleHandler().printOff(step)
143
144

◆ PrintOn()

GaudiKernel.ProcessJobOptions.PrintOn ( step = 1,
force = False )

Definition at line 137 of file ProcessJobOptions.py.

137def PrintOn(step=1, force=False):
138 GetConsoleHandler().printOn(step, force)
139
140

Variable Documentation

◆ _consoleHandler

GaudiKernel.ProcessJobOptions._consoleHandler = None
protected

Definition at line 114 of file ProcessJobOptions.py.

◆ _import_function_mapping

dict GaudiKernel.ProcessJobOptions._import_function_mapping
protected
Initial value:
1= {
2 ".py": _import_python,
3 ".pkl": _import_pickle,
4 ".opts": _import_opts,
5 ".json": _import_json,
6}

Definition at line 519 of file ProcessJobOptions.py.

◆ _included_files

GaudiKernel.ProcessJobOptions._included_files = set()
protected

Definition at line 163 of file ProcessJobOptions.py.

◆ _log

GaudiKernel.ProcessJobOptions._log = logging.getLogger(__name__)
protected

Definition at line 17 of file ProcessJobOptions.py.

◆ _parser

GaudiKernel.ProcessJobOptions._parser = JobOptsParser()
protected

Definition at line 478 of file ProcessJobOptions.py.