Commit 2a03c12e authored by Aidan Richard Wiederhold's avatar Aidan Richard Wiederhold
Browse files

Merge branch 'djwhite/move-checks-run' into 'master'

Move func to run checks to LbAPCommon

See merge request !47
parents 59261879 5d9d276d
Pipeline #3464887 passed with stages
in 2 minutes and 33 seconds
......@@ -31,6 +31,87 @@ class CheckResult:
tree_data: Dict[str, Dict] = field(default_factory=dict)
def run_job_checks(checks_list, check_data, test_ntuple_path_list):
"""
Run the checks listed for the given job, using data from an ntuple made earlier (by `lb-ap test`).
Returns dict of CheckResult objects
"""
check_results = {}
for check in checks_list:
data = check_data[check]
# This is added because some parameters are optional and need to be properly initialized
blind = data["blind_ranges"] if "blind_ranges" in data else []
exp_mean = data["exp_mean"] if "exp_mean" in data else 0.0
exp_std = data["exp_std"] if "exp_std" in data else 0.0
mean_tolerance = data["mean_tolerance"] if "mean_tolerance" in data else 0.0
std_tolerance = data["std_tolerance"] if "std_tolerance" in data else 0.0
tree_pattern = (
data["tree_pattern"]
if "tree_pattern" in data
else r"(.*/DecayTree)|(.*/MCDecayTree)"
)
lumi_pattern = (
data["lumi_pattern"] if "lumi_pattern" in data else r"(.*/LumiTuple)"
)
if data["type"] == "range":
check_results[check] = range_check(
test_ntuple_path_list,
data["expression"],
data["limits"],
blind_ranges=blind,
exp_mean=exp_mean,
exp_std=exp_std,
mean_tolerance=mean_tolerance,
std_tolerance=std_tolerance,
tree_pattern=tree_pattern,
)
elif data["type"] == "range_bkg_subtracted":
check_results[check] = range_check_bkg_subtracted(
test_ntuple_path_list,
data["expression"],
data["limits"],
data["expr_for_subtraction"],
data["mean_sig"],
data["background_shift"],
data["background_window"],
data["signal_window"],
blind_ranges=blind,
tree_pattern=tree_pattern,
)
elif data["type"] == "range_nd":
check_results[check] = range_check_nd(
test_ntuple_path_list,
data["expressions"],
data["limits"],
blind_ranges=blind,
tree_pattern=tree_pattern,
)
elif data["type"] == "num_entries":
check_results[check] = num_entries(
test_ntuple_path_list,
data["count"],
tree_pattern=tree_pattern,
)
elif data["type"] == "num_entries_per_invpb":
check_results[check] = num_entries_per_invpb(
test_ntuple_path_list,
data["count_per_invpb"],
tree_pattern=tree_pattern,
lumi_pattern=lumi_pattern,
)
elif data["type"] == "branches_exist":
check_results[check] = branches_exist(
test_ntuple_path_list,
data["branches"],
tree_pattern=tree_pattern,
)
return check_results
def num_entries(
filepath_list,
count,
......
......@@ -112,6 +112,7 @@ CHECK_TYPE_SCHEMAS = {
},
"num_entries_per_invpb": {
"count_per_invpb": Float(),
Optional("lumi_pattern"): Str(),
},
"range_bkg_subtracted": {
"expression": Str(),
......@@ -139,6 +140,7 @@ BASE_CHECK_DEFAULT_VALUES = {
"exp_std": 0.0,
"mean_tolerance": 0.0,
"std_tolerance": 0.0,
"lumi_pattern": r"(.*/LumiTuple)",
}
......
......@@ -47,13 +47,13 @@ def test_num_entries_parsing_to_JSON():
job_name = list(jobs_data.keys())[0]
check_name = list(checks_data.keys())[0]
result = checks.num_entries(
result = checks.run_job_checks(
[check_name],
checks_data,
[
"root://eospublic.cern.ch//eos/opendata/lhcb/AntimatterMatters2017/data/B2HHH_MagnetDown.root"
],
checks_data[check_name]["count"],
checks_data[check_name]["tree_pattern"],
)
)[check_name]
check_results_with_job = {
job_name: {
......@@ -128,15 +128,13 @@ def test_range_parsing_to_JSON():
job_name = list(jobs_data.keys())[0]
check_name = list(checks_data.keys())[0]
result = checks.range_check(
result = checks.run_job_checks(
[check_name],
checks_data,
[
"root://eospublic.cern.ch//eos/opendata/lhcb/AntimatterMatters2017/data/B2HHH_MagnetDown.root"
],
checks_data[check_name]["expression"],
checks_data[check_name]["limits"],
checks_data[check_name]["blind_ranges"],
checks_data[check_name]["tree_pattern"],
)
)[check_name]
check_results_with_job = {
job_name: {
......
This diff is collapsed.
......@@ -607,6 +607,7 @@ def test_good_with_checks_no_defaults():
check_num_entries_per_invpb:
type: num_entries_per_invpb
count_per_invpb: 12.5
lumi_pattern: LumiTuple
check_branches_exist:
type: branches_exist
branches:
......@@ -686,6 +687,7 @@ def test_good_with_checks_no_defaults():
assert checks_data["check_num_entries_per_invpb"]["type"] == "num_entries_per_invpb"
assert checks_data["check_num_entries_per_invpb"]["count_per_invpb"] == 12.5
assert checks_data["check_num_entries_per_invpb"]["lumi_pattern"] == "LumiTuple"
assert checks_data["check_branches_exist"]["type"] == "branches_exist"
assert checks_data["check_branches_exist"]["branches"] == [
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment