ATLAS Offline Software
Items.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2 
3 from AthenaCommon.Logging import logging
4 
5 from ..Config.MonitorDef import MonitorDef
6 from .PrescaleHelper import getCutFromPrescale, getPrescaleFromCut
7 from .MenuUtils import binstr
8 
9 
10 log = 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
79  def setMenuConfig(mc):
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 
187 class meta_d(type):
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)
python.L1.Base.Items.MenuItemsCollection.json
def json(self)
Definition: Items.py:68
python.L1.Base.Items.PrescaleHandler.psType
psType
Definition: Items.py:176
python.L1.Base.Items.MenuItem.markLegacy
def markLegacy(self, legacyThresholdsSet)
Definition: Items.py:149
python.L1.Base.Items.MenuItemsCollection.menuName
menuName
Definition: Items.py:18
createLinkingScheme.iter
iter
Definition: createLinkingScheme.py:62
vtune_athena.format
format
Definition: vtune_athena.py:14
python.L1.Base.Items.MenuItem.__init__
def __init__(self, name, ctpid=-1, group='1', prescale=1, psCut=None, verbose=False)
Definition: Items.py:86
python.L1.Base.Items.MenuItemsCollection.__contains__
def __contains__(self, itemname)
Definition: Items.py:55
python.L1.Base.Items.MenuItem.addMonitor
def addMonitor(self, flag, frequency)
Definition: Items.py:116
python.L1.Base.Items.MenuItemsCollection.__getitem__
def __getitem__(self, key)
Definition: Items.py:26
python.L1.Base.Items.MenuItem
Definition: Items.py:73
dumpHVPathFromNtuple.append
bool append
Definition: dumpHVPathFromNtuple.py:91
python.TrigConfigSvcUtils.getPrescaleFromCut
def getPrescaleFromCut(cut)
Definition: TrigConfigSvcUtils.py:763
python.L1.Base.Items.PrescaleHandler.__init__
def __init__(self, name, psType, menuitems)
Definition: Items.py:174
python.L1.Base.Items.MenuItemsCollection.pssType
pssType
Definition: Items.py:20
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
python.L1.Base.Items.MenuItem.binary_trigger_type
def binary_trigger_type(self, width=8)
Definition: Items.py:152
python.L1.Base.Items.MenuItem.json
def json(self)
Definition: Items.py:156
python.Bindings.values
values
Definition: Control/AthenaPython/python/Bindings.py:808
covarianceTool.filter
filter
Definition: covarianceTool.py:514
python.L1.Base.Items.meta_d
Definition: Items.py:187
python.L1.Base.Items.MenuItemsCollection.__init__
def __init__(self)
Definition: Items.py:17
python.L1.Base.Items.MenuItem.trigger_type
trigger_type
Definition: Items.py:91
python.L1.Base.Items.MenuItem.name
name
Definition: Items.py:87
python.L1.Base.Items.MenuItem.thresholdNames
def thresholdNames(self, include_bgrp=False)
Definition: Items.py:133
python.L1.Base.Items.MenuItem.ctpid
ctpid
Definition: Items.py:89
python.L1.Base.Items.MenuItemsCollection.__iadd__
def __iadd__(self, item)
Definition: Items.py:41
python.L1.Base.Items.MenuItem.psCut
psCut
Definition: Items.py:90
python.L1.Base.Items.PrescaleHandler
Definition: Items.py:173
python.L1.Base.Items.PrescaleHandler.itemsByPartition
itemsByPartition
Definition: Items.py:178
python.L1.Base.Items.MenuItem.setMenuConfig
def setMenuConfig(mc)
Definition: Items.py:79
python.L1.Base.Items.MenuItemsCollection.itemById
def itemById(self, ctpid)
Definition: Items.py:61
python.L1.Base.Items.MenuItemsCollection.items
items
Definition: Items.py:21
python.L1.Base.Items.meta_d.__getattr__
def __getattr__(cls, attr)
Definition: Items.py:188
python.L1.Base.Items.MenuItem.setLogic
def setLogic(self, logic)
Definition: Items.py:122
python.L1.Base.Items.MenuItem.monitorsHF
monitorsHF
Definition: Items.py:95
python.L1.Base.Items.MenuItem.partition
partition
Definition: Items.py:92
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
python.L1.Base.Items.PrescaleHandler.items
items
Definition: Items.py:177
python.L1.Base.Items.MenuItemsCollection.itemNames
def itemNames(self)
Definition: Items.py:65
python.L1.Base.Items.MenuItem.bunchGroups
bunchGroups
Definition: Items.py:97
python.L1.Base.Items.MenuItemsCollection
Definition: Items.py:13
python.L1.Base.Items.MenuItemsCollection.__setitem__
def __setitem__(self, name, item)
Definition: Items.py:29
python.L1.Base.Items.MenuItem.legacy
legacy
Definition: Items.py:98
python.L1.Base.Items.MenuItem.verbose
verbose
Definition: Items.py:96
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
python.L1.Base.Items.MenuItem.prescale
def prescale(self)
Definition: Items.py:108
python.L1.Base.Items.MenuItemsCollection.__len__
def __len__(self)
Definition: Items.py:58
python.L1.Base.MenuUtils.binstr
def binstr(value, width)
Definition: MenuUtils.py:7
python.L1.Base.Items.MenuItem.setCtpid
def setCtpid(self, x)
Definition: Items.py:129
python.L1.Base.PrescaleHelper.getCutFromPrescale
def getCutFromPrescale(prescale)
Definition: PrescaleHelper.py:24
python.L1.Base.Items.MenuItem.logic
logic
Definition: Items.py:93
python.L1.Base.Items.MenuItem.__str__
def __str__(self)
Definition: Items.py:103
python.L1.Base.Items.MenuItem.setTriggerType
def setTriggerType(self, ttype)
Definition: Items.py:145
python.L1.Base.Items.MenuItem.conditions
def conditions(self, include_internal=False)
Definition: Items.py:139
python.L1.Base.Items.MenuItemsCollection.__iter__
def __iter__(self)
Definition: Items.py:23
pickleTool.object
object
Definition: pickleTool.py:29
str
Definition: BTagTrackIpAccessor.cxx:11
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:801
python.L1.Base.Items.MenuItemsCollection.pssName
pssName
Definition: Items.py:19
python.L1.Base.Items.MenuItem.monitorsLF
monitorsLF
Definition: Items.py:94
python.L1.Base.Items.MenuItem.group
group
Definition: Items.py:88
python.L1.Base.Items.PrescaleHandler.name
name
Definition: Items.py:175