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
17from ROOT.Belle2 import SVDDetectorConfigurationImporter
18import sys
19import argparse
20from termcolor import colored
21from basf2 import conditions as b2conditions
22
23parser = argparse.ArgumentParser(description="SVD Detector Configuration Importer")
24parser.add_argument('--exp', metavar='experiment', dest='exp', type=int, nargs=1, help='Experiment Number, = 1 for GCR')
25parser.add_argument('--run', metavar='run', dest='run', type=int, nargs=1, help='Run Number')
26parser.add_argument('--cfgXML', metavar='config xml', dest='calib', type=str, nargs=1, help='GlobalRun Calibration XML file')
27
28print('')
29
30if(str(sys.argv[1]) == "help"):
31 parser.print_help()
32 exit(1)
33
34args = parser.parse_args()
35
36experiment = args.exp[0]
37run = args.run[0]
38
39if args.calib is not None:
40 calibfile = args.calib[0]
41else:
42 calibfile = args.calib
43
44
45RED = "\033[1;31m"
46BLUE = "\033[1;34m"
47CYAN = "\033[1;36m"
48GREEN = "\033[0;32m"
49RESET = "\033[0;0m"
50BOLD = "\033[;1m"
51BLEU = "\033[34m"
52REVERSE = "\033[;7m"
53sys.stdout.write(RED)
54print('| ---> CHECK HERE: <---')
55print('| experiment number = ' + str(experiment))
56print('|first valid run number = ' + str(run))
57print('| global xml = ' + str(calibfile))
58print('| ---> THANKS! <---')
59sys.stdout.write(RESET)
60
61print('')
62
63proceed = input("Do you want to proceed? y/n ")
64if not str(proceed) == 'y':
65 print(colored(str(proceed) + ' != y, therefore we exit now', 'red'))
66 exit(1)
67
68b2conditions.prepend_globaltag("svd_basic")
69
70main = b2.create_path()
71
72
73# Event info setter - execute single event
74eventinfosetter = b2.register_module('EventInfoSetter')
75eventinfosetter.param({'evtNumList': [1], 'expList': experiment, 'runList': run})
76main.add_module(eventinfosetter)
77
78# Gearbox - access to xml files
79main.add_module("Gearbox")
80
81run = int(run)
82
83
84class configImporterToDBModule(b2.Module):
85 '''detector configuration importer'''
86
87 def beginRun(self):
88 '''begin run'''
89
90 # call the importer class
91 configImporterToDB = SVDDetectorConfigurationImporter(experiment, run, experiment, -1)
92 if args.calib is not None:
93 # import SVDGlobalConfigParameters dbobject: ZS, latency, mask, APV clock units
94 configImporterToDB.importSVDGlobalConfigParametersFromXML(calibfile)
95 print(colored("V) Global Detector Configuration parameters: (ZS, latency, mask, APVClock units) Imported", 'green'))
96 # import SVDLocalConfigParameters dbobject: calibration peak and time units, date
97 configImporterToDB.importSVDLocalConfigParametersFromXML(calibfile)
98 print(colored("V) Local Detector Configuration parameters Imported", 'green'))
99 else:
100 print(colored("X) Detector Configuration parameters are not NOT imported.", 'red'))
101
102
103main.add_module(configImporterToDBModule())
104
105b2.process(main)
106
107print("IMPORT COMPLETED, check the localDB folder and then proceeed with the upload to the central DB")