DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dromap2oks.py
Go to the documentation of this file.
1import conffwk
2import os
3import json
4import sys
5
7 jsonfile: str,
8 oksfile: str,
9 source_id_offset: int,
10 nomap: bool,
11 lcores: str,
12) -> None:
13 """Simple script to convert a JSON readout map file to an OKS file."""
14
15 group_name = os.path.basename(jsonfile).removesuffix(".json")
16 if oksfile == "":
17 oksfile = group_name + ".data.xml"
18
19 print(
20 f"Converting RO map from {jsonfile} to OKS in {oksfile} offsetting source_ids by {source_id_offset}"
21 )
22
23 with open(jsonfile) as f:
24 jsonmap = json.loads(f.read())
25 f.close()
26
27 schemafiles = [
28 "schema/confmodel/dunedaq.schema.xml",
29 "schema/appmodel/application.schema.xml",
30 "schema/appmodel/fdmodules.schema.xml",
31 "schema/appmodel/wiec.schema.xml"
32 ]
33 dal = conffwk.dal.module("dal", schemafiles[-1])
34 db = conffwk.Configuration("oksconflibs")
35 db.create_db(oksfile, schemafiles)
36
37 eth_streams = []
38 hermes_streams = []
39 flx_streams = []
40 eth_senders = []
41 flx_senders = []
42 links = []
43 last_eth_pars = None
44 last_felix_pars = None
45 last_hermes_id = None
46 eth_streams_found = False
47 flx_streams_found = False
48
49 rx_queue = 0
50 link_number = 0
51 last_tx_mac = None
52 last_tx_host = None
53 for entry in jsonmap:
54 source_id = entry["src_id"] + source_id_offset
55 geo_id = entry["geo_id"]
56 geo_dal = dal.GeoId(f"geoId-{source_id}",
57 detector_id=geo_id["det_id"],
58 crate_id=geo_id["crate_id"],
59 slot_id=geo_id["slot_id"],
60 stream_id=geo_id["stream_id"]
61 )
62 db.update_dal(geo_dal)
63
64 stream_dal = dal.DetectorStream(f"stream-{source_id}",
65 source_id = source_id,
66 geo_id = geo_dal
67 )
68 db.update_dal(stream_dal)
69
70 if entry["kind"] == "eth":
71 eth_source_id = source_id
72 if not eth_streams_found:
73 eth_streams_found = True
74 lcore_dal = dal.ProcessingResource(
75 f"lcores-{group_name}",
76 cpu_cores = lcores.split(',')
77 )
78 db.update_dal(lcore_dal)
79 nic_config_dal = dal.DPDKPortConfiguration(
80 f"nicConfig-{group_name}",
81 used_lcores = [ lcore_dal ]
82 )
83 db.update_dal(nic_config_dal)
84
85 pars = entry["parameters"]
86 if last_eth_pars == None or pars["rx_mac"] != last_eth_pars["rx_mac"]:
87 nic_name = f"nic-{pars['rx_host']}"
88 print(f"New nic adding nic {pars['rx_mac']} with id {nic_name}")
89 rxnic_dal = dal.NetworkDevice(
90 nic_name,
91 mac_address = pars["rx_mac"],
92 ip_address = [pars["rx_ip"]]
93 )
94 db.update_dal(rxnic_dal)
95
96 dpdkrec_dal = dal.DPDKReceiver(
97 f"{pars['rx_host']}-receiver",
98 uses = rxnic_dal,
99 configuration = nic_config_dal
100 )
101 db.update_dal(dpdkrec_dal)
102
103
104
105 if last_tx_mac != None and pars["tx_mac"] != last_tx_mac:
106 link_dal = dal.HermesDataSender(
107 hermes_link_id,
108 link_id = link_number,
109 streams = hermes_streams,
110 uses = txnic_dal
111 )
112 db.update_dal(link_dal)
113 links.append(link_dal)
114 link_number = link_number + 1
115 eth_senders.append(link_dal)
116 hermes_streams = []
117
118 if last_tx_mac == None or pars["tx_mac"] != last_tx_mac:
119 if last_tx_host != pars['tx_host']:
120 nic_num = -1
121 nic_num += 1
122 nic_name = f"nw-{pars['tx_host']}-{nic_num}"
123 print(f"Adding NetworkInterface {nic_name}")
124 txnic_dal = dal.NetworkInterface(
125 nic_name,
126 mac_address = pars["tx_mac"],
127 ip_address = [pars["tx_ip"]]
128 )
129 db.update_dal(txnic_dal)
130
131 if last_eth_pars != None:
132 #print(f"streams in nic {pars['rx_mac']} = {len(streams)}")
133 if pars["rx_mac"] != last_eth_pars["rx_mac"]:
134 db.update_dal(rset_dal)
135 daqcon_dal = dal.DetectorToDaqConnection(
136 f"{last_eth_pars['rx_host']}-connections",
137 net_senders = eth_senders,
138 net_receiver = dpdkrec_dal
139 )
140 db.update_dal(daqcon_dal)
141
142 rset_dal = dal.ResourceSetAND(
143 f"{last_eth_pars['rx_host']}-streams",
144 contains = eth_streams
145 )
146 db.update_dal(rset_dal)
147
148 eth_streams = []
149 hermes_streams = []
150 eth_senders = []
151 rx_queue = 0
152 # Update Hermes ids now _after_ making any DataSenders or
153 # Controllers since we don't make them for the current
154 # params but the ones from the loop before
155 hermes_id = f"hermes_{geo_id['det_id']}_{geo_id['crate_id']}_{geo_id['slot_id']}"
156 hermes_link_id = f"{hermes_id}-{link_number}"
157 if pars != last_eth_pars:
158 rx_queue = rx_queue + 1
159 last_eth_pars = pars
160 last_eth_source_id = source_id
161 last_tx_mac = pars["tx_mac"]
162 last_tx_host = pars["tx_host"]
163
164
165 elif entry["kind"] == "flx":
166 print (f"Processing config for FELIX {source_id=}")
167 flx_source_id = source_id
168 flx_streams_found = True
169 pars = entry["parameters"]
170 if not last_felix_pars == None:
171 if (
172 pars["card"] != last_felix_pars["card"]
173 or pars["slr"] != last_felix_pars["slr"]
174 ):
175 print(
176 f'Adding FelixInterface felix-{last_felix_source_id} slr={last_felix_pars["slr"]}'
177 )
178 felix_dal = dal.FelixInterface(
179 f"felix-{last_felix_source_id}",
180 card=last_felix_pars["card"],
181 slr=last_felix_pars["slr"]
182 )
183 db.update_dal(felix_dal)
184
185 daqcon_dal = dal.DetectorToDaqConnection(
186 f"felix-{last_source_id}-connections",
187 felix_senders = [flx_senders],
188 felix_receiver = felix_dal
189 )
190 db.update_dal(daqcon_dal)
191 flx_streams = []
192 flx_senders = []
193 # Not sure how FelixDataSender fits in. What uses it?
194 flx_sender_dal = dal.FelixDataSender(
195 f"flxsender-{source_id}",
196 protocol=pars["protocol"],
197 link=pars["link"],
198 streams = [flx_streams]
199 )
200 db.update_dal(flx_sender_dal)
201 flx_senders.append(flx_sender_dal)
202 last_felix_pars = pars
203 last_felix_source_id = source_id
204 else:
205 raise RuntimeError(f'Unknown kind of readout {entry["kind"]}!')
206
207 if entry["kind"] == "eth":
208 eth_streams.append(stream_dal)
209 hermes_streams.append(stream_dal)
210 else:
211 flx_streams.append(stream_dal)
212
213 last_source_id = source_id
214
215 if eth_streams_found:
216 if link_number > 0:
217 print(f"Adding final HermesDataSender {hermes_link_id}")
218 if len(eth_streams) > 0:
219 link_dal = dal.HermesDataSender(
220 hermes_link_id,
221 link_id = link_number,
222 streams = hermes_streams,
223 uses = txnic_dal
224 )
225 db.update_dal(link_dal)
226 links.append(link_dal)
227
228 daqcon_dal = dal.NetworkDetectorToDaqConnection(
229 f"{last_eth_pars['rx_host']}-connections",
230 net_senders = eth_senders,
231 net_receiver = dpdkrec_dal
232 )
233 db.update_dal(daqcon_dal)
234
235
236 if flx_streams_found and len(flx_senders) > 0:
237 print(f"Adding final FelixInterface felix-{flx_source_id}")
238 felix_dal = dal.FelixInterface(
239 f"felix-{flx_source_id}",
240 card=last_felix_pars["card"],
241 slr=last_felix_pars["slr"]
242 )
243 db.update_dal(felix_dal)
244 daqcon_dal = dal.FelixDetectorToDaqConnection(
245 f"felix-{flx_source_id}-connections",
246 felix_senders = flx_senders,
247 felix_receiver = felix_dal
248 )
249 db.update_dal(daqcon_dal)
250
251 db.commit()
module(name, schema, other_dals=[], backend='oksconflibs', db=None)
Definition dal.py:695
None dro_json_to_oks(str jsonfile, str oksfile, int source_id_offset, bool nomap, str lcores)
Definition dromap2oks.py:12