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