ATLAS Offline Software
Public Member Functions | Public Attributes | Private Member Functions | Static 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, dbalias, dbkey, crestServer)
 
def setQuery (self, query)
 
dict load (self)
 
def getWriteFilename (self)
 
def confirmConfigType (self, config)
 

Public Attributes

 crestServer
 
 dbalias
 
 dbkey
 
 schema
 
 configType
 

Private Member Functions

dict _get_payload (self, str hash)
 

Static Private Member Functions

str _getDBSchemaName (dbalias)
 

Detailed Description

Definition at line 340 of file TriggerConfigAccessBase.py.

Constructor & Destructor Documentation

◆ __init__()

def python.TriggerConfigAccessBase.ConfigCrestLoader.__init__ (   self,
configType,
  dbalias,
  dbkey,
  crestServer 
)

Definition at line 341 of file TriggerConfigAccessBase.py.

341  def __init__(self, *, configType, dbalias, dbkey, crestServer):
342  super().__init__(configType)
343  self.crestServer = crestServer
344  self.dbalias = dbalias
345  self.dbkey = dbkey
346  self.schema = ""
347 

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 354 of file TriggerConfigAccessBase.py.

354  def _get_payload(self, hash: str) -> dict:
355  """get payload from crest server using request library
356 
357  Args:
358  hash (str): the query part of the url as required by the REST api
359 
360  Raises:
361  RuntimeError: when connection or query failed
362 
363  Returns:
364  dict: the json content
365  """
366  import requests
367 
368  url = f"{self.crestServer}/payloads/data"
369  params = {
370  "format": "BLOB",
371  "hash": hash
372  }
373  preq = requests.Request(method='GET', url=url, params=params).prepare()
374  with requests.Session() as session:
375  try:
376  resp = session.send(preq)
377  except requests.ConnectionError as exc:
378  log.error(f"Could not connect to crest server {self.crestServer} ({exc})")
379  raise RuntimeError(f"Could not connect to CREST server {self.crestServer}")
380 
381  if resp.status_code != 200:
382  log.error(f"Error: HTTP GET request '{preq.url}' failed")
383  raise RuntimeError(f"Query {hash} to crest failed with status code {resp.status_code}")
384 
385  config = json.loads(resp.content)
386  self.confirmConfigType(config)
387  return config
388 

◆ _getDBSchemaName()

str python.TriggerConfigAccessBase.ConfigCrestLoader._getDBSchemaName (   dbalias)
staticprivate

Definition at line 390 of file TriggerConfigAccessBase.py.

390  def _getDBSchemaName(dbalias) -> str:
391  dblookupFile = ConfigDBLoader.getResolvedFileName("dblookup.xml", "CORAL_DBLOOKUP_PATH")
392  dbp = ET.parse(dblookupFile)
393  for logSvc in dbp.iter("logicalservice"):
394  if logSvc.attrib["name"] != dbalias:
395  continue
396  oracleServer = ""
397  for serv in logSvc.iter("service"):
398  if serv.attrib["name"].startswith("oracle://"):
399  oracleService = serv.attrib["name"]
400  oracleServer = oracleService.split('/')[3]
401  return oracleServer
402  raise RuntimeError(f"DB {dbalias} has no oracle services listed in {dblookupFile}")
403  raise RuntimeError(f"DB {dbalias} is not listed in {dblookupFile}")
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 49 of file TriggerConfigAccessBase.py.

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

◆ getWriteFilename()

def python.TriggerConfigAccessBase.ConfigCrestLoader.getWriteFilename (   self)

Definition at line 420 of file TriggerConfigAccessBase.py.

420  def getWriteFilename(self):
421  return "{basename}_{schema}_{dbkey}.json".format(basename = self.configType.basename, schema = self.schema, dbkey = self.dbkey)
422 

◆ load()

dict python.TriggerConfigAccessBase.ConfigCrestLoader.load (   self)

Definition at line 405 of file TriggerConfigAccessBase.py.

405  def load(self) -> dict:
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  self.schema = ConfigCrestLoader._getDBSchemaName(self.dbalias)
408  url_schema = {
409  "ATLAS_CONF_TRIGGER_RUN3": "CONF_DATA_RUN3",
410  "ATLAS_CONF_TRIGGER_MC_RUN3": "CONF_MC_RUN3",
411  "ATLAS_CONF_TRIGGER_REPR_RUN3": "CONF_REPR_RUN3",
412  }.get(self.schema)
413  if url_schema is None:
414  raise RuntimeError(f"Oracle server {self.schema} is not implemented in the crest server {self.crestServer}")
415  hash = f"triggerdb://{url_schema}/{self.configType.crestkey}/{self.dbkey}"
416  config = self._get_payload(hash=hash)
417  return config
418 

◆ setQuery()

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

Definition at line 348 of file TriggerConfigAccessBase.py.

348  def setQuery(self, query):
349  """
350  With CREST all queries are defined in the CREST server
351  """
352  pass
353 

Member Data Documentation

◆ configType

python.TriggerConfigAccessBase.ConfigLoader.configType
inherited

Definition at line 48 of file TriggerConfigAccessBase.py.

◆ crestServer

python.TriggerConfigAccessBase.ConfigCrestLoader.crestServer

Definition at line 343 of file TriggerConfigAccessBase.py.

◆ dbalias

python.TriggerConfigAccessBase.ConfigCrestLoader.dbalias

Definition at line 344 of file TriggerConfigAccessBase.py.

◆ dbkey

python.TriggerConfigAccessBase.ConfigCrestLoader.dbkey

Definition at line 345 of file TriggerConfigAccessBase.py.

◆ schema

python.TriggerConfigAccessBase.ConfigCrestLoader.schema

Definition at line 346 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.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18
get
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition: hcg.cxx:127
python.root_pickle.load
def load(f, use_proxy=1, key=None)
Definition: root_pickle.py:476