DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
ctb_hsi_gen.py
Go to the documentation of this file.
1# This module facilitates the generation of FLX card controller apps
2from rich.console import Console
3# Set moo schema search path
4from dunedaq.env import get_moo_model_path
5import moo.io
6moo.io.default_load_path = get_moo_model_path()
7
8# Load configuration types
9import moo.otypes
10
11moo.otypes.load_types('ctbmodules/ctbmodule.jsonnet')
12moo.otypes.load_types('readoutlibs/readoutconfig.jsonnet')
13
14# Import new types
15import dunedaq.ctbmodules.ctbmodule as ctb
16
17import dunedaq.readoutlibs.readoutconfig as rconf
18
19from daqconf.core.app import App, ModuleGraph
20from daqconf.core.daqmodule import DAQModule
21
22from daqconf.core.conf_utils import Direction, Queue
23
24#===============================================================================
25
26def update_triggers(updated_triggers, default_trigger_conf):
27 """
28 Update or add HLT,LLT defintions to the defaults in the schema
29 :param (List) updated_triggers: List of JSON LLT triggers configurations, can be None
30 :param (List) default_trigger_conf: List of default LLTs defined in the MOO schema
31 :return: (List) default or updated list of LLTs
32 """
33 if updated_triggers is None:
34 return default_trigger_conf
35
36 default_triggers = {trig["id"] : idx for idx, trig in enumerate(default_trigger_conf)}
37 for new_trig in updated_triggers:
38 if new_trig["id"] in default_triggers.keys():
39 default_trigger_conf[default_triggers[new_trig["id"]]] = new_trig
40 else:
41 default_trigger_conf.append(new_trig)
42
43 return default_trigger_conf
44
45def update_array(updated_conf, default_conf):
46 """
47 Update an array in the default schema, if needed
48 :param (List) updated_conf: Array of values to update
49 :param (List) default_conf: Array from schema that needs to be updated.
50 :return: (List) default or updated array
51 """
52 if updated_conf is not None and len(updated_conf) != 0:
53 assert len(updated_conf) == len(default_conf), \
54 ("CTBModule: Configured array is being overwritten by array of different length: "
55 f"Default array has length {len(default_conf)}, incoming has length {len(updated_conf)}")
56 default_conf = updated_conf
57 return default_conf
58
59
61 ctb_hsi,
62 nickname,
63 LLT_SOURCE_ID,
64 HLT_SOURCE_ID,
65 QUEUE_POP_WAIT_MS=10,
66 LATENCY_BUFFER_SIZE=100000,
67 DATA_REQUEST_TIMEOUT=1000,
68):
69 '''
70 Here an entire application controlling one CTB board is generated.
71 '''
72
73 # Temp variables - Remove
74 HOST=ctb_hsi.host_ctb_hsi
75 HLT_LIST=ctb_hsi.hlt_triggers
76 BEAM_LLT_LIST=ctb_hsi.beam_llt_triggers
77 CRT_LLT_LIST=ctb_hsi.crt_llt_triggers
78 PDS_LLT_LIST=ctb_hsi.pds_llt_triggers
79 FAKE_TRIG_1=ctb_hsi.fake_trig_1
80 FAKE_TRIG_2=ctb_hsi.fake_trig_2
81 BEAM_RESHAPES = ctb_hsi.beam_reshape_lengths
82 CRT_RESHAPES = ctb_hsi.crt_reshape_lengths
83 PDS_RESHAPES = ctb_hsi.pds_reshape_lengths
84 BEAM_DELAYS = ctb_hsi.beam_delays
85 CRT_DELAYS = ctb_hsi.crt_delays
86 PDS_DELAYS = ctb_hsi.pds_delays
87
88 console = Console()
89
90 # Define modules
91
92 modules = []
93 lus = []
94 # Prepare standard config with no additional configuration
95 console.log('generating DAQ module')
96
97 # Get default LLT and HLTs
98 hlt_conf = ctb.Hlt().pod()
99 beam_conf = ctb.Beam().pod()
100 crt_conf = ctb.Crt().pod()
101 pds_conf = ctb.Pds().pod()
102 fake_triggers = ctb.Misc().pod()
103
104 # Update LLT, HLTs with new or redefined triggers
105 updated_hlt_triggers = update_triggers(updated_triggers=HLT_LIST, default_trigger_conf=hlt_conf["trigger"])
106 updated_beam_triggers = update_triggers(updated_triggers=BEAM_LLT_LIST, default_trigger_conf=beam_conf["triggers"])
107 updated_crt_triggers = update_triggers(updated_triggers=CRT_LLT_LIST, default_trigger_conf=crt_conf["triggers"])
108 updated_pds_triggers = update_triggers(updated_triggers=PDS_LLT_LIST, default_trigger_conf=pds_conf["triggers"])
109
110 # Accept top config level fake trigger definition
111 fake_trig_1 = fake_triggers["randomtrigger_1"]
112 fake_trig_2 = fake_triggers["randomtrigger_2"]
113 if FAKE_TRIG_1 is not None:
114 fake_trig_1 = FAKE_TRIG_1
115 if FAKE_TRIG_2 is not None:
116 fake_trig_2 = FAKE_TRIG_2
117
118 # Accept top config level reshape and delay definitions
119 #updated_beam_reshapes = update_array(BEAM_RESHAPES, beam_conf["reshape_length"])
120 #updated_crt_reshapes = update_array(CRT_RESHAPES, crt_conf["reshape_length"])
121 #updated_pds_reshapes = update_array(PDS_RESHAPES, pds_conf["reshape_length"])
122 updated_beam_delays = update_array(BEAM_DELAYS, beam_conf["delays"])
123 updated_crt_delays = update_array(CRT_DELAYS, crt_conf["delays"])
124 updated_pds_delays = update_array(PDS_DELAYS, pds_conf["delays"])
125
126 updated_pds_conf = ctb.Pds(triggers=updated_pds_triggers,
127 delays=updated_pds_delays)
128 updated_crt_conf = ctb.Crt(triggers=updated_crt_triggers,
129 delays=updated_crt_delays)
130 updated_beam_conf = ctb.Beam(triggers=updated_beam_triggers,
131 delays=updated_beam_delays)
132 modules += [DAQModule(name = nickname,
133 plugin = 'CTBModule',
134 conf = ctb.Conf(board_config=ctb.Board_config(ctb=ctb.Ctb(misc=ctb.Misc(randomtrigger_1=fake_trig_1, randomtrigger_2=fake_trig_2),
135 HLT=ctb.Hlt(trigger=updated_hlt_triggers),
136 subsystems=ctb.Subsystems(pds=updated_pds_conf,
137 crt=updated_crt_conf,
138 beam=updated_beam_conf),
139 sockets=ctb.Sockets(receiver=ctb.Receiver(host=HOST))
140 )))
141 )]
142
143
144 modules += [DAQModule(name = f"ctb_llt_datahandler",
145 plugin = "HSIDataLinkHandler",
146 conf = rconf.Conf(readoutmodelconf = rconf.ReadoutModelConf(source_queue_timeout_ms = QUEUE_POP_WAIT_MS,
147 source_id=LLT_SOURCE_ID,
148 send_partial_fragment_if_available = True),
149 latencybufferconf = rconf.LatencyBufferConf(latency_buffer_size = LATENCY_BUFFER_SIZE),
150 rawdataprocessorconf = rconf.RawDataProcessorConf(source_id=LLT_SOURCE_ID),
151 requesthandlerconf= rconf.RequestHandlerConf(latency_buffer_size = LATENCY_BUFFER_SIZE,
152 pop_limit_pct = 0.8,
153 pop_size_pct = 0.1,
154 source_id=LLT_SOURCE_ID,
155 # output_file = f"output_{idx + MIN_LINK}.out",
156 request_timeout_ms = DATA_REQUEST_TIMEOUT,
157 warn_about_empty_buffer = False,
158 enable_raw_recording = False)
159 ))]
160
161 modules += [DAQModule(name = f"ctb_hlt_datahandler",
162 plugin = "HSIDataLinkHandler",
163 conf = rconf.Conf(readoutmodelconf = rconf.ReadoutModelConf(source_queue_timeout_ms = QUEUE_POP_WAIT_MS,
164 source_id=HLT_SOURCE_ID,
165 send_partial_fragment_if_available = True),
166 latencybufferconf = rconf.LatencyBufferConf(latency_buffer_size = LATENCY_BUFFER_SIZE),
167 rawdataprocessorconf = rconf.RawDataProcessorConf(source_id=HLT_SOURCE_ID),
168 requesthandlerconf= rconf.RequestHandlerConf(latency_buffer_size = LATENCY_BUFFER_SIZE,
169 pop_limit_pct = 0.8,
170 pop_size_pct = 0.1,
171 source_id=HLT_SOURCE_ID,
172 # output_file = f"output_{idx + MIN_LINK}.out",
173 request_timeout_ms = DATA_REQUEST_TIMEOUT,
174 warn_about_empty_buffer = False,
175 enable_raw_recording = False)
176 ))]
177
178 queues = [Queue(f"{nickname}.llt_output",f"ctb_llt_datahandler.raw_input","HSIFrame",f'ctb_llt_link', 100000),Queue(f"{nickname}.hlt_output",f"ctb_hlt_datahandler.raw_input","HSIFrame",f'ctb_hlt_link', 100000)]
179
180 mgraph = ModuleGraph(modules, queues=queues)
181
182 mgraph.add_fragment_producer(id = LLT_SOURCE_ID, subsystem = "HW_Signals_Interface",
183 requests_in = f"ctb_llt_datahandler.request_input",
184 fragments_out = f"ctb_llt_datahandler.fragment_queue")
185
186 mgraph.add_fragment_producer(id = HLT_SOURCE_ID, subsystem = "HW_Signals_Interface",
187 requests_in = f"ctb_hlt_datahandler.request_input",
188 fragments_out = f"ctb_hlt_datahandler.fragment_queue")
189
190 mgraph.add_endpoint(f"timesync_ctb_llt", f"ctb_llt_datahandler.timesync_output", "TimeSync", Direction.OUT, is_pubsub=True, toposort=False)
191 mgraph.add_endpoint(f"timesync_ctb_hlt", f"ctb_hlt_datahandler.timesync_output", "TimeSync", Direction.OUT, is_pubsub=True, toposort=False)
192
193 mgraph.add_endpoint("ctb_hsievents", f"{nickname}.hsievents", "HSIEvent", Direction.OUT)
194
195 # dummy subscriber
196 mgraph.add_endpoint(None, None, data_type="TimeSync", inout=Direction.IN, is_pubsub=True)
197
198 console.log('generated DAQ module')
199 ctb_app = App(modulegraph=mgraph, host=HOST, name=nickname)
200
201 return ctb_app
get_ctb_hsi_app(ctb_hsi, nickname, LLT_SOURCE_ID, HLT_SOURCE_ID, QUEUE_POP_WAIT_MS=10, LATENCY_BUFFER_SIZE=100000, DATA_REQUEST_TIMEOUT=1000)
update_triggers(updated_triggers, default_trigger_conf)
update_array(updated_conf, default_conf)