13from conditions_db
import PayloadInformation
14from b2test_utils
import clean_working_directory
16from ROOT
import Belle2
18ROOT.gInterpreter.Declare(
"#include <framework/database/LocalMetadataProvider.h>")
23 Simple class to obtain all valid payloads matching a given set of names for
24 a given experiment
and run
and compare the python
and the C++
30 Jump through some hoops to create a C++ instance of the local metadata
31 provider so that we can check the framework implementation and compare
32 it to the python version
34 states = ROOT.std.set("string")()
35 states.insert(
"PUBLISHED")
36 tags = ROOT.std.vector(
"string")()
37 for tag
in globaltags:
40 localcpp.setTags(tags)
43 def __init__(self, filename, globaltag, payloads):
44 """Create the local metadata providers for the given globaltag and payload names"""
55 """Check if the c++ and python version return the same payload revisions
56 If not raise a ValueError,
if yes
return the list of payloads
and their
57 revision valid
for the given exp,run
"""
58 from_py = [(p.name, p.revision) for p
in self.
_localpy.get_all_iovs(self.
_globaltag, exp=exp, run=run)
60 info = ROOT.std.vector(
"Belle2::Conditions::PayloadMetadata")()
63 self.
_localcpp.getPayloads(exp, run, info)
64 from_cpp = [(p.name, p.revision)
for p
in info
68 if from_py != from_cpp:
69 raise ValueError(f
"Payloads not equal: {from_py} != {from_cpp}")
73if __name__ ==
"__main__":
74 with clean_working_directory()
as dirname:
77 local.add_globaltag(1,
"test1",
"PUBLISHED", [
78 PayloadInformation(1,
"test", 1,
"",
"",
"",
None, (45, 221, 49, -1))
81 local.add_globaltag(2,
"test2",
"PUBLISHED", [
82 PayloadInformation(1,
"test", 1,
"",
"",
"",
None, (0, 1, 0, 1))
85 local.add_globaltag(3,
"test3",
"PUBLISHED", [
86 PayloadInformation(1,
"test", 1,
"",
"",
"",
None, (1, 1, 1, -1))
89 local.add_globaltag(4,
"test4",
"PUBLISHED", [
90 PayloadInformation(1,
"test", 1,
"",
"",
"",
None, (1, 1, 2, 0))
93 local.add_globaltag(5,
"test5",
"PUBLISHED", [
94 PayloadInformation(1,
"test", 1,
"",
"",
"",
None, (1, 1, -1, -1))
98 for exp, run
in [(44, 1), (44, 9999), (45, 0), (45, 220), (45, 221), (45, 9999), (46, 0), (46, 221),
99 (49, 0), (49, 9999), (50, 0), (50, 221), (50, 9999)]:
100 valid = [(
"test", 1)]
if (45, 221) <= (exp, run) < (50, 0)
else []
101 assert comparer.check(exp, run) == valid, f
"Couldn't find payload for {exp},{run}"
104 for exp, run
in [(0, 0), (0, 1), (0, 2), (0, 9999),
105 (1, 0), (1, 1), (1, 2), (1, 9999), (9999, 9999)]:
106 valid = [(
"test", 1)]
if (exp, run) == (0, 1)
else []
107 assert comparer.check(exp, run) == valid, f
"Couldn't find payload for {exp},{run}"
110 for exp, run
in [(0, 0), (0, 1), (0, 2), (0, 9999),
111 (1, 0), (1, 1), (1, 2), (1, 9999),
112 (243, 0), (245, 9999999), (9999, 9999)]:
113 valid = [(
"test", 1)]
if (1, 1) <= (exp, run) < (2, 0)
else []
114 assert comparer.check(exp, run) == valid, f
"Couldn't find payload for {exp},{run}"
117 for exp, run
in [(0, 0), (0, 1), (0, 2), (0, 9999),
118 (1, 0), (1, 1), (1, 2), (1, 9999),
119 (243, 0), (245, 9999999), (9999, 9999)]:
120 valid = [(
"test", 1)]
if (1, 1) <= (exp, run) <= (2, 0)
else []
121 assert comparer.check(exp, run) == valid, f
"Couldn't find payload for {exp},{run}"
124 for exp, run
in [(0, 0), (0, 1), (0, 2), (0, 9999),
125 (1, 0), (1, 1), (1, 2), (1, 9999),
126 (2, 0), (2, 1), (2, 2), (2, 9999),
127 (243, 0), (245, 9999999), (9999, 9999)]:
128 valid = [(
"test", 1)]
if (1, 1) <= (exp, run)
else []
129 assert comparer.check(exp, run) == valid, f
"Couldn't find payload for {exp},{run}"