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