ATLAS Offline Software
Loading...
Searching...
No Matches
python.L1.L1MenuConfigRun4.L1MenuConfigRun4 Class Reference
Collaboration diagram for python.L1.L1MenuConfigRun4.L1MenuConfigRun4:

Public Member Functions

 __init__ (self, AthConfigFlags flags, Path|None inputFile=None)
 run (self)
bool thresholdExists (self, str thrName)
Threshold|None getDefinedThreshold (self, str name)
Iterator[Threshold] getDefinedThresholds (self)
 registerGlobalAlgo (self, GlobalAlgorithm algo)
 registration of available components
 registerThreshold (self, Threshold thr)
 registerItem (self, str name, MenuItem item)
MenuItem|None getRegisteredItem (self, str name)
 writeJSON (self, outputFile, bgsOutputFile=None, Path destdir=Path("./"))
 mapThresholds (self)
 updateItemPrescales (self)

Public Attributes

str menuFullName = flags.Trigger.triggerMenuSetup
MenuMetaInfo menuInfo = self._menuResolution(self.menuFullName)
str menuName = self.menuInfo.menuBaseName
Path|None inputFile = inputFile
tuple l1menuFromFile = (self.inputFile is not None)
bool isMenuGenerated = False
 l1menu = L1MenuRun4(menuInfo=self.menuInfo, flags=flags)

Protected Member Functions

 _generate (self, AthConfigFlags flags)
 _registerGlobalOutputsAsThresholds (self)
bool _checkMenuExistence (self)
 _importMenuDefinition (self)
 _registerAvailableItemsThresholdsAlgorithms (self)
 _printRegisteredThresholdInfo (self)
 _getGlobalAlgo (self, str algoName)
 _extendInformation (self)
 _generateGlobalHypoMenu (self)
 _generateGlobalMenu (self)
 _generateMenu (self, flags)
 _getMenuBaseName (self, menuName)

Static Protected Member Functions

MenuMetaInfo _menuResolution (str fullMenuName)

Protected Attributes

dict _registeredItems = {}
dict _registeredThresholds = {}
dict _registeredGlobalAlgos = {}
dict _registeredThresholdsStats

Detailed Description

Definition at line 57 of file L1MenuConfigRun4.py.

Constructor & Destructor Documentation

◆ __init__()

python.L1.L1MenuConfigRun4.L1MenuConfigRun4.__init__ ( self,
AthConfigFlags flags,
Path | None inputFile = None )

Definition at line 59 of file L1MenuConfigRun4.py.

59 def __init__(self, flags: AthConfigFlags, inputFile: Path | None = None):
60
61 self.menuFullName: str = flags.Trigger.triggerMenuSetup
62 self.menuInfo: MenuMetaInfo = self._menuResolution(self.menuFullName)
63 self.menuName: str = self.menuInfo.menuBaseName
64 self.inputFile: Path | None = inputFile
65 self.l1menuFromFile: bool = (self.inputFile is not None)
66 self.isMenuGenerated: bool = False
67
68 L1MenuFlags.MenuSetup = self.menuFullName
69 L1MenuFlags.Run = 4
70 L1MenuFlags.CTPVersion = 4
71
72 # menu
73 self.l1menu = L1MenuRun4(menuInfo=self.menuInfo, flags=flags)
74
75 if not self._checkMenuExistence():
76 log.error("Generating L1 menu %s is not possible", self.menuInfo.menuBaseName)
77 raise RuntimeError("Generating L1 menu is not possible, menu file does not exist")
78
79 # all registered items
80 self._registeredItems: dict[str, MenuItem] = {}
81
82 # all registered thresholds
83 self._registeredThresholds: dict[str, Threshold] = {}
84
85 # all registered global algos
86 self._registeredGlobalAlgos: dict[str, Any] = {}
87
88 # threshold statistics
89 self._registeredThresholdsStats: dict[str, int] = {
90 "muon": 0,
91 "calo": 0,
92 "nim": 0,
93 "global": 0
94 }
95
96 self._generate(flags)
97

Member Function Documentation

◆ _checkMenuExistence()

bool python.L1.L1MenuConfigRun4.L1MenuConfigRun4._checkMenuExistence ( self)
protected
Checks if menu file can exists

Definition at line 262 of file L1MenuConfigRun4.py.

