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 = None, jsonString = None, dbalias = None, smkey = None, useCrest=False, crestServer=""):
16 accessor needs to be initialized with either a filename or the dbalias and smkey
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",
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"
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}")
32 return self._config[
"items"].
keys()
35 return self.
items( includeKeys = [
'ctpid'] )
37 def items(self, 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 }
43 return self._config[
"items"]
46 thrTypes =
list(self._config[
"thresholds"].
keys())
47 if "legacyCalo" in thrTypes:
48 thrTypes.remove(
"legacyCalo")
49 thrTypes +=
list(self._config[
"thresholds"][
"legacyCalo"].
keys())
52 def thresholds(self, thresholdType = None, fulldict = False):
54 When setting fulldict the full dictionary is returned, else just thresholds
57 if thresholdType ==
"internal":
59 if thresholdType
in self[
"thresholds"]:
61 return self[
"thresholds"][thresholdType]
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)
74 if thresholdType ==
"internal":
75 return self[
"thresholds"][
"internal"][
"names"]
76 elif thresholdType
is None:
82 if thresholdType
in self[
"thresholds"]:
83 thrDef = self[
"thresholds"][thresholdType]
84 elif thresholdType
in self[
"thresholds"][
"legacyCalo"]:
85 thrDef = self[
"thresholds"][
"legacyCalo"][thresholdType]
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")}
91 return self[
"topoAlgorithms"].
keys()
95 return self[
"topoAlgorithms"][topoAlgoType]
98 for x
in self[
"topoAlgorithms"].
values():
105 return allAlgs.keys()
109 return iter(self[
"boards"])
112 return self[
"boards"]
115 return self[
"boards"][boardName]
118 return iter(self[
"connectors"])
121 return self[
"connectors"]
124 return self[
"connectors"][connectorName]
130 """ inputType should be 'optical', 'electrical' or 'ctpin'
132 return self[
"ctp"][
"inputs"][inputType]
135 print(
"L1 menu %s" % self.name())
136 print(
"Number of items: %i" % len(self))
140 print(
"Number of boards: %i (%i are legacy boards)" % ( len(self.
boards()),
sum([
"legacy" in b
for b
in self.
boards().
values()]) ))
142 print(
"CTP has %i optical, %i electrical, and %i CTPIN inputs" % ( len(self.
ctpInputs(
"optical")), len(self.
ctpInputs(
"electrical")),
145 [7,8,9],
set()) -
set([
""]) )))
152 this class provides access to the L1 prescales set
153 the methods are self-explanatory for people with knowledge of the configuration
158 turns cut value (which is what the hardware is configured with), into a float prescale value
160 return 0xFFFFFF / ( 0x1000000 - cut )
162 def __init__(self, filename = None, jsonString = None, dbalias = None, l1pskey = None, useCrest=False, crestServer=""):
164 accessor needs to be initialized with either a filename or the dbalias and l1pskey
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"
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}")
180 return self[
"cutValues"].
keys()
182 return self[
"cutValues"]
184 return self[
"cutValues"][itemName][
"cut"]
186 return L1PrescalesSetAccess.calcPrescaleFromCut( self.
cut(itemName) )
189 return self[
"cutValues"][itemName][
"enabled"]
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()) )
199 this class provides access to the L1 bunchgroup set
200 the methods are self-explanatory for people with knowledge of the configuration
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"
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}")