Belle II Software development
DBImportTBC.py
1#!/usr/bin/env python
2
3
10
11# --------------------------------------------------------------------------------
12# Example of using Database importer for importing TBC constants to local database
13# User has to set the path to TOPTimeBaseCalibrator output files correctly
14# Name and location of local DB can also be changed
15# --------------------------------------------------------------------------------
16
17import basf2 as b2
18from ROOT import Belle2 # noqa: make Belle2 namespace available
19from ROOT.Belle2 import TOPDatabaseImporter
20import sys
21import glob
22
23# define local database with write access
24b2.conditions.expert_settings(save_payloads="localDB/localDB.txt")
25
26# get a list of root files containing calibration constants
27folder_name = 'tbc' # location of output files from TOPTimeBaseCalibrator
28fNames = glob.glob(folder_name + '/*.root')
29if len(fNames) == 0:
30 print('No root files found in', folder_name)
31 sys.exit()
32
33# convert the list to a single string
34fileNames = ''
35for fName in fNames:
36 fileNames = fileNames + ' ' + fName
37
38
39class 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
50main = b2.create_path()
51
52# Event info setter - execute single event
53main.add_module('EventInfoSetter')
54
55# Gearbox
56main.add_module('Gearbox')
57
58# Geometry parameters
59main.add_module('TOPGeometryParInitializer', useDB=False)
60
61# Importer
62main.add_module(PayloadImporter())
63
64# process single event
65b2.process(main)