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