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

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 343 of file TriggerConfigAccessBase.py.

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

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

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

◆ _getDBSchemaName()

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

Definition at line 392 of file TriggerConfigAccessBase.py.

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

◆ 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)

Definition at line 422 of file TriggerConfigAccessBase.py.

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

◆ load()

dict python.TriggerConfigAccessBase.ConfigCrestLoader.load (   self)

Definition at line 407 of file TriggerConfigAccessBase.py.

407  def load(self) -> dict:
408  # see SCHEMA_MAP in https://gitlab.cern.ch/crest-db/crest/-/blob/master/src/main/java/hep/crest/server/repositories/triggerdb/TriggerDb.java
409  self.schema = ConfigCrestLoader._getDBSchemaName(self.dbalias)
410  url_schema = {
411  "ATLAS_CONF_TRIGGER_RUN3": "CONF_DATA_RUN3",
412  "ATLAS_CONF_TRIGGER_MC_RUN3": "CONF_MC_RUN3",
413  "ATLAS_CONF_TRIGGER_REPR_RUN3": "CONF_REPR_RUN3",
414  }.get(self.schema)
415  if url_schema is None:
416  raise RuntimeError(f"Oracle server {self.schema} is not implemented in the crest server {self.crestServer}")
417  hash = f"triggerdb://{url_schema}/{self.configType.crestkey}/{self.dbkey}"
418  config = self._get_payload(hash=hash)
419  return config
420 

◆ setQuery()

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

Definition at line 350 of file TriggerConfigAccessBase.py.

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

Member Data Documentation

◆ configType

python.TriggerConfigAccessBase.ConfigLoader.configType
inherited

Definition at line 50 of file TriggerConfigAccessBase.py.

◆ crestServer

python.TriggerConfigAccessBase.ConfigCrestLoader.crestServer

Definition at line 345 of file TriggerConfigAccessBase.py.

◆ dbalias

python.TriggerConfigAccessBase.ConfigCrestLoader.dbalias

Definition at line 346 of file TriggerConfigAccessBase.py.

◆ dbkey

python.TriggerConfigAccessBase.ConfigCrestLoader.dbkey

Definition at line 347 of file TriggerConfigAccessBase.py.

◆ schema

python.TriggerConfigAccessBase.ConfigCrestLoader.schema

Definition at line 348 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