Belle II Software development
SVDDetectorConfigurationImporter.py
1#!/usr/bin/env python
2
3
10
11"""
12SVD Detector Configuration Importer.
13Script to the configuration parameters, Local and Global, 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 Detector Configuration 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('--cfgXML', metavar='config xml', dest='calib', type=str, nargs=1, help='GlobalRun Calibration 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.calib is not None:
39 calibfile = args.calib[0]
40else:
41 calibfile = args.calib
42
43
44RED = "\033[1;31m"
45BLUE = "\033[1;34m"
46CYAN = "\033[1;36m"
47GREEN = "\033[0;32m"
48RESET = "\033[0;0m"
49BOLD = "\033[;1m"
50BLEU = "\033[34m"
51REVERSE = "\033[;7m"
52sys.stdout.write(RED)
53print('| ---> CHECK HERE: <---')
54print('| experiment number = ' + str(experiment))
55print('|first valid run number = ' + str(run))
56print('| global xml = ' + str(calibfile))
57print('| ---> THANKS! <---')
58sys.stdout.write(RESET)
59
60print('')
61
62proceed = input("Do you want to proceed? y/n ")
63if not str(proceed) == 'y':
64 print(colored(str(proceed) + ' != y, therefore we exit now', 'red'))
65 exit(1)
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 configImporterToDBModule(b2.Module):
84 '''detector configuration importer'''
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 SVDDetectorConfigurationImporter
91
92 # call the importer class
93 configImporterToDB = SVDDetectorConfigurationImporter(experiment, run, experiment, -1)
94 if args.calib is not None:
95 # import SVDGlobalConfigParameters dbobject: ZS, latency, mask, APV clock units
96 configImporterToDB.importSVDGlobalConfigParametersFromXML(calibfile)
97 print(colored("V) Global Detector Configuration parameters: (ZS, latency, mask, APVClock units) Imported", 'green'))
98 # import SVDLocalConfigParameters dbobject: calibration peak and time units, date
99 configImporterToDB.importSVDLocalConfigParametersFromXML(calibfile)
100 print(colored("V) Local Detector Configuration parameters Imported", 'green'))
101 else:
102 print(colored("X) Detector Configuration parameters are not NOT imported.", 'red'))
103
104
105main.add_module(configImporterToDBModule())
106
107b2.process(main)
108
109print("IMPORT COMPLETED, check the localDB folder and then proceeed with the upload to the central DB")