Belle II Software development
check_payload_metadata.py
1
8'''
9Check the revision number of a payload used by a module.
10'''
11
12import os
13
14import basf2 as b2
15import b2test_utils as b2tu
16from ROOT import Belle2 # noqa: make Belle2 namespace accessible
17import ROOT.Belle2 as B2
18
19
20class CheckPayloadMetadata(b2.Module):
21 '''
22 Small module for checking some payload metadata.
23 '''
24
25 def __init__(self, use_testing_payloads, md5_revision):
26 '''Consructor.'''
27 super().__init__()
28
29 self.beam_parameters = B2.PyDBObj('BeamParameters')
30
31 self.use_testing_payloads = use_testing_payloads
32
33 self.md5_revision = md5_revision
34
35 def beginRun(self):
36 '''Begin run.'''
37 assert (self.beam_parameters.isValid())
39 assert ('testingdb/testingdb.txt' in self.beam_parameters.getGlobaltag())
40 assert (self.beam_parameters.getRevision() == 0)
41 assert (os.path.basename(self.beam_parameters.getFilename()).startswith('dbstore'))
42 assert (os.path.basename(self.beam_parameters.getFilename()).index(self.md5_revision) != -1)
43 assert (self.beam_parameters.getIoV() == B2.IntervalOfValidity(0, 1, 2, 3))
44 else:
45 assert (self.beam_parameters.getGlobaltag() == b2.conditions.default_globaltags[0])
46 assert (self.beam_parameters.getRevision() > 0)
47 assert (self.beam_parameters.getFilename().startswith('/cvmfs'))
48 assert (self.beam_parameters.getIoV() == B2.IntervalOfValidity(0, 0, 0, -1))
49
50
51def create_beam_parameters_payload(testing_database_path):
52 '''
53 Create locally a BeamParameters payload.
54 '''
55 b2.conditions.expert_settings(save_payloads=testing_database_path)
56 beam_parameters = B2.BeamParameters()
57 database = B2.Database.Instance()
58 iov = B2.IntervalOfValidity(0, 1, 2, 3)
59 assert (database.storeData('BeamParameters', beam_parameters, iov))
60
61
62def testing_path(use_testing_payloads=False, remove_default_globaltag=False, testing_database_path=None, md5_revision=None):
63 '''
64 The basf2 steering path for this test.
65 '''
66 if remove_default_globaltag:
67 b2.conditions.override_globaltags()
68 if use_testing_payloads:
69 b2.conditions.prepend_testing_payloads(b2.find_file(testing_database_path))
70 testing_path = b2.Path()
71 testing_path.add_module('EventInfoSetter', expList=[0], runList=[1])
72 testing_path.add_module(CheckPayloadMetadata(use_testing_payloads=use_testing_payloads, md5_revision=md5_revision))
73 b2.process(testing_path)
74
75
76if __name__ == '__main__':
77
78 with b2tu.clean_working_directory():
79
80
81 testing_database_path = 'testingdb/testingdb.txt'
82
83 # Create the testing payloads.
84 assert (b2tu.run_in_subprocess(target=create_beam_parameters_payload, testing_database_path=testing_database_path) == 0)
85
86 # Identify the md5 revision string of the payload.
87
88 md5_revision = None
89 with open(b2.find_file('testingdb/testingdb.txt')) as testing_database_file:
90 for line in testing_database_file:
91 md5_revision = str(line.split(' ')[1])
92
93 # Check if the process aborts because no valid payloads are found.
94 assert (b2tu.run_in_subprocess(target=testing_path,
95 use_testing_payloads=False,
96 remove_default_globaltag=True,
97 ) == 1)
98
99 # Check if the default globaltag is correctly used.
100 assert (b2tu.run_in_subprocess(target=testing_path,
101 use_testing_payloads=False,
102 remove_default_globaltag=False,
103 ) == 0)
104
105 # Check if the testing payload is correctly used.
106 assert (b2tu.run_in_subprocess(target=testing_path,
107 use_testing_payloads=True,
108 remove_default_globaltag=True,
109 testing_database_path=testing_database_path,
110 md5_revision=md5_revision,
111 ) == 0)
112
113 # Check if the testing payload is used instead of the default globaltag.
114 assert (b2tu.run_in_subprocess(target=testing_path,
115 use_testing_payloads=True,
116 remove_default_globaltag=False,
117 testing_database_path=testing_database_path,
118 md5_revision=md5_revision,
119 ) == 0)
md5_revision
md5 revision hash of the payload.
def __init__(self, use_testing_payloads, md5_revision)
beam_parameters
BeamParameters database object.
use_testing_payloads
Flag to mark if testing payloads are used or not.