Belle II Software development
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
19import basf2 as b2
20from ROOT.Belle2 import TOPDatabaseImporter
21import sys
22import glob
23
24# define local database with write access
25b2.conditions.expert_settings(save_payloads="localDB/localDB.txt")
26
27# get a list of root files containing calibration constants
28folder_name = '.' # location of output files from TOPTimeBaseCalibrator
29fNames = glob.glob(folder_name + '/*/*.root')
30if len(fNames) == 0:
31 print('No root files found in', folder_name)
32 sys.exit()
33
34# convert the list to a single string
35fileNames = ''
36for fName in fNames:
37 fileNames = fileNames + ' ' + fName
38
39
40class 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
51main = b2.create_path()
52
53# Event info setter - execute single event
54main.add_module('EventInfoSetter')
55
56# Gearbox
57main.add_module('Gearbox')
58
59# Geometry parameters
60main.add_module('TOPGeometryParInitializer', useDB=False)
61
62# Importer
63main.add_module(PayloadImporter())
64
65# process single event
66b2.process(main)