Commit e3f7ab87 authored by Joerg Stelzer's avatar Joerg Stelzer Committed by Vakhtang Tsulaia
Browse files

L1 menu user improvements

parent 2b58a449
......@@ -183,3 +183,29 @@ class PrescaleHandler(object):
for itemList in self.itemsByPartition.values():
itemList.sort(lambda x,y: cmp(x.ctpid,y.ctpid))
class meta_d(type):
def __getattr__(cls, attr):
import traceback
isTopo = any(filter(lambda x: attr.startswith(x), ["R2TOPO_", "TOPO_", "MUTOPO_", "MULTTOPO_"]))
fs = traceback.extract_stack()[-2]
expProdFile = "L1/Config/"
if isTopo:
if attr.startswith("R2TOPO_"):
expProdFile += "TopoAlgoDefLegacy.py"
elif attr.startswith("TOPO_"):
expProdFile += "TopoAlgoDef.py"
elif attr.startswith("MUTOPO_"):
expProdFile += "TopoAlgoDefMuctpi.py"
elif attr.startswith("MULTTOPO_"):
expProdFile += "TopoMultiplicityAlgoDef.py"
else:
isLegacyThr = any(filter(lambda x: attr.startswith(x), ["EM", "TAU", "J", "XE", "TE", "XS"]))
if isLegacyThr:
expProdFile += "ThresholdDefLegacy.py"
else:
expProdFile += "ThresholdDef.py"
msg = "Item definition issue in file %s, line %i. Threshold %s has not been defined in %s" % ('/'.join(fs.filename.rsplit('/',4)[1:]),fs.lineno, attr, expProdFile)
log.error(msg)
raise RuntimeError(msg)
......@@ -68,7 +68,7 @@ class L1Menu(object):
def addTopoAlgo(self, algo, category):
algo.setThresholds( self.thresholds )
algo.setThresholds( self.thresholds ) # each algo gets a pointer to the full thresholds definition (for the extrainfo)
self.topoAlgos.addAlgo(algo, category)
......
......@@ -65,7 +65,7 @@ class MenuThresholdsCollection( object ):
def json(self):
confObj = odict()
for ttype in (ThrType.Run3Types() + ThrType.NIMTypes() + [ThrType.TOPO, ThrType.MUTOPO, ThrType.MULTTOPO ]):
for ttype in (ThrType.Run3Types() + ThrType.NIMTypes() + [ThrType.TOPO, ThrType.MUTOPO ]):
confObj[ttype.name] = odict()
confObj[ttype.name]["type"] = ttype.name
confObj[ttype.name]["thresholds"] = odict()
......
......@@ -18,15 +18,16 @@ class AlgType(Enum):
self.key = key
class AlgCategory(Enum):
TOPO = (1, 'TOPO', 'new topo')
MUCTPI = (2, 'MUTOPO', 'muctpi topo')
LEGACY = (3, 'R2TOPO', 'legacy topo')
MULTI = (4, 'MULTTOPO', 'multiplicity topo')
TOPO = (1, 'TOPO', 'new topo', 'TopoAlgoDef')
MUCTPI = (2, 'MUTOPO', 'muctpi topo', 'TopoAlgoDefMuctpi')
LEGACY = (3, 'R2TOPO', 'legacy topo', 'TopoAlgoDefLegacy')
MULTI = (4, 'MULTTOPO', 'multiplicity topo', 'TopoAlgoDefMultiplicity')
def __init__(self, _, key, desc ):
def __init__(self, _, key, desc, defFile ):
self.key = key
self.prefix = key + '_' if key else ''
self.desc = desc
self.defFile = defFile
def __str__(self):
return self.desc
......
......@@ -16,7 +16,7 @@ log = logging.getLogger('Menu.L1.Config.ItemDef')
# The trigger types
from ..Base.Limits import Limits
from ..Base.Logic import Logic, Not
from ..Base.Items import MenuItem
from ..Base.Items import MenuItem, meta_d
from ..Base.Thresholds import TopoThreshold
from ..Base.CTPCondition import ThrCondition, InternalTrigger # noqa: F401
from .TriggerTypeDef import TT
......@@ -44,7 +44,7 @@ class ItemDef:
isHIV5 = 'HI_v5' in menuName
isPhaseII = '_PhaseII' in menuName
class d: pass
class d(metaclass=meta_d): pass
# ... and make them accessible by their name
for thr in tc.getDefinedThresholds():
......
......@@ -5,7 +5,7 @@ log = logging.getLogger('Menu.L1.Config.TopoMultiplicityAlgoDef')
from ..Base.TopoAlgos import EMMultiplicityAlgo, TauMultiplicityAlgo, JetMultiplicityAlgo, XEMultiplicityAlgo
class TopoMultiplicityAlgoDef(object):
class TopoAlgoDefMultiplicity(object):
"""
Defines the TopoAlgorithms that calculate multiplicities for L1Calo thresholds
The thresholds have to be explicitly defined here.
......
6# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
import re
from importlib import import_module
from collections import defaultdict as ddict
from AthenaCommon.Logging import logging
......@@ -52,9 +53,9 @@ class L1MenuConfig(object):
AlgCategory.TOPO : 0, AlgCategory.MUCTPI : 0, AlgCategory.LEGACY : 0 }
# all registered topo algos
self._definedTopoAlgos = {}
self._registeredTopoAlgos = {}
for cat in AlgCategory.getAllCategories():
self._definedTopoAlgos[cat] = {}
self._registeredTopoAlgos[cat] = {}
# menu
L1MenuFlags.CTPVersion = 4 # this needs to be done here already, since L1Menu depends on it during init
......@@ -111,28 +112,11 @@ class L1MenuConfig(object):
if self.currentAlgoDef == AlgCategory.MULTI:
algo.name = "Mult_" + algo.name
if algo.name in self._definedTopoAlgos[AlgCategory.MULTI]:
raise RuntimeError('L1Topo multiplicity algo %s is already registered as such' % algo.name)
self._definedTopoAlgos[AlgCategory.MULTI][algo.name] = algo
log.debug("Added in the multiplicity topo algo list: {0}, ID:{1}" .format(algo.name,algo.algoId))
elif self.currentAlgoDef == AlgCategory.MUCTPI:
if algo.name in self._definedTopoAlgos[AlgCategory.MUCTPI]:
raise RuntimeError('L1Topo MuCTPi algo %s is already registered as such' % algo.name)
self._definedTopoAlgos[AlgCategory.MUCTPI][algo.name] = algo
log.debug("Added in the MuCTPi topo algo list: {0}, ID:{1}" .format(algo.name,algo.algoId))
elif self.currentAlgoDef == AlgCategory.TOPO:
if algo.name in self._definedTopoAlgos[AlgCategory.TOPO]:
raise RuntimeError('L1Topo algo %s is already registered as such' % algo.name)
self._definedTopoAlgos[AlgCategory.TOPO][algo.name] = algo
log.debug("Added in the topo algo list: {0}, ID:{1}" .format(algo.name,algo.algoId))
elif self.currentAlgoDef == AlgCategory.LEGACY:
if algo.name in self._definedTopoAlgos[AlgCategory.LEGACY]:
raise RuntimeError('L1Topo legacy algo %s is already registered as such' % algo.name)
self._definedTopoAlgos[AlgCategory.LEGACY][algo.name] = algo
log.debug("Added in the legacy topo algo list: {0}, ID:{1}" .format(algo.name,algo.algoId))
if algo.name in self._registeredTopoAlgos[self.currentAlgoDef]:
raise RuntimeError('%s algo %s is already registered as such' % (self.currentAlgoDef.desc, algo.name))
self._registeredTopoAlgos[self.currentAlgoDef][algo.name] = algo
log.debug("Added in the %s algo list: {0}, ID:{1}" .format(self.currentAlgoDef.desc, algo.name,algo.algoId))
return algo
......@@ -183,7 +167,7 @@ class L1MenuConfig(object):
# for all topo algorithm categories the outputs (sometimes multiple) are defined as thresholds
for cat in AlgCategory.getAllCategories():
outputLines = []
for algo in self._definedTopoAlgos[cat].values():
for algo in self._registeredTopoAlgos[cat].values():
outputLines += algo.outputs if (type(algo.outputs) == list) else [ algo.outputs ]
self._topoTriggers[cat] = sorted(outputLines)
log.info("... found %i topo triggerlines (source: %s)", len(self._topoTriggers[cat]), cat )
......@@ -306,30 +290,14 @@ class L1MenuConfig(object):
MenuItem.setMenuConfig(self) # from now on all newly created MenuItems are automatically registered here
from .Base.Thresholds import Threshold
Threshold.setMenuConfig(self) # from now on all newly created Thresholds definitions are automatically registered here
log.info("Reading TriggerMenuMT.Config.TopoAlgoDef")
self.currentAlgoDef = AlgCategory.TOPO
from .Config.TopoAlgoDef import TopoAlgoDef
TopoAlgoDef.registerTopoAlgos(self)
log.info("... registered %i defined topo algos for the new topo boards", len(self._definedTopoAlgos[AlgCategory.TOPO]))
log.info("Reading TriggerMenuMT.Config.TopoAlgoDefMuctpi")
self.currentAlgoDef = AlgCategory.MUCTPI
from .Config.TopoAlgoDefMuctpi import TopoAlgoDefMuctpi
TopoAlgoDefMuctpi.registerTopoAlgos(self)
log.info("... registered %i defined topo algos for the MuCTPi", len(self._definedTopoAlgos[AlgCategory.MUCTPI]))
log.info("Reading TriggerMenuMT.Config.TopoMultiplicityAlgoDef")
self.currentAlgoDef = AlgCategory.MULTI
from .Config.TopoMultiplicityAlgoDef import TopoMultiplicityAlgoDef
TopoMultiplicityAlgoDef.registerTopoAlgos(self)
log.info("... registered %i defined topo multiplicity algos for the new topo boards", len(self._definedTopoAlgos[AlgCategory.MULTI]))
log.info("Reading TriggerMenuMT.Config.TopoAlgoDefLegacy")
self.currentAlgoDef = AlgCategory.LEGACY
from .Config.TopoAlgoDefLegacy import TopoAlgoDefLegacy
TopoAlgoDefLegacy.registerTopoAlgos(self)
log.info("... registered %i defined topo algos for the legacy topo boards", len(self._definedTopoAlgos[AlgCategory.LEGACY]))
# register Topo algorithms
for algCat in [AlgCategory.TOPO, AlgCategory.MUCTPI, AlgCategory.MULTI, AlgCategory.LEGACY]:
self.currentAlgoDef = algCat
defFile = "TriggerMenuMT.L1.Config.%s" % self.currentAlgoDef.defFile
log.info("Reading %s", defFile)
import_module(defFile).__getattribute__(self.currentAlgoDef.defFile).registerTopoAlgos(self)
log.info("... registered %i defined topo algos for the %s board(s)", len(self._registeredTopoAlgos[self.currentAlgoDef]), self.currentAlgoDef.desc)
log.info("Reading TriggerMenuMT.Config.ThreholdDef")
from .Config.ThresholdDef import ThresholdDef
......@@ -356,9 +324,12 @@ class L1MenuConfig(object):
def _getTopoAlgo(self, algoName, category):
if algoName in self._definedTopoAlgos[category]:
return self._definedTopoAlgos[category][algoName]
raise RuntimeError("Algorithm of name %s is not defined in category %s\nAvailable are %r" % (algoName, category,self._definedTopoAlgos[category].keys()) )
if algoName in self._registeredTopoAlgos[category]:
return self._registeredTopoAlgos[category][algoName]
msg = "Algorithm of name %s in category %s is not registered. Please add the algorithm to L1/Config/%s.py" % (algoName, category, category.defFile)
log.error(msg)
log.info("Available algorithms in this category are %s", ",".join(self._registeredTopoAlgos[category].keys()))
raise RuntimeError(msg)
def _getSortingAlgoThatProvides(self, input, topoAlgCategory):
......@@ -368,7 +339,7 @@ class L1MenuConfig(object):
runtime exception
"""
sortingAlgs = []
for name, alg in self._definedTopoAlgos[topoAlgCategory].items(): # TODO: extend to legacy topo
for name, alg in self._registeredTopoAlgos[topoAlgCategory].items():
if type(alg.outputs)==list:
foundOutput = (input in alg.outputs)
else:
......@@ -377,9 +348,11 @@ class L1MenuConfig(object):
sortingAlgs += [alg]
if len(sortingAlgs)==0:
raise RuntimeError("No sorting algorithm is providing this output: %s" % input)
msg = "No topo sorting algorithm is providing this output: %s. Please add the sorting algorithm to L1/Config/%s.py" % (input, topoAlgCategory.defFile)
raise RuntimeError(msg)
if len(sortingAlgs)>1:
raise RuntimeError("More than one sorting algorithm is providing this output: %s. Here the list: %s" % (input, ', '.join(sortingAlgs)))
msg = "More than one sorting algorithm is providing this output: %s. Here the list: %s" % (input, ', '.join(sortingAlgs))
raise RuntimeError(msg)
return sortingAlgs[0]
......@@ -495,43 +468,6 @@ class L1MenuConfig(object):
self.l1menu.ctp.bunchGroupSet = createDefaultBunchGroupSet()
# ------------------
# Items
# ------------------
# build list of items for the menu from the list of requested names
itemsForMenu = []
ctpIdMap = L1MenuFlags.CtpIdMap()
for itemName in L1MenuFlags.items():
registeredItem = self.getRegisteredItem(itemName)
if registeredItem is None:
msg = "L1 item '%s' has not been defined in L1/Config/ItemDef.py" % itemName
log.error(msg)
raise RuntimeError(msg)
if itemName in ctpIdMap:
newCTPID = ctpIdMap[itemName]
registeredItem.setCtpid(newCTPID)
itemsForMenu += [ registeredItem ]
# CTP IDs available for assignment
assigned_ctpids = set([item.ctpid for item in itemsForMenu])
available_ctpids = sorted( list( set(range(Limits.MaxTrigItems)) - assigned_ctpids ), reverse=True )
# add the items to the menu
for item in itemsForMenu:
# set the physics bit
if not item.name.startswith('L1_CALREQ'):
item.setTriggerType( item.trigger_type | TT.phys )
# assign ctp IDs to items that don't have one
if item.ctpid == -1:
item.setCtpid( available_ctpids.pop() )
# add the items into the menu
self.l1menu.addItem( item )
# ------------------
# Thresholds
# ------------------
......@@ -597,6 +533,51 @@ class L1MenuConfig(object):
(self.l1menu.menuName, ', '.join(list_of_undefined_thresholds)) )
# ------------------
# Items
# ------------------
# build list of items for the menu from the list of requested names
itemsForMenu = []
ctpIdMap = L1MenuFlags.CtpIdMap()
for itemName in L1MenuFlags.items():
registeredItem = self.getRegisteredItem(itemName)
if registeredItem is None:
msg = "L1 item '%s' has not been defined in L1/Config/ItemDef.py" % itemName
log.error(msg)
raise RuntimeError(msg)
if itemName in ctpIdMap:
newCTPID = ctpIdMap[itemName]
registeredItem.setCtpid(newCTPID)
for thrName in registeredItem.thresholdNames():
if thrName not in self.l1menu.thresholds:
isLegacyThr = any(filter(lambda x: thrName.startswith(x), ["R2TOPO_", "EM", "TAU", "J", "XE", "TE", "XS"]))
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{legacy}.py".format(item=itemName, thr=thrName, menu=self.menuToLoad(), legacy = "_legacy" if isLegacyThr else "")
log.error(msg)
raise RuntimeError(msg)
itemsForMenu += [ registeredItem ]
# CTP IDs available for assignment
assigned_ctpids = set([item.ctpid for item in itemsForMenu])
available_ctpids = sorted( list( set(range(Limits.MaxTrigItems)) - assigned_ctpids ), reverse=True )
# add the items to the menu
for item in itemsForMenu:
# set the physics bit
if not item.name.startswith('L1_CALREQ'):
item.setTriggerType( item.trigger_type | TT.phys )
# assign ctp IDs to items that don't have one
if item.ctpid == -1:
item.setCtpid( available_ctpids.pop() )
# add the items into the menu
self.l1menu.addItem( item )
# ------------------
# Connectors
# ------------------
......
......@@ -59,7 +59,7 @@ def defineInputsMenu():
"type" : "ctpin",
"legacy" : False,
"thresholds" : [
'MBTS_C0', 'MBTS_C1', 'MBTS_C2', 'MBTS_C3', 'MBTS_C4' , 'MBTS_C5', 'MBTS_C6', 'MBTS_C7', 'MBTS_C8', 'MBTS_C10', 'MBTS_C12', 'MBTS_C14',
'MBTS_C0', 'MBTS_C1', 'MBTS_C2', 'MBTS_C3', 'MBTS_C4', 'MBTS_C5', 'MBTS_C6', 'MBTS_C7', 'MBTS_C8', 'MBTS_C10', 'MBTS_C12', 'MBTS_C14',
'MBTS_C9', 'MBTS_C11', 'MBTS_C13', 'MBTS_C15', # 16x MBTSSI
('MBTS_C',3), # 1x MBTS_C
'NIMTGC', # TGC
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment