DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
generate.py
Go to the documentation of this file.
1from dataclasses import dataclass
2from daqconf.assets import resolve_asset_file
3from daqconf.utils import find_oksincludes
4import conffwk
5import glob
6import os
7import traceback
8
9
11 oksfile,
12 include,
13 n_dfapps,
14 tpwriting_enabled,
15 generate_segment,
16 n_data_writers=1,
17 trmon_app=False,
18):
19 """Simple script to create an OKS configuration file for a dataflow segment.
20
21 The file will automatically include the relevant schema files and
22 any other OKS files you specify.
23 """
24
25 includefiles = [
26 "schema/confmodel/dunedaq.schema.xml",
27 "schema/appmodel/application.schema.xml",
28 ]
29
30 res, extra_includes = find_oksincludes(include, os.path.dirname(oksfile))
31 if res:
32 includefiles += extra_includes
33 else:
34 return
35
36 dal = conffwk.dal.module("generated", includefiles)
37 db = conffwk.Configuration("oksconflibs")
38 if not oksfile.endswith(".data.xml"):
39 oksfile = oksfile + ".data.xml"
40 print(f"Creating OKS database file {oksfile}")
41 db.create_db(oksfile, includefiles)
42 db.set_active(oksfile)
43
44 hosts = []
45 for vhost in db.get_dals(class_name="VirtualHost"):
46 hosts.append(vhost.id)
47 if vhost.id == "vlocalhost":
48 host = vhost
49 if "vlocalhost" not in hosts:
50 cpus = dal.ProcessingResource("cpus", cpu_cores=[0, 1, 2, 3])
51 db.update_dal(cpus)
52 phdal = dal.PhysicalHost("localhost", contains=[cpus])
53 db.update_dal(phdal)
54 host = dal.VirtualHost("vlocalhost", runs_on=phdal, uses=[cpus])
55 db.update_dal(host)
56 hosts.append("vlocalhost")
57
58 # Services
59 daqapp_control = db.get_dal(class_name="Service", uid="daqapp_control")
60 rccontroller_control = db.get_dal(class_name="Service", uid="rccontroller_control")
61
62 # Source IDs
63 tpw_source_id = db.get_dal("SourceIDConf", uid="srcid-tp-stream-writer")
64
65 # Queue Rules
66 trigger_record_q_rule = db.get_dal(
67 class_name="QueueConnectionRule", uid="trigger-record-q-rule"
68 )
69 dfapp_qrules = [trigger_record_q_rule]
70
71 # Net Rules
72 frag_net_rule = db.get_dal(class_name="NetworkConnectionRule", uid="frag-net-rule")
73 df_token_net_rule = db.get_dal(
74 class_name="NetworkConnectionRule", uid="df-token-net-rule"
75 )
76 tpset_net_rule = db.get_dal(
77 class_name="NetworkConnectionRule", uid="tpset-net-rule"
78 )
79 ti_net_rule = db.get_dal(class_name="NetworkConnectionRule", uid="ti-net-rule")
80 td_dfo_net_rule = db.get_dal(
81 class_name="NetworkConnectionRule", uid="td-dfo-net-rule"
82 )
83 td_trb_net_rule = db.get_dal(
84 class_name="NetworkConnectionRule", uid="td-trb-net-rule"
85 )
86 data_req_trig_net_rule = db.get_dal(
87 class_name="NetworkConnectionRule", uid="data-req-trig-net-rule"
88 )
89 data_req_hsi_net_rule = db.get_dal(
90 class_name="NetworkConnectionRule", uid="data-req-hsi-net-rule"
91 )
92 data_req_readout_net_rule = db.get_dal(
93 class_name="NetworkConnectionRule", uid="data-req-readout-net-rule"
94 )
95 dfapp_netrules = [
96 td_trb_net_rule,
97 frag_net_rule,
98 df_token_net_rule,
99 data_req_hsi_net_rule,
100 data_req_readout_net_rule,
101 data_req_trig_net_rule,
102 ]
103
104 trmon_netrules = []
105 trmon_qrules = []
106 if trmon_app:
107 trmon_req_net_rule = db.get_dal(
108 class_name="NetworkConnectionRule", uid="trmon-req-net-rule"
109 )
110 trigger_record_net_rule = db.get_dal(class_name="NetworkConnectionRule", uid="trigger-record-net-rule")
111 dfapp_netrules.append(trmon_req_net_rule)
112 dfapp_netrules.append(trigger_record_net_rule)
113
114 trmon_netrules.append(trigger_record_net_rule)
115 trigger_decision_token_q_rule = db.get_dal(class_name="QueueConnectionRule", uid="trigger-decision-token-q-rule")
116 trmon_qrules.append(trigger_decision_token_q_rule)
117
118 dfo_netrules = [td_dfo_net_rule, ti_net_rule, df_token_net_rule]
119 tpw_netrules = [tpset_net_rule]
120
121 opmon_conf = db.get_dal(class_name="OpMonConf", uid="slow-all-monitoring")
122
123 dfo_conf = db.get_dal(class_name="DFOConf", uid="dfoconf-01")
124 dfo = dal.DFOApplication(
125 "dfo-01",
126 runs_on=host,
127 application_name="daq_application",
128 exposes_service=[daqapp_control],
129 network_rules=dfo_netrules,
130 opmon_conf=opmon_conf,
131 dfo=dfo_conf,
132 )
133 db.update_dal(dfo)
134
135 trb_conf = db.get_dal(class_name="TRBConf", uid="trb-01")
136 dw_conf = db.get_dal(class_name="DataWriterConf", uid="dw-01")
137 dfhw = db.get_dal(class_name="DFHWConf", uid="dfhw-01")
138 dfapps = []
139 for dfapp_idx in range(n_dfapps):
140 dfapp_id = dfapp_idx + 1
141
142 # Offset sids by one so that TPW sourceID can stay at 1
143 dfapp_source_id = dal.SourceIDConf(
144 f"srcid-df-{dfapp_id:02}", sid=dfapp_id + 1, subsystem="TR_Builder"
145 )
146 db.update_dal(dfapp_source_id)
147
148 dfapp = dal.DFApplication(
149 f"df-{dfapp_id:02}",
150 runs_on=host,
151 application_name="daq_application",
152 exposes_service=[daqapp_control],
153 source_id=dfapp_source_id,
154 queue_rules=dfapp_qrules,
155 network_rules=dfapp_netrules,
156 opmon_conf=opmon_conf,
157 trb=trb_conf,
158 data_writers=[dw_conf] * n_data_writers,
159 uses=dfhw,
160 )
161 db.update_dal(dfapp)
162 dfapps.append(dfapp)
163
164 tpwapps = []
165 if tpwriting_enabled:
166 tpw_writer_conf = db.get_dal(
167 class_name="TPStreamWriterConf", uid="tp-stream-writer-conf"
168 )
169
170 tpwapp = dal.TPStreamWriterApplication(
171 "tp-stream-writer",
172 runs_on=host,
173 application_name="daq_application",
174 exposes_service=[daqapp_control],
175 source_id=tpw_source_id,
176 network_rules=tpw_netrules,
177 opmon_conf=opmon_conf,
178 tp_writer=tpw_writer_conf,
179 )
180 db.update_dal(tpwapp)
181 tpwapps.append(tpwapp)
182
183 trmonapps = []
184 if trmon_app:
185 trmonconf = db.get_dal(class_name="TRMonRequestorConf", uid="trmr-01")
186 trmondwconf = db.get_dal(class_name="DataWriterConf", uid="tr_mon_dw-01")
187
188 trmonapp = dal.TRMonReqApplication(
189 "trmon-01",
190 runs_on=host,
191 application_name="daq_application",
192 exposes_service=[daqapp_control],
193 network_rules=trmon_netrules,
194 queue_rules=trmon_qrules,
195 opmon_conf=opmon_conf,
196 trmonreq = trmonconf,
197 data_writer = trmondwconf,
198 uses=dfhw,
199 )
200 db.update_dal(trmonapp)
201 trmonapps.append(trmonapp)
202
203 if generate_segment:
204 fsm = db.get_dal(class_name="FSMconfiguration", uid="FSMconfiguration_noAction")
205 controller = dal.RCApplication(
206 "df-controller",
207 application_name="drunc-controller",
208 runs_on=host,
209 fsm=fsm,
210 opmon_conf=opmon_conf,
211 exposes_service=[rccontroller_control],
212 )
213 db.update_dal(controller)
214
215 seg = dal.Segment(
216 f"df-segment", controller=controller, applications=[dfo] + dfapps + tpwapps + trmonapps
217 )
218 db.update_dal(seg)
219
220 try:
221 db.commit()
222 except RuntimeError as err:
223 print("Failed to commit Dataflow DB!")
224 print(traceback.format_exc())
225 raise err
226 return
227
228
230 oksfile,
231 include,
232 generate_segment,
233):
234 """Simple script to create an OKS configuration file for a FakeHSI segment.
235
236 The file will automatically include the relevant schema files and
237 any other OKS files you specify.
238
239
240 """
241
242 includefiles = [
243 "schema/confmodel/dunedaq.schema.xml",
244 "schema/appmodel/application.schema.xml",
245 "schema/appmodel/trigger.schema.xml",
246 ]
247
248 res, extra_includes = find_oksincludes(include, os.path.dirname(oksfile))
249 if res:
250 includefiles += extra_includes
251 else:
252 return
253
254 dal = conffwk.dal.module("generated", includefiles)
255 db = conffwk.Configuration("oksconflibs")
256 if not oksfile.endswith(".data.xml"):
257 oksfile = oksfile + ".data.xml"
258 print(f"Creating OKS database file {oksfile}")
259 db.create_db(oksfile, includefiles)
260 db.set_active(oksfile)
261
262 hosts = []
263 for vhost in db.get_dals(class_name="VirtualHost"):
264 hosts.append(vhost.id)
265 if vhost.id == "vlocalhost":
266 host = vhost
267 if "vlocalhost" not in hosts:
268 cpus = dal.ProcessingResource("cpus", cpu_cores=[0, 1, 2, 3])
269 db.update_dal(cpus)
270 phdal = dal.PhysicalHost("localhost", contains=[cpus])
271 db.update_dal(phdal)
272 host = dal.VirtualHost("vlocalhost", runs_on=phdal, uses=[cpus])
273 db.update_dal(host)
274 hosts.append("vlocalhost")
275
276 # Services
277 daqapp_control = db.get_dal(class_name="Service", uid="daqapp_control")
278 rccontroller_control = db.get_dal(class_name="Service", uid="rccontroller_control")
279 dataRequests = db.get_dal(class_name="Service", uid="dataRequests")
280 hsievents = db.get_dal(class_name="Service", uid="HSIEvents")
281
282 # Source IDs
283 hsi_source_id = db.get_dal(class_name="SourceIDConf", uid="hsi-srcid-01")
284 hsi_tc_source_id = db.get_dal(class_name="SourceIDConf", uid="hsi-tc-srcid-1")
285
286 # Queue Rules
287 hsi_dlh_queue_rule = db.get_dal(
288 class_name="QueueConnectionRule", uid="hsi-dlh-data-requests-queue-rule"
289 )
290 hsi_qrules = [hsi_dlh_queue_rule]
291
292 # Net Rules
293 tc_net_rule = db.get_dal(class_name="NetworkConnectionRule", uid="tc-net-rule")
294 hsi_rule = db.get_dal(class_name="NetworkConnectionRule", uid="hsi-rule")
295 ts_hsi_net_rule = db.get_dal(
296 class_name="NetworkConnectionRule", uid="ts-hsi-net-rule"
297 )
298 data_req_hsi_net_rule = db.get_dal(
299 class_name="NetworkConnectionRule", uid="data-req-hsi-net-rule"
300 )
301 hsi_netrules = [hsi_rule, data_req_hsi_net_rule, ts_hsi_net_rule]
302 tc_netrules = [hsi_rule, tc_net_rule]
303
304 opmon_conf = db.get_dal(class_name="OpMonConf", uid="slow-all-monitoring")
305 hsi_handler = db.get_dal(class_name="DataHandlerConf", uid="def-hsi-handler")
306 fakehsi = db.get_dal(class_name="FakeHSIEventGeneratorConf", uid="fakehsi")
307
308 hsi = dal.FakeHSIApplication(
309 "hsi-01",
310 runs_on=host,
311 application_name="daq_application",
312 exposes_service=[daqapp_control],
313 source_id=hsi_source_id,
314 queue_rules=hsi_qrules,
315 network_rules=hsi_netrules,
316 opmon_conf=opmon_conf,
317 link_handler=hsi_handler,
318 generator=fakehsi,
319 )
320 db.update_dal(hsi)
321
322 hsi_to_tc_conf = db.get_dal(class_name="HSI2TCTranslatorConf", uid="hsi-to-tc-conf")
323
324 hsi_to_tc = dal.HSIEventToTCApplication(
325 "hsi-to-tc-app",
326 runs_on=host,
327 application_name="daq_application",
328 exposes_service=[dataRequests, hsievents, daqapp_control],
329 source_id=hsi_tc_source_id,
330 network_rules=tc_netrules,
331 opmon_conf=opmon_conf,
332 hsevent_to_tc_conf=hsi_to_tc_conf,
333 )
334 db.update_dal(hsi_to_tc)
335
336 if generate_segment:
337 fsm = db.get_dal(class_name="FSMconfiguration", uid="FSMconfiguration_noAction")
338 controller = dal.RCApplication(
339 "hsi-controller",
340 application_name="drunc-controller",
341 runs_on=host,
342 fsm=fsm,
343 opmon_conf=opmon_conf,
344 exposes_service=[rccontroller_control],
345 )
346 db.update_dal(controller)
347
348 seg = dal.Segment(
349 f"hsi-segment", controller=controller, applications=[hsi, hsi_to_tc]
350 )
351 db.update_dal(seg)
352
353 db.commit()
354 return
355
356
358 readoutmap,
359 oksfile,
360 include,
361 generate_segment,
362 emulated_file_name,
363 tpg_enabled=True,
364 hosts_to_use=[],
365):
366 """Simple script to create an OKS configuration file for all
367 ReadoutApplications defined in a readout map.
368
369 The file will automatically include the relevant schema files and
370 any other OKS files you specify.
371
372 Example:
373 generate_readoutOKS -i hosts \
374 -i appmodel/connections.data.xml -i appmodel/moduleconfs \
375 config/np04readoutmap.data.xml readoutApps.data.xml
376
377 Will load hosts, connections and moduleconfs data files as well as
378 the readoutmap (config/np04readoutmap.data.xml) and write the
379 generated apps to readoutApps.data.xml.
380
381 generate_readoutOKS --session --segment \
382 -i appmodel/fsm -i hosts \
383 -i appmodel/connections.data.xml -i appmodel/moduleconfs \
384 config/np04readoutmap.data.xml np04readout-session.data.xml
385
386 Will do the same but in addition it will generate a containing
387 Segment for the apps and a containing Session for the Segment.
388
389 NB: Currently FSM generation is not implemented so you must include
390 an fsm file in order to generate a Segment
391
392 """
393
394 if not readoutmap.endswith(".data.xml"):
395 readoutmap = readoutmap + ".data.xml"
396
397 print(f"Readout map file {readoutmap}")
398
399 includefiles = [
400 "schema/confmodel/dunedaq.schema.xml",
401 "schema/appmodel/application.schema.xml",
402 "schema/appmodel/trigger.schema.xml",
403 "schema/appmodel/fdmodules.schema.xml",
404 "schema/appmodel/wiec.schema.xml",
405 readoutmap,
406 ]
407
408 searchdirs = [path for path in os.environ["DUNEDAQ_DB_PATH"].split(":")]
409 searchdirs.append(os.path.dirname(oksfile))
410 for inc in include:
411 # print (f"Searching for {inc}")
412 match = False
413 inc = inc.removesuffix(".xml")
414 if inc.endswith(".data"):
415 sub_dirs = ["config", "data"]
416 elif inc.endswith(".schema"):
417 sub_dirs = ["schema"]
418 else:
419 sub_dirs = ["*"]
420 inc = inc + "*"
421 for path in searchdirs:
422 # print (f" {path}/{inc}.xml")
423 matches = glob.glob(f"{inc}.xml", root_dir=path)
424 if len(matches) == 0:
425 for search_dir in sub_dirs:
426 # print (f" {path}/{search_dir}/{inc}.xml")
427 matches = glob.glob(f"{search_dir}/{inc}.xml", root_dir=path)
428 for filename in matches:
429 if filename not in includefiles:
430 print(f"Adding {filename} to include list")
431 includefiles.append(filename)
432 else:
433 print(f"{filename} already in include list")
434 match = True
435 break
436 if match:
437 break
438 if match:
439 break
440 else:
441 for filename in matches:
442 if filename not in includefiles:
443 print(f"Adding {filename} to include list")
444 includefiles.append(filename)
445 else:
446 print(f"{filename} already in include list")
447 match = True
448 break
449
450 if not match:
451 print(f"Error could not find include file for {inc}")
452 return
453
454 dal = conffwk.dal.module("generated", includefiles)
455 db = conffwk.Configuration("oksconflibs")
456 if not oksfile.endswith(".data.xml"):
457 oksfile = oksfile + ".data.xml"
458 print(f"Creating OKS database file {oksfile}")
459 db.create_db(oksfile, includefiles)
460 db.set_active(oksfile)
461
462 detector_connections = db.get_dals(class_name="DetectorToDaqConnection")
463 daqapp_control = db.get_dal(class_name="Service", uid="daqapp_control")
464 rccontroller_control = db.get_dal(class_name="Service", uid="rccontroller_control")
465
466 try:
467 rule = db.get_dal(
468 class_name="NetworkConnectionRule", uid="data-req-readout-net-rule"
469 )
470 except:
471 print(
472 'Expected NetworkConnectionRule "data-req-readout-net-rule" not found in input databases!'
473 )
474 else:
475 netrules = [rule]
476 # Assume we have all the other rules we need
477 for rule in ["tpset-net-rule", "ts-net-rule", "ta-net-rule"]:
478 netrules.append(db.get_dal(class_name="NetworkConnectionRule", uid=rule))
479
480 try:
481 rule = db.get_dal(
482 class_name="QueueConnectionRule", uid="fd-dlh-data-requests-queue-rule"
483 )
484 except:
485 print(
486 'Expected QueueConnectionRule "fd-dlh-data-requests-queue-rule" not found in input databases!'
487 )
488 else:
489 qrules = [rule]
490 for rule in [
491 "fa-queue-rule",
492 "tp-queue-rule",
493 ]:
494 qrules.append(db.get_dal(class_name="QueueConnectionRule", uid=rule))
495
496 hosts = []
497 if len(hosts_to_use) == 0:
498 for vhost in db.get_dals(class_name="VirtualHost"):
499 if vhost.id == "vlocalhost":
500 hosts.append(vhost.id)
501 if "vlocalhost" not in hosts:
502 cpus = dal.ProcessingResource("cpus", cpu_cores=[0, 1, 2, 3])
503 db.update_dal(cpus)
504 phdal = dal.PhysicalHost("localhost", contains=[cpus])
505 db.update_dal(phdal)
506 host = dal.VirtualHost("vlocalhost", runs_on=phdal, uses=[cpus])
507 db.update_dal(host)
508 hosts.append("vlocalhost")
509 else:
510 for vhost in db.get_dals(class_name="VirtualHost"):
511 if vhost.id in hosts_to_use:
512 hosts.append(vhost.id)
513 assert len(hosts) > 0
514
515 rohw = dal.RoHwConfig(f"rohw-{detector_connections[0].id}")
516 db.update_dal(rohw)
517
518 opmon_conf = db.get_dal(class_name="OpMonConf", uid="slow-all-monitoring")
519
520 appnum = 0
521 nicrec = None
522 flxcard = None
523 wm_conf = None
524 hermes_conf = None
525 ruapps = []
526 for connection in detector_connections:
527
528 geo_id = connection.get("GeoId")
529 det_id = geo_id[0].detector_id
530 if det_id == 0:
531 raise Exception(f"Unable to determine detector ID from Hardware Map!")
532
533 tphandler = db.get_dal(class_name="DataHandlerConf", uid="def-tp-handler")
534
535 if det_id == 2:
536 if "DAPHNEStream" in emulated_file_name:
537 linkhandler = db.get_dal(
538 class_name="DataHandlerConf", uid="def-pds-stream-link-handler"
539 )
540 det_q = db.get_dal(
541 class_name="QueueConnectionRule", uid="pds-stream-raw-data-rule"
542 )
543 else:
544 linkhandler = db.get_dal(
545 class_name="DataHandlerConf", uid="def-pds-link-handler"
546 )
547 det_q = db.get_dal(
548 class_name="QueueConnectionRule", uid="pds-raw-data-rule"
549 )
550
551 elif det_id == 3:
552 linkhandler = db.get_dal(
553 class_name="DataHandlerConf", uid="def-link-handler"
554 )
555 det_q = db.get_dal(
556 class_name="QueueConnectionRule", uid="wib-eth-raw-data-rule"
557 )
558 elif det_id == 11:
559 linkhandler = db.get_dal(
560 class_name="DataHandlerConf", uid="def-tde-link-handler"
561 )
562 det_q = db.get_dal(
563 class_name="QueueConnectionRule", uid="tde-raw-data-rule"
564 )
565 elif det_id == 12:
566 linkhandler = db.get_dal(
567 class_name="DataHandlerConf", uid="def-crt-bern-link-handler"
568 )
569 det_q = db.get_dal(
570 class_name="QueueConnectionRule", uid="crt-bern-raw-data-rule"
571 )
572 elif det_id == 13:
573 linkhandler = db.get_dal(
574 class_name="DataHandlerConf", uid="def-crt-grenoble-link-handler"
575 )
576 det_q = db.get_dal(
577 class_name="QueueConnectionRule", uid="crt-grenoble-raw-data-rule"
578 )
579
580 hostnum = appnum % len(hosts)
581 # print(f"Looking up host[{hostnum}] ({hosts[hostnum]})")
582 host = db.get_dal(class_name="VirtualHost", uid=hosts[hostnum])
583
584 # Find which type of DataReceiver we need for this connection
585 if connection.className() == "NetworkDetectorToDaqConnection":
586 receiver = connection.net_receiver
587 elif connection.className() == "FelixDetectorToDaqConnection":
588 receiver = connection.felix_receiver
589
590 # Emulated stream
591 if type(receiver).__name__ == "FakeDataReceiver":
592 if nicrec == None:
593 try:
594 stream_emu = db.get_dal(
595 class_name="StreamEmulationParameters", uid="stream-emu"
596 )
597 stream_emu.data_file_name = resolve_asset_file(emulated_file_name)
598 db.update_dal(stream_emu)
599 except:
600 stream_emu = dal.StreamEmulationParameters(
601 "stream-emu",
602 data_file_name=resolve_asset_file(emulated_file_name),
603 input_file_size_limit=5777280,
604 set_t0=True,
605 random_population_size=100000,
606 frame_error_rate_hz=0,
607 generate_periodic_adc_pattern=True,
608 TP_rate_per_channel=1,
609 )
610 db.update_dal(stream_emu)
611
612 print("Generating fake DataReaderConf")
613 nicrec = dal.DPDKReaderConf(
614 f"nicrcvr-fake-gen",
615 template_for="FDFakeReaderModule",
616 emulation_mode=1,
617 emulation_conf=stream_emu,
618 )
619 db.update_dal(nicrec)
620 datareader = nicrec
621 elif type(receiver).__name__ == "DPDKReceiver":
622 if nicrec == None:
623 print("Generating DPDKReaderConf")
624 nicrec = dal.DPDKReaderConf(
625 f"nicrcvr-dpdk-gen", template_for="DPDKReaderModule"
626 )
627 db.update_dal(nicrec)
628 if wm_conf == None:
629 try:
630 wm_conf = db.get_dal("WIBModuleConf", "def-wib-conf")
631 except:
632 print(
633 'Expected WIBModuleConf "def-wib-conf" not found in input databases!'
634 )
635 if hermes_conf == None:
636 try:
637 hermes_conf = db.get_dal("HermesModuleConf", "def-hermes-conf")
638 except:
639 print(
640 'Expected HermesModuleConf "def-hermes-conf" not found in input databases!'
641 )
642
643 datareader = nicrec
644
645 wiec_app = dal.WIECApplication(
646 f"wiec-{connection.id}",
647 application_name="daq_application",
648 runs_on=host,
649 detector_connections=[connection],
650 wib_module_conf=wm_conf,
651 hermes_module_conf=hermes_conf,
652 exposes_service=[daqapp_control],
653 )
654 db.update_dal(wiec_app)
655
656 elif type(receiver).__name__ == "FelixInterface":
657 if flxcard == None:
658 print("Generating Felix DataReaderConf")
659 flxcard = dal.DataReaderConf(
660 f"flxConf-1", template_for="FelixReaderModule"
661 )
662 db.update_dal(flxcard)
663 datareader = flxcard
664 else:
665 print(
666 f"ReadoutGroup contains unknown interface type {type(receiver).__name__}"
667 )
668 continue
669
670 db.commit()
671
672 # Services
673 dataRequests = db.get_dal(class_name="Service", uid="dataRequests")
674 timeSyncs = db.get_dal(class_name="Service", uid="timeSyncs")
675 triggerActivities = db.get_dal(class_name="Service", uid="triggerActivities")
676 triggerPrimitives = db.get_dal(class_name="Service", uid="triggerPrimitives")
677
678 # Action Plans
679 readout_start = db.get_dal(class_name="ActionPlan", uid="readout-start")
680 readout_stop = db.get_dal(class_name="ActionPlan", uid="readout-stop")
681
682 ru = dal.ReadoutApplication(
683 f"ru-{connection.id}",
684 application_name="daq_application",
685 runs_on=host,
686 detector_connections=[connection],
687 network_rules=netrules,
688 queue_rules=qrules + [det_q],
689 link_handler=linkhandler,
690 data_reader=datareader,
691 opmon_conf=opmon_conf,
692 tp_generation_enabled=tpg_enabled,
693 ta_generation_enabled=tpg_enabled,
694 uses=rohw,
695 exposes_service=[daqapp_control, dataRequests, timeSyncs],
696 action_plans=[readout_start, readout_stop],
697 )
698 if tpg_enabled:
699 ru.tp_handler = tphandler
700 tp_sources = []
701 tpbaseid = (appnum * 3) + 100
702 # 30-Apr-2025, KAB: added support for 1 "plane" of non-TPC TPs (e.g. PDS).
703 # That is compared with the usual 3 planes of TPs for TPC detectors.
704 for plane in range(1 if det_id not in [3, 10, 11] else 3):
705 s_id = tpbaseid + plane
706 tps_dal = dal.SourceIDConf(
707 f"tp-srcid-{s_id}", sid=s_id, subsystem="Trigger"
708 )
709 db.update_dal(tps_dal)
710 tp_sources.append(tps_dal)
711 ru.tp_source_ids = tp_sources
712 ru.exposes_service += [triggerActivities, triggerPrimitives]
713 appnum = appnum + 1
714 print(f"{ru=}")
715 db.update_dal(ru)
716 db.commit()
717 ruapps.append(ru)
718 if appnum == 0:
719 print(f"No ReadoutApplications generated\n")
720 return
721
722 db.commit()
723
724 if generate_segment:
725 # fsm = db.get_dal(class_name="FSMconfiguration", uid="fsmConf-test")
726 fsm = db.get_dal(class_name="FSMconfiguration", uid="FSMconfiguration_noAction")
727 controller = dal.RCApplication(
728 "ru-controller",
729 application_name="drunc-controller",
730 runs_on=host,
731 fsm=fsm,
732 opmon_conf=opmon_conf,
733 exposes_service=[rccontroller_control],
734 )
735 db.update_dal(controller)
736 db.commit()
737
738 seg = dal.Segment(f"ru-segment", controller=controller, applications=ruapps)
739 db.update_dal(seg)
740 db.commit()
741
742 db.commit()
743 return
744
745
747 oksfile, include, generate_segment, n_streams, n_apps, det_id
748):
749 """Simple script to create an OKS configuration file for a FakeDataProd-based readout segment.
750
751 The file will automatically include the relevant schema files and
752 any other OKS files you specify.
753
754 """
755
756 includefiles = [
757 "schema/confmodel/dunedaq.schema.xml",
758 "schema/appmodel/application.schema.xml",
759 ]
760
761 res, extra_includes = find_oksincludes(include, os.path.dirname(oksfile))
762 if res:
763 includefiles += extra_includes
764 else:
765 return
766
767 dal = conffwk.dal.module("generated", includefiles)
768 db = conffwk.Configuration("oksconflibs")
769 if not oksfile.endswith(".data.xml"):
770 oksfile = oksfile + ".data.xml"
771 print(f"Creating OKS database file {oksfile}")
772 db.create_db(oksfile, includefiles)
773 db.set_active(oksfile)
774
775 hosts = []
776 for vhost in db.get_dals(class_name="VirtualHost"):
777 hosts.append(vhost.id)
778 if vhost.id == "vlocalhost":
779 host = vhost
780 if "vlocalhost" not in hosts:
781 cpus = dal.ProcessingResource("cpus", cpu_cores=[0, 1, 2, 3])
782 db.update_dal(cpus)
783 phdal = dal.PhysicalHost("localhost", contains=[cpus])
784 db.update_dal(phdal)
785 host = dal.VirtualHost("vlocalhost", runs_on=phdal, uses=[cpus])
786 db.update_dal(host)
787 hosts.append("vlocalhost")
788
789 source_id = 0
790 fakeapps = []
791 # Services
792 daqapp_control = db.get_dal(class_name="Service", uid="daqapp_control")
793 rccontroller_control = db.get_dal(class_name="Service", uid="rccontroller_control")
794 dataRequests = db.get_dal(class_name="Service", uid="dataRequests")
795 timeSyncs = db.get_dal(class_name="Service", uid="timeSyncs")
796 opmon_conf = db.get_dal(class_name="OpMonConf", uid="slow-all-monitoring")
797
798 rule = db.get_dal(
799 class_name="NetworkConnectionRule", uid="data-req-readout-net-rule"
800 )
801 netrules = [rule]
802 for rule in ["ts-fdp-net-rule"]:
803 netrules.append(db.get_dal(class_name="NetworkConnectionRule", uid=rule))
804
805 try:
806 rule = db.get_dal(
807 class_name="QueueConnectionRule", uid="fpdm-data-requests-queue-rule"
808 )
809 except:
810 print(
811 'Expected QueueConnectionRule "fpdm-data-requests-queue-rule" not found in input databases!'
812 )
813 else:
814 qrules = [rule]
815 for rule in [
816 "fa-queue-rule",
817 ]:
818 qrules.append(db.get_dal(class_name="QueueConnectionRule", uid=rule))
819
820 frame_size=0
821 fragment_type=""
822 if det_id == 3:
823 frame_size=7200
824 time_tick_diff=32*64
825 response_delay=0
826 fragment_type="WIBEth"
827 else:
828 raise Exception(f"FakeDataProd parameters not configured for detector ID {det_id}")
829
830 for appidx in range(n_apps):
831
832 fakeapp = dal.FakeDataApplication(f"fakedata_{appidx}",
833 runs_on=host,
834 application_name="daq_application",
835 exposes_service=[daqapp_control, dataRequests, timeSyncs],
836 queue_rules=qrules,
837 network_rules=netrules,
838 opmon_conf=opmon_conf,)
839
840 for streamidx in range(n_streams):
841 stream = dal.FakeDataProdConf(
842 f"fakedata_{appidx}_stream_{streamidx}",
843 system_type="Detector_Readout",
844 source_id=source_id,
845 time_tick_diff=time_tick_diff,
846 frame_size=frame_size,
847 response_delay=response_delay,
848 fragment_type=fragment_type,
849 )
850 db.update_dal(stream)
851 fakeapp.producers.append(stream)
852 source_id = source_id + 1
853
854 db.update_dal(fakeapp)
855 fakeapps.append(fakeapp)
856
857
858 if generate_segment:
859 fsm = db.get_dal(class_name="FSMconfiguration", uid="FSMconfiguration_noAction")
860 controller = dal.RCApplication(
861 "ru-controller",
862 application_name="drunc-controller",
863 opmon_conf=opmon_conf,
864 runs_on=host,
865 fsm=fsm,
866 exposes_service=[rccontroller_control],
867 )
868 db.update_dal(controller)
869
870 seg = dal.Segment(
871 f"ru-segment",
872 controller=controller,
873 applications=fakeapps,
874 )
875 db.update_dal(seg)
876
877 db.commit()
878 return
879
880
882 oksfile,
883 include,
884 generate_segment,
885 tpg_enabled=True,
886 hsi_enabled=False,
887):
888 """Simple script to create an OKS configuration file for a trigger segment.
889
890 The file will automatically include the relevant schema files and
891 any other OKS files you specify.
892
893 """
894
895 includefiles = [
896 "schema/confmodel/dunedaq.schema.xml",
897 "schema/appmodel/application.schema.xml",
898 "schema/appmodel/trigger.schema.xml",
899 ]
900
901 res, extra_includes = find_oksincludes(include, os.path.dirname(oksfile))
902 if res:
903 includefiles += extra_includes
904 else:
905 return
906
907 dal = conffwk.dal.module("generated", includefiles)
908 db = conffwk.Configuration("oksconflibs")
909 if not oksfile.endswith(".data.xml"):
910 oksfile = oksfile + ".data.xml"
911 print(f"Creating OKS database file {oksfile}")
912 db.create_db(oksfile, includefiles)
913 db.set_active(oksfile)
914
915 hosts = []
916 for vhost in db.get_dals(class_name="VirtualHost"):
917 hosts.append(vhost.id)
918 if vhost.id == "vlocalhost":
919 host = vhost
920 if "vlocalhost" not in hosts:
921 cpus = dal.ProcessingResource("cpus", cpu_cores=[0, 1, 2, 3])
922 db.update_dal(cpus)
923 phdal = dal.PhysicalHost("localhost", contains=[cpus])
924 db.update_dal(phdal)
925 host = dal.VirtualHost("vlocalhost", runs_on=phdal, uses=[cpus])
926 db.update_dal(host)
927 hosts.append("vlocalhost")
928
929 # Services
930 daqapp_control = db.get_dal(class_name="Service", uid="daqapp_control")
931 rccontroller_control = db.get_dal(class_name="Service", uid="rccontroller_control")
932 dataRequests = db.get_dal(class_name="Service", uid="dataRequests")
933 triggerActivities = db.get_dal(class_name="Service", uid="triggerActivities")
934 triggerCandidates = db.get_dal(class_name="Service", uid="triggerCandidates")
935 triggerInhibits = db.get_dal(class_name="Service", uid="triggerInhibits")
936
937 # Source IDs
938 mlt_source_id = db.get_dal(class_name="SourceIDConf", uid="tc-srcid-1")
939 tc_source_id = db.get_dal(class_name="SourceIDConf", uid="ta-srcid-1")
940
941 # Queue Rules
942 tc_queue_rule = db.get_dal(class_name="QueueConnectionRule", uid="tc-queue-rule")
943 td_queue_rule = db.get_dal(class_name="QueueConnectionRule", uid="td-queue-rule")
944 ta_queue_rule = db.get_dal(class_name="QueueConnectionRule", uid="ta-queue-rule")
945 mlt_qrules = [tc_queue_rule, td_queue_rule]
946 tapp_qrules = [ta_queue_rule]
947
948 # Net Rules
949 tc_net_rule = db.get_dal(class_name="NetworkConnectionRule", uid="tc-net-rule")
950 ta_net_rule = db.get_dal(class_name="NetworkConnectionRule", uid="ta-net-rule")
951 ts_net_rule = db.get_dal(class_name="NetworkConnectionRule", uid="ts-net-rule")
952 ti_net_rule = db.get_dal(class_name="NetworkConnectionRule", uid="ti-net-rule")
953 td_dfo_net_rule = db.get_dal(
954 class_name="NetworkConnectionRule", uid="td-dfo-net-rule"
955 )
956 data_req_trig_net_rule = db.get_dal(
957 class_name="NetworkConnectionRule", uid="data-req-trig-net-rule"
958 )
959 mlt_netrules = [
960 tc_net_rule,
961 ti_net_rule,
962 td_dfo_net_rule,
963 data_req_trig_net_rule,
964 ts_net_rule,
965 ]
966 tapp_netrules = [ta_net_rule, tc_net_rule, data_req_trig_net_rule]
967
968 opmon_conf = db.get_dal(class_name="OpMonConf", uid="slow-all-monitoring")
969 tc_subscriber = db.get_dal(class_name="DataReaderConf", uid="tc-subscriber-1")
970 tc_handler = db.get_dal(class_name="DataHandlerConf", uid="def-tc-handler")
971 mlt_conf = db.get_dal(class_name="MLTConf", uid="def-mlt-conf")
972 random_tc_generator = db.get_dal(
973 class_name="RandomTCMakerConf", uid="random-tc-generator"
974 )
975 tc_confs = [] if hsi_enabled else [random_tc_generator]
976
977 mlt = dal.MLTApplication(
978 "mlt",
979 runs_on=host,
980 application_name="daq_application",
981 exposes_service=[daqapp_control, triggerCandidates, triggerInhibits, dataRequests],
982 source_id=mlt_source_id,
983 queue_rules=mlt_qrules,
984 network_rules=mlt_netrules,
985 opmon_conf=opmon_conf,
986 data_subscriber=tc_subscriber,
987 trigger_inputs_handler=tc_handler,
988 mlt_conf=mlt_conf,
989 standalone_candidate_maker_confs=tc_confs,
990 )
991 db.update_dal(mlt)
992
993 if tpg_enabled:
994 ta_subscriber = db.get_dal(class_name="DataReaderConf", uid="ta-subscriber-1")
995 ta_handler = db.get_dal(class_name="DataHandlerConf", uid="def-ta-handler")
996
997 # Action Plans
998 tc_maker_start = db.get_dal(class_name="ActionPlan", uid="tc-maker-start")
999
1000 tcmaker = dal.TriggerApplication(
1001 "tc-maker-1",
1002 runs_on=host,
1003 application_name="daq_application",
1004 exposes_service=[daqapp_control, triggerActivities, dataRequests],
1005 source_id=tc_source_id,
1006 queue_rules=tapp_qrules,
1007 network_rules=tapp_netrules,
1008 opmon_conf=opmon_conf,
1009 data_subscriber=ta_subscriber,
1010 trigger_inputs_handler=ta_handler,
1011 action_plans=[tc_maker_start],
1012 )
1013 db.update_dal(tcmaker)
1014
1015 if generate_segment:
1016 fsm = db.get_dal(class_name="FSMconfiguration", uid="FSMconfiguration_noAction")
1017 controller = dal.RCApplication(
1018 "trg-controller",
1019 application_name="drunc-controller",
1020 opmon_conf=opmon_conf,
1021 runs_on=host,
1022 fsm=fsm,
1023 exposes_service=[rccontroller_control],
1024 )
1025 db.update_dal(controller)
1026
1027 seg = dal.Segment(
1028 f"trg-segment",
1029 controller=controller,
1030 applications=[mlt] + ([tcmaker] if tpg_enabled else []),
1031 )
1032 db.update_dal(seg)
1033
1034 db.commit()
1035 return
1036
1037
1039 oksfile,
1040 include,
1041 session_name,
1042 op_env,
1043 connectivity_service_is_infrastructure_app=True,
1044 disable_connectivity_service=False,
1045):
1046 """Simple script to create an OKS configuration file for a session.
1047
1048 The file will automatically include the relevant schema files and
1049 any other OKS files you specify.
1050
1051 """
1052
1053 includefiles = [
1054 "schema/confmodel/dunedaq.schema.xml",
1055 "schema/appmodel/application.schema.xml",
1056 ]
1057 res, extra_includes = find_oksincludes(include, os.path.dirname(oksfile))
1058 if res:
1059 includefiles += extra_includes
1060 else:
1061 return
1062
1063 dal = conffwk.dal.module("generated", includefiles)
1064 db = conffwk.Configuration("oksconflibs")
1065 if not oksfile.endswith(".data.xml"):
1066 oksfile = oksfile + ".data.xml"
1067 print(f"Creating OKS database file {oksfile} with includes {includefiles}")
1068 db.create_db(oksfile, includefiles)
1069 db.set_active(oksfile)
1070
1071 hosts = []
1072 for vhost in db.get_dals(class_name="VirtualHost"):
1073 hosts.append(vhost.id)
1074 if vhost.id == "vlocalhost":
1075 host = vhost
1076 if "vlocalhost" not in hosts:
1077 cpus = dal.ProcessingResource("cpus", cpu_cores=[0, 1, 2, 3])
1078 db.update_dal(cpus)
1079 phdal = dal.PhysicalHost("localhost", contains=[cpus])
1080 db.update_dal(phdal)
1081 host = dal.VirtualHost("vlocalhost", runs_on=phdal, uses=[cpus])
1082 db.update_dal(host)
1083 hosts.append("vlocalhost")
1084
1085 fsm = db.get_dal(class_name="FSMconfiguration", uid="fsmConf-test")
1086 rccontroller_control = db.get_dal(class_name="Service", uid="rccontroller_control")
1087 controller = dal.RCApplication(
1088 "root-controller",
1089 application_name="drunc-controller",
1090 runs_on=host,
1091 fsm=fsm,
1092 exposes_service=[rccontroller_control],
1093 )
1094 db.update_dal(controller)
1095
1096 segments = db.get_dals(class_name="Segment")
1097
1098 seg = dal.Segment(f"root-segment", controller=controller, segments=segments)
1099 db.update_dal(seg)
1100
1101 detconf = db.get_dal(class_name="DetectorConfig", uid="dummy-detector")
1102
1103 detconf.op_env = op_env
1104 db.update_dal(detconf)
1105
1106 opmon_svc = db.get_dal(class_name="OpMonURI", uid="local-opmon-uri")
1107
1108 trace_file_var = None
1109 TRACE_FILE = os.getenv("TRACE_FILE")
1110 if TRACE_FILE is not None:
1111 trace_file_var = dal.Variable(
1112 "session-env-trace-file", name="TRACE_FILE", value=TRACE_FILE
1113 )
1114 db.update_dal(trace_file_var)
1115
1116 infrastructure_applications = []
1117 if connectivity_service_is_infrastructure_app:
1118 conn_svc = db.get_dal(
1119 class_name="ConnectionService", uid="local-connection-server"
1120 )
1121 infrastructure_applications.append(conn_svc)
1122
1123 env_vars_for_local_running = db.get_dal(
1124 class_name="VariableSet", uid="local-variables"
1125 ).contains
1126 if trace_file_var is not None:
1127 env_vars_for_local_running.append(trace_file_var)
1128
1129 sessiondal = dal.Session(
1130 session_name,
1131 environment=env_vars_for_local_running,
1132 segment=seg,
1133 detector_configuration=detconf,
1134 infrastructure_applications=infrastructure_applications,
1135 opmon_uri=opmon_svc,
1136 )
1137
1138 if not disable_connectivity_service:
1139 conn_svc_cfg = db.get_dal(
1140 class_name="ConnectivityService", uid="local-connectivity-service-config"
1141 )
1142 sessiondal.connectivity_service = conn_svc_cfg
1143
1144 db.update_dal(sessiondal)
1145
1146 db.commit()
1147 return
module(name, schema, other_dals=[], backend='oksconflibs', db=None)
Definition dal.py:673
generate_session(oksfile, include, session_name, op_env, connectivity_service_is_infrastructure_app=True, disable_connectivity_service=False)
Definition generate.py:1045
generate_dataflow(oksfile, include, n_dfapps, tpwriting_enabled, generate_segment, n_data_writers=1, trmon_app=False)
Definition generate.py:18
generate_readout(readoutmap, oksfile, include, generate_segment, emulated_file_name, tpg_enabled=True, hosts_to_use=[])
Definition generate.py:365
generate_hsi(oksfile, include, generate_segment)
Definition generate.py:233
generate_trigger(oksfile, include, generate_segment, tpg_enabled=True, hsi_enabled=False)
Definition generate.py:887
generate_fakedata(oksfile, include, generate_segment, n_streams, n_apps, det_id)
Definition generate.py:748