Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Public Member Functions | Public Attributes | List of all members
python.Checks.SimpleCheck Class Reference
Inheritance diagram for python.Checks.SimpleCheck:
Collaboration diagram for python.Checks.SimpleCheck:

Public Member Functions

def __init__ (self, TestSetup setup, str name, str quantity, str unit, int field, float threshold)
 
bool run (self, WorkflowTest test)
 
Optional[Path] reference_file (self, "WorkflowTest" test, str file_name)
 

Public Attributes

 name
 
 quantity
 
 unit
 
 field
 
 threshold
 
 setup
 
 logger
 

Detailed Description

Run A Very Simple Check.

Definition at line 454 of file Checks.py.

Constructor & Destructor Documentation

◆ __init__()

def python.Checks.SimpleCheck.__init__ (   self,
TestSetup  setup,
str  name,
str  quantity,
str  unit,
int  field,
float  threshold 
)

Definition at line 457 of file Checks.py.

457  def __init__(self, setup: TestSetup, name: str, quantity: str, unit: str, field: int, threshold: float):
458  super().__init__(setup)
459  self.name = name
460  self.quantity = quantity
461  self.unit = unit
462  self.field = field
463  self.threshold = threshold
464 

Member Function Documentation

◆ reference_file()

Optional[Path] python.Test.WorkflowCheck.reference_file (   self,
"WorkflowTest"  test,
str  file_name 
)
inherited

Definition at line 91 of file Tools/WorkflowTestRunner/python/Test.py.

91  def reference_file(self, test: "WorkflowTest", file_name: str) -> Optional[Path]:
92  reference_path: Path = test.reference_path
93  reference_file = reference_path / file_name
94 
95  # Read references from CVMFS
96  if self.setup.validation_only:
97  # Resolve the subfolder first. Results are stored like: main_folder/branch/test/version/.
98  reference_revision = references_map[f"{test.ID}"]
99  cvmfs_path = Path(references_CVMFS_path)
100  rel_path = Path(self.setup.release_ID) / test.ID / reference_revision
101  reference_path = cvmfs_path / rel_path
102  reference_file = reference_path / file_name
103 
104  if not reference_path.exists():
105  self.logger.error(f"CVMFS reference location {reference_path} does not exist!")
106  return None
107 
108  if references_override_url is not None:
109  import requests
110 
111  url = references_override_url
112  if not url.endswith("/"): url += "/"
113  url += str(rel_path / file_name)
114  self.logger.info("Checking for reference override at %s", url)
115  if requests.head(url).ok: # file exists at url
116  reference_file = Path.cwd() / f"reference_{file_name}"
117  self.logger.info("Downloading reference from %s to %s", url, reference_file)
118  r = requests.get(url, stream=True)
119  with reference_file.open('wb') as f:
120  for chunk in r.iter_content(chunk_size=1024):
121  if chunk: # filter out keep-alive new chunks
122  f.write(chunk)
123  else:
124  self.logger.info("No reference override found")
125 
126  return reference_file
127 
128 

◆ run()

bool python.Checks.SimpleCheck.run (   self,
WorkflowTest  test 
)

Definition at line 465 of file Checks.py.

465  def run(self, test: WorkflowTest) -> bool:
466  self.logger.info("-----------------------------------------------------")
467  self.logger.info(f"Running {test.ID} {self.name} Check")
468 
469  result = True
470  for step in test.steps:
471  log_name = f"log.{step}"
472  reference_log = test.reference_path / log_name
473  validation_log = test.validation_path / log_name
474 
475  reference_value = 0
476  with reference_log.open() as file:
477  found = False
478  for line in file:
479  if self.quantity in line:
480  reference_value = float(line.split()[self.field])
481  found = True
482  break
483  if not found:
484  self.logger.error(f"No data available in {reference_log}. Job failed.")
485  return False
486 
487  validation_value = 0
488  with validation_log.open() as file:
489  found = False
490  for line in file:
491  if self.quantity in line:
492  validation_value = float(line.split()[self.field])
493  found = True
494  break
495  if not found:
496  self.logger.error(f"No data available in {validation_log}. Job failed.")
497  return False
498 
499  if reference_value != 0:
500  factor = validation_value / reference_value
501 
502  # Error if the factor increases (very bad things)
503  # Warning if the factor decreases (should be an understood feature)
504  if factor > 1. + self.threshold:
505  self.logger.error(f"{self.quantity} in the {step} step with(out) your change is {validation_value} ({reference_value}) {self.unit}")
506  self.logger.error(f"Your change changes {self.quantity} by a factor {factor}")
507  self.logger.error("Is this an expected outcome of your change(s)?")
508  result = False
509  self.logger.error(f"{step}: {self.name}")
510  self.logger.error(f"ref {reference_value} {self.unit}")
511  self.logger.error(f"val {validation_value} {self.unit}")
512  if factor < 1. - self.threshold:
513  self.logger.warning(f"{self.quantity} in the {step} step with(out) your change is {validation_value} ({reference_value}) {self.unit}")
514  self.logger.warning(f"Your change changes {self.quantity} by a factor {factor}")
515  self.logger.warning("Is this an expected outcome of your change(s)?")
516  result = True
517  self.logger.warning(f"{step}: {self.name}")
518  self.logger.warning(f"ref {reference_value} {self.unit}")
519  self.logger.warning(f"val {validation_value} {self.unit}")
520 
521  if result:
522  self.logger.info("Passed!\n")
523  else :
524  self.logger.error("Failed!\n")
525 
526  return result
527 
528 

Member Data Documentation

◆ field

python.Checks.SimpleCheck.field

Definition at line 462 of file Checks.py.

◆ logger

python.Test.WorkflowCheck.logger
inherited

Definition at line 89 of file Tools/WorkflowTestRunner/python/Test.py.

◆ name

python.Checks.SimpleCheck.name

Definition at line 459 of file Checks.py.

◆ quantity

python.Checks.SimpleCheck.quantity

Definition at line 460 of file Checks.py.

◆ setup

python.Test.WorkflowCheck.setup
inherited

Definition at line 88 of file Tools/WorkflowTestRunner/python/Test.py.

◆ threshold

python.Checks.SimpleCheck.threshold

Definition at line 463 of file Checks.py.

◆ unit

python.Checks.SimpleCheck.unit

Definition at line 461 of file Checks.py.


The documentation for this class was generated from the following file:
grepfile.info
info
Definition: grepfile.py:38
run
int run(int argc, char *argv[])
Definition: ttree2hdf5.cxx:28
python.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18
str
Definition: BTagTrackIpAccessor.cxx:11
error
Definition: IImpactPoint3dEstimator.h:70
python.LArMinBiasAlgConfig.float
float
Definition: LArMinBiasAlgConfig.py:65