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