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