3 from collections
import OrderedDict
as odict
5 from AthenaCommon.Logging
import logging
7 from ..Config.MonitorDef
import MonitorDef
8 from .PrescaleHelper
import getCutFromPrescale, getPrescaleFromCut
9 from .MenuUtils
import binstr
11 from past.builtins
import cmp
14 log = logging.getLogger(__name__)
19 splitBunchGroups =
False
31 return self.
items[key]
36 if name
in self.
items:
37 log.warning(
"LVL1 item %s is already in the menu, will not add it again", name)
39 if item.ctpid
in [x.ctpid
for x
in self.
items]:
40 log.warning(
"LVL1 item with ctpid %i is already in the menu, will not add %s", item.ctpid, name)
42 self.
items[ name ] = item
48 if item.name
in self.
items:
49 msg =
"LVL1 item %s is already in the menu, will not add it again" % item.name
51 raise RuntimeError(msg)
52 if item.ctpid
in [x.ctpid
for x
in self.
items.
values()]:
53 msg =
"LVL1 item %s with ctpid %i is already in the menu, will not add %s with the same ctpid" % (self.
itemById(item.ctpid).name, item.ctpid, item.name)
55 raise RuntimeError(msg)
56 self.
items[ item.name ] = item
60 return itemname
in self.
items
63 return len(self.
items)
66 itemById = {it.ctpid:it
for it
in self.
items.
values()}
67 return itemById[ctpid]
if ctpid
in itemById
else None
75 confObj[item.name] = item.json()
82 l1configForRegistration =
None
86 MenuItem.l1configForRegistration = mc
91 __slots__ = [
'name',
'group',
'ctpid',
'psCut',
'trigger_type',
'partition',
'logic',
'bunchGroups',
'legacy',
'monitorsLF',
'monitorsHF',
'verbose']
92 def __init__(self, name, ctpid=-1, group='1', prescale=1, psCut=None, verbose=False):
106 if MenuItem.l1configForRegistration:
107 MenuItem.l1configForRegistration.registerItem(self.
name, self)
110 s =
"Item %s (ctp id=%i) [%s]" % (self.
name, self.
ctpid, self.
logic)
123 if frequency == MonitorDef.LOW_FREQ:
125 if frequency == MonitorDef.HIGH_FREQ:
129 if MenuItemsCollection.splitBunchGroups:
140 if self.
logic is not None:
146 if self.
logic is not None:
159 """Turns integer triggertype in a binary string of given width"""
164 confObj[
"name"] = self.
name
166 confObj[
"legacy"] = self.
legacy
167 confObj[
"ctpid"] = self.
ctpid
168 confObj[
"definition"] =
str(self.
logic)
186 for item
in menuitems:
190 itemList.sort(
lambda x,y:
cmp(x.ctpid,y.ctpid))
196 isTopo = any(
filter(
lambda x: attr.startswith(x), [
"R2TOPO_",
"TOPO_",
"MUTOPO_",
"MULTTOPO_"]))
197 fs = traceback.extract_stack()[-2]
198 expProdFile =
"L1/Config/"
200 if attr.startswith(
"R2TOPO_"):
201 expProdFile +=
"TopoAlgoDefLegacy.py"
202 elif attr.startswith(
"TOPO_"):
203 expProdFile +=
"TopoAlgoDef.py"
204 elif attr.startswith(
"MUTOPO_"):
205 expProdFile +=
"TopoAlgoDefMuctpi.py"
206 elif attr.startswith(
"MULTTOPO_"):
207 expProdFile +=
"TopoMultiplicityAlgoDef.py"
209 isLegacyThr = any(
filter(
lambda x: attr.startswith(x), [
"EM",
"TAU",
"J",
"XE",
"TE",
"XS"]))
211 expProdFile +=
"ThresholdDefLegacy.py"
213 expProdFile +=
"ThresholdDef.py"
215 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)
217 raise RuntimeError(msg)