58 self.
lib.py_bootstrap_fsm_configure(self.
ptr)
63 self.
lib.py_bootstrap_fsm_initialize(self.
ptr)
79 self.
lib.py_bootstrap_fsm_finalize(self.
ptr)
84 self.
lib.py_bootstrap_fsm_terminate(self.
ptr)
88 return self.
lib.py_bootstrap_getService(self.
ptr, name.encode(
"ascii"))
92 self.
lib.py_bootstrap_setProperty(
93 self.
ptr, name.encode(
"ascii"), value.encode(
"ascii")
99 self.
lib.py_bootstrap_getProperty(self.
ptr, name.encode(
"ascii"))
106 self.
lib.py_bootstrap_setOption(
107 self.
ptr, key.encode(
"ascii"), value.encode(
"ascii")
111 from ctypes
import RTLD_GLOBAL, PyDLL, c_bool, c_char_p, c_int, c_void_p, util
116 class IInterface_p(c_void_p):
118 return "IInterface_p(0x%x)" % (0
if self.
value is None else self.
value)
120 self.
log = logging.getLogger(
"BootstrapHelper")
121 libname = util.find_library(
"GaudiKernel")
or "libGaudiKernel.so"
122 self.
log.debug(
"loading GaudiKernel (%s)", libname)
126 self.
lib = gkl = PyDLL(libname, mode=RTLD_GLOBAL)
129 (
"createApplicationMgr", IInterface_p, []),
130 (
"getService", IInterface_p, [IInterface_p, c_char_p]),
131 (
"setProperty", c_bool, [IInterface_p, c_char_p, c_char_p]),
132 (
"getProperty", c_char_p, [IInterface_p, c_char_p]),
133 (
"setOption",
None, [IInterface_p, c_char_p, c_char_p]),
134 (
"ROOT_VERSION_CODE", c_int, []),
137 for name, restype, argtypes
in functions:
138 f = getattr(gkl,
"py_bootstrap_%s" % name)
139 f.restype, f.argtypes = restype, argtypes
142 if name
not in self.__class__.__dict__:
143 setattr(self, name, f)
153 f = getattr(gkl,
"py_bootstrap_fsm_%s" % name)
154 f.restype, f.argtypes = c_bool, [IInterface_p]
155 gkl.py_bootstrap_app_run.restype = c_bool
156 gkl.py_bootstrap_app_run.argtypes = [IInterface_p, c_int]
158 gkl.py_helper_printAlgsSequences.restype =
None
159 gkl.py_helper_printAlgsSequences.argtypes = [IInterface_p]
162 ptr = self.
lib.py_bootstrap_createApplicationMgr()
167 return self.
lib.py_bootstrap_ROOT_VERSION_CODE()
172 a = root_version_code >> 16 & 0xFF
173 b = root_version_code >> 8 & 0xFF
174 c = root_version_code & 0xFF
180 Return all options from the old configuration system as a dictionary.
182 If explicit_defaults is true, include default values of unset properties in the dictionary.
184 from itertools
import chain
186 from GaudiKernel.Proxy.Configurable
import Configurable, getNeededConfigurables
197 needed_conf = [n
for n
in getNeededConfigurables()
if n
not in done_conf]
201 for n
in needed_conf:
203 c = Configurable.allConfigurables[n]
204 items = getattr(c,
"getValuedProperties", dict)().items()
205 if explicit_defaults:
206 items = chain(c.getDefaultProperties().items(), items)
209 if hasattr(Configurable,
"PropertyReference")
and isinstance(
210 v, Configurable.PropertyReference
215 if isinstance(v, str):
217 v =
'"%s"' % v.replace(
'"',
'\\"')
218 elif hasattr(v,
"__opt_value__"):
219 v = v.__opt_value__()
220 old_opts[
".".join((n, p))] = str(v)
227 Return all options from the old and new configuration system as a dictionary.
229 If explicit_defaults is true, include default values of unset properties in the dictionary.
236 opts = GaudiConfig2.all_options(
False)
238 conflicts = [n
for n
in set(opts).intersection(old_opts)
if opts[n] != old_opts[n]]
241 log.error(
"Some properties are set in old and new style configuration")
242 log.warning(
"name: old -> new")
244 log.warning(
"%s: %s -> %s", n, old_opts[n], opts[n])
247 opts.update(old_opts)
249 if explicit_defaults:
253 all_opts.update(GaudiConfig2.all_options(
True))
257 all_opts.update(opts)
265 Helper to convert values to old .opts format.
267 >>> print(toOpt('some "text"'))
269 >>> print(toOpt('first\\nsecond'))
272 >>> print(toOpt({'a': [1, 2, '3']}))
275 if isinstance(value, str):
276 return '"{0}"'.
format(value.replace(
'"',
'\\"'))
277 elif isinstance(value, dict):
281 elif hasattr(value,
"__iter__"):
282 return "[{0}]".
format(
", ".join(map(toOpt, value)))
289 Helper to parse option strings to Python values.
291 Ideally it should just be "eval", but the string parser of Gaudi
292 is different from the Python one, so we get string options that
293 cannot be just evaluated.
295 >>> print(parseOpt('123'))
297 >>> print(parseOpt('"some\\n\\\\"text\\\\""'))
300 >>> print(parseOpt(''))
307 quoted_string = re.compile(
r'^"(.*)"$', re.DOTALL)
312 m = quoted_string.match(s)
314 return m.group(1).replace(
'\\"',
'"')
320 from Configurables
import 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__)
336 import multiprocessing
339 from time
import ctime
342 datetime = datetime.replace(
" ",
"_")
343 outfile = open(
"gaudirun-%s.log" % (datetime),
"w")
345 streamhandler = logging.StreamHandler(stream=outfile)
346 console = logging.StreamHandler()
348 formatter = logging.Formatter(
349 "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
352 streamhandler.setFormatter(formatter)
353 console.setFormatter(formatter)
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 = []
362 self.
log.addHandler(streamhandler)
363 self.
log.addHandler(console)
364 self.
log.removeHandler(console)
366 self.
log.setLevel = logging.INFO
371 from collections
import defaultdict
372 from pprint
import pformat
374 optDict = defaultdict(dict)
377 c, p = key.rsplit(
".", 1)
378 optDict[c][p] =
parseOpt(allOpts[key])
379 formatted = pformat(dict(optDict))
382 return re.sub(
r'"\n +"',
"", formatted, flags=re.MULTILINE)
395 output = open(filename,
"wb")
397 from GaudiKernel.Proxy.Configurable
import getNeededConfigurables
400 for n
in getNeededConfigurables():
401 to_dump[n] = Configuration.allConfigurables[n]
402 pickle.dump(to_dump, output, -1)
406 msg =
"Dumping all configurables and properties"
408 msg +=
" (different from default)"
420 ".pkl":
lambda filename, all: self.
_writepickle(filename),
421 ".py":
lambda filename, all: open(filename,
"w").write(
424 ".opts":
lambda filename, all: open(filename,
"w").write(
427 ".json":
lambda filename, all: json.dump(
428 getAllOpts(all), open(filename,
"w"), indent=2, sort_keys=
True
434 write[
".yaml"] =
lambda filename, all: yaml.safe_dump(
437 write[
".yml"] = write[
".yaml"]
441 from os.path
import splitext
443 ext = splitext(filename)[1]
445 write[ext](filename, all)
448 "Unknown file type '%s'. Must be any of %r.", ext, sorted(write.keys())
454 def run(self, attach_debugger, ncpus=None):
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.
469 child_pid = os.fork()
478 args = [arg
for arg
in sys.argv
if arg !=
"--gdb"]
487 f
"set args {' '.join(args)}",
493 from GaudiKernel.Proxy.Configurable
import expandvars
496 def expandvars(data):
499 from GaudiKernel.Proxy.Configurable
import Configurable
501 self.
log.debug(
"runSerial: apply options")
503 conf_dict[
"ApplicationMgr.JobOptionsType"] =
'"NONE"'
506 conf_dict[
"ApplicationMgr.PrintAlgsSequence"] =
"true"
508 if hasattr(Configurable,
"_configurationLocked"):
509 Configurable._configurationLocked =
True
514 self.
log.debug(
"-" * 80)
515 self.
log.debug(
"%s: running in serial mode", __name__)
516 self.
log.debug(
"-" * 80)
524 sysTime = time() - sysStart
525 self.
log.debug(
"-" * 80)
527 "%s: serial system finished, time taken: %5.4fs", __name__, sysTime
529 self.
log.debug(
"-" * 80)
538 c = Configurable.allConfigurables
539 self.
log.info(
"-" * 80)
540 self.
log.info(
"%s: Parallel Mode : %i ", __name__, ncpus)
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")),
547 self.
log.info(
"%s: %30s : %s ", __name__, name, value
or "Undefined")
549 events = str(c[
"ApplicationMgr"].EvtMax)
551 events =
"Undetermined"
552 self.
log.info(
"%s: Events Specified : %s ", __name__, events)
553 self.
log.info(
"-" * 80)
555 Parall = gpp.Coord(ncpus, c, self.
log)
558 self.
log.info(
"MAIN.PY : received %s from Coordinator" % (sc))
561 sysTime = time() - sysStart
562 self.
log.name =
"Gaudi/Main.py Logger"
563 self.
log.info(
"-" * 80)
565 "%s: parallel system finished, time taken: %5.4fs", __name__, sysTime
567 self.
log.info(
"-" * 80)