503 def _generateMenu(self, flags):
505 if len(self.l1menu.items) > 0:
506 log.info(
"L1MenuConfig.generate() has already been called. Will ignore")
510 Generates the menu structure from the list of item and threshold names in the L1MenuFlags
516 from .Base.BunchGroupSet
import createDefaultBunchGroupSet
524 allBoards = (
list(L1MenuFlags.boards().
items()) +
list(L1MenuFlags.legacyBoards().
items()))
526 if 'AllCTPIn' in self.menuName:
530 ItemDef.registerItems_AllCTPIn(self)
532 for (boardName, boardDef)
in L1MenuFlags.legacyBoards().
items():
533 for connDef
in boardDef[
"connectors"]:
535 if connDef[
"type"] ==
"ctpin" and connDef[
"format"] ==
"multiplicity":
536 self.l1menu.checkL1CaloThresholds(connDef[
"thresholds"], boardName, connDef[
"name"])
538 list_of_undefined_thresholds = []
540 for (boardName, boardDef)
in L1MenuFlags.boards().
items():
541 for connDef
in boardDef[
"connectors"]:
542 if connDef[
"type"] ==
"ctpin" or connDef[
"format"] !=
"multiplicity":
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):
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 ]
554 self.l1menu.addThreshold( threshold )
556 zbThrName = connDef[
"zeroBias"]
557 zbThr = self.getDefinedThreshold(zbThrName)
559 log.error(
'Zero bias threshold %s is listed in menu but not defined', zbThrName )
560 list_of_undefined_thresholds += [ zbThrName ]
562 self.l1menu.addThreshold( zbThr )
568 for (boardName, boardDef)
in L1MenuFlags.boards().
items():
569 for connDef
in boardDef[
"connectors"]:
570 if connDef[
"format"] !=
"simple":
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:
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 ]
583 self.l1menu.addThreshold( threshold )
586 for (boardName, boardDef)
in allBoards:
587 for connDef
in boardDef[
"connectors"]:
588 if connDef[
"type"] !=
"ctpin":
590 for entry
in connDef[
"thresholds"]:
591 if type(entry)
is dict:
593 thrNames =
sum([x.outputlines
for x
in entry[
"algorithms"]],[])
594 elif type(entry)
is str:
596 elif type(entry)
is tuple:
597 thrNames = [ entry[0] ]
599 for thrName
in thrNames:
600 if thrName
is None or thrName
in self.l1menu.thresholds:
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 ]
607 self.l1menu.addThreshold( threshold )
609 zbThrName = connDef[
"zeroBias"]
610 zbThr = self.getDefinedThreshold(zbThrName)
612 log.error(
'Zero bias threshold %s is listed in menu but not defined', zbThrName )
613 list_of_undefined_thresholds += [ zbThrName ]
615 self.l1menu.addThreshold( zbThr )
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)) )
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
636 raise RuntimeError(msg)
638 if itemName
in ctpIdMap:
639 newCTPID = ctpIdMap[itemName]
640 registeredItem.setCtpid(newCTPID)
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"]))
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])
648 raise RuntimeError(msg)
650 itemsForMenu += [ registeredItem ]
655 assigned_ctpids =
set([item.ctpid
for item
in itemsForMenu])
656 available_ctpids =
sorted(
list(
set(
range(Limits.MaxTrigItems)) - assigned_ctpids ), reverse=
True )
659 for item
in itemsForMenu:
661 if not item.name.startswith(
'L1_CALREQ'):
662 item.setTriggerType( item.trigger_type | TT.phys )
665 if len(available_ctpids)==0:
666 raise RuntimeError(
"No more CTP IDs available at L1!!")
667 item.setCtpid( available_ctpids.pop() )
669 self.l1menu.addItem( item )
675 for (boardName, boardDef)
in allBoards:
676 for connDef
in boardDef[
"connectors"]:
677 self.l1menu.addConnector( connDef )
683 for (boardName, boardDef)
in allBoards:
684 self.l1menu.addBoard(boardDef)
689 legacyThresholdsSet =
set()
690 for conn
in self.l1menu.connectors:
691 if not conn.isLegacy():
693 legacyThresholdsSet.update(conn.triggerThresholds())
694 for item
in self.l1menu.items:
695 item.markLegacy(legacyThresholdsSet)
704 self.l1menu.ctp.checkConnectorAvailability(self.l1menu.connectors, self.menuFilesToLoad)
707 self.l1menu.setupCTPMonitoring()
716 self.l1menu.checkBGRP()
719 if 'pp' in self.l1menu.menuName:
720 self.l1menu.checkLegacyThresholds()
724 TopoAlgoDefMultiplicity.checkMultAlgoFWconstraints(self.l1menu)
727 self.l1menu.checkCountCTPInputsOutput()
730 self.l1menu.checkCTPINconnectors()
733 self.l1menu.checkPerfThresholds()
736 self.l1menu.checkPtMinToTopo()
739 self.l1menu.checkL1TopoParams()
742 self.l1menu.checkItemsHaveInputs()