503 def _generateMenu(self, flags):
504
505 if len(self.l1menu.items) > 0:
506 log.info("L1MenuConfig.generate() has already been called. Will ignore")
507 return
508
509 """
510 Generates the menu structure from the list of item and threshold names in the L1MenuFlags
511 """
512
513
514
515
516 from .Base.BunchGroupSet import createDefaultBunchGroupSet
517 self.l1menu.ctp.bunchGroupSet = createDefaultBunchGroupSet(flags)
518
519
520
521
522
523
524 allBoards = (list(L1MenuFlags.boards().items()) + list(L1MenuFlags.legacyBoards().items()))
525
526 if 'AllCTPIn' in self.menuName:
527
528
529
530 ItemDef.registerItems_AllCTPIn(self)
531
532 for (boardName, boardDef) in L1MenuFlags.legacyBoards().items():
533 for connDef in boardDef["connectors"]:
534
535 if connDef["type"] == "ctpin" and connDef["format"] == "multiplicity":
536 self.l1menu.checkL1CaloThresholds(connDef["thresholds"], boardName, connDef["name"])
537
538 list_of_undefined_thresholds = []
539
540 for (boardName, boardDef) in L1MenuFlags.boards().items():
541 for connDef in boardDef["connectors"]:
542 if connDef["type"] == "ctpin" or connDef["format"] != "multiplicity":
543 continue
544 for thrName in connDef["thresholds"]:
545 if type(thrName)
is tuple:
546 (thrName, _) = thrName
547 if (thrName is None) or (thrName in self.l1menu.thresholds):
548 continue
549 threshold = self.getDefinedThreshold(thrName)
550 if threshold is None:
551 log.error('Threshold %s is required in menu on board %s, connector %s, but it is not defined', thrName, boardName, connDef['name'] )
552 list_of_undefined_thresholds += [ thrName ]
553 else:
554 self.l1menu.addThreshold( threshold )
555 try:
556 zbThrName = connDef["zeroBias"]
557 zbThr = self.getDefinedThreshold(zbThrName)
558 if zbThr is None:
559 log.error('Zero bias threshold %s is listed in menu but not defined', zbThrName )
560 list_of_undefined_thresholds += [ zbThrName ]
561 else:
562 self.l1menu.addThreshold( zbThr )
563 except KeyError:
564 pass
565
566
567
568 for (boardName, boardDef) in L1MenuFlags.boards().items():
569 for connDef in boardDef["connectors"]:
570 if connDef["format"] != "simple":
571 continue
572 for sGrp in connDef["signalGroups"]:
573 for thrName in sGrp["signals"]:
574 if type(thrName)
is tuple:
575 (thrName, _) = thrName
576 if thrName is None or thrName in self.l1menu.thresholds:
577 continue
578 threshold = self.getDefinedThreshold(thrName)
579 if threshold is None:
580 log.error('Threshold %s is required in menu on board %s, connector %s, but it is not defined', thrName, boardName, connDef['name'] )
581 list_of_undefined_thresholds += [ thrName ]
582 else:
583 self.l1menu.addThreshold( threshold )
584
585
586 for (boardName, boardDef) in allBoards:
587 for connDef in boardDef["connectors"]:
588 if connDef["type"] != "ctpin":
589 continue
590 for entry in connDef["thresholds"]:
591 if type(entry)
is dict:
592
593 thrNames = sum([x.outputlines for x in entry["algorithms"]],[])
594 elif type(entry)
is str:
595 thrNames = [ entry ]
596 elif type(entry)
is tuple:
597 thrNames = [ entry[0] ]
598
599 for thrName in thrNames:
600 if thrName is None or thrName in self.l1menu.thresholds:
601 continue
602 threshold = self.getDefinedThreshold(thrName)
603 if threshold is None:
604 log.error('Threshold %s is listed in menu but not defined', thrName )
605 list_of_undefined_thresholds += [ thrName ]
606 else:
607 self.l1menu.addThreshold( threshold )
608 try:
609 zbThrName = connDef["zeroBias"]
610 zbThr = self.getDefinedThreshold(zbThrName)
611 if zbThr is None:
612 log.error('Zero bias threshold %s is listed in menu but not defined', zbThrName )
613 list_of_undefined_thresholds += [ zbThrName ]
614 else:
615 self.l1menu.addThreshold( zbThr )
616 except KeyError:
617 pass
618
619 if len(list_of_undefined_thresholds)>0:
620 raise RuntimeError("Found undefined threshold in menu %s, please add these thresholds to l1menu/ThresholdDef.py: %s" % \
621 (self.l1menu.menuName, ', '.join(list_of_undefined_thresholds)) )
622
623
624
625
626
627
628
629 itemsForMenu = []
630 ctpIdMap = L1MenuFlags.CtpIdMap()
631 for itemName in L1MenuFlags.items():
632 registeredItem = self.getRegisteredItem(itemName)
633 if registeredItem is None:
634 msg = "L1 item '%s' has not been defined in L1/Config/ItemDef.py" % itemName
635 log.error(msg)
636 raise RuntimeError(msg)
637
638 if itemName in ctpIdMap:
639 newCTPID = ctpIdMap[itemName]
640 registeredItem.setCtpid(newCTPID)
641
642 for thrName in registeredItem.thresholdNames():
643 if thrName not in self.l1menu.thresholds:
644 isLegacyThr = any(filter(lambda x: thrName.startswith(x), ["R2TOPO_", "EM", "HA", "J", "XE", "TE", "XS"]))
645
646 msg = "L1 item {item} has been added to the menu L1/Menu/Menu_{menu}.py, but the required threshold {thr} is not listed as input in L1/Menu/Menu_{menu_inputs}.py".format(item=itemName, thr=thrName, menu=self.menuFilesToLoad[0], menu_inputs=self.menuFilesToLoad[2] if isLegacyThr else self.menuFilesToLoad[1])
647 log.error(msg)
648 raise RuntimeError(msg)
649
650 itemsForMenu += [ registeredItem ]
651
652
653
654
655 assigned_ctpids =
set([item.ctpid
for item
in itemsForMenu])
656 available_ctpids = sorted( list(
set(range(Limits.MaxTrigItems)) - assigned_ctpids ), reverse=
True )
657
658
659 for item in itemsForMenu:
660
661 if not item.name.startswith('L1_CALREQ'):
662 item.setTriggerType( item.trigger_type | TT.phys )
663
664 if item.ctpid == -1:
665 if len(available_ctpids)==0:
666 raise RuntimeError("No more CTP IDs available at L1!!")
667 item.setCtpid( available_ctpids.pop() )
668
669 self.l1menu.addItem( item )
670
671
672
673
674
675 for (boardName, boardDef) in allBoards:
676 for connDef in boardDef["connectors"]:
677 self.l1menu.addConnector( connDef )
678
679
680
681
682
683 for (boardName, boardDef) in allBoards:
684 self.l1menu.addBoard(boardDef)
685
686
687
688
689 legacyThresholdsSet =
set()
690 for conn in self.l1menu.connectors:
691 if not conn.isLegacy():
692 continue
693 legacyThresholdsSet.update(conn.triggerThresholds())
694 for item in self.l1menu.items:
695 item.markLegacy(legacyThresholdsSet)
696
697
698
699 self.mapThresholds()
700
701
702
703
704 self.l1menu.ctp.checkConnectorAvailability(self.l1menu.connectors, self.menuFilesToLoad[0])
705
706
707 if 'run4' not in self.menuName:
708 self.l1menu.setupCTPMonitoring()
709
710
711
712
713
714 self.l1menu.check()
715
716
717 self.l1menu.checkBGRP()
718
719
720 if 'pp' in self.l1menu.menuName:
721 self.l1menu.checkLegacyThresholds()
722
723
724
725 TopoAlgoDefMultiplicity.checkMultAlgoFWconstraints(self.l1menu)
726
727
728 self.l1menu.checkCountCTPInputsOutput()
729
730
731 self.l1menu.checkCTPINconnectors()
732
733
734 self.l1menu.checkPerfThresholds()
735
736
737 self.l1menu.checkPtMinToTopo()
738
739
740 self.l1menu.checkL1TopoParams()
741
742
743 self.l1menu.checkItemsHaveInputs()
744
745
746 self.l1menu.checkTOPObits()
747
748
749 if 'PhysicsP1' in self.menuFullName:
750 self.l1menu.checkHFmonitoring()
751