ATLAS Offline Software
Public Member Functions | Public Attributes | Private Member Functions | List of all members
python.TriggerConfigAccessBase.ConfigCrestLoader Class Reference
Inheritance diagram for python.TriggerConfigAccessBase.ConfigCrestLoader:
Collaboration diagram for python.TriggerConfigAccessBase.ConfigCrestLoader:

Public Member Functions

def __init__ (self, *ConfigType configType, str dbname, int dbkey, str crestServer)
 
def setQuery (self, query)
 
dict[str, Any] load (self)
 
def getWriteFilename (self)
 
def confirmConfigType (self, config)
 

Public Attributes

 crestServer
 
 dbname
 
 dbkey
 
 schema
 

Private Member Functions

dict _get_payload (self, str hash)
 

Detailed Description

Definition at line 356 of file TriggerConfigAccessBase.py.

Constructor & Destructor Documentation

◆ __init__()

def python.TriggerConfigAccessBase.ConfigCrestLoader.__init__ (   self,
*ConfigType  configType,
str  dbname,
int  dbkey,
str  crestServer 
)

Definition at line 357 of file TriggerConfigAccessBase.py.

357  def __init__(self, *, configType: ConfigType, dbname: str, dbkey: int, crestServer: str):
358  super().__init__(configType)
359  self.crestServer = crestServer
360  self.dbname = dbname
361  self.dbkey = dbkey
362  self.schema = ""
363 

Member Function Documentation

◆ _get_payload()

dict python.TriggerConfigAccessBase.ConfigCrestLoader._get_payload (   self,
str  hash 
)
private
get payload from crest server using request library

Args:
    hash (str): the query part of the url as required by the REST api

Raises:
    RuntimeError: when connection or query failed

Returns:
    dict: the json content

Definition at line 370 of file TriggerConfigAccessBase.py.

370  def _get_payload(self, hash: str) -> dict:
371  """get payload from crest server using request library
372 
373  Args:
374  hash (str): the query part of the url as required by the REST api
375 
376  Raises:
377  RuntimeError: when connection or query failed
378 
379  Returns:
380  dict: the json content
381  """
382  import requests
383 
384  url = f"{self.crestServer}/payloads/data"
385  params = {
386  "format": "BLOB",
387  "hash": hash
388  }
389  preq = requests.Request(method='GET', url=url, params=params).prepare()
390  with requests.Session() as session:
391  try:
392  resp = session.send(preq)
393  except requests.ConnectionError as exc:
394  log.error(f"Could not connect to crest server {self.crestServer} ({exc})")
395  raise RuntimeError(f"Could not connect to CREST server {self.crestServer}")
396 
397  if resp.status_code != 200:
398  log.error(f"Error: HTTP GET request '{preq.url}' failed")
399  raise RuntimeError(f"Query {hash} to crest failed with status code {resp.status_code}")
400 
401  config = json.loads(resp.content)
402  self.confirmConfigType(config)
403  return config
404 

◆ confirmConfigType()

def python.TriggerConfigAccessBase.ConfigLoader.confirmConfigType (   self,
  config 
)
inherited
checks that the in-file specification of the configuration type matches the expected type

Definition at line 51 of file TriggerConfigAccessBase.py.

51  def confirmConfigType(self,config):
52  """
53  checks that the in-file specification of the configuration type matches the expected type
54  """
55  if config['filetype'] != self.configType:
56  raise RuntimeError("Can not load file with filetype '%s' when expecting '%s'" % (config['filetype'], self.configType.filetype))
57 

◆ getWriteFilename()

def python.TriggerConfigAccessBase.ConfigCrestLoader.getWriteFilename (   self)

Reimplemented from python.TriggerConfigAccessBase.ConfigLoader.

Definition at line 415 of file TriggerConfigAccessBase.py.

415  def getWriteFilename(self):
416  schema = TriggerCrestUtil.crestconn_dbname_mapping.get(self.dbname, self.dbname)
417  return "{basename}_{schema}_{dbkey}.json".format(basename = self.configType.basename, schema = schema, dbkey = self.dbkey)
418 

◆ load()

dict[str, Any] python.TriggerConfigAccessBase.ConfigCrestLoader.load (   self)

Reimplemented from python.TriggerConfigAccessBase.ConfigLoader.

Definition at line 405 of file TriggerConfigAccessBase.py.

405  def load(self) -> dict[str, Any]:
406  # see SCHEMA_MAP in https://gitlab.cern.ch/crest-db/crest/-/blob/master/src/main/java/hep/crest/server/repositories/triggerdb/TriggerDb.java
407  crest_conn = TriggerCrestUtil.getCrestConnection(self.dbname)
408  if crest_conn is None:
409  raise RuntimeError(f"Cannot resolve CREST connection for dbname {self.dbname}")
410  hash = f"triggerdb://{crest_conn}/{self.configType.crestkey}/{self.dbkey}"
411  config = self._get_payload(hash=hash)
412  return config
413 

◆ setQuery()

def python.TriggerConfigAccessBase.ConfigCrestLoader.setQuery (   self,
  query 
)
With CREST all queries are defined in the CREST server

Reimplemented from python.TriggerConfigAccessBase.ConfigLoader.

Definition at line 364 of file TriggerConfigAccessBase.py.

364  def setQuery(self, query):
365  """
366  With CREST all queries are defined in the CREST server
367  """
368  pass
369 

Member Data Documentation

◆ crestServer

python.TriggerConfigAccessBase.ConfigCrestLoader.crestServer

Definition at line 359 of file TriggerConfigAccessBase.py.

◆ dbkey

python.TriggerConfigAccessBase.ConfigCrestLoader.dbkey

Definition at line 361 of file TriggerConfigAccessBase.py.

◆ dbname

python.TriggerConfigAccessBase.ConfigCrestLoader.dbname

Definition at line 360 of file TriggerConfigAccessBase.py.

◆ schema

python.TriggerConfigAccessBase.ConfigCrestLoader.schema

Definition at line 362 of file TriggerConfigAccessBase.py.


The documentation for this class was generated from the following file:
vtune_athena.format
format
Definition: vtune_athena.py:14
python.processes.powheg.ZZj_MiNNLO.ZZj_MiNNLO.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZj_MiNNLO.py:18
python.root_pickle.load
def load(f, use_proxy=1, key=None)
Definition: root_pickle.py:430