Belle II Software  release-08-01-10
DBImportTBC.py
1 #!/usr/bin/env python
2 
3 
10 
11 # ---------------------------------------------------------------------------------------------------------
12 # Database importer for importing TBC constants to local database.
13 # User has to set the path to TOPTimeBaseCalibrator output files correctly or just run from that directory.
14 # Name and location of local DB can also be changed.
15 #
16 # usage: basf2 DBImportTBC.py
17 # ---------------------------------------------------------------------------------------------------------
18 
19 import basf2 as b2
20 from ROOT.Belle2 import TOPDatabaseImporter
21 import sys
22 import glob
23 
24 # define local database with write access
25 b2.conditions.expert_settings(save_payloads="localDB/localDB.txt")
26 
27 # get a list of root files containing calibration constants
28 folder_name = '.' # location of output files from TOPTimeBaseCalibrator
29 fNames = glob.glob(folder_name + '/*/*.root')
30 if len(fNames) == 0:
31  print('No root files found in', folder_name)
32  sys.exit()
33 
34 # convert the list to a single string
35 fileNames = ''
36 for fName in fNames:
37  fileNames = fileNames + ' ' + fName
38 
39 
40 class PayloadImporter(b2.Module):
41  ''' Payload importer using TOPDatabaseImporter '''
42 
43  def initialize(self):
44  ''' Import timebase calibration '''
45 
46  dbImporter = TOPDatabaseImporter()
47  dbImporter.importSampleTimeCalibration(fileNames)
48 
49 
50 # create path
51 main = b2.create_path()
52 
53 # Event info setter - execute single event
54 main.add_module('EventInfoSetter')
55 
56 # Gearbox
57 main.add_module('Gearbox')
58 
59 # Geometry parameters
60 main.add_module('TOPGeometryParInitializer', useDB=False)
61 
62 # Importer
63 main.add_module(PayloadImporter())
64 
65 # process single event
66 b2.process(main)