262 def _checkMenuExistence(self) -> bool:
263 """Checks if menu file can exists"""
264 modname = f'TriggerMenuMT.L1.Menu.Menu_{self.menuInfo.menuFile}'
265 if not moduleExists(modname):
266 log.error("No L1 menu available for %s, module %s does not exist", self.menuInfo.menuBaseName, modname)
267 return False
268
269 return True
270

◆ _extendInformation()

python.L1.L1MenuConfigRun4.L1MenuConfigRun4._extendInformation ( self)
protected
this function is called first after the menu definition is imported
it can be used to update some of the information or to perform initial checks

Definition at line 357 of file L1MenuConfigRun4.py.

357 def _extendInformation(self):
358 """
359 this function is called first after the menu definition is imported
360 it can be used to update some of the information or to perform initial checks
361 """
362 allBoards = (list(L1MenuFlags.boards().items()) + list(L1MenuFlags.legacyBoards().items()))
363 # set boardName in each connector
364 for (boardName, boardDef) in allBoards:
365 boardDef["name"] = boardName
366 if "connectors" in boardDef:
367 for connDef in boardDef["connectors"]:
368 connDef["board"] = boardName
369 else:
370 for connDef in boardDef["inputConnectors"]:
371 connDef["board"] = boardName
372

◆ _generate()

python.L1.L1MenuConfigRun4.L1MenuConfigRun4._generate ( self,
AthConfigFlags flags )
protected

Definition at line 102 of file L1MenuConfigRun4.py.

102 def _generate(self, flags: AthConfigFlags):
103
104 log.info("=== Generating L1 menu %s ===", self.menuInfo.menuBaseName)
105
106 log.info("=== Registering definitions of algorithms, thresholds, and items ===")
107
108 self._registerAvailableItemsThresholdsAlgorithms()
109
110 log.info("=== Loading definition of menu ===")
111
112 # Build menu
113
114 # puts thresholds and items names for the menu into the LVL1Flags
115 self._importMenuDefinition()
116
117 self._extendInformation()
118
119 self._generateGlobalHypoMenu()
120
121 self._generateMenu(flags)
122
123 self.isMenuGenerated = True
124

◆ _generateGlobalHypoMenu()

python.L1.L1MenuConfigRun4.L1MenuConfigRun4._generateGlobalHypoMenu ( self)
protected

Definition at line 373 of file L1MenuConfigRun4.py.

373 def _generateGlobalHypoMenu(self):
374 log.info("Generating GlobalHypo menu")
375 boardDef = L1MenuFlags.boards()["Global"]
376 connDef = boardDef["connectors"][0]
377 for thr in connDef['thresholds']:
378 if isinstance(thr, tuple):
379 thrName = thr[0]
380 else:
381 thrName = thr
382 thrDef = self.getDefinedThreshold(thrName)
383 if thrDef is None:
384 msg = (
385 f'Threshold {thrName} is required by L1Global to provide output to CTP, specified in connector {connDef["name"]} '
386 f'in file L1/Menu/Menu_{self.menuInfo.menuInputFile}.py), but it is not defined. '
387 f'Please add the threshold {thrName.split("_", 1)[-1]} to L1/Config/ThresholdDefRun4.py or L1/Config/GlobalHypoAlgoDef.py.'
388 )
389 log.error(msg)
390 raise RuntimeError(msg)
391
392 self.l1menu.addThreshold(thrDef)
393
394 algoName = "Mult_" + thrName
395 algo = self._getGlobalAlgo(algoName)
396 self.l1menu.addGlobalAlgo(algo)
397

◆ _generateGlobalMenu()

python.L1.L1MenuConfigRun4.L1MenuConfigRun4._generateGlobalMenu ( self)
protected

Definition at line 398 of file L1MenuConfigRun4.py.

