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