13from zmq_daq.utils import get_monitor_table, show_monitoring, write_monitoring
19def yaml_settings(yaml_file):
20 with open(yaml_file,
"r")
as f:
24def command_load(args):
25 execution = CleanBasf2Execution()
27 for app
in args.settings_file[
"programs"]:
32 except KeyboardInterrupt:
36def command_monitor(args):
38 sockets = get_sockets(args.settings_file)
41 if not args.watch
and not args.dat:
42 df = get_monitor_table(sockets, show_detail=args.show_detail)
48 f = open(args.dat,
"wb")
54 df = get_monitor_table(sockets, show_detail=args.show_detail)
59 write_monitoring(df, f)
67def command_start(args):
68 sockets = get_sockets(args.settings_file)
69 for socket
in sockets.values():
70 socket.send_multipart([b
"n", b
"", b
""])
73def command_input_file(args):
74 execution = CleanBasf2Execution()
76 input_port = args.settings_file[
"input"]
79 remaining_args += [
"--raw"]
81 remaining_args += [
"--repeat"]
82 execution.start([
"b2hlt_file2socket", args.data_file, str(input_port)] + remaining_args)
86 except KeyboardInterrupt:
90def command_stop(args):
91 sockets = get_sockets(args.settings_file)
92 sockets[
"distributor"].send_multipart([b
"l", b
"", b
""])
95 for socket
in sockets.keys():
96 if socket ==
"distributor":
99 sockets[socket].send_multipart([b
"l", b
"", b
""])
102def command_terminate(args):
103 sockets = get_sockets(args.settings_file)
104 sockets[
"distributor"].send_multipart([b
"x", b
"", b
""])
107 for socket
in sockets.keys():
108 if socket ==
"distributor":
111 sockets[socket].send_multipart([b
"x", b
"", b
""])
114if __name__ ==
'__main__':
115 parser = argparse.ArgumentParser(description=
"""Try out different modes for the ZMQ HLT.
116 By choosing the settings_file, the different modes can be chosen.
117 Together with the settings file, a command needs to be chosen.
118 Typically, this will be
"load" in one console
and "input_file" in a different console.
119 You can then monitor the process either
with the
"monitor" command
120 or by using
"b2hlt_monitor.py".
123 parser.add_argument("settings_file", type=yaml_settings,
124 help=
"Which config file to load for the test")
126 subparsers = parser.add_subparsers(help=
"Choose the command", dest=
"command")
127 subparsers.required =
True
129 subparser = subparsers.add_parser(
"load")
130 subparser.set_defaults(func=command_load)
132 subparser = subparsers.add_parser(
"monitor")
133 subparser.add_argument(
136 help=
"By default, some information are omitted. With this flag, all details are shown (can be very long output).")
137 subparser.add_argument(
"--watch", action=
"store_true", help=
"Enter watch mode, where the script is called every 1 second.")
138 subparser.add_argument(
"--dat", help=
"Write out the results of the monitoring periodically into a dat file. " +
139 "If not combined with --watch, the output will not be shown.")
140 subparser.set_defaults(func=command_monitor)
142 subparser = subparsers.add_parser(
"send_stop")
143 subparser.add_argument(
"--all", action=
"store_true", help=
"Send the signal to all processes")
144 subparser.set_defaults(func=command_stop)
146 subparser = subparsers.add_parser(
"send_terminate")
147 subparser.add_argument(
"--all", action=
"store_true", help=
"Send the signal to all processes")
148 subparser.set_defaults(func=command_terminate)
150 subparser = subparsers.add_parser(
"send_start")
151 subparser.set_defaults(func=command_start)
153 subparser = subparsers.add_parser(
"input_file")
154 subparser.add_argument(
"data_file", help=
"Which data file to send")
155 subparser.add_argument(
"--raw", help=
"send and receive raw data instead of event buffers", action=
"store_true")
156 subparser.add_argument(
"--repeat", help=
"repeat after the file is finished", action=
"store_true")
157 subparser.set_defaults(func=command_input_file)
159 args = parser.parse_args()