Belle II Software  release-06-02-00
DBImportTBC.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 # --------------------------------------------------------------------------------
13 # Example of using Database importer for importing TBC constants to local database
14 # User has to set the path to TOPTimeBaseCalibrator output files correctly
15 # Name and location of local DB can also be changed
16 # --------------------------------------------------------------------------------
17 
18 import basf2 as b2
19 from ROOT.Belle2 import TOPDatabaseImporter
20 import sys
21 import glob
22 
23 # define a local database with write access
24 # (will be created automatically, if doesn't exist)
25 b2.use_local_database("localDB/localDB.txt", "localDB", False)
26 
27 # create path
28 main = b2.create_path()
29 
30 # Event info setter - execute single event
31 eventinfosetter = b2.register_module('EventInfoSetter')
32 eventinfosetter.param('evtNumList', [1])
33 main.add_module(eventinfosetter)
34 
35 # Gearbox - access to xml files
36 gearbox = b2.register_module('Gearbox')
37 main.add_module(gearbox)
38 
39 geometry = b2.register_module('Geometry')
40 geometry.param('useDB', False)
41 geometry.param('components', ['TOP'])
42 main.add_module(geometry)
43 
44 # process single event
45 b2.process(main)
46 
47 # and then run the importer (note: input file is not there - must change the path!)
48 dbImporter = TOPDatabaseImporter()
49 
50 dir = 'tbc' # location of output files from TOPTimeBaseCalibrator
51 fNames = glob.glob(dir + '/*.root')
52 if len(fNames) == 0:
53  print('No root files found in', dir)
54  sys.exit()
55 fileNames = ''
56 
57 # convert a list to a single string (since list doesn't work for some reasons)
58 for fName in fNames:
59  fileNames = fileNames + ' ' + fName
60 
61 # import constants
62 dbImporter.importSampleTimeCalibration(fileNames)