466 def _generateMenu(self, flags):
467
468 if len(self.l1menu.items) > 0:
469 log.info("L1MenuConfig.generate() has already been called. Will ignore")
470 return
471
472 """
473 Generates the menu structure from the list of item and threshold names in the L1MenuFlags
474 """
475
476
477
478
479 from .Base.BunchGroupSet import createDefaultBunchGroupSet
480 self.l1menu.ctp.bunchGroupSet = createDefaultBunchGroupSet(flags)
481
482
483
484
485 allBoards = (list(L1MenuFlags.boards().items()) + list(L1MenuFlags.legacyBoards().items()))
486
487 if self.menuInfo.menuPurpose == MenuMetaInfo.MenuType.ALLCTPIN:
488
489
490
491 ItemDef.registerItems_AllCTPIn(self)
492
493 for (boardName, boardDef) in L1MenuFlags.legacyBoards().items():
494 for connDef in boardDef["connectors"]:
495
496 if connDef["type"] == "ctpin" and connDef["format"] == "multiplicity":
497 self.l1menu.checkL1CaloThresholds(connDef["thresholds"], boardName, connDef["name"])
498
499 list_of_undefined_thresholds = []
500
501 for (boardName, boardDef) in L1MenuFlags.boards().items():
502 for connDef in boardDef["connectors"]:
503 if connDef["type"] == "ctpin" or connDef["format"] != "multiplicity":
504 continue
505 for thrName in connDef["thresholds"]:
506 if type(thrName)
is tuple:
507 (thrName, _) = thrName
508 if (thrName is None) or (thrName in self.l1menu.thresholds):
509 continue
510 threshold = self.getDefinedThreshold(thrName)
511 if threshold is None:
512 log.error('Threshold %s is required in menu on board %s, connector %s, but it is not defined',
513 thrName, boardName, connDef['name'])
514 list_of_undefined_thresholds += [thrName]
515 else:
516 self.l1menu.addThreshold(threshold)
517 try:
518 zbThrName = connDef["zeroBias"]
519 zbThr = self.getDefinedThreshold(zbThrName)
520 if zbThr is None:
521 log.error('Zero bias threshold %s is listed in menu but not defined', zbThrName)
522 list_of_undefined_thresholds += [zbThrName]
523 else:
524 self.l1menu.addThreshold(zbThr)
525 except KeyError:
526 pass
527
528
529 for (boardName, boardDef) in L1MenuFlags.boards().items():
530 for connDef in boardDef["connectors"]:
531 if connDef["format"] != "simple":
532 continue
533 for sGrp in connDef["signalGroups"]:
534 for thrName in sGrp["signals"]:
535 if type(thrName)
is tuple:
536 (thrName, _) = thrName
537 if thrName is None or thrName in self.l1menu.thresholds:
538 continue
539 threshold = self.getDefinedThreshold(thrName)
540 if threshold is None:
541 log.error('Threshold %s is required in menu on board %s, connector %s, but it is not defined',
542 thrName, boardName, connDef['name'])
543 list_of_undefined_thresholds += [thrName]
544 else:
545 self.l1menu.addThreshold(threshold)
546
547
548 for (_, boardDef) in allBoards:
549 for connDef in boardDef["connectors"]:
550 if connDef["type"] != "ctpin":
551 continue
552 for entry in connDef["thresholds"]:
553 thrNames = []
554 if type(entry)
is dict:
555
556 thrNames = sum([x.outputlines for x in entry["algorithms"]], [])
557 elif type(entry)
is str:
558 thrNames = [entry]
559 elif type(entry)
is tuple:
560 thrNames = [entry[0]]
561
562 for thrName in thrNames:
563 if thrName is None or thrName in self.l1menu.thresholds:
564 continue
565 threshold = self.getDefinedThreshold(thrName)
566 if threshold is None:
567 log.error('Threshold %s is listed in menu but not defined', thrName)
568 list_of_undefined_thresholds += [thrName]
569 else:
570 self.l1menu.addThreshold(threshold)
571 try:
572 zbThrName = connDef["zeroBias"]
573 zbThr = self.getDefinedThreshold(zbThrName)
574 if zbThr is None:
575 log.error('Zero bias threshold %s is listed in menu but not defined', zbThrName)
576 list_of_undefined_thresholds += [zbThrName]
577 else:
578 self.l1menu.addThreshold(zbThr)
579 except KeyError:
580 pass
581
582 if len(list_of_undefined_thresholds) > 0:
583 raise RuntimeError("Found undefined threshold in menu %s, please add these thresholds to l1menu/ThresholdDef.py: %s" %
584 (self.l1menu.menuName, ', '.join(list_of_undefined_thresholds)))
585
586
587
588
589
590 itemsForMenu = []
591 ctpIdMap = L1MenuFlags.CtpIdMap()
592 for itemName in L1MenuFlags.items():
593 registeredItem = self.getRegisteredItem(itemName)
594 if registeredItem is None:
595 msg = f"L1 item '{itemName}' has not been defined in L1/Config/ItemDef{'Run4' if L1MenuFlags.Run() == 4 else ''}.py"
596 log.error(msg)
597 raise RuntimeError(msg)
598
599 if itemName in ctpIdMap:
600 newCTPID = ctpIdMap[itemName]
601 registeredItem.setCtpid(newCTPID)
602
603 for thrName in registeredItem.thresholdNames():
604 if thrName not in self.l1menu.thresholds:
605 msg = (
606 f"L1 item {itemName} has been added to the menu L1/Menu/Menu_{self.menuInfo.menuFile}.py, "
607 f"but the required threshold {thrName} is not listed as input in L1/Menu/Menu_{self.menuInfo.menuInputFile}.py"
608 )
609 log.error(msg)
610 raise RuntimeError(msg)
611
612 itemsForMenu += [registeredItem]
613
614
615 assigned_ctpids =
set([item.ctpid
for item
in itemsForMenu])
616 available_ctpids = sorted(list(
set(range(Limits.MaxTrigItems)) - assigned_ctpids), reverse=
True)
617
618
619 for item in itemsForMenu:
620
621 if not item.name.startswith('L1_CALREQ'):
622 item.setTriggerType(item.trigger_type | TT.phys)
623
624 if item.ctpid == -1:
625 if len(available_ctpids) == 0:
626 raise RuntimeError("No more CTP IDs available at L1!!")
627 item.setCtpid(available_ctpids.pop())
628
629 self.l1menu.addItem(item)
630
631
632
633
634
635 for (_, boardDef) in allBoards:
636 for connDef in boardDef["connectors"]:
637 self.l1menu.addConnector(connDef)
638
639
640
641
642
643 for (_, boardDef) in allBoards:
644 self.l1menu.addBoard(boardDef)
645
646
647
648
649 legacyThresholdsSet =
set()
650 for conn in self.l1menu.connectors:
651 if not conn.isLegacy():
652 continue
653 legacyThresholdsSet.update(conn.triggerThresholds())
654 for item in self.l1menu.items:
655 item.markLegacy(legacyThresholdsSet)
656
657
658 self.mapThresholds()
659
660
661
662
663 self.l1menu.ctp.checkConnectorAvailability(self.l1menu.connectors, self.menuInfo.menuInputFile)
664
665
666 self.l1menu.setupCTPMonitoring()
667
668
669
670
671
672 self.l1menu.check()
673
674
675 self.l1menu.checkBGRP()
676
677
678 if 'pp' in self.l1menu.menuName:
679 self.l1menu.checkLegacyThresholds()
680
681
682
683 TopoAlgoDefMultiplicity.checkMultAlgoFWconstraints(self.l1menu)
684
685
686 self.l1menu.checkCountCTPInputsOutput()
687
688
689 self.l1menu.checkCTPINconnectors()
690
691
692 self.l1menu.checkPerfThresholds()
693
694
695 self.l1menu.checkItemsHaveInputs()
696
697
698 self.l1menu.checkTOPObits()
699
700
701 if 'PhysicsP1' in self.menuFullName:
702 self.l1menu.checkHFmonitoring()
703