Belle II Software light-2406-ragdoll
test_globaltag_forwarding.py
1#!/usr/bin/env python3
2
3
10
11# Test that globaltags are forwarded correclty to the output file even if the
12# database isn't used (BII-5790)
13
14import basf2
15import b2test_utils
16from ROOT import Belle2
17import json
18import unittest
19
20
21class TestGTForwarding(unittest.TestCase):
22 """Test that we forward globaltags correctly"""
23
24 def test_it(self):
25 """Only one test here ..."""
26 inputfile = b2test_utils.require_file("mdst12.root", "validation", self)
27 metadata = basf2.get_file_metadata(inputfile)
28 inputtags = metadata.getDatabaseGlobalTag()
29 self.assertNotEqual(inputtags, "")
30
32 basf2.conditions.globaltags = ["A", "B", "C", "A", "B", "C", "C", "A"]
33 Belle2.MetadataService.Instance().setJsonFileName("info.json")
34 p = basf2.Path()
35 p.add_module("RootInput", inputFileName=inputfile)
36 p.add_module("RootOutput", outputFileName="test.root")
37 basf2.process(p, 3)
38 with open("info.json") as jobinfo:
39 data = json.load(jobinfo)
40
41 self.assertIn('output_files', data, "Expecting output file info")
42 self.assertEqual(len(data['output_files']), 1, "Expecting exactly one output file")
43 fileinfo = data['output_files'][0]
44 # FIXME: Once we get rid of the legacy ip globaltag this will get nicer
45 self.assertEqual(fileinfo['metadata']['globalTag'], f"A,B,C,{inputtags},Legacy_IP_Information,Legacy_CollisionAxisCMS",
46 "Globaltags not forwarded correctly")
47 self.assertEqual(fileinfo['stats']['events'], 3, "Number of events is wrong")
48
49
50if __name__ == '__main__':
51 unittest.main()
static MetadataService & Instance()
Static method to get a reference to the MetadataService instance.
def require_file(filename, data_type="", py_case=None)
Definition: __init__.py:54
def clean_working_directory()
Definition: __init__.py:189