Belle II Software  release-05-01-25
SVDChannelMappingImporter.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 
4 """
5 SVD Database importer.
6 Script to Import SVD Channel Mapping into a local DB
7 """
8 
9 from basf2 import *
10 import ROOT
11 from ROOT.Belle2 import SVDLocalCalibrationsImporter
12 from ROOT.Belle2 import FileSystem
13 import os
14 import sys
15 import glob
16 import subprocess
17 import interactive
18 import argparse
19 from fnmatch import fnmatch
20 from termcolor import colored
21 
22 parser = argparse.ArgumentParser(description="SVD Local Calibrations Importer")
23 parser.add_argument('--exp', metavar='experiment', dest='exp', type=int, nargs=1, help='Experiment Number, = 1 for GCR')
24 parser.add_argument('--run', metavar='run', dest='run', type=int, nargs=1, help='Run Number')
25 parser.add_argument('--mapXML', metavar='channel map xml', dest='mapp', type=str, nargs=1, help='Channel Mapping xml file')
26 
27 print('')
28 
29 if(str(sys.argv[1]) == "help"):
30  parser.print_help()
31  exit(1)
32 
33 args = parser.parse_args()
34 
35 experiment = args.exp[0]
36 run = args.run[0]
37 
38 if args.mapp is not None:
39  mappingfile = args.mapp[0]
40 else:
41  mappingfile = args.mapp
42 
43 RED = "\033[1;31m"
44 BLUE = "\033[1;34m"
45 CYAN = "\033[1;36m"
46 GREEN = "\033[0;32m"
47 RESET = "\033[0;0m"
48 BOLD = "\033[;1m"
49 BLEU = "\033[34m"
50 REVERSE = "\033[;7m"
51 sys.stdout.write(RED)
52 print('| ---> CHECK HERE: <---')
53 print('| experiment number = ' + str(experiment))
54 print('|first valid run number = ' + str(run))
55 print('| mapping xml = ' + str(mappingfile))
56 print('| ---> THANKS! <---')
57 sys.stdout.write(RESET)
58 
59 print('')
60 
61 proceed = input("Do you want to proceed? y/n ")
62 if not str(proceed) == 'y':
63  print(colored(str(proceed) + ' != y, therefore we exit now', 'red'))
64  exit(1)
65 
66 reset_database()
67 use_database_chain()
68 # central DB needed for the channel mapping DB object
69 GLOBAL_TAG = "svd_basic"
70 use_central_database(GLOBAL_TAG)
71 use_local_database("localDBchannelMapping/database.txt", "localDBchannelMapping", invertLogging=True)
72 
73 # local tag and database needed for commissioning
74 
75 main = create_path()
76 
77 
78 # Event info setter - execute single event
79 eventinfosetter = register_module('EventInfoSetter')
80 eventinfosetter.param({'evtNumList': [1], 'expList': experiment, 'runList': run})
81 main.add_module(eventinfosetter)
82 
83 # Gearbox - access to xml files
84 main.add_module("Gearbox")
85 
86 run = int(run)
87 
88 # TO DO, enable calibration of calib or mapping, depending on the user input
89 
90 
91 class dbImporterModule(Module):
92  '''channel mapping importer module'''
93 
94  def beginRun(self):
95  '''begin run'''
96 
97  # call the importer class
98  dbImporter = SVDLocalCalibrationsImporter(experiment, run, experiment, -1)
99  if args.mapp is not None:
100  # import channel mapping
101  dbImporter.importSVDChannelMapping(mappingfile)
102  print(colored("V) Channel Mapping Imported", 'green'))
103 
104 
105 main.add_module(dbImporterModule())
106 
107 process(main)
108 
109 print("IMPORT COMPLETED, check the localDBchannelMapping folder and then proceeed with the upload to the central DB")
SVDLocalCalibrationsImporter
Definition: SVDLocalCalibrationsImporter.py:1
SVDChannelMappingImporter.dbImporterModule.beginRun
def beginRun(self)
Definition: SVDChannelMappingImporter.py:94
SVDChannelMappingImporter.dbImporterModule
Definition: SVDChannelMappingImporter.py:91