Belle II Software release-09-00-00
SVDLocalCalibrationsImporter.py
1#!/usr/bin/env python
2
3
10
11"""
12SVD Database importer.
13Script to Import Calibrations into a local DB
14"""
15
16import basf2 as b2
17from ROOT.Belle2 import SVDLocalCalibrationsImporter
18import sys
19import argparse
20from termcolor import colored
21from basf2 import conditions as b2conditions
22
23parser = argparse.ArgumentParser(description="SVD Local Calibrations 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')
27parser.add_argument('--isLocalXML', dest='localXml', action='store_const', const=True, default=False,
28 help='Add this parameter if the XML is a Local run configuration instead of a Global Run Configuration')
29parser.add_argument('--nomask', dest='mask', action='store_const', default=False, const=True,
30 help='Add this parameter if the XML does not contain the attribute <masks>')
31
32print('')
33
34if(str(sys.argv[1]) == "help"):
35 parser.print_help()
36 exit(1)
37
38args = parser.parse_args()
39
40experiment = args.exp[0]
41run = args.run[0]
42
43if args.calib is not None:
44 calibfile = args.calib[0]
45else:
46 calibfile = args.calib
47
48
49RED = "\033[1;31m"
50BLUE = "\033[1;34m"
51CYAN = "\033[1;36m"
52GREEN = "\033[0;32m"
53RESET = "\033[0;0m"
54BOLD = "\033[;1m"
55BLEU = "\033[34m"
56REVERSE = "\033[;7m"
57sys.stdout.write(RED)
58print('| ---> CHECK HERE: <---')
59print('| experiment number = ' + str(experiment))
60print('|first valid run number = ' + str(run))
61print('| calibration xml = ' + str(calibfile))
62print('| is a global run xml = ' + str(not args.localXml))
63print('| import masks = ' + str(not args.mask))
64print('| ---> THANKS! <---')
65sys.stdout.write(RESET)
66
67print('')
68
69proceed = input("Do you want to proceed? y/n ")
70if not str(proceed) == 'y':
71 print(colored(str(proceed) + ' != y, therefore we exit now', 'red'))
72 exit(1)
73
74b2conditions.prepend_globaltag("svd_basic")
75
76# local tag and database needed for commissioning
77
78main = b2.create_path()
79
80
81# Event info setter - execute single event
82eventinfosetter = b2.register_module('EventInfoSetter')
83eventinfosetter.param({'evtNumList': [1], 'expList': experiment, 'runList': run})
84main.add_module(eventinfosetter)
85
86# Gearbox - access to xml files
87main.add_module("Gearbox")
88
89run = int(run)
90
91
92class dbImporterModule(b2.Module):
93 """
94 Module to call the importer methods for the payloads creation from XML file
95 :param calibfile: path to the xml file containing the local calibrations
96 :type calibfile: string
97 """
98
99 def beginRun(self):
100 """
101 Function to call the dbImporter methods to upload the different local payloads
102 """
103 # call the importer class
104 dbImporter = SVDLocalCalibrationsImporter(experiment, run, experiment, -1)
105 if args.calib is not None:
106 # import the noises
107 dbImporter.importSVDNoiseCalibrationsFromXML(calibfile)
108 print(colored("V) Noise Imported", 'green'))
109 # import the pedestals
110 dbImporter.importSVDPedestalCalibrationsFromXML(calibfile)
111 print(colored("V) Pedestal Imported", 'green'))
112 # import pulse shape calibrations
113 dbImporter.importSVDCalAmpCalibrationsFromXML(calibfile)
114 print(colored("V) Pulse Shape Calibrations Imported", 'green'))
115 # import FADCMasked strips only if NOT --nomask
116 if not args.mask:
117 dbImporter.importSVDFADCMaskedStripsFromXML(calibfile)
118 print(colored("V) FADC Masked Strips Imported", 'green'))
119 else:
120 print(colored("X) FADC Masked Strips are NOT imported.", 'red'))
121 if not args.localXml:
122 # import XML file only if NOT --isLocalXML
123 dbImporter.importSVDGlobalXMLFile(calibfile)
124 print(colored("V) Global Run Configuration xml payload file Imported", 'green'))
125 else:
126 print(colored("X) Global Run Configuration xml payload file is NOT imported.", 'red'))
127
128
129main.add_module(dbImporterModule())
130
131b2.process(main)
132
133print("IMPORT COMPLETED, check the localDB folder and then proceeed with the upload to the central DB")