5 from conditions_db
import PayloadInformation
6 from b2test_utils
import clean_working_directory
8 from ROOT
import Belle2
10 ROOT.gInterpreter.Declare(
"#include <framework/database/LocalMetadataProvider.h>")
15 Simple class to obtain all valid payloads matching a given set of names for
16 a given experiment and run and compare the python and the C++
22 Jump through some hoops to create a C++ instance of the local metadata
23 provider so that we can check the framework implementation and compare
24 it to the python version
26 states = ROOT.std.set(
"string")()
27 states.insert(
"PUBLISHED")
28 tags = ROOT.std.vector(
"string")()
29 for tag
in globaltags:
32 localcpp.setTags(tags)
35 def __init__(self, filename, globaltag, payloads):
36 """Create the local metadata providers for the given globaltag and payload names"""
43 """Check if the c++ and python version return the same payload revisions
44 If not raise a ValueError, if yes return the list of payloads and their
45 revision valid for the given exp,run"""
46 from_py = [(p.name, p.revision)
for p
in self.
_localpy.get_all_iovs(self.
_globaltag, exp=exp, run=run)
48 info = ROOT.std.vector(
"Belle2::Conditions::PayloadMetadata")()
51 self.
_localcpp.getPayloads(exp, run, info)
52 from_cpp = [(p.name, p.revision)
for p
in info
56 if from_py != from_cpp:
57 raise ValueError(f
"Payloads not equal: {from_py} != {from_cpp}")
61 if __name__ ==
"__main__":
62 with clean_working_directory()
as dirname:
65 local.add_globaltag(1,
"test1",
"PUBLISHED", [
66 PayloadInformation(1,
"test", 1,
"",
"",
"",
None, (45, 221, 49, -1))
69 local.add_globaltag(2,
"test2",
"PUBLISHED", [
70 PayloadInformation(1,
"test", 1,
"",
"",
"",
None, (0, 1, 0, 1))
73 local.add_globaltag(3,
"test3",
"PUBLISHED", [
74 PayloadInformation(1,
"test", 1,
"",
"",
"",
None, (1, 1, 1, -1))
77 local.add_globaltag(4,
"test4",
"PUBLISHED", [
78 PayloadInformation(1,
"test", 1,
"",
"",
"",
None, (1, 1, 2, 0))
81 local.add_globaltag(5,
"test5",
"PUBLISHED", [
82 PayloadInformation(1,
"test", 1,
"",
"",
"",
None, (1, 1, -1, -1))
86 for exp, run
in [(44, 1), (44, 9999), (45, 0), (45, 220), (45, 221), (45, 9999), (46, 0), (46, 221),
87 (49, 0), (49, 9999), (50, 0), (50, 221), (50, 9999)]:
88 valid = [(
"test", 1)]
if (45, 221) <= (exp, run) < (50, 0)
else []
89 assert comparer.check(exp, run) == valid, f
"Couldn't find payload for {exp},{run}"
92 for exp, run
in [(0, 0), (0, 1), (0, 2), (0, 9999),
93 (1, 0), (1, 1), (1, 2), (1, 9999), (9999, 9999)]:
94 valid = [(
"test", 1)]
if (exp, run) == (0, 1)
else []
95 assert comparer.check(exp, run) == valid, f
"Couldn't find payload for {exp},{run}"
98 for exp, run
in [(0, 0), (0, 1), (0, 2), (0, 9999),
99 (1, 0), (1, 1), (1, 2), (1, 9999),
100 (243, 0), (245, 9999999), (9999, 9999)]:
101 valid = [(
"test", 1)]
if (1, 1) <= (exp, run) < (2, 0)
else []
102 assert comparer.check(exp, run) == valid, f
"Couldn't find payload for {exp},{run}"
105 for exp, run
in [(0, 0), (0, 1), (0, 2), (0, 9999),
106 (1, 0), (1, 1), (1, 2), (1, 9999),
107 (243, 0), (245, 9999999), (9999, 9999)]:
108 valid = [(
"test", 1)]
if (1, 1) <= (exp, run) <= (2, 0)
else []
109 assert comparer.check(exp, run) == valid, f
"Couldn't find payload for {exp},{run}"
112 for exp, run
in [(0, 0), (0, 1), (0, 2), (0, 9999),
113 (1, 0), (1, 1), (1, 2), (1, 9999),
114 (2, 0), (2, 1), (2, 2), (2, 9999),
115 (243, 0), (245, 9999999), (9999, 9999)]:
116 valid = [(
"test", 1)]
if (1, 1) <= (exp, run)
else []
117 assert comparer.check(exp, run) == valid, f
"Couldn't find payload for {exp},{run}"