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