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