ATLAS Offline Software
Loading...
Searching...
No Matches
validateBDTTau.py
Go to the documentation of this file.
1#!/usr/bin/env python
2
3import sys
4import os, os.path
5import numpy as np
6import json
7from collections import OrderedDict
8import re
9
10test_status = int(os.environ["ATLAS_CTEST_TESTSTATUS"])
11if test_status != 0:
12 print(f"Post evaluation: ERROR: previous step went wrong (exit code {test_status})")
13 sys.exit(test_status)
14
15test_output_file = os.environ["ATLAS_CTEST_TESTNAME"]+".log"
16bdt_config_file = os.environ["TAU_EFEX_BDT_CONFIG_PATH"]
17
18def get_vector(lines, startswith):
19 """
20 Extract a vector of numbers from a line that starts with a string from a list of Athena log file lines
21 """
22 vals = [x[x.rfind(':')+1:].split() for x in lines if startswith in x]
23 vals = np.array(vals).astype(int)
24 return vals
25
26out_log_content = open(test_output_file, "r").read()
27
28# Filter to get only BDT-related lines
29bdt_algo_lines = [l for l in out_log_content.split('\n') if re.findall(r"eFEXDriver\..+eFEXtauBDTAlgo", l)]
30
31# Get supercells used to compute the variables, as appears in the test output. Check that they're the same as in the bdt config file
32rgx_vartitle = re.compile(r"DEBUG\s+([0-9]+) is (l[0-4]_d[0-9_pld]*), sum of supercells$")
33rgx_coretitle = re.compile(r"DEBUG\s+([0-9]+) is CORE, sum of supercells$")
34rgx_etaphilayer = re.compile(r"DEBUG\s+eta=([0-9]+)\s+phi=([0-9]+)\s+layer=([0-9]+)$")
35variables = OrderedDict()
36last_var_line = [i for i,x in enumerate(bdt_algo_lines) if "Will use sum of supercells" in x][0]
37for l in bdt_algo_lines[:last_var_line]:
38 vartitle = rgx_vartitle.findall(l)
39 coretitle = rgx_coretitle.findall(l)
40 etaphilayer = rgx_etaphilayer.findall(l)
41 if len(vartitle) > 0:
42 variables[vartitle[0][1]] = []
43 vt = vartitle[0][1]
44 elif len(coretitle) > 0:
45 vt="CORE"
46 variables[vt] = []
47 elif len(etaphilayer) > 0:
48 variables[vt].append([int(x) for x in etaphilayer[0]])
49
50bdt_config=json.load(open(bdt_config_file, "r"))
51
52assert set(v['name'] for v in bdt_config['variables']) == set(variables.keys()), "Variables as read from this test's log file are not as they appear in the data/bdt_config.json. They must be consistent with each other."
53
54for v in bdt_config['variables']:
55 assert sorted(v['scells']) == sorted(variables[v['name']]), f"For BDT variable {v['name']}, the supercells used to compute it are different in the log file vs. in data/bdt_config.json"
56
57# Check BDT scores are within range
58bdt_scores=get_vector(bdt_algo_lines, 'DEBUG BDT Score: ').reshape(-1)
59assert ((bdt_scores>500) &(bdt_scores < 2000)).all()
void print(char *figname, TCanvas *c1)
STL class.
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:177
get_vector(lines, startswith)
IovVectorMap_t read(const Folder &theFolder, const SelectionCriterion &choice, const unsigned int limit=10)