DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
hsi_app_confgen.py
Go to the documentation of this file.
1# Set moo schema search path
2from dunedaq.env import get_moo_model_path
3import moo.io
4moo.io.default_load_path = get_moo_model_path()
5
6# Load configuration types
7import moo.otypes
8moo.otypes.load_types('appfwk/cmd.jsonnet')
9moo.otypes.load_types('appfwk/app.jsonnet')
10moo.otypes.load_types('cmdlib/cmd.jsonnet')
11moo.otypes.load_types('rcif/cmd.jsonnet')
12moo.otypes.load_types('timinglibs/hsireadout.jsonnet')
13moo.otypes.load_types('trigger/timingtriggercandidatemaker.jsonnet')
14moo.otypes.load_types('networkmanager/nwmgr.jsonnet')
15
16# Import new types
17import dunedaq.appfwk.cmd as cmd # AddressedCmd,
18import dunedaq.appfwk.app as app # Queue spec
19import dunedaq.cmdlib.cmd as cmdlib # Command
20import dunedaq.rcif.cmd as rcif # rcif
21import dunedaq.networkmanager.nwmgr as nwmgr
22
23import dunedaq.timinglibs.hsireadout as hsi
24import dunedaq.trigger.timingtriggercandidatemaker as ttcm
25
26from appfwk.utils import mcmd, mspec, mrccmd
27
28import json
29import math
30
32 PARTITION = "hsi_readout_test",
33 RUN_NUMBER = 333,
34 CONNECTIONS_FILE="${TIMING_SHARE}/config/etc/connections.xml",
35 READOUT_PERIOD = 1e3,
36 HSI_DEVICE_NAME="BOREAS_FMC",
37 TTCM_S1: int = 1,
38 TTCM_S2: int = 2,
39 UHAL_LOG_LEVEL="notice",
40 OUTPUT_PATH=".",
41 ):
42
43 # network connection
44 nw_specs = [nwmgr.Connection(name=PARTITION + ".hsievent",topics=[], address="tcp://127.0.0.1:12344")]
45
46 # Define modules and queues
47 queue_bare_specs = [
48 app.QueueSpec(inst="trigger_candidate_q", kind='FollySPSCQueue', capacity=2000),
49
50 ]
51
52 # Only needed to reproduce the same order as when using jsonnet
53 queue_specs = app.QueueSpecs(sorted(queue_bare_specs, key=lambda x: x.inst))
54
55 mod_specs = [
56 mspec("hsi", "HSIReadout", []),
57
58 mspec("ttcm", "TimingTriggerCandidateMaker", [
59 app.QueueInfo(name="output", inst="trigger_candidate_q", dir="output"),
60 ]),
61 ]
62
63 init_specs = app.Init(queues=queue_specs, modules=mod_specs, nwconnections=nw_specs)
64
65 jstr = json.dumps(init_specs.pod(), indent=4, sort_keys=True)
66 print(jstr)
67
68 initcmd = rcif.RCCommand(
69 id=cmdlib.CmdId("init"),
70 entry_state="NONE",
71 exit_state="INITIAL",
72 data=init_specs
73 )
74
75 mods = [
76 ("hsi", hsi.ConfParams(
77 connections_file=CONNECTIONS_FILE,
78 readout_period=READOUT_PERIOD,
79 hsi_device_name=HSI_DEVICE_NAME,
80 uhal_log_level=UHAL_LOG_LEVEL,
81 hsievent_connection_name = f"{PARTITION}.hsievent",
82 )),
83
84 ("ttcm", ttcm.Conf(
85 s1=ttcm.map_t(signal_type=TTCM_S1,
86 time_before=100000,
87 time_after=200000),
88 s2=ttcm.map_t(signal_type=TTCM_S2,
89 time_before=100000,
90 time_after=200000),
91 hsievent_connection_name = PARTITION+".hsievent",
92 )),
93 ]
94
95 confcmd = mrccmd("conf", "INITIAL", "CONFIGURED", mods)
96
97 jstr = json.dumps(confcmd.pod(), indent=4, sort_keys=True)
98 print(jstr)
99
100 startpars = rcif.StartParams(run=1, disable_data_storage=False)
101
102 startcmd = mrccmd("start", "CONFIGURED", "RUNNING", [
103 ("hsi", None),
104 ("ttcm", startpars),
105 ])
106
107 jstr = json.dumps(startcmd.pod(), indent=4, sort_keys=True)
108 print("="*80+"\nStart\n\n", jstr)
109
110 stopcmd = mrccmd("stop", "RUNNING", "CONFIGURED", [
111 ("hsi", None),
112 ("ttcm", None),
113 ])
114
115 jstr = json.dumps(stopcmd.pod(), indent=4, sort_keys=True)
116 print("="*80+"\nStop\n\n", jstr)
117
118
119 scrapcmd = mcmd("scrap", [
120 ("", None)
121 ])
122
123 jstr = json.dumps(scrapcmd.pod(), indent=4, sort_keys=True)
124 print("="*80+"\nScrap\n\n", jstr)
125
126 # Create a list of commands
127 cmd_seq = [initcmd, confcmd, startcmd, stopcmd]
128
129 # Print them as json (to be improved/moved out)
130 jstr = json.dumps([c.pod() for c in cmd_seq], indent=4, sort_keys=True)
131 return jstr
132
133if __name__ == '__main__':
134 # Add -h as default help option
135 CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
136
137 import click
138
139 @click.command(context_settings=CONTEXT_SETTINGS)
140 @click.option('-p', '--partition', default="hsi_readout_test")
141 @click.option('-r', '--run-number', default=333)
142 @click.option('-c', '--connections-file', default="${TIMING_SHARE}/config/etc/connections.xml")
143 @click.option('--readout-period', default=1e3)
144 @click.option('-h', '--hsi-device-name', default="BOREAS_FMC")
145 @click.option('--ttcm-s1', default=1, help="Timing trigger candidate maker accepted HSI signal ID 1")
146 @click.option('--ttcm-s2', default=2, help="Timing trigger candidate maker accepted HSI signal ID 2")
147 @click.option('-u', '--uhal-log-level', default="notice")
148 @click.option('-o', '--output-path', type=click.Path(), default='.')
149 @click.argument('json_file', type=click.Path(), default='hsi_readout_app.json')
150 def cli(partition, run_number, connections_file, readout_period, hsi_device_name, ttcm_s1, ttcm_s2, uhal_log_level, output_path, json_file):
151 """
152 JSON_FILE: Input raw data file.
153 JSON_FILE: Output json configuration file.
154 """
155
156 with open(json_file, 'w') as f:
157 f.write(generate(
158 PARTITION=partition,
159 RUN_NUMBER = run_number,
160 CONNECTIONS_FILE=connections_file,
161 READOUT_PERIOD = readout_period,
162 HSI_DEVICE_NAME = hsi_device_name,
163 TTCM_S1 = ttcm_s1,
164 TTCM_S2 = ttcm_s2,
165 UHAL_LOG_LEVEL = uhal_log_level,
166 OUTPUT_PATH = output_path,
167 ))
168
169 print(f"'{json_file}' generation completed.")
170
171 cli()
172
cli(partition, run_number, connections_file, readout_period, hsi_device_name, ttcm_s1, ttcm_s2, uhal_log_level, output_path, json_file)