398 def _generateGlobalMenu(self):
399
400 boardName = "Global"
401 boardDef: dict[str, Any] = L1MenuFlags.boards().get(boardName, {})
402
403 #
404 # Add the global thresholds to the menu
405 #
406 nAlgos = 0
407 nLines = 0
408 for connDef in boardDef["connectors"]:
409 for algGrp in connDef["algorithmGroups"]:
410 for topodef in algGrp["algorithms"]:
411 nAlgos += 1
412 nLines += len(topodef.outputlines)
413 # this is identical to outputlines except that ["MULT-CMU4ab[0]", "MULT-CMU4ab[1]"] becomes [ "MULT-CMU4ab" ]
414 outputlines = list(dict.fromkeys(map(lambda x: re.split(r"\‍[\d\‍]", x)[0], topodef.outputlines)))
415 for lineName in outputlines:
416 thrName = lineName
417 thr = self.getDefinedThreshold(thrName) # threshold has to be registered
418 if thr is None:
419 msg = 'Global threshold %s is required in Global2CTP connector %s (file L1/Menu/Menu_%s.py), but it is not registered. ' % (thrName, connDef['name'], self.menuInfo.menuInputFile)
420 msg += 'Please add the threshold output %s to L1/Config/ThresholdDefRun4.py or L1/Config/GlobalHypoAlgoDef.py.' % (thrName.split('_', 1)[-1])
421 log.error(msg)
422 raise RuntimeError(msg)
423 self.l1menu.addThreshold(thr)
424 log.info("Generating global menu using %i global algorithms with %i trigger lines", nAlgos, nLines)
425
426 #
427 # Add the global algorithms to the menu
428 #
429
430 # loop over all topo boards and their connectors
431 for connDef in boardDef["connectors"]:
432
433 algoNames = []
434 algoNbits = []
435 fpgaNames = []
436 if connDef["format"] == 'multiplicity':
437 for thrName in connDef["thresholds"]:
438 if thrName is None:
439 continue
440 nBits = connDef["nbitsDefault"]
441 if type(thrName) is tuple:
442 (thrName, nBits) = thrName
443 if thrName is None:
444 continue
445 algoname = "Mult_" + thrName
446 algoNames += [algoname]
447 algoNbits += [int(nBits)]
448 fpgaNames += ['']
449 elif connDef["format"] == 'topological':
450 for algGrp in connDef["algorithmGroups"]:
451 for topodef in algGrp["algorithms"]:
452 algoNames += [topodef.algoname]
453 algoNbits += [-1]
454 fpgaNames += [str(algGrp['fpga'])]
455 for algoName, algoBits, fpgaName in zip(algoNames, algoNbits, fpgaNames):
456 algo = self._getGlobalAlgo(algoName)
457 # check that the output bits of the multiplicity topo algorithms are as many as the output bits of the associated thresholds
458 if algoBits > 0:
459 if algoBits != algo.nbits:
460 msg = "Algorithm %s defined with %i bits, but the associated threshold has %i bits " % (algo.name, algo.nbits, algoBits)
461 raise RuntimeError(msg)
462 self.l1menu.checkBoardInputs(algo, connDef["name"], fpgaName)
463 # add the decision algorithms to the menu
464 self.l1menu.addGlobalAlgo(algo)
465
STL class.
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition hcg.cxx:132

◆ _generateMenu()

python.L1.L1MenuConfigRun4.L1MenuConfigRun4._generateMenu ( self,
flags )
protected

