ATLAS Offline Software
TriggerCrestUtil.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
2 from functools import cache
3 from typing import Any, cast
4 from collections.abc import Iterable
5 from pycrest.api.crest_api import CrestApi, HTTPResponse, IovSetDto, TagMetaSetDto
6 
7 import json
8 from pprint import pprint
9 from datetime import datetime as dt
10 
11 from AthenaCommon.Logging import logging
12 log = logging.getLogger('TriggerCrestUtil.py')
13 
15 
16  # the mapping from triggerdb or triggerdb-alias to crest connection
17  # See https://its.cern.ch/jira/browse/ATR-32030
18  dbname_crestconn_mapping: dict[str, str] = {
19  # schema name mapping
20  "ATLAS_CONF_TRIGGER_RUN3": "CONF_DATA_RUN3",
21  "ATLAS_CONF_TRIGGER_MC_RUN3": "CONF_MC_RUN3",
22  "ATLAS_CONF_TRIGGER_REPR_RUN3": "CONF_REPR_RUN3",
23  "ATLAS_CONF_TRIGGER_RUN4": "CONF_DATA_RUN4",
24  "ATLAS_CONF_TRIGGER_MC_RUN4": "CONF_MC_RUN4",
25  "ATLAS_CONF_TRIGGER_REPR_RUN4": "CONF_REPR_RUN4",
26  "ATLAS_CONF_TRIGGER_LS3_DEV": "CONF_DEV_LS3",
27  "ATLAS_CONF_TRIGGER_LS3_L0": "CONF_DEV_L0",
28  "ATLAS_CONF_TRIGGER_RUN2_NF": "CONF_DATA_RUN2",
29  # alias mapping
30  "TRIGGERDB_RUN3": "CONF_DATA_RUN3",
31  "TRIGGERDBREPR_RUN3": "CONF_REPR_RUN3",
32  "TRIGGERDBMC_RUN3": "CONF_MC_RUN3",
33  "TRIGGERDB_RUN4": "CONF_DATA_RUN4",
34  "TRIGGERDBREPR_RUN4": "CONF_REPR_RUN4",
35  "TRIGGERDBMC_RUN4": "CONF_MC_RUN4",
36  "TRIGGERDBLS3_DEV": "CONF_DEV_LS3",
37  "TRIGGERDBLS3_L0": "CONF_DEV_L0",
38  "TRIGGERDB_RUN2_NF": "CONF_DATA_RUN2_NF"
39  }
40 
41  crestconn_dbname_mapping: dict[str, str] = {
42  # schema name mapping
43  "CONF_DATA_RUN3": "ATLAS_CONF_TRIGGER_RUN3",
44  "CONF_MC_RUN3": "ATLAS_CONF_TRIGGER_MC_RUN3",
45  "CONF_REPR_RUN3": "ATLAS_CONF_TRIGGER_REPR_RUN3",
46  "CONF_DATA_RUN4": "ATLAS_CONF_TRIGGER_RUN4",
47  "CONF_MC_RUN4" : "ATLAS_CONF_TRIGGER_MC_RUN4",
48  "CONF_REPR_RUN4" : "ATLAS_CONF_TRIGGER_REPR_RUN4",
49  "CONF_DEV_LS3" : "ATLAS_CONF_TRIGGER_LS3_DEV",
50  "CONF_DEV_L0" : "ATLAS_CONF_TRIGGER_LS3_L0",
51  "CONF_DATA_RUN2" : "ATLAS_CONF_TRIGGER_RUN2_NF"
52  }
53 
54  @staticmethod
55  def allCrestConnections() -> list[str]:
56  """list of all known crest connections
57 
58  Returns:
59  list[str]: list of crest connection names
60  """
61  return list(TriggerCrestUtil.dbname_crestconn_mapping.values())
62 
63  @staticmethod
64  def getCrestConnection(dbname: str) -> str | None:
65  """maps from triggerdb schema or triggerdb-alias to crest connection
66  See https://its.cern.ch/jira/browse/ATR-32030
67 
68  If the input dbname is already a crest connection name, it is returned as is.
69 
70  Args:
71  dbname (str): triggerdb name or alias or crest connection name.
72  Returns:
73  str | None: crest connection name or None if not found.
74  """
75  if dbname in TriggerCrestUtil.dbname_crestconn_mapping.values():
76  return dbname
77  return TriggerCrestUtil.dbname_crestconn_mapping.get(dbname, None)
78 
79  @cache
80  @staticmethod
81  def getDBNameMapping() -> dict[str, str]:
82  return TriggerCrestUtil.dbname_crestconn_mapping
83 
84  @staticmethod
85  def getCrestApi(server: str) -> CrestApi:
86  """ Crest API object
87 
88  Args:
89  server (str): crest server name.
90 
91  Returns:
92  CrestApi: Crest API instance.
93  """
94  return CrestApi(host=server)
95 
96  @staticmethod
97  def getConditionsForTimestamp(tag: str, *, timestamp: int, server: str = "", api: CrestApi | None = None,
98  get_time_type: bool = False) -> dict[str, dict[str, Any]]:
99  """ Conditions data for tag at a specific timestamp
100 
101  Conditions data is returned as a dict with 'since' and 'payload' keys.
102  The 'payload' itself is a dict of channel:'data dicts'. The 'data dict' has attribute names as
103  keys and the corresponding values. If get_time_type is True, also 'time_type' key is added to
104  each IOV dict and the since is further expanded into 'since_run' and 'since_lb' (for run/lb-based
105  timestamps) or 'since_formatted' (for time-based timestamps).
106 
107  Args:
108  tag (str): The tag name
109  timestamp (int): The timestamp to query (either run<32+lb or time in nanoseconds since 1.1.1970)
110  server (str, optional): Crest server name. Only needed if api is not provided. Defaults to "".
111  api (_type_, optional): Crest API instance. Defaults to None.
112  get_time_type (bool, optional): Whether to retrieve the time type. Defaults to False.
113 
114  Raises:
115  RuntimeError: If both server and api are missing
116 
117  Returns:
118  dict[str, dict[str, any]]: Conditions data
119  """
120  if server=="" and api is None:
121  log.error("Need either crest server name or crest api specified for accessing Crest")
122  raise RuntimeError("Crest access information missing")
123  if api is None:
124  api = CrestApi(host=server)
125  # get the payload specification
126  attr_list, _ = TriggerCrestUtil._get_payload_spec(tag, api)
127  # get the IOVs in the given range
128  iov = TriggerCrestUtil._get_iov_for_timestamp(tag, timestamp=timestamp, api=api)
129 
130  if get_time_type:
131  time_type = TriggerCrestUtil.getTagTimeType(tag, api=api)
132 
133  payload_for_iov = {}
134  payload_hash: str = cast(list, iov['resources'])[0]['payload_hash']
135  since: int = cast(list, iov['resources'])[0]['since']
136  payload = TriggerCrestUtil.getPayloadFromHash(payload_hash, api=api)
137  for channel, data in payload.items():
138  payload_for_iov[channel] = dict(zip(attr_list, data))
139 
140  result: dict[str, Any] = {
141  'since': since,
142  'payload': payload_for_iov
143  }
144  if get_time_type:
145  TriggerCrestUtil._update_with_time_type(result, time_type, since)
146  return result
147 
148 
149  @staticmethod
150  def getConditionsInRange(tag: str, *, since: int, until: int, server: str = "", api: CrestApi | None = None,
151  get_time_type: bool = False) -> list[dict[str, dict[str, Any]]]:
152  """ Conditions data for tag in given range
153 
154  List goes over the IOVs found. For each IOV, there is a dict with 'since' and 'payload' keys.
155  The 'payload' itself is a dict of channel:'data dicts'. The 'data dict' has attribute names as
156  keys and the corresponding values. If get_time_type is True, also 'time_type' key is added to
157  each IOV dict and the since is further expanded into 'since_run' and 'since_lb' (for run/lb-based
158  timestamps) or 'since_formatted' (for time-based timestamps).
159 
160  Args:
161  tag (str): tag name
162  since (int): start of the range (either run<32+lb or time in nanoseconds since 1.1.1970, inclusive)
163  until (int): end of the range (either run<32+lb or time in nanoseconds since 1.1.1970, exclusive)
164  server (str, optional): crest server name. Only needed if api is not provided. Defaults to "".
165  api (CrestApi, optional): Crest API instance. Defaults to None.
166  get_time_type (bool, optional): whether to retrieve the time type. Defaults to False.
167 
168  Raises:
169  RuntimeError: if both server and api are missing
170 
171  Returns:
172  list[dict[str, dict[str, any]]]: conditions data
173  """
174  if server=="" and api is None:
175  log.error("Need either crest server name or crest api specified for accessing Crest")
176  raise RuntimeError("Crest access information missing")
177  if api is None:
178  api = CrestApi(host=server)
179  # get the payload specification
180  attr_list, type_dict = TriggerCrestUtil._get_payload_spec(tag, api)
181  # get the IOVs in the given range
182  all_iovs = TriggerCrestUtil._get_iovs_range(since=since, until=until, api=api, tag=tag)
183 
184  if get_time_type:
185  time_type = TriggerCrestUtil.getTagTimeType(tag, api=api)
186 
187  result: list[dict[str, dict[str, Any]]] = []
188  for iov in cast(Iterable, all_iovs['resources']):
189  payload_for_iov = {}
190  payload_hash = iov['payload_hash']
191  since = iov['since']
192  payload = TriggerCrestUtil.getPayloadFromHash(payload_hash, api=api)
193  for channel, data in payload.items():
194  payload_for_iov[channel] = dict(zip(attr_list, data))
195  entry = {'since': since, 'payload': payload_for_iov}
196  if get_time_type:
197  TriggerCrestUtil._update_with_time_type(entry, time_type, since)
198  result += [entry]
199  return result
200 
201  @staticmethod
202  def getTagTimeType(tag: str, *, server: str = "", api: CrestApi | None = None) -> str:
203  """ time type of the tag, either 'run-lumi' or 'time'
204 
205  Args:
206  tag (str): tag name
207  server (str, optional): crest server name. Only needed if api is not provided. Defaults to "".
208  api (CrestApi, optional): Crest API instance. Defaults to None.
209 
210  Raises:
211  RuntimeError: if both server and api are missing
212 
213  Returns:
214  str: time type of the tag ['run-lumi' or 'time']
215  """
216  if server=="" and api is None:
217  log.error("Need either crest_server name or crest api for retrieving the payload")
218  raise RuntimeError("Crest access information missing")
219  if api is None:
220  api = CrestApi(host=server)
221  tag_info = api.find_tag(tag)
222  time_type: str = tag_info['time_type']
223  return time_type
224 
225  @staticmethod
226  def getAttribs(tag: str, *, server: str = "", api: CrestApi | None = None) -> list[str]:
227  """ list of attributes for this tag
228 
229  Args:
230  tag (str): tag name
231  server (str, optional): crest server name. Only needed if api is not provided. Defaults to "".
232  api (CrestApi, optional): Crest API instance. Defaults to None.
233 
234  Raises:
235  RuntimeError: if both server and api are missing
236 
237  Returns:
238  dict: list of attributes
239  """
240  if server=="" and api is None:
241  log.error("Need either crest_server name or crest api for retrieving the payload")
242  raise RuntimeError("Crest access information missing")
243  if api is None:
244  api = CrestApi(host=server)
245  attr_list, _ = TriggerCrestUtil._get_payload_spec(tag, api)
246  return attr_list
247 
248  @staticmethod
249  def getPayloadFromHash(payload_hash: str, *, server: str = "", api: CrestApi | None = None) -> dict:
250  """ Get payload from hash
251 
252  Args:
253  payload_hash (str): hash of the payload
254  server (str, optional): crest server name. Defaults to "".
255  api (CrestApi, optional): Crest API instance. Defaults to None.
256 
257  Raises:
258  RuntimeError: if both server and api are missing
259 
260  Returns:
261  dict: payload retrieved from the hash
262  """
263  if server == "" and api is None:
264  log.error("Need either crest_server name or crest api for retrieving the payload")
265  raise RuntimeError("Crest access information missing")
266  useWorkAround = True
267  if useWorkAround:
268  if server == "":
269  server = api._host # type: ignore
270  return TriggerCrestUtil._get_payload_workaround(payload_hash, server)
271  else:
272  if api is None:
273  api = CrestApi(host=server)
274  return TriggerCrestUtil._get_payload(payload_hash, api)
275 
276  # Specific utility functions for trigger configuration retrieval
277  @staticmethod
278  def getEORParams(run: int, *, server: str = "", api: CrestApi | None = None) -> dict[str, Any] | None:
279  if api is None:
280  api = CrestApi(host=server)
281  start_of_run = (run << 32)
282  cond_data = TriggerCrestUtil.getConditionsForTimestamp("TDAQRunCtrlEOR-HEAD", timestamp=start_of_run, api=api, get_time_type=False)
283  if not cond_data:
284  log.error("No EOR params found for run %s", run)
285  return None
286  return cond_data['payload']['0']
287 
288  @staticmethod
289  def getHLTPrescaleKeys(run: int, *, server: str = "", api: CrestApi | None = None) -> list[dict[str, dict[str, Any]]]: # -> list[dict[str, dict[str, Any]]]:
290  if api is None:
291  api = CrestApi(host=server)
292  run_start = (run << 32)
293  run_end = ((run + 1) << 32) - 1
294  cond = TriggerCrestUtil.getConditionsInRange("TRIGGERHLTPrescaleKey-HEAD", since=run_start, until=run_end, api=api, get_time_type=True)
295  for entry in cond:
296  entry.update(entry.pop('payload')['0'])
297  entry['key'] = entry['HltPrescaleKey']
298  # filter to only those starting in this run (since CREST IOVs are open-ended, we otherwise might get IOVs from previous runs)
299  # since the first IOV of a run always starts at lb=0, this should only be the case for future runs and return an empty list in that case
300  cond: list[dict[str, dict[str, Any]]] = [entry for entry in cond if entry['since_run']==run]
301  return cond
302 
303  @staticmethod
304  def getHLTPrescaleKey(run: int, lb: int, *, server: str = "", api: CrestApi | None = None) -> int | None:
305  if api is None:
306  api = CrestApi(host=server)
307  run_lb = (run << 32) + lb
308  cond_entry: dict[str, Any] = TriggerCrestUtil.getConditionsForTimestamp("TRIGGERHLTPrescaleKey-HEAD", timestamp=run_lb, api=api, get_time_type=True)
309  if cond_entry['since_run'] < run: # CREST returned an IOV from a previous run (all IOVs are open-ended in CREST), no prescale key for this run
310  return None
311  return cond_entry['payload']['0']['HltPrescaleKey']
312 
313  @staticmethod
314  def getL1PrescaleKeys(run: int, *, server: str = "", api: CrestApi | None = None) -> list[dict[str, dict[str, Any]]]:
315  if api is None:
316  api = CrestApi(host=server)
317  run_start = (run << 32)
318  run_end = ((run + 1) << 32) - 1
319  cond = TriggerCrestUtil.getConditionsInRange("TRIGGERLVL1Lvl1ConfigKey-HEAD", since=run_start, until=run_end, api=api, get_time_type=True)
320  for entry in cond:
321  entry.update(entry.pop('payload')['0'])
322  entry['key'] = entry['Lvl1PrescaleConfigurationKey']
323  # filter to only those starting in this run (since CREST IOVs are open-ended, we otherwise might get IOVs from previous runs)
324  # since the first IOV of a run always starts at lb=0, this should only be the case for future runs and return an empty list in that case
325  cond: list[dict[str, dict[str, Any]]] = [entry for entry in cond if entry['since_run']==run]
326  return cond
327 
328  @staticmethod
329  def getL1PrescaleKey(run: int, lb: int, *, server: str = "", api: CrestApi | None = None) -> int | None:
330  if api is None:
331  api = CrestApi(host=server)
332  run_lb = (run << 32) + lb
333  cond_entry: dict[str, Any] = TriggerCrestUtil.getConditionsForTimestamp("TRIGGERLVL1Lvl1ConfigKey-HEAD", timestamp=run_lb, api=api, get_time_type=True)
334  if cond_entry['since_run'] < run: # CREST returned an IOV from a previous run (IOVs are open-ended in CREST), no prescale key for this run
335  return None
336  return cond_entry['payload']['0']['Lvl1PrescaleConfigurationKey']
337 
338  @staticmethod
339  def getBunchGroupKeys(run: int, *, server: str = "", api: CrestApi | None = None) -> list[dict[str, dict[str, Any]]]:
340  if api is None:
341  api = CrestApi(host=server)
342  run_start = (run << 32)
343  run_end = ((run+1) << 32)-1
344  cond = TriggerCrestUtil.getConditionsInRange("TRIGGERLVL1BunchGroupKey-HEAD", since=run_start, until=run_end, api=api, get_time_type=True)
345  for entry in cond:
346  entry.update(entry.pop('payload')['0'])
347  entry['key'] = entry['Lvl1BunchGroupConfigurationKey']
348  # filter to only those starting in this run (since CREST IOVs are open-ended, we otherwise might get IOVs from previous runs)
349  # since the first IOV of a run always starts at lb=0, this should only be the case for future runs and return an empty list in that case
350  cond: list[dict[str, dict[str, Any]]] = [entry for entry in cond if entry['since_run']==run]
351  return cond
352 
353  @staticmethod
354  def getBunchGroupKey(run: int, lb: int, *, server: str = "", api: CrestApi | None = None) -> int | None:
355  if api is None:
356  api = CrestApi(host=server)
357  run_lb = (run << 32) + lb
358  cond_entry: dict[str, Any] = TriggerCrestUtil.getConditionsForTimestamp("TRIGGERLVL1BunchGroupKey-HEAD", timestamp=run_lb, api=api, get_time_type=True)
359  if cond_entry['since_run'] < run: # CREST returned an IOV from a previous run (all IOVs are open-ended in CREST), no prescale key for this run
360  return None
361  return cond_entry['payload']['0']['Lvl1BunchGroupConfigurationKey']
362 
363  @staticmethod
364  def getMenuConfigKey(run: int, *, server: str = "", api: CrestApi | None = None) -> dict[str, Any] | None:
365  # helper function to turn the payload of the TRIGGERHLTHltConfigKeys into a dictionary
366  def _parse_info(run, cond):
367  # Format for ConfigSource (see ATR-21550):
368  # Run-4: currently like Run-3
369  # Run-3: TRIGGERDB_RUN3;22.0.101;Athena,22.0.101 --extra_args ...
370  # Run-2: TRIGGERDBR2R,21.1.24,AthenaP1
371  release = 'unknown'
372  if run > 379000: # Run-3
373  confsrc = cond['ConfigSource'].split(';')
374  dbalias = confsrc[0]
375  if len(confsrc) > 2:
376  release = confsrc[2].split(',')[0] + f",{confsrc[1]}"
377  else: # Run-2
378  confsrc = cond['ConfigSource'].split(',', maxsplit=1)
379  dbalias = confsrc[0]
380  if len(confsrc) > 2:
381  release = f"{confsrc[2]},{confsrc[1]}"
382  return {
383  "SMK": cond['MasterConfigurationKey'],
384  "HLTPSK": cond['HltPrescaleConfigurationKey'],
385  "DB": dbalias,
386  "REL": release
387  }
388 
389  if api is None:
390  api = CrestApi(host=server)
391 
392  run_start = (run << 32) + 1
393  cond: dict[str, Any] = TriggerCrestUtil.getConditionsForTimestamp("TRIGGERHLTHltConfigKeys-HEAD", timestamp=run_start, api=api, get_time_type=True)
394  if cond['since_run'] < run: # CREST returned an IOV from a previous run (all IOVs are open-ended in CREST), no prescale key for this run
395  return None
396  cond.update(cond.pop('payload')['0'])
397  return _parse_info(run, cond)
398 
399  @staticmethod
400  def getTrigConfKeys(runNumber: int, lumiBlock: int, server: str = "", api: CrestApi | None = None) -> dict[str, Any]:
401  if api is None:
402  api = CrestApi(host=server)
403  bgkey: int | None = TriggerCrestUtil.getBunchGroupKey(runNumber, lumiBlock, api=api)
404  l1pskey: int | None = TriggerCrestUtil.getL1PrescaleKey(runNumber, lumiBlock, api=api)
405  hltpskey: int | None = TriggerCrestUtil.getHLTPrescaleKey(runNumber, lumiBlock, api=api)
406  menucfg: dict[str, Any] | None = TriggerCrestUtil.getMenuConfigKey(runNumber, api=api)
407  return {
408  "SMK": menucfg['SMK'] if menucfg else None,
409  "DB": menucfg['DB'] if menucfg else None,
410  "LVL1PSK": l1pskey,
411  "HLTPSK": hltpskey,
412  "BGSK": bgkey
413  }
414 
415  # internal helper functions
416  @staticmethod
417  def _update_with_time_type(result: dict[str, Any], time_type: str, since: int) -> None:
418  result['time_type'] = time_type
419  if time_type == 'run-lumi':
420  result.update({
421  'since_run': since >> 32,
422  'since_lb': since & 0xFFFFFFFF
423  })
424  elif time_type == 'time':
425  result.update({
426  'since_formatted': dt.fromtimestamp(since / 1e9)
427  })
428 
429 
430  @staticmethod
431  def _get_payload(payload_hash, api) -> dict:
432  return api.get_payload(hash=payload_hash).decode('utf-8')
433 
434  @staticmethod
435  def _get_payload_workaround(payload_hash, server) -> dict:
436  import requests
437  import json
438  url = f"{server}/payloads/data"
439  params = {
440  "format": "BLOB",
441  "hash": payload_hash
442  }
443  preq = requests.Request(method='GET', url=url, params=params).prepare()
444  with requests.Session() as session:
445  try:
446  resp = session.send(preq)
447  except requests.ConnectionError as exc:
448  raise RuntimeError(f"Could not connect to CREST server {server}") from exc
449 
450  if resp.status_code != 200:
451  raise RuntimeError(f"Query {payload_hash} to crest failed with status code {resp.status_code}")
452 
453  return json.loads(resp.content)
454 
455  @staticmethod
456  def _get_iovs_for_run(tag: str, *, run: int, api: CrestApi):
457  """Helper to retrieve all IOVs for a run"""
458  run_start = (run << 32) + 1
459  run_end = ((run + 1) << 32) - 1
460  return TriggerCrestUtil._get_iovs_range(since=run_start, until=run_end, api=api, tag=tag)
461 
462  @staticmethod
463  def _get_iov_for_timestamp(tag: str, *, timestamp: int, api: CrestApi) -> IovSetDto | HTTPResponse:
464  """Helper to retrieve the IOV for a given timestamp
465 
466  Args:
467  tag (str): tag name
468  timestamp (int): time-stamp in format run<32+lb or time in nanoseconds since 1.1.1970
469  api (CrestApi): Crest API instance.
470 
471  Returns:
472  IovSetDto: set of IOVs (of size 1)
473  """
474  # the upper limit of the iov-search is exclusive, so we need to add 1
475  return api.select_iovs(tag, "0", str(timestamp+1), sort='id.since:DESC', size=1, snapshot=0) # type: ignore
476 
477  @staticmethod
478  def _get_iovs_range(*, since: int, until: int, api: CrestApi, tag: str) -> IovSetDto | HTTPResponse:
479  """Helper to retrieve the IOV in a given range
480 
481  Args:
482  tag (str): tag name
483  since (int): start of the range (either run<32+lb or time in nanoseconds since 1.1.1970, inclusive)
484  until (int): end of the range (either run<32+lb or time in nanoseconds since 1.1.1970, exclusive)
485  api (CrestApi): Crest API instance.
486 
487  Returns:
488  IovSetDto: set of IOVs
489  """
490  # the upper limit of the iov-search is exclusive, so we need to add 1 to find the iov which includes 'since'
491  iovs = api.select_iovs(tag, "0", str(since+1), sort='id.since:DESC', size=1, snapshot=0) # type: ignore
492  if cast(int, iovs['size']) < 1:
493  raise RuntimeError(f"Did not get an iov which includes the start of run {since}")
494  firstiov = cast(list, iovs['resources'])[0]
495  all_iovs = api.select_iovs(tag, str(firstiov['since']), str(until), sort='id.since:ASC', snapshot=0) # type: ignore
496  return all_iovs
497 
498  @staticmethod
499  def _get_payload_spec(tag: str, api: CrestApi) -> tuple[list[Any], dict[Any, Any]]:
500  """Helper to retrieve the payload spec for a given tag"""
501  meta: TagMetaSetDto | HTTPResponse = api.find_tag_meta(tag)
502  tag_info = cast(list, meta['resources'])[0]['tag_info']
503  tag_info_dict = json.loads(tag_info)
504  attr_list = []
505  type_dict = {}
506  for d in tag_info_dict['payload_spec']:
507  attr_list += list(d)
508  type_dict.update(d)
509  return attr_list, type_dict
510 
511 
512 if __name__ == "__main__":
513 
514  testrun = 435333 # Run-3
515  testrunR2 = 360026 # Run-2
516  crest_server = "https://crest.cern.ch/api-v5.0"
517  api = CrestApi(crest_server)
518 
519  print(f"run {testrun}:")
520  print("\nSuper master key, etc:")
521  pprint(TriggerCrestUtil.getMenuConfigKey(testrun, api=api))
522  print("\nL1 prescale keys:")
523  pprint(TriggerCrestUtil.getL1PrescaleKeys(testrun, api=api))
524  pprint(TriggerCrestUtil.getL1PrescaleKey(testrun, 1, api=api))
525  print("\nL1 bunchgroup keys:")
526  pprint(TriggerCrestUtil.getBunchGroupKeys(testrun, api=api))
527  pprint(TriggerCrestUtil.getBunchGroupKey(testrun, 1, api=api))
528  print("\nHLT prescale keys:")
529  pprint(TriggerCrestUtil.getHLTPrescaleKeys(testrun, api=api))
530  pprint(TriggerCrestUtil.getHLTPrescaleKey(testrun, 506, api=api))
531  pprint(TriggerCrestUtil.getHLTPrescaleKey(testrun, 507, api=api))
532  print("\nEOR params:")
533  pprint(TriggerCrestUtil.getEORParams(testrun, api=api),sort_dicts=False)
534 
535  print("\nNon existing lb:")
536  pprint(TriggerCrestUtil.getHLTPrescaleKey(testrun, 1_000_000, api=api))
537 
538  print("\nNon existing run:")
539  pprint(TriggerCrestUtil.getHLTPrescaleKey(1_000_000, 1, api=api))
540  pprint(TriggerCrestUtil.getHLTPrescaleKeys(1_000_000, api=api))
python.TriggerCrestUtil.TriggerCrestUtil.getCrestConnection
str|None getCrestConnection(str dbname)
Definition: TriggerCrestUtil.py:64
AtlasMcWeight::decode
double decode(number_type binnedWeight)
Convert weight from unsigned to double.
Definition: AtlasMcWeight.cxx:32
python.TriggerCrestUtil.TriggerCrestUtil.getAttribs
list[str] getAttribs(str tag, *str server="", CrestApi|None api=None)
Definition: TriggerCrestUtil.py:226
python.TriggerCrestUtil.TriggerCrestUtil.getPayloadFromHash
dict getPayloadFromHash(str payload_hash, *str server="", CrestApi|None api=None)
Definition: TriggerCrestUtil.py:249
python.TriggerCrestUtil.TriggerCrestUtil._get_payload_spec
tuple[list[Any], dict[Any, Any]] _get_payload_spec(str tag, CrestApi api)
Definition: TriggerCrestUtil.py:499
python.TriggerCrestUtil.TriggerCrestUtil.getHLTPrescaleKeys
list[dict[str, dict[str, Any]]] getHLTPrescaleKeys(int run, *str server="", CrestApi|None api=None)
Definition: TriggerCrestUtil.py:289
python.TriggerCrestUtil.TriggerCrestUtil.getConditionsForTimestamp
dict[str, dict[str, Any]] getConditionsForTimestamp(str tag, *int timestamp, str server="", CrestApi|None api=None, bool get_time_type=False)
Definition: TriggerCrestUtil.py:97
python.TriggerCrestUtil.TriggerCrestUtil.getDBNameMapping
dict[str, str] getDBNameMapping()
Definition: TriggerCrestUtil.py:81
python.TriggerCrestUtil.TriggerCrestUtil.getL1PrescaleKeys
list[dict[str, dict[str, Any]]] getL1PrescaleKeys(int run, *str server="", CrestApi|None api=None)
Definition: TriggerCrestUtil.py:314
python.TriggerCrestUtil.TriggerCrestUtil.getTagTimeType
str getTagTimeType(str tag, *str server="", CrestApi|None api=None)
Definition: TriggerCrestUtil.py:202
python.TriggerCrestUtil.TriggerCrestUtil._get_payload
dict _get_payload(payload_hash, api)
Definition: TriggerCrestUtil.py:431
python.TriggerCrestUtil.TriggerCrestUtil.getEORParams
dict[str, Any]|None getEORParams(int run, *str server="", CrestApi|None api=None)
Definition: TriggerCrestUtil.py:278
python.TriggerCrestUtil.TriggerCrestUtil.getConditionsInRange
list[dict[str, dict[str, Any]]] getConditionsInRange(str tag, *int since, int until, str server="", CrestApi|None api=None, bool get_time_type=False)
Definition: TriggerCrestUtil.py:150
python.TriggerCrestUtil.TriggerCrestUtil.getL1PrescaleKey
int|None getL1PrescaleKey(int run, int lb, *str server="", CrestApi|None api=None)
Definition: TriggerCrestUtil.py:329
python.TriggerCrestUtil.TriggerCrestUtil.getMenuConfigKey
dict[str, Any]|None getMenuConfigKey(int run, *str server="", CrestApi|None api=None)
Definition: TriggerCrestUtil.py:364
python.TriggerCrestUtil.TriggerCrestUtil._get_iovs_range
IovSetDto|HTTPResponse _get_iovs_range(*int since, int until, CrestApi api, str tag)
Definition: TriggerCrestUtil.py:478
python.TriggerCrestUtil.TriggerCrestUtil.getCrestApi
CrestApi getCrestApi(str server)
Definition: TriggerCrestUtil.py:85
python.TriggerCrestUtil.TriggerCrestUtil.allCrestConnections
list[str] allCrestConnections()
Definition: TriggerCrestUtil.py:55
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
python.TriggerCrestUtil.TriggerCrestUtil.getTrigConfKeys
dict[str, Any] getTrigConfKeys(int runNumber, int lumiBlock, str server="", CrestApi|None api=None)
Definition: TriggerCrestUtil.py:400
python.TriggerCrestUtil.TriggerCrestUtil._get_iovs_for_run
def _get_iovs_for_run(str tag, *int run, CrestApi api)
Definition: TriggerCrestUtil.py:456
python.TriggerCrestUtil.TriggerCrestUtil._get_payload_workaround
dict _get_payload_workaround(payload_hash, server)
Definition: TriggerCrestUtil.py:435
python.TriggerCrestUtil.TriggerCrestUtil._get_iov_for_timestamp
IovSetDto|HTTPResponse _get_iov_for_timestamp(str tag, *int timestamp, CrestApi api)
Definition: TriggerCrestUtil.py:463
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:26
python.TriggerCrestUtil.TriggerCrestUtil.getBunchGroupKeys
list[dict[str, dict[str, Any]]] getBunchGroupKeys(int run, *str server="", CrestApi|None api=None)
Definition: TriggerCrestUtil.py:339
python.TriggerCrestUtil.TriggerCrestUtil.getBunchGroupKey
int|None getBunchGroupKey(int run, int lb, *str server="", CrestApi|None api=None)
Definition: TriggerCrestUtil.py:354
str
Definition: BTagTrackIpAccessor.cxx:11
python.TriggerCrestUtil.TriggerCrestUtil.getHLTPrescaleKey
int|None getHLTPrescaleKey(int run, int lb, *str server="", CrestApi|None api=None)
Definition: TriggerCrestUtil.py:304
Trk::split
@ split
Definition: LayerMaterialProperties.h:38
python.TriggerCrestUtil.TriggerCrestUtil._update_with_time_type
None _update_with_time_type(dict[str, Any] result, str time_type, int since)
Definition: TriggerCrestUtil.py:417
python.TriggerCrestUtil.TriggerCrestUtil
Definition: TriggerCrestUtil.py:14