Belle II Software development
ARICHDatabaseImporter_condDB.py
1#!/usr/bin/env python
2
3
10
11import basf2 as b2
12import ROOT
13from ROOT.Belle2 import ARICHDatabaseImporter
14import os
15from optparse import OptionParser
16from fnmatch import fnmatch
17
18parser = OptionParser()
19parser.add_option('-c', '--class', dest='whatclass', default='none', help='')
20parser.add_option('-x', '--i-e', dest='importexport', default='export', help='')
21parser.add_option('-t', '--hvtest', dest='hvtest', default='no', help='')
22parser.add_option('-o', '--aopRootF', dest='aopRootF', default='ARICH_AerogelOpticalProperties.root', help='')
23(options, args) = parser.parse_args()
24ie = options.importexport
25ieClass = options.whatclass
26hvtest = options.hvtest
27aopRootF = options.aopRootF
28
29home = os.environ['BELLE2_LOCAL_DIR']
30
31# More information about use_local_database please find here:
32# https://software.belle2.org/development/sphinx/framework/doc/index-03-framework.html?highlight=use_local_database#basf2.use_local_database
33b2.use_local_database()
34# use_local_database("./ARICHdata/centraldb/database.txt", "./ARICHdata/centraldb/", False, LogLevel.ERROR, False)
35# use_local_database("./ARICH_db_Test/centraldb/database.txt", "", False, LogLevel.ERROR, False)
36# use_local_database("test_database.txt", "test_payloads")
37# use_local_database("test_database.txt", "test_payloads")
38# use use_central_database for uploading data to PNNL
39# use_central_database("ARICHdata", LogLevel.ERROR)
40# use_central_database("ARICH_db_Test", LogLevel.ERROR)
41# use_central_database("development", LogLevel.ERROR)
42#
43
44# EventInfoSetter is only needed to register EventMetaData in the Datastore to
45# get rid of an error message with gearbox
46eventinfo = b2.register_module('EventInfoSetter')
47eventinfo.initialize()
48
49main = b2.create_path()
50main.add_module(eventinfo)
51
52# create a gearbox module to read the aerogel data so it can be used
53# it needs to open just the aerogel/AerogelData.xml which includes all other xml
54# files in that folder. What we do is that we set the backend to point to that
55# folder so that gearbox can find all files in there.
56
57if ie == "import":
58 paramloader = b2.register_module('Gearbox')
59 pathname = 'file://%s/data/AllData/' % (os.getcwd())
60 paramloader.param('backends', [pathname])
61 paramloader.param('fileName', 'ArichData.xml')
62 paramloader.initialize()
63
64 # create a std::vector<string>
65 rootFilesHapdQA = ROOT.vector('string')()
66 # and add the files we want to read
67 xdirHapdQA = '%s/hapdQA/' % (os.getcwd())
68 for path, subdirs, files in os.walk(xdirHapdQA):
69 for name in files:
70 if fnmatch(name, "*.root"):
71 rootFilesHapdQA.push_back(os.path.join(path, name))
72
73 # create a std::vector<string>
74 rootFilesHapdQE = ROOT.vector('string')()
75 # and add the files we want to read
76 # QE can be downloaded from http://research.kek.jp/group/arich/internal/pixel_map/
77 xdirHapdQE = '%s/hapdQE/' % (os.getcwd())
78 for path, subdirs, files in os.walk(xdirHapdQE):
79 for name in files:
80 if fnmatch(name, "*.root"):
81 rootFilesHapdQE.push_back(os.path.join(path, name))
82
83 # create a std::vector<string>
84 rootFilesAsics = ROOT.vector('string')()
85 txtFilesAsics = ROOT.vector('string')()
86 # create path to directory
87 number = 'UY'
88 xdir = ('%s/asicData' + number + '/') % (os.getcwd())
89 # and add the files we want to read
90 for path, subdirs, files in os.walk(xdir):
91 for name in files:
92 if fnmatch(name, "*.root"):
93 rootFilesAsics.push_back(os.path.join(path, name))
94 if fnmatch(name, "*.txt"):
95 txtFilesAsics.push_back(os.path.join(path, name))
96
97 # create a std::vector<string>
98 rootFilesFebTest = ROOT.vector('string')()
99 # and add the files we want to read
100 xdirFebTest = '%s/febTest/' % (os.getcwd())
101 for path, subdirs, files in os.walk(xdirFebTest):
102 for name in files:
103 if fnmatch(name, "*.root"):
104 rootFilesFebTest.push_back(os.path.join(path, name))
105 mypath = '%s/moduleTest/modules/' % (os.getcwd())
106
107elif ie == 'importAerogelInfoOnly':
108 paramloader = b2.register_module('Gearbox')
109 pathname = '/home/b-lab050/KEK/xmlarichdata/data/aerogel_xml_ver3_R/'
110 paramloader.param('backends', [pathname])
111 paramloader.param('fileName', 'AerogelData.xml')
112 paramloader.initialize()
113
114elif ie == 'importAerogelRayleighScatteringFit':
115 paramloader = b2.register_module('Gearbox')
116 pathname = '/home/b-lab050/KEK/xmlarichdata/xmlData/aerogel_xml_ver3_L/'
117 paramloader.param('backends', [pathname])
118 paramloader.param('fileName', 'aerogel_xml_ver3_L_fit.xml')
119 paramloader.initialize()
120
121b2.process(main)
122
123if ie == 'importAerogelInfoOnly':
124 dbImporter = ARICHDatabaseImporter()
125 dbImporter.importAerogelInfo("Right")
126
127elif ie == 'importAerogelRayleighScatteringFit':
128 dbImporter = ARICHDatabaseImporter()
129 dbImporter.importAeroRayleighScatteringFit("Left")
130
131
132# and run the importer
133elif ie == 'import':
134 dbImporter = ARICHDatabaseImporter(rootFilesHapdQA, rootFilesAsics, txtFilesAsics, rootFilesHapdQE, rootFilesFebTest)
135 if ieClass == 'aerogelInfo':
136 dbImporter.importAerogelInfo()
137 elif ieClass == 'aerogelMap':
138 dbImporter.importAerogelMap()
139 elif ieClass == 'aerogelTilesInfo':
140 dbImporter.importAeroTilesInfo()
141 elif ieClass == 'hapdQA':
142 dbImporter.importHapdQA()
143 elif ieClass == 'hapdQE':
144 dbImporter.importHapdQE()
145 elif ieClass == 'hapdChipInfo':
146 dbImporter.importHapdChipInfo()
147 elif ieClass == 'hapdInfo':
148 dbImporter.importHapdInfo()
149 elif ieClass == 'hapd':
150 dbImporter.importHapdQA()
151 dbImporter.importHapdQE()
152 dbImporter.importHapdChipInfo()
153 dbImporter.importHapdInfo()
154 elif ieClass == 'asicInfo':
155 dbImporter.importAsicInfo()
156 elif ieClass == 'febTest':
157 dbImporter.importFebTest()
158 elif ieClass == 'febInfo':
159 dbImporter.importFEBoardInfo()
160 elif ieClass == 'moduleTest':
161 dbImporter.importModuleTest(mypath, hvtest)
162 elif ieClass == 'sensorInfo':
163 dbImporter.importSensorModuleInfo()
164 elif ieClass == 'sensorMap':
165 dbImporter.importSensorModuleMap()
166
167elif ie == 'importAerogelTilesInfo':
168 dbImporter = ARICHDatabaseImporter()
169 if ieClass == 'aerogelTilesInfo':
170 dbImporter.importAeroTilesInfo()
171
172elif ie == 'export':
173 dbImporter = ARICHDatabaseImporter()
174 if ieClass == 'aerogelInfo':
175 dbImporter.exportAerogelInfo()
176 elif ieClass == 'aerogelMap':
177 dbImporter.exportAerogelMap()
178 elif ieClass == 'aerogelTilesInfo':
179 dbImporter.printAeroTileInfo()
180 elif ieClass == 'dumpAerogelOpticalProperties':
181 # dbImporter.dumpAerogelOpticalProperties()
182 # dbImporter.dumpAerogelOpticalProperties("ARICH_AerogelOpticalProperties.root")
183 dbImporter.dumpAerogelOpticalProperties(aopRootF)
184 com = 'root -l ' + aopRootF + ' ' + home + '/arich/utility/scripts/plotTestARICHAerogelHist.C'
185 os.system(com)
186 elif ieClass == 'hapdQA':
187 dbImporter.exportHapdQA()
188 elif ieClass == 'hapdQE':
189 dbImporter.exportHapdQE()
190 elif ieClass == 'hapdInfo':
191 dbImporter.exportHapdInfo()
192 elif ieClass == 'hapdChipInfo':
193 dbImporter.exportHapdChipInfo()
194 elif ieClass == 'hapd':
195 dbImporter.exportHapdQA()
196 dbImporter.exportHapdQE()
197 dbImporter.exportHapdInfo()
198 elif ieClass == 'asicInfo':
199 dbImporter.exportAsicInfo()
200 elif ieClass == 'febTest':
201 dbImporter.exportFebTest()
202 elif ieClass == 'febInfo':
203 dbImporter.exportFEBoardInfo()
204 elif ieClass == 'moduleTest':
205 dbImporter.exportModuleTest(hvtest)
206 elif ieClass == 'sensorMap':
207 dbImporter.exportSensorModuleMap()
208 elif ieClass == 'all':
209 dbImporter.exportAll()
210
211
212# print parameters used in simulation/reconstruction software
213# dbImporter.printSimulationPar()
214# dbImporter.printModulesInfo()
215# dbImporter.printChannelMapping()
216# dbImporter.printGeometryConfig()
217# dbImporter.dumpQEMap(True)
218# dbImporter.dumpModuleNumbering()
219
220
221# simple example that shows how to read data from database and use it
222# dbImporter.getBiasVoltagesForHapdChip("KA0167")
223
224# simple example that shows how to extract aerogel recontruction data from database
225# dbImporter.getMyParams("A165")