ATLAS Offline Software
Loading...
Searching...
No Matches
Items.py
Go to the documentation of this file.
1# Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2
3from AthenaCommon.Logging import logging
4
5from ..Config.MonitorDef import MonitorDef
6from .PrescaleHelper import getCutFromPrescale, getPrescaleFromCut
7from .MenuUtils import binstr
8
9
10log = logging.getLogger(__name__)
11
12
14
15 splitBunchGroups = False
16
17 def __init__(self):
18 self.menuName = ''
19 self.pssName = ''
20 self.pssType = 'Physics'
21 self.items = {}
22
23 def __iter__(self):
24 return iter(self.items.values())
25
26 def __getitem__(self, key):
27 return self.items[key]
28
29 def __setitem__(self, name, item):
30 if item is None:
31 return self
32 if name in self.items:
33 log.warning("LVL1 item %s is already in the menu, will not add it again", name)
34 return self
35 if item.ctpid in [x.ctpid for x in self.items]:
36 log.warning("LVL1 item with ctpid %i is already in the menu, will not add %s", item.ctpid, name)
37 return self
38 self.items[ name ] = item
39 return self
40
41 def __iadd__(self, item):
42 if item is None:
43 return self
44 if item.name in self.items:
45 msg = "LVL1 item %s is already in the menu, will not add it again" % item.name
46 log.error(msg)
47 raise RuntimeError(msg)
48 if item.ctpid in [x.ctpid for x in self.items.values()]:
49 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)
50 log.error(msg)
51 raise RuntimeError(msg)
52 self.items[ item.name ] = item
53 return self
54
55 def __contains__(self, itemname):
56 return itemname in self.items
57
58 def __len__(self):
59 return len(self.items)
60
61 def itemById(self,ctpid):
62 itemById = {it.ctpid:it for it in self.items.values()}
63 return itemById[ctpid] if ctpid in itemById else None
64
65 def itemNames(self):
66 return self.items.keys()
67
68 def json(self):
69 confObj = {item.name: item.json() for item in self}
70 return confObj
71
72
74
75 # global variable for item registration, if set, new items will be registered with l1configForRegistration (type TriggerConfigL1)
76 l1configForRegistration = None
77
78 @staticmethod
80 MenuItem.l1configForRegistration = mc
81
82 # New items will be assigned to this partition
83 currentPartition = 0
84
85 __slots__ = ['name', 'group', 'ctpid', 'psCut', 'trigger_type', 'partition', 'logic', 'bunchGroups', 'legacy', 'monitorsLF', 'monitorsHF', 'verbose']
86 def __init__(self, name, ctpid=-1, group='1', prescale=1, psCut=None, verbose=False):
87 self.name = name
88 self.group = group
89 self.ctpid = int(ctpid)
90 self.psCut = psCut if psCut is not None else getCutFromPrescale(prescale)
91 self.trigger_type = 0
92 self.partition = MenuItem.currentPartition
93 self.logic = None
94 self.monitorsLF = 0
95 self.monitorsHF = 0
96 self.verbose = verbose
97 self.bunchGroups = None
98 self.legacy = False
99
100 if MenuItem.l1configForRegistration:
101 MenuItem.l1configForRegistration.registerItem(self.name, self)
102
103 def __str__(self):
104 s = "Item %s (ctp id=%i) [%s]" % (self.name, self.ctpid, self.logic)
105 return s
106
107 @property
108 def prescale(self):
109 return getPrescaleFromCut(self.psCut)
110
111 @prescale.setter
112 def prescale(self, prescale):
113 self.psCut = getCutFromPrescale(prescale)
114 return self
115
116 def addMonitor(self, flag, frequency):
117 if frequency == MonitorDef.LOW_FREQ:
118 self.monitorsLF |= flag
119 if frequency == MonitorDef.HIGH_FREQ:
120 self.monitorsHF |= flag
121
122 def setLogic(self, logic):
123 if MenuItemsCollection.splitBunchGroups:
124 (self.logic, self.bunchGroups) = logic.stripBunchGroups(logic)
125 else:
126 self.logic = logic
127 return self
128
129 def setCtpid(self, x):
130 self.ctpid = int(x)
131 return self
132
133 def thresholdNames(self, include_bgrp=False):
134 if self.logic is not None:
135 return self.logic.thresholdNames(include_bgrp)
136 else:
137 return []
138
139 def conditions(self, include_internal=False):
140 if self.logic is not None:
141 return self.logic.conditions(include_internal)
142 else:
143 return []
144
145 def setTriggerType(self, ttype):
146 self.trigger_type = int(ttype) & 0xff
147 return self
148
149 def markLegacy(self,legacyThresholdsSet):
150 self.legacy = bool ( legacyThresholdsSet.intersection(self.logic.thresholdNames()) )
151
152 def binary_trigger_type(self, width=8):
153 """Turns integer triggertype in a binary string of given width"""
154 return binstr(self.trigger_type, width=width)
155
156 def json(self):
157 confObj = {}
158 confObj["name"] = self.name
159 if self.legacy:
160 confObj["legacy"] = self.legacy
161 confObj["ctpid"] = self.ctpid
162 confObj["definition"] = str(self.logic)
163 if self.bunchGroups:
164 confObj["bunchgroups"] = self.bunchGroups
165 confObj["triggerType"] = self.binary_trigger_type(8 if self.partition==1 else 4)
166 confObj["partition"] = self.partition
167 confObj["monitor"] = 'LF:{0:03b}|HF:{1:03b}'.format(self.monitorsLF,self.monitorsHF)
168 return confObj
169
170
171
172
174 def __init__(self, name, psType, menuitems):
175 self.name = name
176 self.psType = psType
177 self.items = menuitems
179
180 for item in menuitems:
181 self.itemsByPartition.setdefault(item.partition,[]).append(item)
182
183 for itemList in self.itemsByPartition.values():
184 itemList.sort(key = lambda x: x.ctpid)
185
186
188 def __getattr__(cls, attr):
189 import traceback
190 isTopo = any(filter(lambda x: attr.startswith(x), ["R2TOPO_", "TOPO_", "MUTOPO_", "MULTTOPO_"]))
191 fs = traceback.extract_stack()[-2]
192 expProdFile = "L1/Config/"
193 if isTopo:
194 if attr.startswith("R2TOPO_"):
195 expProdFile += "TopoAlgoDefLegacy.py"
196 elif attr.startswith("TOPO_"):
197 expProdFile += "TopoAlgoDef.py"
198 elif attr.startswith("MUTOPO_"):
199 expProdFile += "TopoAlgoDefMuctpi.py"
200 elif attr.startswith("MULTTOPO_"):
201 expProdFile += "TopoMultiplicityAlgoDef.py"
202 else:
203 isLegacyThr = any(filter(lambda x: attr.startswith(x), ["EM", "TAU", "J", "XE", "TE", "XS"]))
204 if isLegacyThr:
205 expProdFile += "ThresholdDefLegacy.py"
206 else:
207 expProdFile += "ThresholdDef.py"
208
209 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)
210 log.error(msg)
211 raise RuntimeError(msg)
nlohmann::json json
binary_trigger_type(self, width=8)
Definition Items.py:152
__init__(self, name, ctpid=-1, group='1', prescale=1, psCut=None, verbose=False)
Definition Items.py:86
addMonitor(self, flag, frequency)
Definition Items.py:116
thresholdNames(self, include_bgrp=False)
Definition Items.py:133
conditions(self, include_internal=False)
Definition Items.py:139
setTriggerType(self, ttype)
Definition Items.py:145
markLegacy(self, legacyThresholdsSet)
Definition Items.py:149
__init__(self, name, psType, menuitems)
Definition Items.py:174