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