Belle II Software development
SVDChannelMappingImporter.py
1#!/usr/bin/env python
2
3
10
11"""
12SVD Database importer.
13Script to Import SVD Channel Mapping into a local DB
14"""
15
16import basf2 as b2
17import sys
18import argparse
19from termcolor import colored
20from basf2 import conditions as b2conditions
21
22parser = argparse.ArgumentParser(description="SVD Local Calibrations Importer")
23parser.add_argument('--exp', metavar='experiment', dest='exp', type=int, nargs=1, help='Experiment Number, = 1 for GCR')
24parser.add_argument('--run', metavar='run', dest='run', type=int, nargs=1, help='Run Number')
25parser.add_argument('--mapXML', metavar='channel map xml', dest='mapp', type=str, nargs=1, help='Channel Mapping xml file')
26
27print('')
28
29if (str(sys.argv[1]) == "help"):
30 parser.print_help()
31 exit(1)
32
33args = parser.parse_args()
34
35experiment = args.exp[0]
36run = args.run[0]
37
38if args.mapp is not None:
39 mappingfile = args.mapp[0]
40else:
41 mappingfile = args.mapp
42
43RED = "\033[1;31m"
44BLUE = "\033[1;34m"
45CYAN = "\033[1;36m"
46GREEN = "\033[0;32m"
47RESET = "\033[0;0m"
48BOLD = "\033[;1m"
49BLEU = "\033[34m"
50REVERSE = "\033[;7m"
51sys.stdout.write(RED)
52print('| ---> CHECK HERE: <---')
53print('| experiment number = ' + str(experiment))
54print('|first valid run number = ' + str(run))
55print('| mapping xml = ' + str(mappingfile))
56print('| ---> THANKS! <---')
57sys.stdout.write(RESET)
58
59print('')
60
61proceed = input("Do you want to proceed? y/n ")
62if not str(proceed) == 'y':
63 print(colored(str(proceed) + ' != y, therefore we exit now', 'red'))
64 exit(1)
65
66
67b2conditions.prepend_globaltag("svd_basic")
68
69main = b2.create_path()
70
71
72# Event info setter - execute single event
73eventinfosetter = b2.register_module('EventInfoSetter')
74eventinfosetter.param({'evtNumList': [1], 'expList': experiment, 'runList': run})
75main.add_module(eventinfosetter)
76
77# Gearbox - access to xml files
78main.add_module("Gearbox")
79
80run = int(run)
81
82
83class dbImporterModule(b2.Module):
84 '''channel mapping importer module'''
85
86 def beginRun(self):
87 '''begin run'''
88 # avoid top level ROOT imports
89 from ROOT import Belle2 # noqa: make Belle2 namespace available
90 from ROOT.Belle2 import SVDLocalCalibrationsImporter
91
92 # call the importer class
93 dbImporter = SVDLocalCalibrationsImporter(experiment, run, experiment, -1)
94 if args.mapp is not None:
95 # import channel mapping
96 dbImporter.importSVDChannelMapping(mappingfile)
97 print(colored("V) Channel Mapping Imported", 'green'))
98
99
100main.add_module(dbImporterModule())
101
102b2.process(main)
103
104print("IMPORT COMPLETED, check the localDB folder and then proceeed with the upload to the central DB")