Definition at line 466 of file L1MenuConfigRun4.py.

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 # Bunchgroups
478 # ------------------
479 from .Base.BunchGroupSet import createDefaultBunchGroupSet
480 self.l1menu.ctp.bunchGroupSet = createDefaultBunchGroupSet(flags)
481
482 # ------------------
483 # Thresholds
484 # ------------------
485 allBoards = (list(L1MenuFlags.boards().items()) + list(L1MenuFlags.legacyBoards().items()))
486
487 if self.menuInfo.menuPurpose == MenuMetaInfo.MenuType.ALLCTPIN:
488 # Only after we know all boards are defined, in the special case
489 # that we are running the dummy L1 menu for CTP input configuration
490 # we need to register more items that access every input
491 ItemDef.registerItems_AllCTPIn(self)
492
493 for (boardName, boardDef) in L1MenuFlags.legacyBoards().items():
494 for connDef in boardDef["connectors"]:
495 # Verify number and ordering of thresholds on L1Calo boards
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 # new thresholds
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 # signals from merger boards
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 # ctpin thresholds
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 # section that defines topo legacy thresholds
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 # Items
588 # ------------------
589 # build list of items for the menu from the list of requested names
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 # CTP IDs available for assignment
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 # add the items to the menu
619 for item in itemsForMenu:
620 # set the physics bit
621 if not item.name.startswith('L1_CALREQ'):
622 item.setTriggerType(item.trigger_type | TT.phys)
623 # assign ctp IDs to items that don't have one
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 # add the items into the menu
629 self.l1menu.addItem(item)
630
631 # ------------------
632 # Connectors
633 # ------------------
634
635 for (_, boardDef) in allBoards:
636 for connDef in boardDef["connectors"]:
637 self.l1menu.addConnector(connDef)
638
639 # ------------------
640 # Boards
641 # ------------------
642
643 for (_, boardDef) in allBoards:
644 self.l1menu.addBoard(boardDef)
645
646 # ------------------
647 # Mark items legacy
648 # ------------------
649 legacyThresholdsSet = set() # determine from connectors
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 # assign mapping to thresholds according to their use in the menu
658 self.mapThresholds()
659
660 # ------------------
661 # CTP
662 # ------------------
663 self.l1menu.ctp.checkConnectorAvailability(self.l1menu.connectors, self.menuInfo.menuInputFile)
664
665 # set the ctp monitoring (only now after the menu is defined)
666 self.l1menu.setupCTPMonitoring()
667
668 # ------------------
669 # final consistency check
670 # ------------------
671
672 self.l1menu.check()
673
674 # check that no L1 items are defined with BGRP0 only
675 self.l1menu.checkBGRP()
676
677 # check that only the minimal set of legacy and detector thresholds is used
678 if 'pp' in self.l1menu.menuName:
679 self.l1menu.checkLegacyThresholds()
680
681 # check for the topo multiplicity algorithms and CTP inputs
682 # TOPO1
683 TopoAlgoDefMultiplicity.checkMultAlgoFWconstraints(self.l1menu)
684
685 # check #number of CTP inputs and outputs <=512
686 self.l1menu.checkCountCTPInputsOutput()
687
688 # check #number of inputs on the CTPIN connectors
689 self.l1menu.checkCTPINconnectors()
690
691 # check that performance thresholds are not used in the physics L1 menu
692 self.l1menu.checkPerfThresholds()
693
694 # check that every item in the menu is on a board connected to CTP
695 self.l1menu.checkItemsHaveInputs()
696
697 # check TOPO bits
698 self.l1menu.checkTOPObits()
699
700 # check that items essential for detector operations are monitored
701 if 'PhysicsP1' in self.menuFullName:
702 self.l1menu.checkHFmonitoring()
703
STL class.

◆ _getGlobalAlgo()

python.L1.L1MenuConfigRun4.L1MenuConfigRun4._getGlobalAlgo ( self,
str algoName )
protected

Definition at line 349 of file L1MenuConfigRun4.py.

349 def _getGlobalAlgo(self, algoName: str):
350 if algoName in self._registeredGlobalAlgos:
351 return self._registeredGlobalAlgos[algoName]
352 msg = f"Global algorithm of name {algoName} is not registered. Please add the algorithm to L1/Config/GlobalAlgoDef.py"
353 log.error(msg)
354 log.info("Available algorithms in this category are %s", ",".join(self._registeredGlobalAlgos.keys()))
355 raise RuntimeError(msg)
356

◆ _getMenuBaseName()

python.L1.L1MenuConfigRun4.L1MenuConfigRun4._getMenuBaseName ( self,
menuName )
protected

Definition at line 739 of file L1MenuConfigRun4.py.

739 def _getMenuBaseName(self, menuName):
740 pattern = re.compile(r'_v\d+|DC14')
741 patternPos = pattern.search(menuName)
742 if patternPos:
743 menuName = menuName[:patternPos.end()]
744 else:
745 log.info('Can\'t find pattern to shorten menu name, either non-existent in name or not implemented.')
746 return menuName

◆ _importMenuDefinition()

python.L1.L1MenuConfigRun4.L1MenuConfigRun4._importMenuDefinition ( self)
protected
Defines the list if item and threshold names that will be in the menu
Calls defineMenu() of the correct module 'Menu_<menuname>.py'
Menu.defineMenu() defines the menu via L1MenuFlags "items", "thresholds",

Definition at line 271 of file L1MenuConfigRun4.py.

