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