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