271 def _importMenuDefinition(self):
272 """
273 Defines the list if item and threshold names that will be in the menu
274 Calls defineMenu() of the correct module 'Menu_<menuname>.py'
275 Menu.defineMenu() defines the menu via L1MenuFlags "items", "thresholds",
276 """
277
278 # we apply a hack here. menu group is working on Dev_pp_run3_v1, until ready we will use MC_pp_run3_v1
279 log.info("Reading TriggerMenuMT.Menu.Menu_%s", self.menuInfo.menuFile)
280 menumodule = __import__('TriggerMenuMT.L1.Menu.Menu_%s' % self.menuInfo.menuFile, globals(), locals(), ['defineMenu'], 0)
281 menumodule.defineMenu()
282 log.info("... L1 menu '%s' contains %i items", self.menuInfo.menuFile, len(L1MenuFlags.items()))
283 if log.getEffectiveLevel() <= logging.DEBUG:
284 log.debug("Items: %s", ', '.join(L1MenuFlags.items()))
285
286 log.info("Importing input definition from TriggerMenuMT.L1.Menu.Menu_%s", self.menuInfo.menuInputFile)
287 topomenumodule = __import__('TriggerMenuMT.L1.Menu.Menu_%s' % self.menuInfo.menuInputFile, globals(), locals(), ['defineMenu'], 0)
288 topomenumodule.defineInputsMenu() # this adds the inputs definition (boards) to L1MenuFlags.boards
289 connectorCount = 0
290 algoCount = 0
291 for _, boardDef in L1MenuFlags.boards().items():
292 if "connectors" in boardDef:
293 connectorCount += len(boardDef["connectors"])
294 for c in boardDef["connectors"]:
295 if "thresholds" in c:
296 algoCount += len(c["thresholds"])
297 elif "algorithmGroups" in c:
298 for t in c["algorithmGroups"]:
299 algoCount += len(t["algorithms"])
300 else:
301 for t in c["signalGroups"]:
302 algoCount += len(t["signals"])
303 log.info(" with %i connectors and %i input signals", connectorCount, algoCount)
304

◆ _menuResolution()

MenuMetaInfo python.L1.L1MenuConfigRun4.L1MenuConfigRun4._menuResolution ( str fullMenuName)
staticprotected
Resolve the menu name to the actual menu to be used based from the mapping above.

Definition at line 126 of file L1MenuConfigRun4.py.

126 def _menuResolution(fullMenuName: str) -> MenuMetaInfo:
127 """Resolve the menu name to the actual menu to be used based from the mapping above.
128 """
129
130 # remove prescale suffix
131 menuBaseName = fullMenuName
132 if fullMenuName.endswith('prescale'):
133 # take everything upto _vXX
134 if (m := re.match(r'\w*_v\d*', fullMenuName)) is not None:
135 menuBaseName = m.group(0)
136
137 if (menuInfo := menuMap.get(menuBaseName)) is not None:
138 menuFile, menuInputFile, _ = (menuInfo + ["", ""])[:3]
139 else:
140 menuFile = menuBaseName
141 menuInputFile = menuFile + "_inputs"
142
143 menuPurpose = MenuMetaInfo.MenuType.PHYSICS
144 if "MC_" in menuBaseName:
145 menuPurpose = MenuMetaInfo.MenuType.MC
146 elif "Dev_" in menuBaseName:
147 menuPurpose = MenuMetaInfo.MenuType.DEV
148 elif "HI_" in menuBaseName:
149 menuPurpose = MenuMetaInfo.MenuType.HI
150 elif "AllCTPIn_" in menuBaseName:
151 menuPurpose = MenuMetaInfo.MenuType.ALLCTPIN
152
153 # for run 4 fall back to default menu during LS3 development period
154 moduleName = 'TriggerMenuMT.L1.Menu.Menu_%s' % menuFile
155 if not moduleExists(moduleName):
156 log.info("Could not find menu definition for %s (module %s does not exist)", fullMenuName, moduleName)
157 raise ModuleNotFoundError(f"Could not find menu definition for {fullMenuName}")
158
159 return MenuMetaInfo(fullMenuName, menuBaseName=menuBaseName,
160 menuFile=menuFile, menuInputFile=menuInputFile,
161 menuPurpose=menuPurpose)
162

◆ _printRegisteredThresholdInfo()

python.L1.L1MenuConfigRun4.L1MenuConfigRun4._printRegisteredThresholdInfo ( self)
protected

Definition at line 337 of file L1MenuConfigRun4.py.

337 def _printRegisteredThresholdInfo(self):
338 thresholdsByType = ddict(list)
339 for thr in self._registeredThresholds.values():
340 thresholdsByType[thr.ttype].append(thr)
341
342 for ttype, thrList in thresholdsByType.items():
343 log.debug("Registered %i thresholds of type %s: %s", len(thrList), ttype, ', '.join([t.name for t in thrList]))
344 log.info("... registered %i calo thresholds", self._registeredThresholdsStats["calo"])
345 log.info("... registered %i muon thresholds", self._registeredThresholdsStats["muon"])
346 log.info("... registered %i nim thresholds", self._registeredThresholdsStats["nim"])
347 log.info("... registered %i global hypo thresholds", self._registeredThresholdsStats["global"])
348

