Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Service generating unique, reproducible numbers to be used for seeding RNG used
## k4run
```
$ k4run --help
usage: k4run [--dry-run] [-v] [-n NUM_EVENTS] [-l] [--gdb] [--interactive-root] [-h] [config_files ...]
usage: k4run [--dry-run] [-v] [-n NUM_EVENTS] [-l] [--gdb] [--interactive-root] [--log-level {VERBOSE,DEBUG,INFO,WARNING,ERROR}] [-i] [-h] [config_files ...]

Run job in the Key4hep framework

Expand All @@ -58,6 +58,9 @@ options:
-l, --list Print all the configurable components available in the framework and exit
--gdb Attach gdb debugger
--interactive-root Run with ROOT in interactive mode (e.g. to see plots)
--log-level {VERBOSE,DEBUG,INFO,WARNING,ERROR}
Set the log (output) level for python and the ApplicationMgr
-i,--interactive Start a Python command loop after reading the configuration files
-h, --help show this help message and exit
```
When supplied with a Gaudi steering file `k4run --help file.py` also shows the settable properties of the Gaudi algorithms used in the file. Additionally, it is possible to add further arguments and use them in the steering file by using the Python `argparse.ArgumentParser` shared by `k4run`.
Expand Down
29 changes: 28 additions & 1 deletion k4FWCore/scripts/k4run
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,21 @@ class DeprecatedStoreTrueAction(argparse.Action):
setattr(namespace, self.dest, True)


def startInteractive(vars):
"""Start an interactive session"""
import code

# collect all global and local variables
vars = vars.copy()

# start the interpreter
code.interact(
local=vars,
banner="Starting interactive Python session. Exit with Ctrl-D to resume the job.",
)
return


def main():
# ensure that we (and the subprocesses) use the C standard localization
os.environ["LC_ALL"] = "C"
Expand Down Expand Up @@ -180,6 +195,14 @@ def main():
choices=LOG_LEVELS,
)

parser.add_argument(
"-i",
"--interactive",
action="store_true",
help="Start a Python command loop after reading the configuration files",
default=False,
)

# Once to parse the files and another time below to have the new parameters
# in the namespace since parsing of the file happens when the namespace
# has already been filled
Expand All @@ -202,8 +225,9 @@ def main():
print(f"{item} (from {cfgdb[item]['lib']}), path: {path_to_component}")
sys.exit()

config_ns = {}
for file in opts[0].config_files:
load_file(file)
config_ns.update(load_file(file))

from Configurables import ApplicationMgr

Expand Down Expand Up @@ -260,6 +284,9 @@ def main():

from Gaudi.Main import gaudimain

if opts.interactive:
startInteractive(config_ns)

gaudi = gaudimain()
if not opts.dry_run:
if not opts.interactive_root:
Expand Down
1 change: 1 addition & 0 deletions python/k4FWCore/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def load_file(opt_file: Union[str, os.PathLike]) -> None:

check_wrong_imports(code)
exec(compile(code, ofile.name, "exec"), namespace)
return namespace


_logger = None
Expand Down