Belle II Software development
test_software_trigger_variables_database.py
1#!/usr/bin/env python3
2
3
10
11import basf2 as b2
12import modularAnalysis as ma
13import b2test_utils as b2tu
14
15
16triggers_to_test = [
17 ("software_trigger_cut&filter&1_Estargt1_GeV_cluster_no_other_cluster_Estargt0.3_GeV",
18 "filter 1_Estargt1_GeV_cluster_no_other_cluster_Estargt0.3_GeV"),
19 ("INVALID_INPUT", "this is not a valid trigger identifier")
20]
21
22
23def check_file(input_file_name, trigger_variables):
24 """Run the check with a quick basf2 printout for the
25 first event in ``input_file_name`` on the validation server"""
26 input_file = b2tu.require_file(input_file_name, 'validation')
27 pa = b2.Path()
28 ma.inputMdst(input_file, path=pa)
29 ma.printVariableValues("", trigger_variables, path=pa)
30 b2tu.safe_process(pa, 1)
31
32
33def swtr(name):
34 """Make the string form variable name"""
35 return f"SoftwareTriggerResult({name})"
36
37
38def swtp(name):
39 """Make the string form prescale variable name"""
40 return f"SoftwareTriggerPrescaling({name})"
41
42
43if __name__ == "__main__":
44
45 # build the variables
46 trigger_variables = [f(lng) for lng, _ in triggers_to_test for f in (swtr, swtp)]
47 trigger_variables += [f(shrt) for _, shrt in triggers_to_test for f in (swtr, swtp)]
48
49 # test on some files
50 b2.set_random_seed(r"\m/")
51 b2tu.configure_logging_for_tests()
52 check_file("mdst16.root", trigger_variables)
53 # TODO: update this to check a data event when a suitable file is added