◆ _registerAvailableItemsThresholdsAlgorithms()

python.L1.L1MenuConfigRun4.L1MenuConfigRun4._registerAvailableItemsThresholdsAlgorithms ( self)
protected
Registers the list if items and thresholds that could be used in the menu
Calls registerItem() of the correct module 'ItemDef.py'

Definition at line 305 of file L1MenuConfigRun4.py.

305 def _registerAvailableItemsThresholdsAlgorithms(self):
306 """
307 Registers the list if items and thresholds that could be used in the menu
308 Calls registerItem() of the correct module 'ItemDef.py'
309 """
310 MenuItem.setMenuConfig(self) # from now on all newly created MenuItems are automatically registered here
311 Threshold.setMenuConfig(self) # from now on all newly created Thresholds definitions are automatically registered here
312
313 # register Global hypothesis algorithms
314 defFile = "TriggerMenuMT.L1.Config.GlobalAlgoDef"
315 log.info("Importing %s", defFile)
316 try:
317 import_module(defFile).__getattribute__('GlobalAlgoDef').registerGlobalAlgos(self)
318 except ImportError as ie:
319 log.fatal("No global algorithm definition file found. %s", ie.msg)
320 raise
321 log.info("... registered %i global algorithms for the L1Global",
322 len(self._registeredGlobalAlgos))
323
324 log.info("Importing TriggerMenuMT.Config.ThresholdDefRun4")
325 from .Config.ThresholdDefRun4 import ThresholdDef
326 ThresholdDef.registerThresholds(self, self.menuFullName)
327
328 log.info("Turning global algorithm outputs into thresholds (except multiplicity counters)")
329 self._registerGlobalOutputsAsThresholds()
330
331 self._printRegisteredThresholdInfo()
332
333 log.info("Registering items from TriggerMenuMT.Config.ItemDefRun4")
334 ItemDefRun4.registerItems(self, self.menuInfo)
335 log.info("... registered %i defined items", len(self._registeredItems))
336

◆ _registerGlobalOutputsAsThresholds()

python.L1.L1MenuConfigRun4.L1MenuConfigRun4._registerGlobalOutputsAsThresholds ( self)
protected
Register all L1Global triggers that are available as allowed input to the menu

Definition at line 209 of file L1MenuConfigRun4.py.

209 def _registerGlobalOutputsAsThresholds(self):
210 """
211 Register all L1Global triggers that are available as allowed input to the menu
212 """
213
214 # for all global algorithms the outputs (sometimes multiple) are defined as thresholds
215 outputLines = []
216 for algo in self._registeredGlobalAlgos.values():
217 if isinstance(algo, GlobalMultiplicityAlgo):
218 continue # multiplicity counters are already registered as thresholds
219 outputLines += algo.output() if (isinstance(algo.output(), list)) else [algo.output()]
220 _globalTriggers = sorted(outputLines)
221 log.info("... found %i global triggerlines", len(_globalTriggers))
222 log.debug("%r", _globalTriggers)
223
224 multibitPattern = re.compile(r"(?P<line>.*)\‍[(?P<bit>\d+)\‍]")
225 multibitTopoTriggers = set()
226 for topoLineName in _globalTriggers:
227 m = multibitPattern.match(topoLineName) # tries to match "trigger[bit]"
228 if m:
229 topoThrName = m.groupdict()['line']
230 multibitTopoTriggers.add(topoThrName)
231 else:
232 topoThrName = topoLineName
233 GlobalThreshold(name=topoThrName)
234 # create thresholds from topo-multibit
235 for topoThrName in multibitTopoTriggers: # ( 'MULT-CMU4ab', ...)
236 GlobalThreshold(name=topoThrName)
237

◆ getDefinedThreshold()

Threshold | None python.L1.L1MenuConfigRun4.L1MenuConfigRun4.getDefinedThreshold ( self,
str name )

Definition at line 166 of file L1MenuConfigRun4.py.

166 def getDefinedThreshold(self, name: str) -> Threshold | None:
167 return self._registeredThresholds.get(name)
168

◆ getDefinedThresholds()

Iterator[Threshold] python.L1.L1MenuConfigRun4.L1MenuConfigRun4.getDefinedThresholds ( self)

Definition at line 169 of file L1MenuConfigRun4.py.

169 def getDefinedThresholds(self) -> Iterator[Threshold]:
170 return iter(self._registeredThresholds.values())
171

◆ getRegisteredItem()

