Belle II Software development
mdst_class_versions.py
1#!/usr/bin/env python3
2
3
10
11"""
12Check that all the classdef versions and class checksums are consistent to prevent accidental mismatch:
13
14If one forgets to increase the ClassDef but the streamer info checksum changes this will trigger a test failure. We can distuingish
15
161. ClassDef version changed unnecessary
172. forgot to change ClassDef
183. both changed
19"""
20
21import sys
22from b2test_utils import get_object_with_name, get_streamer_checksums
23
24
25EXPECTED_CHECKSUMS = {
26 'Belle2::Const::DetectorSet': (1, 1222446098),
27 'Belle2::ECLCluster': (15, 835771092),
28 'Belle2::EventLevelClusteringInfo': (4, 1906636092),
29 'Belle2::EventLevelTrackingInfo': (2, 1667284927),
30 'Belle2::EventMetaData': (4, 2999207747),
31 'Belle2::FileMetaData': (11, 3436141238),
32 'Belle2::KLMCluster': (3, 1419175697),
33 'Belle2::KlId': (2, 230716330),
34 'Belle2::PIDLikelihood': (4, 4027053936),
35 'Belle2::RelationContainer': (1, 1725678837),
36 'Belle2::RelationElement': (1, 1883389510),
37 'Belle2::RelationsInterface<TObject>': (0, 3862127315),
38 'Belle2::SoftwareTriggerResult': (5, 241059817),
39 'Belle2::TRGSummary': (7, 1658421299),
40 'Belle2::Track': (6, 327743743),
41 'Belle2::TrackFitResult': (10, 1213379524),
42 'Belle2::V0': (4, 422320450),
43}
44
45
46OBJECT_NAMES = [
47 "FileMetaData",
48 "EventMetaData",
49 "RelationContainer",
50 "Track",
51 "V0",
52 "TrackFitResult",
53 "EventLevelTrackingInfo",
54 "PIDLikelihood",
55 "ECLCluster",
56 "EventLevelClusteringInfo",
57 "KLMCluster",
58 "KlId",
59 "TRGSummary",
60 "SoftwareTriggerResult",
61]
62
63if __name__ == "__main__":
64 # Now get
65
66 objects = [get_object_with_name(object_name)() for object_name in OBJECT_NAMES]
67
68 # Check the checksums of every entry and
69
70 problems = []
71
72
73 found = get_streamer_checksums(objects)
74 # we don't care about TObject ...
75 if 'TObject' in found:
76 del found['TObject']
77
78 # print list we found to be able to copy pasta
79 print("found_checksums = {\n " + "\n ".join(f"{k!r}: {v!r}," for k, v in sorted(found.items())) + "\n}")
80 for key, (version, checksum) in found.items():
81 if key not in EXPECTED_CHECKSUMS:
82 problems.append(f"There is no {key} in the checksum dictionary!")
83 continue
84
85
89 expected_version, expected_checksum = EXPECTED_CHECKSUMS[key]
90
91 if expected_version != version and expected_checksum == checksum:
92 problems.append(f"The version for {key} has changed (expected={expected_version}, found={version}) "
93 f"while the checksum has not. This probably means the ClassDef version was increased unnecessarily. "
94 f"If this is intentional please update the expected version in this test")
95 elif expected_version == version and expected_checksum != checksum:
96 problems.append(f"The checksum for {key} has changed (expected={expected_checksum}, found={checksum}) "
97 f"while the version has not. This probably means you forgot to increase the ClassDef version "
98 f"after changing the class. Please update the ClassDef version and the expected values in this test")
99 elif expected_version != version and expected_checksum != checksum:
100 problems.append(f"The version and checksum for {key} have changed, (expected version={expected_version}, "
101 f"checksum={expected_checksum}, found version={version}, checksum={checksum}). "
102 f"Please update the expected values")
103 del EXPECTED_CHECKSUMS[key]
104
105 for remaining, (version, checksum) in EXPECTED_CHECKSUMS.items():
106 problems.append(f"Additional class expected but not needed: {remaining} (version {version}, checksum {checksum})")
107
108 if not problems:
109 print("Check finished")
110 else:
111 problems = "\n\t * ".join([""] + problems)
112 print("Check failed: Most likely a mdst class has been modified and the list of expected checksums needs to be adjusted:",
113 problems)
114 sys.exit(1)