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