3 from functools
import reduce
5 from TrigConfIO.TriggerConfigAccessBase
import TriggerConfigAccess, ConfigType
6 from AthenaCommon.Logging
import logging
7 log = logging.getLogger(
'L1TriggerConfigAccess.py')
11 this class provides access to the L1Menu
12 the methods are self-explanatory for people with knowledge of the configuration
14 def __init__(self, filename: str =
"", jsonString: str =
"", dbalias: str =
"", smkey: int = 0,
15 useCrest: bool =
False, crestServer: str =
""):
17 accessor needs to be initialized with either a filename or the dbalias and smkey
19 super().
__init__(ConfigType.L1MENU, mainkey =
"items",
20 jsonString = jsonString, filename = filename, dbalias = dbalias, dbkey = smkey,
21 useCrest=useCrest, crestServer=crestServer)
22 self.loader.setQuery({
23 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",
24 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"
28 log.info(f
"Loaded L1 menu {self.name()} with {len(self)} items from {dbalias} with smk {smkey}{' using CREST' if useCrest else ''}")
29 elif filename
is not None:
30 log.info(f
"Loaded L1 menu {self.name()} with {len(self)} chains from file {filename}")
33 return self[
"items"].
keys()
36 return self.
items( includeKeys = [
'ctpid'] )
38 def items(self, includeKeys = [] ):
40 """ reduce returned dictionary """
42 return { x : {k : items[x][k]
for k
in includeKeys
if k
in items[x]}
for x
in items }
47 thrTypes =
list(self[
"thresholds"].
keys())
48 if "legacyCalo" in thrTypes:
49 thrTypes.remove(
"legacyCalo")
50 thrTypes +=
list(self[
"thresholds"][
"legacyCalo"].
keys())
53 def thresholds(self, thresholdType = None, fulldict = False):
55 When setting fulldict the full dictionary is returned, else just thresholds
58 if thresholdType ==
"internal":
60 if thresholdType
in self[
"thresholds"]:
62 return self[
"thresholds"][thresholdType]
64 return self[
"thresholds"][thresholdType][
"thresholds"]
65 if thresholdType
in self[
"thresholds"][
"legacyCalo"]:
66 return self[
"thresholds"][
"legacyCalo"][thresholdType][
"thresholds"]
67 raise RuntimeError(
"Threshold type %s not known in thresholds section of the menu" % thresholdType)
75 if thresholdType ==
"internal":
76 return self[
"thresholds"][
"internal"][
"names"]
77 elif thresholdType
is None:
83 if thresholdType
in self[
"thresholds"]:
84 thrDef = self[
"thresholds"][thresholdType]
85 elif thresholdType
in self[
"thresholds"][
"legacyCalo"]:
86 thrDef = self[
"thresholds"][
"legacyCalo"][thresholdType]
88 raise KeyError(
"Threshold type %s not known in thresholds section of the menu" % thresholdType)
89 return {k:thrDef[k]
for k
in thrDef
if k
not in (
"thresholds",
"type")}
92 return self[
"topoAlgorithms"].
keys()
96 return self[
"topoAlgorithms"][topoAlgoType]
99 for x
in self[
"topoAlgorithms"].
values():
100 for gr
in x.values():
106 return allAlgs.keys()
110 return iter(self[
"boards"])
113 return self[
"boards"]
116 return self[
"boards"][boardName]
119 return iter(self[
"connectors"])
122 return self[
"connectors"]
125 return self[
"connectors"][connectorName]
131 """ inputType should be 'optical', 'electrical' or 'ctpin'
133 return self[
"ctp"][
"inputs"][inputType]
136 print(
"L1 menu %s" % self.name())
137 print(
"Number of items: %i" % len(self))
141 print(
"Number of boards: %i (%i are legacy boards)" % ( len(self.
boards()),
sum([
"legacy" in b
for b
in self.
boards().
values()]) ))
143 print(
"CTP has %i optical, %i electrical, and %i CTPIN inputs" % ( len(self.
ctpInputs(
"optical")), len(self.
ctpInputs(
"electrical")),
146 [7,8,9],
set()) -
set([
""]) )))
153 this class provides access to the L1 prescales set
154 the methods are self-explanatory for people with knowledge of the configuration
159 turns cut value (which is what the hardware is configured with), into a float prescale value
161 return 0xFFFFFF / ( 0x1000000 - cut )
163 def __init__(self, filename: str =
"", jsonString: str =
"", dbalias: str =
"", l1pskey: int = 0,
164 useCrest: bool =
False, crestServer: str =
""):
166 accessor needs to be initialized with either a filename or the dbalias and l1pskey
168 super().
__init__(ConfigType.L1PS, mainkey =
"cutValues", jsonString = jsonString, filename = filename,
169 dbalias = dbalias, dbkey = l1pskey, useCrest=useCrest, crestServer=crestServer)
170 self.loader.setQuery({
171 1:
"SELECT L1PS_DATA FROM {schema}.L1_PRESCALE_SET L1PS WHERE L1PS_ID=:dbkey"
174 if l1pskey
is not None:
175 log.info(f
"Loaded L1 prescales {self.name()} with {len(self)} items from {dbalias} with psk {l1pskey}{' using CREST' if useCrest else ''}")
176 elif filename
is not None:
177 log.info(f
"Loaded L1 prescales {self.name()} with {len(self)} items from file {filename}")
181 return self[
"cutValues"].
keys()
183 return self[
"cutValues"]
185 return self[
"cutValues"][itemName][
"cut"]
187 return L1PrescalesSetAccess.calcPrescaleFromCut( self.
cut(itemName) )
190 return self[
"cutValues"][itemName][
"enabled"]
193 print(
"L1 prescales set %s" % self.name())
194 print(
"Number of prescales: %i" % len(self) )
195 print(
"Number of enabled prescales: %i" %
sum(x[
"enabled"]
for x
in self[
"cutValues"].
values()) )
200 this class provides access to the L1 bunchgroup set
201 the methods are self-explanatory for people with knowledge of the configuration
203 def __init__(self, filename: str =
"", jsonString: str =
"", dbalias: str =
"", bgskey: int = 0,
204 useCrest: bool =
False, crestServer: str =
""):
205 super().
__init__(ConfigType.BGS, mainkey =
"bunchGroups",
206 jsonString = jsonString, filename = filename, dbalias = dbalias, dbkey = bgskey,
207 useCrest=useCrest, crestServer=crestServer)
208 self.loader.setQuery({
209 1:
"SELECT L1BGS_DATA FROM {schema}.L1_BUNCH_GROUP_SET BGS WHERE L1BGS_ID=:dbkey"
212 if bgskey
is not None:
213 log.info(f
"Loaded L1 bunchgroup set {self.name()} with {len(self)} bunchgroups from {dbalias} with bgsk {bgskey}{' using CREST' if useCrest else ''}")
214 elif filename
is not None:
215 log.info(f
"Loaded L1 bunchgroup set {self.name()} with {len(self)} bunchgroups from file {filename}")