MenuItem | None python.L1.L1MenuConfigRun4.L1MenuConfigRun4.getRegisteredItem ( self,
str name )

Definition at line 247 of file L1MenuConfigRun4.py.

247 def getRegisteredItem(self, name: str) -> MenuItem | None:
248 return self._registeredItems.get(name)
249

◆ mapThresholds()

python.L1.L1MenuConfigRun4.L1MenuConfigRun4.mapThresholds ( self)
Set the correct mapping of thresholds according to the
order it was given in L1MenuFlags.thresholds list. That list
is usually defined in the setupMenu function of each menu

NIM and CALREQ types are not remapped !!

Definition at line 704 of file L1MenuConfigRun4.py.

704 def mapThresholds(self):
705 """
706 Set the correct mapping of thresholds according to the
707 order it was given in L1MenuFlags.thresholds list. That list
708 is usually defined in the setupMenu function of each menu
709
710 NIM and CALREQ types are not remapped !!
711 """
712
713 alreadyUsedMappingNumbers = ddict(set)
714 for thr in self.l1menu.thresholds:
715 if thr.mapping < 0:
716 continue
717 alreadyUsedMappingNumbers[thr.ttype].add(thr.mapping)
718
719 nextFreeMapping = ddict(lambda: 0)
720 for k in alreadyUsedMappingNumbers:
721 nextFreeMapping[k] = 0
722 for thr in self.l1menu.thresholds():
723 if thr.mapping < 0:
724 while nextFreeMapping[thr.ttype] in alreadyUsedMappingNumbers[thr.ttype]:
725 nextFreeMapping[thr.ttype] += 1
726 log.debug('Setting mapping of threshold %s as %i', thr, nextFreeMapping[thr.ttype])
727 thr.mapping = nextFreeMapping[thr.ttype]
728 nextFreeMapping[thr.ttype] += 1
729
bool add(const std::string &hname, TKey *tobj)
Definition fastadd.cxx:55

◆ registerGlobalAlgo()

python.L1.L1MenuConfigRun4.L1MenuConfigRun4.registerGlobalAlgo ( self,
GlobalAlgorithm algo )

registration of available components

Register a L1Global algorithm for later use

Definition at line 177 of file L1MenuConfigRun4.py.

177 def registerGlobalAlgo(self, algo: GlobalAlgorithm):
178 """Register a L1Global algorithm for later use"""
179
180 if algo.name in self._registeredGlobalAlgos:
181 raise RuntimeError(f'Global algo {algo.name} is already registered ')
182 self._registeredGlobalAlgos[algo.name] = algo
183 log.debug("Registered global algo: %s", algo.name)
184 return algo
185

◆ registerItem()

python.L1.L1MenuConfigRun4.L1MenuConfigRun4.registerItem ( self,
str name,
MenuItem item )
Adds a LVL1 item to the set of items which are registered for further use

Definition at line 239 of file L1MenuConfigRun4.py.

239 def registerItem(self, name: str, item: MenuItem):
240 """ Adds a LVL1 item to the set of items which are registered for further use"""
241 if name in self._registeredItems:
242 log.error('LVL1 item %s is already registered with ctpid=%d',
243 name, int(self._registeredItems[name].ctpid))
244 else:
245 self._registeredItems[name] = item
246

◆ registerThreshold()

python.L1.L1MenuConfigRun4.L1MenuConfigRun4.registerThreshold ( self,
Threshold thr )
Add externally created L1 threshold to the list of available thresholds.

Definition at line 186 of file L1MenuConfigRun4.py.

186 def registerThreshold(self, thr: Threshold):
187 """
188 Add externally created L1 threshold to the list of available thresholds.
189 """
190 if self.thresholdExists(thr.name):
191 raise RuntimeError("LVL1 threshold of name '%s' already defined, need to abort" % thr.name)
192
193 self._registeredThresholds[thr.name] = thr
194
195 # collect stats
196 isTopo = isinstance(thr, GlobalThreshold)
197 if isTopo:
198 self._registeredThresholdsStats["global"] += 1
199 return
200
201 isNIM = thr.ttype in ['NIM', 'CALREQ', 'MBTSSI', 'MBTS', 'LUCID', 'BCM', 'BCMCMB', 'ZDC', 'BPTX', 'ZB']
202 if isNIM:
203 self._registeredThresholdsStats["nim"] += 1
204 elif thr.ttype == 'MU':
205 self._registeredThresholdsStats["muon"] += 1
206 else:
207 self._registeredThresholdsStats["calo"] += 1
208

