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