DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dromap2oks Namespace Reference

Functions

 dro_json_to_oks (jsonfile, oksfile, source_id_offset, nomap, lcores)
 

Function Documentation

◆ dro_json_to_oks()

dromap2oks.dro_json_to_oks ( jsonfile,
oksfile,
source_id_offset,
nomap,
lcores )
Simple script to convert a JSON readout map file to an OKS file.

Definition at line 6 of file dromap2oks.py.

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 contains = 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 rset_dal = dal.ResourceSetAND(
129 f"{last_eth_pars['rx_host']}-senders",
130 contains = eth_senders
131 )
132 db.update_dal(rset_dal)
133 daqcon_dal = dal.DetectorToDaqConnection(
134 f"{last_eth_pars['rx_host']}-connections",
135 contains = [rset_dal, dpdkrec_dal]
136 )
137 db.update_dal(daqcon_dal)
138
139 rset_dal = dal.ResourceSetAND(
140 f"{last_eth_pars['rx_host']}-streams",
141 contains = eth_streams
142 )
143 db.update_dal(rset_dal)
144
145 eth_streams = []
146 hermes_streams = []
147 eth_senders = []
148 rx_queue = 0
149 # Update Hermes ids now _after_ making any DataSenders or
150 # Controllers since we don't make them for the current
151 # params but the ones from the loop before
152 hermes_id = f"hermes_{geo_id['det_id']}_{geo_id['crate_id']}_{geo_id['slot_id']}"
153 hermes_link_id = f"{hermes_id}-{link_number}"
154 if pars != last_eth_pars:
155 rx_queue = rx_queue + 1
156 last_eth_pars = pars
157 last_eth_source_id = source_id
158 last_tx_mac = pars["tx_mac"]
159 last_tx_host = pars["tx_host"]
160
161
162 elif entry["kind"] == "flx":
163 print (f"Processing config for FELIX {source_id=}")
164 flx_source_id = source_id
165 flx_streams_found = True
166 pars = entry["parameters"]
167 if not last_felix_pars == None:
168 if (
169 pars["card"] != last_felix_pars["card"]
170 or pars["slr"] != last_felix_pars["slr"]
171 ):
172 print(
173 f'Adding FelixInterface felix-{last_felix_source_id} slr={last_felix_pars["slr"]}'
174 )
175 felix_dal = dal.FelixInterface(
176 f"felix-{last_felix_source_id}",
177 card=last_felix_pars["card"],
178 slr=last_felix_pars["slr"]
179 )
180 db.update_dal(felix_dal)
181 rset_dal = dal.ResourceSetAND(
182 f"felix-{last_source_id}-streams",
183 contains = flx_streams
184 )
185 db.update_dal(rset_dal)
186 daqcon_dal = dal.DetectorToDaqConnection(
187 f"felix-{last_source_id}-connections",
188 contains = [rset_dal, felix_dal]
189 )
190 db.update_dal(daqcon_dal)
191 flx_streams = []
192 # Not sure how FelixDataSender fits in. What uses it?
193 flx_sender_dal = dal.FelixDataSender(
194 f"flxsender-{source_id}",
195 protocol=pars["protocol"],
196 link=pars["link"],
197 contains = [stream_dal]
198 )
199 db.update_dal(flx_sender_dal)
200 flx_senders.append(flx_sender_dal)
201 last_felix_pars = pars
202 last_felix_source_id = source_id
203 else:
204 raise RuntimeError(f'Unknown kind of readout {entry["kind"]}!')
205
206 if entry["kind"] == "eth":
207 eth_streams.append(stream_dal)
208 hermes_streams.append(stream_dal)
209 else:
210 flx_streams.append(stream_dal)
211
212 last_source_id = source_id
213
214 if eth_streams_found:
215 if link_number > 0:
216 print(f"Adding final HermesDataSender {hermes_link_id}")
217 if len(eth_streams) > 0:
218 link_dal = dal.HermesDataSender(
219 hermes_link_id,
220 link_id = link_number,
221 contains = hermes_streams,
222 uses = txnic_dal
223 )
224 db.update_dal(link_dal)
225 links.append(link_dal)
226
227 rset_dal = dal.ResourceSetAND(
228 f"{last_eth_pars['rx_host']}-senders",
229 contains = eth_senders
230 )
231 db.update_dal(rset_dal)
232 rset_dal = dal.ResourceSetAND(
233 f"{last_eth_pars['rx_host']}-streams",
234 contains = eth_streams
235 )
236 db.update_dal(rset_dal)
237 daqcon_dal = dal.DetectorToDaqConnection(
238 f"{last_eth_pars['rx_host']}-connections",
239 contains = [rset_dal, dpdkrec_dal]
240 )
241 db.update_dal(daqcon_dal)
242
243
244 if flx_streams_found and len(flx_senders) > 0:
245 print(f"Adding final FelixInterface felix-{flx_source_id}")
246 felix_dal = dal.FelixInterface(
247 f"felix-{flx_source_id}",
248 card=last_felix_pars["card"],
249 slr=last_felix_pars["slr"]
250 )
251 db.update_dal(felix_dal)
252 rset_dal = dal.ResourceSetAND(
253 f"felix-{flx_source_id}-streams",
254 contains = flx_streams
255 )
256 db.update_dal(rset_dal)
257 daqcon_dal = dal.DetectorToDaqConnection(
258 f"felix-{flx_source_id}-connections",
259 contains = [rset_dal, felix_dal]
260 )
261 db.update_dal(daqcon_dal)
262
263 db.commit()
module(name, schema, other_dals=[], backend='oksconflibs', db=None)
Definition dal.py:673