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