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