371):
372 """Simple script to create an OKS configuration file for all
373 ReadoutApplications defined in a readout map.
374
375 The file will automatically include the relevant schema files and
376 any other OKS files you specify.
377
378 Example:
379 generate_readoutOKS -i hosts \
380 -i appmodel/connections.data.xml -i appmodel/moduleconfs \
381 config/np04readoutmap.data.xml readoutApps.data.xml
382
383 Will load hosts, connections and moduleconfs data files as well as
384 the readoutmap (config/np04readoutmap.data.xml) and write the
385 generated apps to readoutApps.data.xml.
386
387 generate_readoutOKS --session --segment \
388 -i appmodel/fsm -i hosts \
389 -i appmodel/connections.data.xml -i appmodel/moduleconfs \
390 config/np04readoutmap.data.xml np04readout-session.data.xml
391
392 Will do the same but in addition it will generate a containing
393 Segment for the apps and a containing Session for the Segment.
394
395 NB: Currently FSM generation is not implemented so you must include
396 an fsm file in order to generate a Segment
397
398 """
399
400 if not readoutmap.endswith(".data.xml"):
401 readoutmap = readoutmap + ".data.xml"
402
403 print(f"Readout map file {readoutmap}")
404
405 includefiles = (
406 [
407 "schema/confmodel/dunedaq.schema.xml",
408 "schema/appmodel/application.schema.xml",
409 "schema/appmodel/trigger.schema.xml",
410 "schema/appmodel/fdmodules.schema.xml",
411 "schema/appmodel/wiec.schema.xml",
412 ]
413 + [readoutmap]
414 if os.path.exists(readoutmap)
415 else []
416 )
417
418 searchdirs = [path for path in os.environ["DUNEDAQ_DB_PATH"].split(":")]
419 searchdirs.append(os.path.dirname(oksfile))
420 for inc in include:
421
422 match = False
423 inc = inc.removesuffix(".xml")
424 if inc.endswith(".data"):
425 sub_dirs = ["config", "data"]
426 elif inc.endswith(".schema"):
427 sub_dirs = ["schema"]
428 else:
429 sub_dirs = ["*"]
430 inc = inc + "*"
431 for path in searchdirs:
432
433 matches = glob.glob(f"{inc}.xml", root_dir=path)
434 if len(matches) == 0:
435 for search_dir in sub_dirs:
436
437 matches = glob.glob(f"{search_dir}/{inc}.xml", root_dir=path)
438 for filename in matches:
439 if filename not in includefiles:
440 print(f"Adding {filename} to include list")
441 includefiles.append(filename)
442 else:
443 print(f"{filename} already in include list")
444 match = True
445 break
446 if match:
447 break
448 if match:
449 break
450 else:
451 for filename in matches:
452 if filename not in includefiles:
453 print(f"Adding {filename} to include list")
454 includefiles.append(filename)
455 else:
456 print(f"{filename} already in include list")
457 match = True
458 break
459
460 if not match:
461 print(f"Error could not find include file for {inc}")
462 return
463
466 if not oksfile.endswith(".data.xml"):
467 oksfile = oksfile + ".data.xml"
468 print(f"Creating OKS database file {oksfile}")
469 db.create_db(oksfile, includefiles)
470 db.set_active(oksfile)
471
472 detector_connections = db.get_dals(class_name="DetectorToDaqConnection")
473 daqapp_control = db.get_dal(class_name="Service", uid="daqapp_control")
474 rccontroller_control = db.get_dal(class_name="Service", uid="rccontroller_control")
475
476 try:
477 rule = db.get_dal(
478 class_name="NetworkConnectionRule", uid="data-req-readout-net-rule"
479 )
480 except:
481 print(
482 'Expected NetworkConnectionRule "data-req-readout-net-rule" not found in input databases!'
483 )
484 else:
485 netrules = [rule]
486
487 for rule in ["tpset-net-rule", "ts-net-rule", "ta-net-rule"]:
488 netrules.append(db.get_dal(class_name="NetworkConnectionRule", uid=rule))
489
490 try:
491 rule = db.get_dal(
492 class_name="QueueConnectionRule", uid="fd-dlh-data-requests-queue-rule"
493 )
494 except:
495 print(
496 'Expected QueueConnectionRule "fd-dlh-data-requests-queue-rule" not found in input databases!'
497 )
498 else:
499 qrules = [rule]
500 for rule in [
501 "fa-queue-rule",
502 "tp-queue-rule",
503 ]:
504 qrules.append(db.get_dal(class_name="QueueConnectionRule", uid=rule))
505
506 hosts = []
507 if len(hosts_to_use) == 0:
508 for vhost in db.get_dals(class_name="VirtualHost"):
509 if vhost.id == "vlocalhost":
510 hosts.append(vhost.id)
511 if "vlocalhost" not in hosts:
512 cpus = dal.ProcessingResource("cpus", cpu_cores=[0, 1, 2, 3])
513 db.update_dal(cpus)
514 phdal = dal.PhysicalHost("localhost", contains=[cpus])
515 db.update_dal(phdal)
516 host = dal.VirtualHost("vlocalhost", runs_on=phdal, uses=[cpus])
517 db.update_dal(host)
518 hosts.append("vlocalhost")
519 else:
520 for vhost in db.get_dals(class_name="VirtualHost"):
521 if vhost.id in hosts_to_use:
522 hosts.append(vhost.id)
523 assert len(hosts) > 0
524
525 rohw = dal.RoHwConfig(f"rohw-{detector_connections[0].id}")
526 db.update_dal(rohw)
527
528 opmon_conf = db.get_dal(class_name="OpMonConf", uid="slow-all-monitoring")
529 fragagg = db.get_dal(class_name="FragmentAggregatorConf", uid="frag-agg-01")
530
531 appnum = 0
532 nicrec = None
533 flxcard = None
534 wm_conf = None
535 hermes_conf = None
536 ruapps = []
537 for connection in detector_connections:
538
539 geo_id = connection.get("GeoId")
540 det_id = geo_id[0].detector_id
541 if det_id == 0:
542 raise Exception(f"Unable to determine detector ID from Hardware Map!")
543
544 tphandler = db.get_dal(class_name="DataHandlerConf", uid="def-tp-handler")
545
546 if det_id == 2:
547 if "DAPHNEStream" in emulated_file_name:
548 linkhandler = db.get_dal(
549 class_name="DataHandlerConf", uid="def-pds-stream-link-handler"
550 )
551 det_q = db.get_dal(
552 class_name="QueueConnectionRule", uid="pds-stream-raw-data-rule"
553 )
554 else:
555 linkhandler = db.get_dal(
556 class_name="DataHandlerConf", uid="def-pds-link-handler"
557 )
558 det_q = db.get_dal(
559 class_name="QueueConnectionRule", uid="pds-raw-data-rule"
560 )
561
562 elif det_id == 3 or det_id == 10:
563 linkhandler = db.get_dal(
564 class_name="DataHandlerConf", uid="def-link-handler"
565 )
566 det_q = db.get_dal(
567 class_name="QueueConnectionRule", uid="wib-eth-raw-data-rule"
568 )
569 elif det_id == 11:
570 linkhandler = db.get_dal(
571 class_name="DataHandlerConf", uid="def-tde-link-handler"
572 )
573 det_q = db.get_dal(
574 class_name="QueueConnectionRule", uid="tde-raw-data-rule"
575 )
576 elif det_id == 12:
577 linkhandler = db.get_dal(
578 class_name="DataHandlerConf", uid="def-crt-bern-link-handler"
579 )
580 det_q = db.get_dal(
581 class_name="QueueConnectionRule", uid="crt-bern-raw-data-rule"
582 )
583 elif det_id == 13:
584 linkhandler = db.get_dal(
585 class_name="DataHandlerConf", uid="def-crt-grenoble-link-handler"
586 )
587 det_q = db.get_dal(
588 class_name="QueueConnectionRule", uid="crt-grenoble-raw-data-rule"
589 )
590
591 hostnum = appnum % len(hosts)
592
593 host = db.get_dal(class_name="VirtualHost", uid=hosts[hostnum])
594
595
596 if connection.className() == "NetworkDetectorToDaqConnection":
597 receiver = connection.net_receiver
598 elif connection.className() == "FelixDetectorToDaqConnection":
599 receiver = connection.felix_receiver
600
601
602 readout_start = db.get_dal(class_name="ActionPlan", uid="readout-start")
603 readout_stop = db.get_dal(class_name="ActionPlan", uid="readout-stop")
604
605
606 if type(receiver).__name__ == "FakeDataReceiver":
607 if nicrec == None:
608 try:
609 stream_emu = db.get_dal(
610 class_name="StreamEmulationParameters", uid="stream-emu"
611 )
612 stream_emu.data_file_name = resolve_asset_file(emulated_file_name)
613 db.update_dal(stream_emu)
614 except:
615 stream_emu = dal.StreamEmulationParameters(
616 "stream-emu",
617 data_file_name=resolve_asset_file(emulated_file_name),
618 input_file_size_limit=5777280,
619 set_t0=True,
620 random_population_size=100000,
621 frame_error_rate_hz=0,
622 generate_periodic_adc_pattern=True,
623 TP_rate_per_channel=1,
624 )
625 db.update_dal(stream_emu)
626
627 print("Generating fake DataReaderConf")
628 nicrec = dal.DPDKReaderConf(
629 f"nicrcvr-fake-gen",
630 template_for="FDFakeReaderModule",
631 emulation_mode=1,
632 emulation_conf=stream_emu,
633 )
634 db.update_dal(nicrec)
635 datareader = nicrec
636 elif type(receiver).__name__ == "DPDKReceiver":
637 if nicrec == None:
638 print("Generating DPDKReaderConf")
639 nicrec = dal.DPDKReaderConf(
640 f"nicrcvr-dpdk-gen", template_for="DPDKReaderModule"
641 )
642 db.update_dal(nicrec)
643 if wm_conf == None:
644 try:
645 wm_conf = db.get_dal("WIBModuleConf", "def-wib-conf")
646 except:
647 print(
648 'Expected WIBModuleConf "def-wib-conf" not found in input databases!'
649 )
650 if hermes_conf == None:
651 try:
652 hermes_conf = db.get_dal("HermesModuleConf", "def-hermes-conf")
653 except:
654 print(
655 'Expected HermesModuleConf "def-hermes-conf" not found in input databases!'
656 )
657
658 datareader = nicrec
659
660 wiec_app = dal.WIECApplication(
661 f"wiec-{connection.id}",
662 application_name="daq_application",
663 runs_on=host,
664 detector_connections=[connection],
665 wib_module_conf=wm_conf,
666 hermes_module_conf=hermes_conf,
667 exposes_service=[daqapp_control],
668 )
669 db.update_dal(wiec_app)
670
671 elif type(receiver).__name__ == "FelixInterface":
672 if flxcard == None:
673 print("Generating Felix DataReaderConf")
674 flxcard = dal.DataReaderConf(
675 f"flxConf-1", template_for="FelixReaderModule"
676 )
677 db.update_dal(flxcard)
678 datareader = flxcard
679 elif type(receiver).__name__ == "FileReaderReceiver":
680 if nicrec == None:
681 try:
682 snb_files = db.get_dal(
683 class_name="SNBFileSourceParameters", uid=f"snb-files-{connection.id}"
684 )
685 snb_files.data_files = [resolve_asset_file(emulated_file_name)]
686 db.update_dal(snb_files)
687 except:
688 snb_files = dal.SNBFileSourceParameters(
689 "snb-files-0",
690 data_files=[resolve_asset_file(emulated_file_name)],
691 input_buffer_size=5777280,
692 file_compression_algorithm="None",
693 )
694 db.update_dal(snb_files)
695
696 print("Generating fake DataReaderConf")
697 nicrec = dal.SNBFileReaderConf(
698 f"nicrcvr-file-reader",
699 template_for="SNBFileReaderModule",
700 emulation_mode=1,
701 snb_conf=snb_files,
702 )
703 db.update_dal(nicrec)
704 datareader = nicrec
705
706 print(f"Using SNB DataHandler")
707 linkhandler.template_for = "SNBDataHandlerModule"
708 db.update_dal(linkhandler)
709
710 readout_start = db.get_dal(class_name="ActionPlan", uid="snb-readout-start")
711 readout_stop = db.get_dal(class_name="ActionPlan", uid="snb-readout-stop")
712 else:
713 print(
714 f"ReadoutGroup contains unknown interface type {type(receiver).__name__}"
715 )
716 continue
717
718 db.commit()
719
720
721 dataRequests = db.get_dal(class_name="Service", uid="dataRequests")
722 timeSyncs = db.get_dal(class_name="Service", uid="timeSyncs")
723 triggerActivities = db.get_dal(class_name="Service", uid="triggerActivities")
724 triggerPrimitives = db.get_dal(class_name="Service", uid="triggerPrimitives")
725
726 ru = dal.ReadoutApplication(
727 f"ru-{connection.id}",
728 application_name="daq_application",
729 runs_on=host,
730 detector_connections=[connection],
731 network_rules=netrules,
732 queue_rules=qrules + [det_q],
733 link_handler=linkhandler,
734 data_reader=datareader,
735 fragment_aggregator=fragagg,
736 opmon_conf=opmon_conf,
737 tp_generation_enabled=tpg_enabled,
738 ta_generation_enabled=tpg_enabled,
739 uses=rohw,
740 exposes_service=[daqapp_control, dataRequests, timeSyncs],
741 action_plans=[readout_start, readout_stop],
742 )
743 if tpg_enabled:
744 ru.tp_handler = tphandler
745 tp_sources = []
746 tpbaseid = (appnum * 3) + 100
747
748
749 for plane in range(1 if det_id not in [3, 10, 11] else 3):
750 s_id = tpbaseid + plane
751 tps_dal = dal.SourceIDConf(
752 f"tp-srcid-{s_id}", sid=s_id, subsystem="Trigger"
753 )
754 db.update_dal(tps_dal)
755 tp_sources.append(tps_dal)
756 ru.tp_source_ids = tp_sources
757 ru.exposes_service += [triggerActivities, triggerPrimitives]
758 appnum = appnum + 1
759 print(f"{ru=}")
760 db.update_dal(ru)
761 db.commit()
762 ruapps.append(ru)
763 if appnum == 0:
764 print(f"No ReadoutApplications generated\n")
765 return
766
767 db.commit()
768
769 if generate_segment:
770
771 fsm = db.get_dal(class_name="FSMconfiguration", uid="FSMconfiguration_noAction")
772 controller = dal.RCApplication(
773 "ru-controller",
774 application_name="drunc-controller",
775 runs_on=host,
776 fsm=fsm,
777 opmon_conf=opmon_conf,
778 exposes_service=[rccontroller_control],
779 )
780 db.update_dal(controller)
781 db.commit()
782
783 seg = dal.Segment(f"ru-segment", controller=controller, applications=ruapps)
784 db.update_dal(seg)
785 db.commit()
786
787 db.commit()
788 return
789
790