Belle II Software development
importChannelMask.py
1#!/usr/bin/env python
2
3
10
11import basf2 as b2
12from ROOT.Belle2 import TOPDatabaseImporter
13import os
14import sys
15import glob
16
17# Create path
18main = b2.create_path()
19
20# Event info setter - execute single event
21main.add_module('EventInfoSetter', evtNumList=[1])
22
23# Initialize TOP geometry parameters using default GT
24main.add_module('TOPGeometryParInitializer')
25
26# process single event
27b2.process(main)
28
29# define local database with write access
30b2.conditions.expert_settings(save_payloads="localDB/localDB.txt")
31
32# and then run the importer
33dbImporter = TOPDatabaseImporter()
34
35# import constants
36fileNames = sorted(glob.glob('masks/*.root'))
37numFiles = len(fileNames)
38if numFiles == 0:
39 print('No files found')
40 sys.exit()
41
42if not os.path.exists('masks/imported'):
43 os.makedirs('masks/imported')
44
45for i, fileName in enumerate(fileNames):
46 runFirst = int((fileName.split('_r')[1]).split('.')[0])
47 expNo = int((fileName.split('_e')[1]).split('_')[0])
48 runLast = runFirst
49 k = i + 1
50 if k < len(fileNames):
51 nextName = fileNames[k]
52 runLast = int((nextName.split('_r')[1]).split('.')[0]) - 1
53 expNext = int((nextName.split('_e')[1]).split('_')[0])
54 if expNext > expNo or k == len(fileNames): # last run in exp or last run in total
55 runLast = -1
56 elif runLast < runFirst:
57 b2.B2ERROR("first run:", runFirst, "last run:", runLast)
58 b2.B2ERROR("Last run is less than the first one: exiting!")
59 sys.exit()
60 dbImporter.importChannelMask(fileName, expNo, runFirst, runLast)
61 os.rename(fileName, fileName.replace('masks/', 'masks/imported/'))
62b2.B2RESULT("Done")