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