Belle II Software development
check_paths.py
1#!/usr/bin/env python3
2
3
10
11"""
12Check for possible problems on the processing path that will affect HLT procesing
13
141. Conditions not continuing to main path
15
16 On HLT we never want to just end processing, we always want to reach the end
17 to send the event on to the output. So make sure no conditions with
18 AfterConditionPath.END is present.
19
202. Multiple EventErrorFlags on one path
21
22 We don't want to sent multiple error flags unconditionally after each other so if there are two ore more EventErrorFlags on one path this is wrong.
23"""
24
25import sys
26import itertools
27import basf2
28from softwaretrigger import constants
29from softwaretrigger.processing import add_hlt_processing
30
31
32def short_path(path):
33 """Just print a short version of the path"""
34 return '[' + " -> ".join(m.name() for m in path.modules()) + ']'
35
36
37def check_path(path):
38 """Check the given path recursively"""
39 result = True
40 max_number = {
41 'EventErrorFlag': 1
42 }
43 for m in path.modules():
44 if m.type() in max_number:
45 max_number[m.type()] -= 1
46 if max_number[m.type()] < 0:
47 basf2.B2ERROR("Too many identical modules in path", type=m.type(), path=short_path(path))
48 result = False
49
50 for c in m.get_all_conditions():
51 if c.get_after_path() != basf2.AfterConditionPath.CONTINUE:
52 basf2.B2ERROR(f"Condition on '{m.name()}' doesn't return to original path, potential loss of events",
53 condition=str(c))
54 result = False
55 result &= check_path(c.get_path())
56 return result
57
58
59if __name__ == "__main__":
60 all_good = True
61 for run_type, mode in itertools.product(constants.RunTypes, constants.SoftwareTriggerModes):
62 basf2.B2INFO(f"Checking processing path for {run_type} in {mode} mode")
63 path = basf2.Path()
64 add_hlt_processing(path, run_type=run_type, softwaretrigger_mode=mode)
65 basf2.print_path(path)
66 if not check_path(path):
67 basf2.B2ERROR(f"Problems found for {run_type} in {mode} mode")
68 all_good = False
69
70 sys.exit(0 if all_good else 1)
71