Belle II Software  release-08-01-10
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 local database with write access
24 b2.conditions.expert_settings(save_payloads="localDB/localDB.txt")
25 
26 # get a list of root files containing calibration constants
27 folder_name = 'tbc' # location of output files from TOPTimeBaseCalibrator
28 fNames = glob.glob(folder_name + '/*.root')
29 if len(fNames) == 0:
30  print('No root files found in', folder_name)
31  sys.exit()
32 
33 # convert the list to a single string
34 fileNames = ''
35 for fName in fNames:
36  fileNames = fileNames + ' ' + fName
37 
38 
39 class PayloadImporter(b2.Module):
40  ''' Payload importer using TOPDatabaseImporter '''
41 
42  def initialize(self):
43  ''' Import timebase calibration '''
44 
45  dbImporter = TOPDatabaseImporter()
46  dbImporter.importSampleTimeCalibration(fileNames)
47 
48 
49 # create path
50 main = b2.create_path()
51 
52 # Event info setter - execute single event
53 main.add_module('EventInfoSetter')
54 
55 # Gearbox
56 main.add_module('Gearbox')
57 
58 # Geometry parameters
59 main.add_module('TOPGeometryParInitializer', useDB=False)
60 
61 # Importer
62 main.add_module(PayloadImporter())
63 
64 # process single event
65 b2.process(main)