ATLAS Offline Software
HLTTriggerConfigAccess.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
2 from functools import lru_cache, reduce
3 
4 from TrigConfIO.TriggerConfigAccessBase import TriggerConfigAccess, ConfigType
5 
6 from AthenaCommon.Logging import logging
7 log = logging.getLogger('HLTTriggerConfigAccess.py')
8 
9 class 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 = None, jsonString = None, dbalias = None, smkey = None,
15  useCrest=False, crestServer=""):
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 
59 class 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 = None, jsonString = None, dbalias = None, hltpskey = None,
65  useCrest=False, crestServer=""):
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 
100 class 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 = None, dbalias = None, smkey = None,
106  useCrest = False, crestServer = ""):
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 
143 class HLTMonitoringAccess(TriggerConfigAccess):
144  """
145  this class provides access to the HLT monitoring json
146  """
147  def __init__(self, filename = None, jsonString = None, dbalias = None, smkey = None, monikey = None,
148  useCrest=False, crestServer=""):
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())))
python.HLTTriggerConfigAccess.HLTMenuAccess.sequencers
def sequencers(self)
Definition: HLTTriggerConfigAccess.py:41
python.HLTTriggerConfigAccess.HLTMenuAccess
Definition: HLTTriggerConfigAccess.py:9
python.HLTTriggerConfigAccess.HLTMonitoringAccess
Definition: HLTTriggerConfigAccess.py:143
python.HLTTriggerConfigAccess.HLTJobOptionsAccess.properties
def properties(self, algName)
Definition: HLTTriggerConfigAccess.py:129
python.HLTTriggerConfigAccess.HLTJobOptionsAccess.algorithmNames
def algorithmNames(self)
Definition: HLTTriggerConfigAccess.py:126
python.HLTTriggerConfigAccess.HLTMonitoringAccess.printSummary
def printSummary(self)
Definition: HLTTriggerConfigAccess.py:247
python.HLTTriggerConfigAccess.HLTPrescalesSetAccess.__init__
def __init__(self, filename=None, jsonString=None, dbalias=None, hltpskey=None, useCrest=False, crestServer="")
Definition: HLTTriggerConfigAccess.py:64
python.HLTTriggerConfigAccess.HLTPrescalesSetAccess.enabled
def enabled(self, chainName)
Definition: HLTTriggerConfigAccess.py:90
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.Bindings.values
values
Definition: Control/AthenaPython/python/Bindings.py:805
python.HLTTriggerConfigAccess.HLTMonitoringAccess.monitoringDict
def monitoringDict(self)
Definition: HLTTriggerConfigAccess.py:170
python.HLTTriggerConfigAccess.HLTPrescalesSetAccess.prescale
def prescale(self, chainName)
Definition: HLTTriggerConfigAccess.py:87
covarianceTool.filter
filter
Definition: covarianceTool.py:514
python.HLTTriggerConfigAccess.HLTMenuAccess.printSummary
def printSummary(self)
Definition: HLTTriggerConfigAccess.py:44
python.HLTTriggerConfigAccess.HLTMenuAccess.chainNames
def chainNames(self)
Definition: HLTTriggerConfigAccess.py:32
python.HLTTriggerConfigAccess.HLTMenuAccess.streams
def streams(self)
Definition: HLTTriggerConfigAccess.py:38
python.HLTTriggerConfigAccess.HLTPrescalesSetAccess.printSummary
def printSummary(self)
Definition: HLTTriggerConfigAccess.py:93
convertTimingResiduals.sum
sum
Definition: convertTimingResiduals.py:55
python.HLTTriggerConfigAccess.HLTMonitoringAccess.__init__
def __init__(self, filename=None, jsonString=None, dbalias=None, smkey=None, monikey=None, useCrest=False, crestServer="")
Definition: HLTTriggerConfigAccess.py:147
python.HLTTriggerConfigAccess.HLTJobOptionsAccess.name
def name(self)
Definition: HLTTriggerConfigAccess.py:132
python.HLTTriggerConfigAccess.HLTJobOptionsAccess.printSummary
def printSummary(self)
Definition: HLTTriggerConfigAccess.py:137
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
python.HLTTriggerConfigAccess.HLTJobOptionsAccess.algorithms
def algorithms(self)
Definition: HLTTriggerConfigAccess.py:123
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
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:25
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
TrigJetMonitorAlgorithm.items
items
Definition: TrigJetMonitorAlgorithm.py:79
python.HLTTriggerConfigAccess.HLTMonitoringAccess.monitoringLevels
def monitoringLevels(self, signatures=None)
Definition: HLTTriggerConfigAccess.py:230
python.HLTTriggerConfigAccess.HLTPrescalesSetAccess.prescales
def prescales(self)
Definition: HLTTriggerConfigAccess.py:81
python.HLTTriggerConfigAccess.HLTJobOptionsAccess
Definition: HLTTriggerConfigAccess.py:100
python.HLTTriggerConfigAccess.HLTMenuAccess.chains
def chains(self)
Definition: HLTTriggerConfigAccess.py:35
python.HLTTriggerConfigAccess.HLTMonitoringAccess.monitoredChains
def monitoredChains(self, signatures="", monLevels="", wildcard="")
Definition: HLTTriggerConfigAccess.py:177
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:798
python.HLTTriggerConfigAccess.HLTMenuAccess.__init__
def __init__(self, filename=None, jsonString=None, dbalias=None, smkey=None, useCrest=False, crestServer="")
Definition: HLTTriggerConfigAccess.py:14
python.HLTTriggerConfigAccess.HLTPrescalesSetAccess
Definition: HLTTriggerConfigAccess.py:59
python.HLTTriggerConfigAccess.HLTMenuAccess.printDetails
def printDetails(self)
Definition: HLTTriggerConfigAccess.py:50
python.HLTTriggerConfigAccess.HLTPrescalesSetAccess.chainNames
def chainNames(self)
Definition: HLTTriggerConfigAccess.py:84
python.HLTTriggerConfigAccess.HLTJobOptionsAccess.__init__
def __init__(self, filename=None, dbalias=None, smkey=None, useCrest=False, crestServer="")
Definition: HLTTriggerConfigAccess.py:105