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 hasattr(v,
"__opt_value__"):
216 v = v.__opt_value__()
217 elif isinstance(v, str):
221 old_opts[
".".join((n, p))] = v
228 Return all options from the old and new configuration system as a dictionary.
230 If explicit_defaults is true, include default values of unset properties in the dictionary.
237 opts = GaudiConfig2.all_options(
False)
239 conflicts = [n
for n
in set(opts).intersection(old_opts)
if opts[n] != old_opts[n]]
242 log.error(
"Some properties are set in old and new style configuration")
243 log.warning(
"name: old -> new")
245 log.warning(
"%s: %s -> %s", n, old_opts[n], opts[n])
248 opts.update(old_opts)
250 if explicit_defaults:
254 all_opts.update(GaudiConfig2.all_options(
True))
258 all_opts.update(opts)
266 Helper to convert values to old .opts format.
268 >>> print(toOpt('some "text"'))
270 >>> print(toOpt('first\\nsecond'))
273 >>> print(toOpt({'a': [1, 2, '3']}))
276 if isinstance(value, str):
277 return '"{0}"'.
format(value.replace(
'"',
'\\"'))
278 elif isinstance(value, dict):
282 elif hasattr(value,
"__iter__"):
283 return "[{0}]".
format(
", ".join(map(toOpt, value)))
290 Helper to parse option strings to Python values.
292 Ideally it should just be "eval", but the string parser of Gaudi
293 is different from the Python one, so we get string options that
294 cannot be just evaluated.
296 >>> print(parseOpt('123'))
298 >>> print(parseOpt('"some\\n\\\\"text\\\\""'))
301 >>> print(parseOpt(''))
308 quoted_string = re.compile(
r'^"(.*)"$', re.DOTALL)
313 m = quoted_string.match(s)
315 return m.group(1).replace(
'\\"',
'"')
321 from Configurables
import ApplicationMgr
324 if os.environ.get(
"GAUDIAPPNAME"):
325 appMgr.AppName = str(os.environ[
"GAUDIAPPNAME"])
326 if os.environ.get(
"GAUDIAPPVERSION"):
327 appMgr.AppVersion = str(os.environ[
"GAUDIAPPVERSION"])
328 self.
log = logging.getLogger(__name__)
337 import multiprocessing
340 from time
import ctime
343 datetime = datetime.replace(
" ",
"_")
344 outfile = open(
"gaudirun-%s.log" % (datetime),
"w")
346 streamhandler = logging.StreamHandler(stream=outfile)
347 console = logging.StreamHandler()
349 formatter = logging.Formatter(
350 "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
353 streamhandler.setFormatter(formatter)
354 console.setFormatter(formatter)
358 self.
log = multiprocessing.log_to_stderr()
359 self.
log.setLevel(logging.INFO)
360 self.
log.name =
"Gaudi/Main.py Logger"
361 self.
log.handlers = []
363 self.
log.addHandler(streamhandler)
364 self.
log.addHandler(console)
365 self.
log.removeHandler(console)
367 self.
log.setLevel = logging.INFO
372 from collections
import defaultdict
373 from pprint
import pformat
375 optDict = defaultdict(dict)
378 c, p = key.rsplit(
".", 1)
379 optDict[c][p] =
parseOpt(allOpts[key])
380 formatted = pformat(dict(optDict))
383 return re.sub(
r'"\n +"',
"", formatted, flags=re.MULTILINE)
396 output = open(filename,
"wb")
398 from GaudiKernel.Proxy.Configurable
import getNeededConfigurables
401 for n
in getNeededConfigurables():
402 to_dump[n] = Configuration.allConfigurables[n]
403 pickle.dump(to_dump, output, -1)
407 msg =
"Dumping all configurables and properties"
409 msg +=
" (different from default)"
421 ".pkl":
lambda filename, all: self.
_writepickle(filename),
422 ".py":
lambda filename, all: open(filename,
"w").write(
425 ".opts":
lambda filename, all: open(filename,
"w").write(
428 ".json":
lambda filename, all: json.dump(
429 getAllOpts(all), open(filename,
"w"), indent=2, sort_keys=
True
435 write[
".yaml"] =
lambda filename, all: yaml.safe_dump(
438 write[
".yml"] = write[
".yaml"]
442 from os.path
import splitext
444 ext = splitext(filename)[1]
446 write[ext](filename, all)
449 "Unknown file type '%s'. Must be any of %r.", ext, sorted(write.keys())
455 def run(self, attach_debugger, ncpus=None):
465 """Hook gdb to the current session. This is done by forking
466 the current process and replacing the parent with gdb, while
467 the child continues to run the program.
470 child_pid = os.fork()
479 args = [arg
for arg
in sys.argv
if arg !=
"--gdb"]
488 f
"set args {' '.join(args)}",
494 from GaudiKernel.Proxy.Configurable
import expandvars
497 def expandvars(data):
500 from GaudiKernel.Proxy.Configurable
import Configurable
502 self.
log.debug(
"runSerial: apply options")
504 conf_dict[
"ApplicationMgr.JobOptionsType"] =
'"NONE"'
507 conf_dict[
"ApplicationMgr.PrintAlgsSequence"] =
"true"
509 if hasattr(Configurable,
"_configurationLocked"):
510 Configurable._configurationLocked =
True
515 self.
log.debug(
"-" * 80)
516 self.
log.debug(
"%s: running in serial mode", __name__)
517 self.
log.debug(
"-" * 80)
525 sysTime = time() - sysStart
526 self.
log.debug(
"-" * 80)
528 "%s: serial system finished, time taken: %5.4fs", __name__, sysTime
530 self.
log.debug(
"-" * 80)
539 c = Configurable.allConfigurables
540 self.
log.info(
"-" * 80)
541 self.
log.info(
"%s: Parallel Mode : %i ", __name__, ncpus)
543 (
"platform",
" ".join(os.uname())),
544 (
"config", os.environ.get(
"BINARY_TAG")
or os.environ.get(
"CMTCONFIG")),
545 (
"app. name", os.environ.get(
"GAUDIAPPNAME")),
546 (
"app. version", os.environ.get(
"GAUDIAPPVERSION")),
548 self.
log.info(
"%s: %30s : %s ", __name__, name, value
or "Undefined")
550 events = str(c[
"ApplicationMgr"].EvtMax)
552 events =
"Undetermined"
553 self.
log.info(
"%s: Events Specified : %s ", __name__, events)
554 self.
log.info(
"-" * 80)
556 Parall = gpp.Coord(ncpus, c, self.
log)
559 self.
log.info(
"MAIN.PY : received %s from Coordinator" % (sc))
562 sysTime = time() - sysStart
563 self.
log.name =
"Gaudi/Main.py Logger"
564 self.
log.info(
"-" * 80)
566 "%s: parallel system finished, time taken: %5.4fs", __name__, sysTime
568 self.
log.info(
"-" * 80)