Belle II Software  release-08-01-10
SVDChannelMappingImporter.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 """
13 SVD Database importer.
14 Script to Import SVD Channel Mapping 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('--mapXML', metavar='channel map xml', dest='mapp', type=str, nargs=1, help='Channel Mapping 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.mapp is not None:
41  mappingfile = args.mapp[0]
42 else:
43  mappingfile = args.mapp
44 
45 RED = "\033[1;31m"
46 BLUE = "\033[1;34m"
47 CYAN = "\033[1;36m"
48 GREEN = "\033[0;32m"
49 RESET = "\033[0;0m"
50 BOLD = "\033[;1m"
51 BLEU = "\033[34m"
52 REVERSE = "\033[;7m"
53 sys.stdout.write(RED)
54 print('| ---> CHECK HERE: <---')
55 print('| experiment number = ' + str(experiment))
56 print('|first valid run number = ' + str(run))
57 print('| mapping xml = ' + str(mappingfile))
58 print('| ---> THANKS! <---')
59 sys.stdout.write(RESET)
60 
61 print('')
62 
63 proceed = input("Do you want to proceed? y/n ")
64 if not str(proceed) == 'y':
65  print(colored(str(proceed) + ' != y, therefore we exit now', 'red'))
66  exit(1)
67 
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 dbImporterModule(b2.Module):
86  '''channel mapping importer module'''
87 
88  def beginRun(self):
89  '''begin run'''
90 
91  # call the importer class
92  dbImporter = SVDLocalCalibrationsImporter(experiment, run, experiment, -1)
93  if args.mapp is not None:
94  # import channel mapping
95  dbImporter.importSVDChannelMapping(mappingfile)
96  print(colored("V) Channel Mapping Imported", 'green'))
97 
98 
99 main.add_module(dbImporterModule())
100 
101 b2.process(main)
102 
103 print("IMPORT COMPLETED, check the localDB folder and then proceeed with the upload to the central DB")