ATLAS Offline Software
Loading...
Searching...
No Matches
L1TriggerConfigAccess.py
Go to the documentation of this file.
1# Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
2
3from functools import reduce
4
5from TrigConfIO.TriggerConfigAccessBase import TriggerConfigAccess, ConfigType
6from AthenaCommon.Logging import logging
7log = logging.getLogger('L1TriggerConfigAccess.py')
8
9class 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: str = "", jsonString: str = "", dbalias: str = "", smkey: int = 0,
15 useCrest: bool = False, crestServer: str = ""):
16 """
17 accessor needs to be initialized with either a filename or the dbalias and smkey
18 """
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", # for new db schema
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" # for current db schema
25 })
26 self.load()
27 if smkey is not None:
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}")
31
32 def itemNames(self):
33 return self["items"].keys()
34
35 def itemsWithCtpid(self ):
36 return self.items( includeKeys = ['ctpid'] )
37
38 def items(self, includeKeys = [] ):
39 if includeKeys:
40 """ reduce returned dictionary """
41 items = self["items"]
42 return { x : {k : items[x][k] for k in includeKeys if k in items[x]} for x in items }
43 else:
44 return self["items"]
45
46 def thresholdTypes(self):
47 thrTypes = list(self["thresholds"].keys())
48 if "legacyCalo" in thrTypes:
49 thrTypes.remove("legacyCalo")
50 thrTypes += list(self["thresholds"]["legacyCalo"].keys())
51 return thrTypes
52
53 def thresholds(self, thresholdType = None, fulldict = False):
54 """
55 When setting fulldict the full dictionary is returned, else just thresholds
56 """
57 if thresholdType:
58 if thresholdType == "internal":
59 return {}
60 if thresholdType in self["thresholds"]:
61 if fulldict:
62 return self["thresholds"][thresholdType]
63 else:
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)
68 else:
69 thrs = {}
70 for thrType in self.thresholdTypes():
71 thrs.update( self.thresholds(thrType) )
72 return thrs
73
74 def thresholdNames(self, thresholdType = None):
75 if thresholdType == "internal":
76 return self["thresholds"]["internal"]["names"]
77 elif thresholdType is None:
78 return list(self.thresholds().keys()) + self.thresholdNames("internal")
79 else:
80 return list(self.thresholds(thresholdType).keys())
81
82 def thresholdExtraInfo(self, thresholdType):
83 if thresholdType in self["thresholds"]:
84 thrDef = self["thresholds"][thresholdType]
85 elif thresholdType in self["thresholds"]["legacyCalo"]:
86 thrDef = self["thresholds"]["legacyCalo"][thresholdType]
87 else:
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")}
90
92 return self["topoAlgorithms"].keys()
93
94 def topoAlgorithms(self, topoAlgoType = None):
95 if topoAlgoType:
96 return self["topoAlgorithms"][topoAlgoType]
97 else:
98 d = {}
99 for x in self["topoAlgorithms"].values():
100 for gr in x.values():
101 d.update(gr)
102 return d
103
104 def topoAlgorithmNames(self, topoAlgoType = None):
105 allAlgs = self.topoAlgorithms(topoAlgoType)
106 return allAlgs.keys()
107
108
109 def boardNames(self):
110 return iter(self["boards"])
111
112 def boards(self):
113 return self["boards"]
114
115 def board(self, boardName):
116 return self["boards"][boardName]
117
118 def connectorNames(self):
119 return iter(self["connectors"])
120
121 def connectors(self):
122 return self["connectors"]
123
124 def connector(self, connectorName):
125 return self["connectors"][connectorName]
126
127 def ctp(self):
128 return self["ctp"]
129
130 def ctpInputs(self, inputType):
131 """ inputType should be 'optical', 'electrical' or 'ctpin'
132 """
133 return self["ctp"]["inputs"][inputType]
134
135 def printSummary(self):
136 print("L1 menu %s" % self.name())
137 print("Number of items: %i" % len(self))
138 print("Number of threshold types: %i" % len(self.thresholdTypes()) )
139 print("Number of thresholds: %i" % len(self.thresholds()) )
140 print("Number of topo algorithms: %i" % len(self.topoAlgorithms()))
141 print("Number of boards: %i (%i are legacy boards)" % ( len(self.boards()), sum(["legacy" in b for b in self.boards().values()]) ))
142 print("Number of connectors: %i (%i are legacy connetors)" % ( len(self.connectors()), sum(["legacy" in c for c in self.connectors().values()]) ))
143 print("CTP has %i optical, %i electrical, and %i CTPIN inputs" % ( len(self.ctpInputs("optical")), len(self.ctpInputs("electrical")),
144 len(reduce(
145 lambda s1,i: s1.union(self.ctpInputs("ctpin")[f"slot{i}"].values()),
146 [7,8,9], set()) - set([""]) )))
147
148
149
150
151class L1PrescalesSetAccess(TriggerConfigAccess):
152 """
153 this class provides access to the L1 prescales set
154 the methods are self-explanatory for people with knowledge of the configuration
155 """
156 @staticmethod
158 """
159 turns cut value (which is what the hardware is configured with), into a float prescale value
160 """
161 return 0xFFFFFF / ( 0x1000000 - cut )
162
163 def __init__(self, filename: str = "", jsonString: str = "", dbalias: str = "", l1pskey: int = 0,
164 useCrest: bool = False, crestServer: str = ""):
165 """
166 accessor needs to be initialized with either a filename or the dbalias and l1pskey
167 """
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" # for current and new db schema
172 })
173 self.load()
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}")
178
179
180 def itemNames(self):
181 return self["cutValues"].keys()
182 def cutValues(self):
183 return self["cutValues"]
184 def cut(self, itemName):
185 return self["cutValues"][itemName]["cut"]
186 def prescale(self, itemName):
187 return L1PrescalesSetAccess.calcPrescaleFromCut( self.cut(itemName) )
188
189 def enabled(self, itemName):
190 return self["cutValues"][itemName]["enabled"]
191
192 def printSummary(self):
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()) )
196
197
198class BunchGroupSetAccess(TriggerConfigAccess):
199 """
200 this class provides access to the L1 bunchgroup set
201 the methods are self-explanatory for people with knowledge of the configuration
202 """
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" # for current and new db schema
210 })
211 self.load()
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}")
216
static void reduce(HepMC::GenEvent *ge, HepMC::GenParticle *gp)
Remove an unwanted particle from the event, collapsing the graph structure consistently.
Definition FixHepMC.cxx:39
void print(char *figname, TCanvas *c1)
__init__(self, str filename="", str jsonString="", str dbalias="", int bgskey=0, bool useCrest=False, str crestServer="")
__init__(self, str filename="", str jsonString="", str dbalias="", int smkey=0, bool useCrest=False, str crestServer="")
thresholds(self, thresholdType=None, fulldict=False)
__init__(self, str filename="", str jsonString="", str dbalias="", int l1pskey=0, bool useCrest=False, str crestServer="")
STL class.