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