ATLAS Offline Software
Loading...
Searching...
No Matches
HLTTriggerConfigAccess.py
Go to the documentation of this file.
1# Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
2from functools import lru_cache, reduce
3
4from TrigConfIO.TriggerConfigAccessBase import TriggerConfigAccess, ConfigType
5
6from AthenaCommon.Logging import logging
7log = logging.getLogger('HLTTriggerConfigAccess.py')
8
9class HLTMenuAccess(TriggerConfigAccess):
10 """
11 this class provides access to the HLT menu
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.HLTMENU, mainkey = "chains",
20 filename = filename, jsonString = jsonString, dbalias = dbalias, dbkey = smkey,
21 useCrest=useCrest, crestServer=crestServer)
22 self.loader.setQuery({
23 2: "SELECT HMT.HTM_DATA FROM {schema}.SUPER_MASTER_TABLE SMT, {schema}.HLT_MENU HMT WHERE HMT.HTM_ID=SMT.SMT_HLT_MENU_ID AND SMT.SMT_ID=:dbkey", # for new db schema
24 1: "SELECT HMT.HMT_MENU FROM {schema}.SUPER_MASTER_TABLE SMT, {schema}.HLT_MASTER_TABLE HMT WHERE HMT.HMT_ID=SMT.SMT_HLT_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 HLT menu {self.name()} with {len(self)} chains from {dbalias} with smk {smkey}{' using CREST' if useCrest else ''}")
29 elif filename is not None:
30 log.info(f"Loaded HLT menu {self.name()} with {len(self)} chains from file {filename}")
31
32 def chainNames(self):
33 return self["chains"].keys()
34
35 def chains(self):
36 return self["chains"]
37
38 def streams(self):
39 return self["streams"]
40
41 def sequencers(self):
42 return self["sequencers"]
43
44 def printSummary(self):
45 print("HLT menu %s" % self.name())
46 print("Number of chains: %i" % len(self.chains()) )
47 print("Number of streams: %i" % len(self.streams()) )
48 print("Number of sequencers: %i" % len(self.sequencers()) )
49
50 def printDetails(self):
51 import pprint
52 print("Chains:")
53 pprint.pprint(list(self.chains()))
54 print("Streams:")
55 pprint.pprint(list(self.streams()))
56 print("Sequencers:")
57 pprint.pprint(list(self.sequencers()))
58
59class HLTPrescalesSetAccess(TriggerConfigAccess):
60 """
61 this class provides access to the HLT prescales set
62 the methods are self-explanatory for people with knowledge of the configuration
63 """
64 def __init__(self, filename: str = "", jsonString: str = "", dbalias: str = "", hltpskey: int = 0,
65 useCrest: bool = False, crestServer: str = ""):
66 """
67 accessor needs to be initialized with either a filename or the dbalias and hlpskey
68 """
69 super().__init__(ConfigType.HLTPS, mainkey = "prescales",
70 jsonString = jsonString, filename = filename, dbalias = dbalias, dbkey = hltpskey,
71 useCrest=useCrest, crestServer=crestServer)
72 self.loader.setQuery({
73 1: "SELECT HPS_DATA FROM {schema}.HLT_PRESCALE_SET HPS WHERE HPS_ID=:dbkey" # for current and new db schema
74 })
75 self.load()
76 if hltpskey is not None:
77 log.info(f"Loaded HLT prescales {self.name()} (size {len(self)}) from {dbalias} with psk {hltpskey}{' using CREST' if useCrest else ''}")
78 elif filename is not None:
79 log.info(f"Loaded HLT prescales {self.name()} with {len(self)} chains from file {filename}")
80
81 def prescales(self):
82 return self["prescales"]
83
84 def chainNames(self):
85 return iter(self)
86
87 def prescale(self, chainName):
88 return self["prescales"][chainName]["prescale"]
89
90 def enabled(self, chainName):
91 return self["prescales"][chainName]["enabled"]
92
93 def printSummary(self):
94 print("HLT prescales set %s" % self.name())
95 print("Number of prescales: %i" % len(self) )
96 print("Number of enabled prescales: %i" % sum(x["enabled"] for x in self["prescales"].values()) )
97
98
99
100class HLTJobOptionsAccess(TriggerConfigAccess):
101 """
102 this class provides access to the HLT algorithm configuration
103 the methods are self-explanatory for people with knowledge of the configuration
104 """
105 def __init__(self, filename: str = "", dbalias: str = "", smkey: int = 0,
106 useCrest: bool = False, crestServer: str = ""):
107 """
108 accessor needs to be initialized with either a filename or the dbalias and smkey
109 """
110 super().__init__(ConfigType.HLTJO, mainkey = "properties",
111 filename = filename, dbalias = dbalias, dbkey = smkey,
112 useCrest = useCrest, crestServer = crestServer)
113 self.loader.setQuery({
114 2: "SELECT JO.HJO_DATA FROM {schema}.SUPER_MASTER_TABLE SMT, {schema}.HLT_JOBOPTIONS JO WHERE JO.HJO_ID=SMT.SMT_HLT_JOBOPTIONS_ID AND SMT.SMT_ID=:dbkey", # for new db schema
115 1: "SELECT JO.JO_CONTENT FROM {schema}.SUPER_MASTER_TABLE SMT, {schema}.JO_MASTER_TABLE JO WHERE JO.JO_ID=SMT.SMT_JO_MASTER_TABLE_ID AND SMT.SMT_ID=:dbkey" # for current db schema
116 })
117 self.load()
118 if smkey is not None:
119 log.info(f"Loaded HLT job options {self.name()} with {len(self)} algorithms from {dbalias} with smk {smkey}{' using CREST' if useCrest else ''}")
120 elif filename is not None:
121 log.info(f"Loaded HLT job options {self.name()} with {len(self)} chains from file {filename}")
122
123 def algorithms(self):
124 return self["properties"]
125
126 def algorithmNames(self):
127 return iter(self)
128
129 def properties(self, algName):
130 return self["properties"][algName]
131
132 def name(self):
133 # job options don't have a name
134 return "HLT JobOptions"
135
136
137 def printSummary(self):
138 print("Job options")
139 print("Number of algorithms: %i" % len(self) )
140 print("Number of properties: %i" % sum(len(alg) for alg in self.algorithms().values()) )
141
142
143class HLTMonitoringAccess(TriggerConfigAccess):
144 """
145 this class provides access to the HLT monitoring json
146 """
147 def __init__(self, filename: str = "", jsonString: str = "", dbalias: str = "", smkey: int = 0, monikey: int = 0,
148 useCrest: bool = False, crestServer: str = ""):
149 """
150 accessor needs to be initialized with either a filename or the dbalias and hlpskey
151 """
152 super().__init__(ConfigType.HLTMON, mainkey = "signatures",
153 jsonString = jsonString, filename = filename, dbalias = dbalias, dbkey = smkey if smkey else monikey,
154 useCrest=useCrest, crestServer=crestServer)
155 self.loader.setQuery({
156 7: (
157 "SELECT HMG.HMG_DATA FROM {schema}.HLT_MONITORING_GROUPS HMG, {schema}.SUPER_MASTER_TABLE SMT WHERE HMG.HMG_IN_USE=1 "
158 "AND SMT.SMT_HLT_MENU_ID = HMG.HMG_HLT_MENU_ID AND SMT.SMT_ID=:dbkey ORDER BY HMG.HMG_ID DESC"
159 )
160 } if smkey else {
161 7: "SELECT HMG.HMG_DATA FROM {schema}.HLT_MONITORING_GROUPS HMG WHERE HMG.HMG_ID=:dbkey"
162 })
163 self.load()
164 if smkey is not None:
165 log.info(f"Loaded HLT monitoring {self.name()} with {len(self)} signatures from {dbalias} with smk {smkey}{' using CREST' if useCrest else ''}")
166 elif filename is not None:
167 log.info(f"Loaded HLT monitoring {self.name()} with {len(self)} signatures from file {filename}")
168
169
170 def monitoringDict(self):
171 """
172 return stored monitoring dictionary
173 """
174 return self["signatures"]
175
176
177 def monitoredChains(self, signatures="", monLevels="", wildcard=""):
178 """
179 return list of all monitored shifter chains for given signature and for a given monitoring level
180
181 signatures - monitored signature or list of signatures for which to return the chains
182 empty string means all signatures
183 monLevels - levels of monitoring (shifter, t0 (expert), val (validation))
184 wildcard - regexp pattern to match the chains' names
185
186 if monitoring level is not defined return all the chains for given signature
187 if signature is not defined return all the chains for given monitoring level
188 if both monitoring level and signature are not defined, raturn all chains
189
190 return can be filtered by wildcard
191 """
192 chains = set()
193
194 if signatures=="": # empty string means all signatures
195 signatures = set(self)
196
197 # turn input (str,list) into a set of signature names
198 if isinstance(signatures, str):
199 signatures = set([signatures])
200 signatures = set(signatures)
201
202 # warn about requested signatures that don't have a monitoring entry and remove from the request
203 noMonAvailable = signatures.difference(self)
204 if noMonAvailable:
205 log.warning("These monitoring signatures are requested but not available in HLT monitoring: %s", ', '.join(noMonAvailable))
206 signatures.intersection_update(self) # ignore non-existing signatures
207
208 # turn input (str,list) into a set of monLevels
209 if isinstance(monLevels, str):
210 monLevels = set([monLevels])
211 monLevels = set(monLevels)
212
213 for signature in signatures:
214 for chainName, targets in self["signatures"][signature].items():
215 if monLevels.intersection(targets+[""]): # if there is an overlap between requested and configured
216 chains.add(chainName)
217
218 try:
219 import re
220 r = re.compile(wildcard)
221 chains = filter(r.search, chains)
222 except re.error as exc:
223 log.warning("Wildcard regex: %r is not correct!", exc)
224
225 # Create set first to ensure uniquness of elements
226 return list(chains)
227
228
229 @lru_cache(maxsize=5)
230 def monitoringLevels(self, signatures = None):
231 """
232 return all monitoring levels
233 If one ore more signatures are specified, return only monitoring levels for those
234 """
235 if signatures is None:
236 signatures = set(self)
237 if isinstance(signatures, str):
238 signatures = set([signatures])
239 signatures = set(signatures)
240 levels = set()
241 for signatureName, chains in self["signatures"].items():
242 if signatureName in signatures:
243 levels = reduce( lambda x, y: x.union(y), chains.values(), levels )
244 return levels
245
246
247 def printSummary(self):
248 print("HLT monitoring groups %s" % self.name())
249 print("Signatures (%i): %s" % (len(self), ", ".join(self)) )
250 print("Monitoring levels (%i): %s" % (len(self.monitoringLevels()), ", ".join(self.monitoringLevels())))
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 dbalias="", int smkey=0, bool useCrest=False, str crestServer="")
__init__(self, str filename="", str jsonString="", str dbalias="", int smkey=0, bool useCrest=False, str crestServer="")
monitoredChains(self, signatures="", monLevels="", wildcard="")
__init__(self, str filename="", str jsonString="", str dbalias="", int smkey=0, int monikey=0, bool useCrest=False, str crestServer="")
__init__(self, str filename="", str jsonString="", str dbalias="", int hltpskey=0, bool useCrest=False, str crestServer="")
STL class.