◆ run()

python.L1.L1MenuConfigRun4.L1MenuConfigRun4.run ( self)

Definition at line 99 of file L1MenuConfigRun4.py.

99 def run(self):
100 return 4
101
int run(int argc, char *argv[])

◆ thresholdExists()

bool python.L1.L1MenuConfigRun4.L1MenuConfigRun4.thresholdExists ( self,
str thrName )

Definition at line 163 of file L1MenuConfigRun4.py.

163 def thresholdExists(self, thrName: str) -> bool:
164 return thrName in self._registeredThresholds
165

◆ updateItemPrescales()

python.L1.L1MenuConfigRun4.L1MenuConfigRun4.updateItemPrescales ( self)

Definition at line 730 of file L1MenuConfigRun4.py.

730 def updateItemPrescales(self):
731 for (it_name, ps) in L1MenuFlags.prescales().items():
732 item = self.l1menu.getItem(it_name)
733 if item:
734 item.prescale = ps
735 else:
736 log.warning('Cannot find item %s to set the prescale', it_name)
737

◆ writeJSON()

python.L1.L1MenuConfigRun4.L1MenuConfigRun4.writeJSON ( self,
outputFile,
bgsOutputFile = None,
Path destdir = Path("./") )

Definition at line 250 of file L1MenuConfigRun4.py.

250 def writeJSON(self, outputFile, bgsOutputFile=None, destdir: Path = Path("./")):
251 if self.isMenuGenerated:
252 outputFile = destdir / outputFile
253 if bgsOutputFile is not None:
254 bgsOutputFile = destdir / bgsOutputFile
255 L1MenuJSONConverter(l1menu=self.l1menu, outputFile=outputFile,
256 bgsOutputFile=bgsOutputFile).writeJSON(pretty=True)
257 return outputFile, bgsOutputFile
258 else:
259 log.error("No menu was generated, can not create json file")
260 return None
261

Member Data Documentation

◆ _registeredGlobalAlgos

python.L1.L1MenuConfigRun4.L1MenuConfigRun4._registeredGlobalAlgos = {}
protected

Definition at line 86 of file L1MenuConfigRun4.py.

◆ _registeredItems

python.L1.L1MenuConfigRun4.L1MenuConfigRun4._registeredItems = {}
protected

Definition at line 80 of file L1MenuConfigRun4.py.

◆ _registeredThresholds

dict python.L1.L1MenuConfigRun4.L1MenuConfigRun4._registeredThresholds = {}
protected

Definition at line 83 of file L1MenuConfigRun4.py.

◆ _registeredThresholdsStats

dict python.L1.L1MenuConfigRun4.L1MenuConfigRun4._registeredThresholdsStats
protected
Initial value:
= {
"muon": 0,
"calo": 0,
"nim": 0,
"global": 0
}

Definition at line 89 of file L1MenuConfigRun4.py.

◆ inputFile

Path | None python.L1.L1MenuConfigRun4.L1MenuConfigRun4.inputFile = inputFile

Definition at line 64 of file L1MenuConfigRun4.py.

◆ isMenuGenerated

bool python.L1.L1MenuConfigRun4.L1MenuConfigRun4.isMenuGenerated = False

Definition at line 66 of file L1MenuConfigRun4.py.

◆ l1menu

python.L1.L1MenuConfigRun4.L1MenuConfigRun4.l1menu = L1MenuRun4(menuInfo=self.menuInfo, flags=flags)

Definition at line 73 of file L1MenuConfigRun4.py.

◆ l1menuFromFile

tuple python.L1.L1MenuConfigRun4.L1MenuConfigRun4.l1menuFromFile = (self.inputFile is not None)

Definition at line 65 of file L1MenuConfigRun4.py.

◆ menuFullName

python.L1.L1MenuConfigRun4.L1MenuConfigRun4.menuFullName = flags.Trigger.triggerMenuSetup

Definition at line 61 of file L1MenuConfigRun4.py.

◆ menuInfo

python.L1.L1MenuConfigRun4.L1MenuConfigRun4.menuInfo = self._menuResolution(self.menuFullName)

Definition at line 62 of file L1MenuConfigRun4.py.

◆ menuName

str python.L1.L1MenuConfigRun4.L1MenuConfigRun4.menuName = self.menuInfo.menuBaseName

Definition at line 63 of file L1MenuConfigRun4.py.


The documentation for this class was generated from the following file: