remage package¶
Submodules¶
remage.cli module¶
- remage.cli._cleanup_tmp_files(ipc_info)¶
Remove temporary files created by the C++ application, that might not have been cleaned up.
- Parameters:
ipc_info (IpcResult)
- Return type:
None
- remage.cli._run_remage_cpp(args=None, is_cli=False)¶
run the remage-cpp executable and return the exit code as seen in bash.
- remage.cli.remage_run(macros=(), *, gdml_files=(), output=None, threads=1, overwrite_output=False, merge_output_files=False, flat_output=False, time_window=None, macro_substitutions=None, log_level=None, raise_on_error=True, raise_on_warning=False)¶
Run the remage simulation utility with the provided args.
This is the main entry point for users wanting to run remage from Python code.
- Parameters:
macros (Sequence[str] | str) – one or more remage/Geant4 macro command listings to execute.
gdml_files (Sequence[str] | str) – supply one or more GDML files describing the experimental geometry.
threads (int) – set the number of threads used by remage.
overwrite_output (bool) – overwrite existing output files.
merge_output_files (bool) – merge output files created by individual remage threads.
flat_output (bool) – if
False, perform a reshaping of the output files so that each row in the output table contains data about all steps in a physical interaction in a detector, based on the time-window. This results in each column being aVectorOfVectors. IfTrue, the output table will be flat with each row holding information about a single Geant4 step.time_window (float | None) – time window to group together steps into hits, in microseconds.
macro_substitutions (Mapping[str, str] | None) – key-value-pairs that will be substituted in macros as Geant4 aliases.
log_level (str | None) – logging level. One of debug, detail, summary, warning, error, fatal, nothing.
raise_on_error (bool) – raise a
RuntimeErrorwhen an error in the C++ application occurs. This applies to non-fatal errors being logged as well as fatal errors. If false, the function only returns the error code, the Python-based post-processing will be skipped in any case.raise_on_warning (bool) – raise a
RuntimeErrorwhen a warning (or error) is logged in the C++ application. If false, warnings are only logged and the python-based post-processing will be run normally.
- Return type:
- remage.cli.remage_run_from_args(args=None, *, raise_on_error=True, raise_on_warning=False)¶
Run the remage simulation utility with the provided args.
- Parameters:
args (list[str] | None) – argument list, as passed to the remage CLI utility.
raise_on_error (bool) – see
remage_run()raise_on_warning (bool) – see
remage_run()
- Return type:
remage.find_remage module¶
remage.ipc module¶
IPC message receiver implementation for remage-cpp.
Note
The C++ IPC sender implementation can be found in RMGIpc.
Binary message format¶
Messages are encoded as UTF-8 strings; transmitting binary (non-string) data with this IPC mechanism is not possible.
Message parts are separated using ASCII control characters. Each message ends with
GS (group separator, 0x1D) which may be optionally preceded by ENQ (enquiry,
0x05) to indicate that the C++ process expects an acknowledgement with a POSIX signal
before continuing.
Records within a message are delimited by RS (record separator, 0x1E). Each
message must contain at least two records. The first is treated as the message’s
key, whereas the second one is the associated value:
key |
|
value |
[ |
|
More values can follow afterwards, again delimited by RS.
Each record may contain multiple units split by US (unit separator, 0x1F). Records
with more then one unit are returned as tuples on the python side.
Example: A message
key |
|
value0 |
|
value1 |
|
value2 |
[ |
|
would be decoded to ["value0", ("value1", "value2")].
Blocking messages¶
Blocking messages need to be acknowledged by sending the POSIX signal SIGUSR2 to
the remage-cpp process, after performing the associated action (example: checking
version equality of python and C++ IPC sides, pre-processing files).
Transmitting additional response data with the acknowledgement is not possible.
- class remage.ipc.IpcResult(ipc_info)¶
Bases:
objectStorage structure for the IPC messages returned by
remage-cpp.- get(name, expected_len=1)¶
Return all messages of a given key
namefrom the IPC message list.
- get_single(name, default)¶
Return the single single value for the key
nameordefaultif not present.Note
if more then one value for the key had been submitted, this function will throw.
- remage.ipc.handle_ipc_message(msg)¶
Parse a already UTF-8 decoded IPC message from
remage-cpp.This function should directly handle all known blocking IPC messages, which will not be returned for subsequent processing.
- Parameters:
msg (str) – The raw message bytes decoded to UTF-8, still including the trailing separator(s).
- Returns:
(is_blocking, parsed_message, is_fatal)whereis_blockingisTruewhen the sender waits for a reply,parsed_messageis the decoded message orNoneif it was consumed internally, andis_fatalsignals that the application should terminate.- Return type:
- remage.ipc.ipc_thread_fn(pipe_r, proc, unhandled_ipc_messages)¶
Read and handle IPC messages coming from
remage-cpp.Important
This function runs in a dedicated thread in
remage.cli._run_remage_cpp()and should not be called directly by the user. The parameterunhandled_ipc_messagesacts as a return value, as thread functions cannot directly return.The function reads from the pipe file descriptor
pipe_rand dispatches each complete IPC message tohandle_ipc_message()for parsing and handling of the associated action. Any message parts will be decoded as UTF-8 before parsing.Blocking messages are acknowledged by sending the POSIX signal
SIGUSR2to the child process, while fatal messages triggerSIGTERM. Any messages that are not handled byhandle_ipc_message()are appended to the listunhandled_ipc_messagesfor later processing.
remage.logging module¶
- remage.logging.set_logging_level(logger, rmg_log_level)¶
remage.post_proc module¶
- remage.post_proc.copy_links(original_file, output_files, lh5_links_group_name)¶
- remage.post_proc.get_reboost_config(reshape_table_list, other_table_list, *, time_window=10)¶
Get the config file to run reboost.
- Parameters:
- Return type:
config file as a dictionary.
- remage.post_proc.make_tmp(files)¶
Hide files.
Prepend a . to their name and rename them on disk.
- remage.post_proc.post_proc(ipc_info, flat_output, merge_output_files, time_window_in_us)¶
- remage.post_proc.tmp_renamed_files(remage_files)¶
Temporarily rename files, restoring originals on error and deleting temps on success.
remage.utils module¶
- remage.utils._to_list(thing)¶