502 def _generateMenu(self, flags):
504 if len(self.l1menu.items) > 0:
505 log.info(
"L1MenuConfig.generate() has already been called. Will ignore")
509 Generates the menu structure from the list of item and threshold names in the L1MenuFlags
515 from .Base.BunchGroupSet
import createDefaultBunchGroupSet
523 allBoards = (
list(L1MenuFlags.boards().
items()) +
list(L1MenuFlags.legacyBoards().
items()))
525 if 'AllCTPIn' in self.menuName:
529 ItemDef.registerItems_AllCTPIn(self)
531 for (boardName, boardDef)
in L1MenuFlags.legacyBoards().
items():
532 for connDef
in boardDef[
"connectors"]:
534 if connDef[
"type"] ==
"ctpin" and connDef[
"format"] ==
"multiplicity":
535 self.l1menu.checkL1CaloThresholds(connDef[
"thresholds"], boardName, connDef[
"name"])
537 list_of_undefined_thresholds = []
539 for (boardName, boardDef)
in L1MenuFlags.boards().
items():
540 for connDef
in boardDef[
"connectors"]:
541 if connDef[
"type"] ==
"ctpin" or connDef[
"format"] !=
"multiplicity":
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):
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 ]
553 self.l1menu.addThreshold( threshold )
555 zbThrName = connDef[
"zeroBias"]
556 zbThr = self.getDefinedThreshold(zbThrName)
558 log.error(
'Zero bias threshold %s is listed in menu but not defined', zbThrName )
559 list_of_undefined_thresholds += [ zbThrName ]
561 self.l1menu.addThreshold( zbThr )
567 for (boardName, boardDef)
in L1MenuFlags.boards().
items():
568 for connDef
in boardDef[
"connectors"]:
569 if connDef[
"format"] !=
"simple":
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:
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 ]
582 self.l1menu.addThreshold( threshold )
585 for (boardName, boardDef)
in allBoards:
586 for connDef
in boardDef[
"connectors"]:
587 if connDef[
"type"] !=
"ctpin":
589 for entry
in connDef[
"thresholds"]:
590 if type(entry)
is dict:
592 thrNames =
sum([x.outputlines
for x
in entry[
"algorithms"]],[])
593 elif type(entry)
is str:
595 elif type(entry)
is tuple:
596 thrNames = [ entry[0] ]
598 for thrName
in thrNames:
599 if thrName
is None or thrName
in self.l1menu.thresholds:
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 ]
606 self.l1menu.addThreshold( threshold )
608 zbThrName = connDef[
"zeroBias"]
609 zbThr = self.getDefinedThreshold(zbThrName)
611 log.error(
'Zero bias threshold %s is listed in menu but not defined', zbThrName )
612 list_of_undefined_thresholds += [ zbThrName ]
614 self.l1menu.addThreshold( zbThr )
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)) )
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
635 raise RuntimeError(msg)
637 if itemName
in ctpIdMap:
638 newCTPID = ctpIdMap[itemName]
639 registeredItem.setCtpid(newCTPID)
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"]))
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])
647 raise RuntimeError(msg)
649 itemsForMenu += [ registeredItem ]
654 assigned_ctpids =
set([item.ctpid
for item
in itemsForMenu])
655 available_ctpids =
sorted(
list(
set(
range(Limits.MaxTrigItems)) - assigned_ctpids ), reverse=
True )
658 for item
in itemsForMenu:
660 if not item.name.startswith(
'L1_CALREQ'):
661 item.setTriggerType( item.trigger_type | TT.phys )
664 if len(available_ctpids)==0:
665 raise RuntimeError(
"No more CTP IDs available at L1!!")
666 item.setCtpid( available_ctpids.pop() )
668 self.l1menu.addItem( item )
674 for (boardName, boardDef)
in allBoards:
675 for connDef
in boardDef[
"connectors"]:
676 self.l1menu.addConnector( connDef )
682 for (boardName, boardDef)
in allBoards:
683 self.l1menu.addBoard(boardDef)
688 legacyThresholdsSet =
set()
689 for conn
in self.l1menu.connectors:
690 if not conn.isLegacy():
692 legacyThresholdsSet.update(conn.triggerThresholds())
693 for item
in self.l1menu.items:
694 item.markLegacy(legacyThresholdsSet)
703 self.l1menu.ctp.checkConnectorAvailability(self.l1menu.connectors, self.menuFilesToLoad)
706 self.l1menu.setupCTPMonitoring()
715 self.l1menu.checkBGRP()
718 if 'pp' in self.l1menu.menuName:
719 self.l1menu.checkLegacyThresholds()
723 TopoAlgoDefMultiplicity.checkMultAlgoFWconstraints(self.l1menu)
726 self.l1menu.checkCountCTPInputsOutput()
729 self.l1menu.checkCTPINconnectors()
732 self.l1menu.checkPerfThresholds()
735 self.l1menu.checkPtMinToTopo()
738 self.l1menu.checkL1TopoParams()
741 self.l1menu.checkItemsHaveInputs()
744 self.l1menu.checkTOPObits()
747 if 'PhysicsP1' in self.menuFullName:
748 self.l1menu.checkHFmonitoring()