ATLAS Offline Software
L1TriggerConfigAccess.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
2 
3 from functools import reduce
4 
5 from TrigConfIO.TriggerConfigAccessBase import TriggerConfigAccess, ConfigType
6 from AthenaCommon.Logging import logging
7 log = logging.getLogger('L1TriggerConfigAccess.py')
8 
9 class L1MenuAccess(TriggerConfigAccess):
10  """
11  this class provides access to the L1Menu
12  the methods are self-explanatory for people with knowledge of the configuration
13  """
14  def __init__(self, filename = None, jsonString = None, dbalias = None, smkey = None, useCrest=False, crestServer=""):
15  """
16  accessor needs to be initialized with either a filename or the dbalias and smkey
17  """
18  super().__init__(ConfigType.L1MENU, mainkey = "items",
19  jsonString = jsonString, filename = filename, dbalias = dbalias, dbkey = smkey,
20  useCrest=useCrest, crestServer=crestServer)
21  self.loader.setQuery({
22  2: "SELECT L1MT.L1TM_DATA FROM {schema}.SUPER_MASTER_TABLE SMT, {schema}.L1_MENU L1MT WHERE L1MT.L1TM_ID=SMT.SMT_L1_MENU_ID AND SMT.SMT_ID=:dbkey", # for new db schema
23  1: "SELECT L1MT.L1MT_MENU FROM {schema}.SUPER_MASTER_TABLE SMT, {schema}.L1_MASTER_TABLE L1MT WHERE L1MT.L1MT_ID=SMT.SMT_L1_MASTER_TABLE_ID AND SMT.SMT_ID=:dbkey" # for current db schema
24  })
25  self.load()
26  if smkey is not None:
27  log.info(f"Loaded L1 menu {self.name()} with {len(self)} items from {dbalias} with smk {smkey}{' using CREST' if useCrest else ''}")
28  elif filename is not None:
29  log.info(f"Loaded L1 menu {self.name()} with {len(self)} chains from file {filename}")
30 
31  def itemNames(self):
32  return self._config["items"].keys()
33 
34  def itemsWithCtpid(self ):
35  return self.items( includeKeys = ['ctpid'] )
36 
37  def items(self, includeKeys = [] ):
38  if includeKeys:
39  """ reduce returned dictionary """
40  items = self._config["items"]
41  return { x : {k : items[x][k] for k in includeKeys if k in items[x]} for x in items }
42  else:
43  return self._config["items"]
44 
45  def thresholdTypes(self):
46  thrTypes = list(self._config["thresholds"].keys())
47  if "legacyCalo" in thrTypes:
48  thrTypes.remove("legacyCalo")
49  thrTypes += list(self._config["thresholds"]["legacyCalo"].keys())
50  return thrTypes
51 
52  def thresholds(self, thresholdType = None, fulldict = False):
53  """
54  When setting fulldict the full dictionary is returned, else just thresholds
55  """
56  if thresholdType:
57  if thresholdType == "internal":
58  return {}
59  if thresholdType in self["thresholds"]:
60  if fulldict:
61  return self["thresholds"][thresholdType]
62  else:
63  return self["thresholds"][thresholdType]["thresholds"]
64  if thresholdType in self["thresholds"]["legacyCalo"]:
65  return self["thresholds"]["legacyCalo"][thresholdType]["thresholds"]
66  raise RuntimeError("Threshold type %s not known in thresholds section of the menu" % thresholdType)
67  else:
68  thrs = {}
69  for thrType in self.thresholdTypes():
70  thrs.update( self.thresholds(thrType) )
71  return thrs
72 
73  def thresholdNames(self, thresholdType = None):
74  if thresholdType == "internal":
75  return self["thresholds"]["internal"]["names"]
76  elif thresholdType is None:
77  return list(self.thresholds().keys()) + self.thresholdNames("internal")
78  else:
79  return list(self.thresholds(thresholdType).keys())
80 
81  def thresholdExtraInfo(self, thresholdType):
82  if thresholdType in self["thresholds"]:
83  thrDef = self["thresholds"][thresholdType]
84  elif thresholdType in self["thresholds"]["legacyCalo"]:
85  thrDef = self["thresholds"]["legacyCalo"][thresholdType]
86  else:
87  raise KeyError("Threshold type %s not known in thresholds section of the menu" % thresholdType)
88  return {k:thrDef[k] for k in thrDef if k not in ("thresholds", "type")}
89 
90  def topoAlgorithmTypes(self):
91  return self["topoAlgorithms"].keys()
92 
93  def topoAlgorithms(self, topoAlgoType = None):
94  if topoAlgoType:
95  return self["topoAlgorithms"][topoAlgoType]
96  else:
97  d = {}
98  for x in self["topoAlgorithms"].values():
99  for gr in x.values():
100  d.update(gr)
101  return d
102 
103  def topoAlgorithmNames(self, topoAlgoType = None):
104  allAlgs = self.topoAlgorithms(topoAlgoType)
105  return allAlgs.keys()
106 
107 
108  def boardNames(self):
109  return iter(self["boards"])
110 
111  def boards(self):
112  return self["boards"]
113 
114  def board(self, boardName):
115  return self["boards"][boardName]
116 
117  def connectorNames(self):
118  return iter(self["connectors"])
119 
120  def connectors(self):
121  return self["connectors"]
122 
123  def connector(self, connectorName):
124  return self["connectors"][connectorName]
125 
126  def ctp(self):
127  return self["ctp"]
128 
129  def ctpInputs(self, inputType):
130  """ inputType should be 'optical', 'electrical' or 'ctpin'
131  """
132  return self["ctp"]["inputs"][inputType]
133 
134  def printSummary(self):
135  print("L1 menu %s" % self.name())
136  print("Number of items: %i" % len(self))
137  print("Number of threshold types: %i" % len(self.thresholdTypes()) )
138  print("Number of thresholds: %i" % len(self.thresholds()) )
139  print("Number of topo algorithms: %i" % len(self.topoAlgorithms()))
140  print("Number of boards: %i (%i are legacy boards)" % ( len(self.boards()), sum(["legacy" in b for b in self.boards().values()]) ))
141  print("Number of connectors: %i (%i are legacy connetors)" % ( len(self.connectors()), sum(["legacy" in c for c in self.connectors().values()]) ))
142  print("CTP has %i optical, %i electrical, and %i CTPIN inputs" % ( len(self.ctpInputs("optical")), len(self.ctpInputs("electrical")),
143  len(reduce(
144  lambda s1,i: s1.union(self.ctpInputs("ctpin")[f"slot{i}"].values()),
145  [7,8,9], set()) - set([""]) )))
146 
147 
148 
149 
150 class L1PrescalesSetAccess(TriggerConfigAccess):
151  """
152  this class provides access to the L1 prescales set
153  the methods are self-explanatory for people with knowledge of the configuration
154  """
155  @staticmethod
157  """
158  turns cut value (which is what the hardware is configured with), into a float prescale value
159  """
160  return 0xFFFFFF / ( 0x1000000 - cut )
161 
162  def __init__(self, filename = None, jsonString = None, dbalias = None, l1pskey = None, useCrest=False, crestServer=""):
163  """
164  accessor needs to be initialized with either a filename or the dbalias and l1pskey
165  """
166  super().__init__(ConfigType.L1PS, mainkey = "cutValues",
167  jsonString = jsonString, filename = filename, dbalias = dbalias, dbkey = l1pskey,
168  useCrest=useCrest, crestServer=crestServer)
169  self.loader.setQuery({
170  1: "SELECT L1PS_DATA FROM {schema}.L1_PRESCALE_SET L1PS WHERE L1PS_ID=:dbkey" # for current and new db schema
171  })
172  self.load()
173  if l1pskey is not None:
174  log.info(f"Loaded L1 prescales {self.name()} with {len(self)} items from {dbalias} with psk {l1pskey}{' using CREST' if useCrest else ''}")
175  elif filename is not None:
176  log.info(f"Loaded L1 prescales {self.name()} with {len(self)} items from file {filename}")
177 
178 
179  def itemNames(self):
180  return self["cutValues"].keys()
181  def cutValues(self):
182  return self["cutValues"]
183  def cut(self, itemName):
184  return self["cutValues"][itemName]["cut"]
185  def prescale(self, itemName):
186  return L1PrescalesSetAccess.calcPrescaleFromCut( self.cut(itemName) )
187 
188  def enabled(self, itemName):
189  return self["cutValues"][itemName]["enabled"]
190 
191  def printSummary(self):
192  print("L1 prescales set %s" % self.name())
193  print("Number of prescales: %i" % len(self) )
194  print("Number of enabled prescales: %i" % sum(x["enabled"] for x in self["cutValues"].values()) )
195 
196 
197 class BunchGroupSetAccess(TriggerConfigAccess):
198  """
199  this class provides access to the L1 bunchgroup set
200  the methods are self-explanatory for people with knowledge of the configuration
201  """
202  def __init__(self, filename = None, jsonString = None, dbalias = None, bgskey = None, useCrest=False, crestServer=""):
203  super().__init__(ConfigType.BGS, mainkey = "bunchGroups",
204  jsonString = jsonString, filename = filename, dbalias = dbalias, dbkey = bgskey,
205  useCrest=useCrest, crestServer=crestServer)
206  self.loader.setQuery({
207  1: "SELECT L1BGS_DATA FROM {schema}.L1_BUNCH_GROUP_SET BGS WHERE L1BGS_ID=:dbkey" # for current and new db schema
208  })
209  self.load()
210  if bgskey is not None:
211  log.info(f"Loaded L1 bunchgroup set {self.name()} with {len(self)} bunchgroups from {dbalias} with bgsk {bgskey}{' using CREST' if useCrest else ''}")
212  elif filename is not None:
213  log.info(f"Loaded L1 bunchgroup set {self.name()} with {len(self)} bunchgroups from file {filename}")
214 
python.L1TriggerConfigAccess.L1PrescalesSetAccess.itemNames
def itemNames(self)
Definition: L1TriggerConfigAccess.py:179
python.L1TriggerConfigAccess.L1MenuAccess.topoAlgorithmNames
def topoAlgorithmNames(self, topoAlgoType=None)
Definition: L1TriggerConfigAccess.py:103
python.L1TriggerConfigAccess.L1MenuAccess.thresholds
def thresholds(self, thresholdType=None, fulldict=False)
Definition: L1TriggerConfigAccess.py:52
python.L1TriggerConfigAccess.L1PrescalesSetAccess
Definition: L1TriggerConfigAccess.py:150
python.L1TriggerConfigAccess.L1MenuAccess.thresholdExtraInfo
def thresholdExtraInfo(self, thresholdType)
Definition: L1TriggerConfigAccess.py:81
python.L1TriggerConfigAccess.L1MenuAccess.connectors
def connectors(self)
Definition: L1TriggerConfigAccess.py:120
python.L1TriggerConfigAccess.L1PrescalesSetAccess.prescale
def prescale(self, itemName)
Definition: L1TriggerConfigAccess.py:185
python.L1TriggerConfigAccess.L1MenuAccess.ctpInputs
def ctpInputs(self, inputType)
Definition: L1TriggerConfigAccess.py:129
python.L1TriggerConfigAccess.L1MenuAccess.boardNames
def boardNames(self)
Definition: L1TriggerConfigAccess.py:108
python.L1TriggerConfigAccess.L1MenuAccess.thresholdNames
def thresholdNames(self, thresholdType=None)
Definition: L1TriggerConfigAccess.py:73
python.L1TriggerConfigAccess.L1PrescalesSetAccess.cutValues
def cutValues(self)
Definition: L1TriggerConfigAccess.py:181
python.L1TriggerConfigAccess.L1PrescalesSetAccess.__init__
def __init__(self, filename=None, jsonString=None, dbalias=None, l1pskey=None, useCrest=False, crestServer="")
Definition: L1TriggerConfigAccess.py:162
python.L1TriggerConfigAccess.L1PrescalesSetAccess.enabled
def enabled(self, itemName)
Definition: L1TriggerConfigAccess.py:188
python.L1TriggerConfigAccess.L1MenuAccess.thresholdTypes
def thresholdTypes(self)
Definition: L1TriggerConfigAccess.py:45
reduce
void reduce(HepMC::GenEvent *ge, std::vector< HepMC::GenParticlePtr > toremove)
Remove unwanted particles from the event, collapsing the graph structure consistently.
Definition: FixHepMC.cxx:81
python.L1TriggerConfigAccess.L1PrescalesSetAccess.printSummary
def printSummary(self)
Definition: L1TriggerConfigAccess.py:191
python.L1TriggerConfigAccess.BunchGroupSetAccess.__init__
def __init__(self, filename=None, jsonString=None, dbalias=None, bgskey=None, useCrest=False, crestServer="")
Definition: L1TriggerConfigAccess.py:202
python.Bindings.values
values
Definition: Control/AthenaPython/python/Bindings.py:805
python.L1TriggerConfigAccess.L1MenuAccess.topoAlgorithms
def topoAlgorithms(self, topoAlgoType=None)
Definition: L1TriggerConfigAccess.py:93
python.L1TriggerConfigAccess.L1MenuAccess.printSummary
def printSummary(self)
Definition: L1TriggerConfigAccess.py:134
python.L1TriggerConfigAccess.L1MenuAccess.topoAlgorithmTypes
def topoAlgorithmTypes(self)
Definition: L1TriggerConfigAccess.py:90
convertTimingResiduals.sum
sum
Definition: convertTimingResiduals.py:55
python.L1TriggerConfigAccess.L1PrescalesSetAccess.cut
def cut(self, itemName)
Definition: L1TriggerConfigAccess.py:183
python.L1TriggerConfigAccess.L1MenuAccess.items
def items(self, includeKeys=[])
Definition: L1TriggerConfigAccess.py:37
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
python.L1TriggerConfigAccess.L1MenuAccess.itemsWithCtpid
def itemsWithCtpid(self)
Definition: L1TriggerConfigAccess.py:34
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition: bitmask.h:232
python.L1TriggerConfigAccess.L1MenuAccess.itemNames
def itemNames(self)
Definition: L1TriggerConfigAccess.py:31
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:25
python.L1TriggerConfigAccess.L1PrescalesSetAccess.calcPrescaleFromCut
def calcPrescaleFromCut(cut)
Definition: L1TriggerConfigAccess.py:156
python.L1TriggerConfigAccess.L1MenuAccess.boards
def boards(self)
Definition: L1TriggerConfigAccess.py:111
python.L1TriggerConfigAccess.L1MenuAccess.connector
def connector(self, connectorName)
Definition: L1TriggerConfigAccess.py:123
python.L1TriggerConfigAccess.L1MenuAccess
Definition: L1TriggerConfigAccess.py:9
python.L1TriggerConfigAccess.L1MenuAccess.board
def board(self, boardName)
Definition: L1TriggerConfigAccess.py:114
python.L1TriggerConfigAccess.BunchGroupSetAccess
Definition: L1TriggerConfigAccess.py:197
python.L1TriggerConfigAccess.L1MenuAccess.ctp
def ctp(self)
Definition: L1TriggerConfigAccess.py:126
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:798
python.L1TriggerConfigAccess.L1MenuAccess.__init__
def __init__(self, filename=None, jsonString=None, dbalias=None, smkey=None, useCrest=False, crestServer="")
Definition: L1TriggerConfigAccess.py:14
python.L1TriggerConfigAccess.L1MenuAccess.connectorNames
def connectorNames(self)
Definition: L1TriggerConfigAccess.py:117