Belle II Software development
TrgEclDatabaseImporter.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9// Own header.
10#include <trg/ecl/dbobjects/TrgEclDatabaseImporter.h>
11
12// framework - Database
13#include <framework/database/DBObjPtr.h>
14#include <framework/database/IntervalOfValidity.h>
15#include <framework/database/DBImportArray.h>
16
17// framework aux
18#include <framework/logging/Logger.h>
19
20// DB objects
21#include "trg/ecl/dbobjects/TRGECLFAMPara.h"
22#include "trg/ecl/dbobjects/TRGECLTMMPara.h"
23#include "trg/ecl/dbobjects/TRGECLETMPara.h"
24#include "trg/ecl/dbobjects/TRGECLBadRun.h"
25
26#include "trg/ecl/TrgEclMapping.h"
27
28#include <iostream>
29#include <fstream>
30
31using namespace std;
32namespace Belle2 {
38 TrgEclDatabaseImporter::TrgEclDatabaseImporter(): startExp(0), startRun(0), endExp(-1), endRun(-1)
39 {}
40
41 void TrgEclDatabaseImporter::importFAMParameter(std::string InputFileName, std::string InputFileSignalPDF,
42 std::string InputFileNoise)
43 {
44 std::ifstream stream;
45 stream.open(InputFileName.c_str());
46 if (!stream) {
47 B2ERROR("openFile: " << InputFileName << " *** failed to open");
48 return;
49 }
50 std::ifstream stream1;
51 stream1.open(InputFileSignalPDF.c_str());
52 if (!stream1) {
53 B2ERROR("openFile: " << InputFileSignalPDF << " *** failed to open");
54 return;
55 }
56
57 std::ifstream stream2;
58 stream2.open(InputFileNoise.c_str());
59 if (!stream2) {
60 B2ERROR("openFile: " << InputFileNoise << " *** failed to open");
61 return;
62 }
63
64 TrgEclMapping* _map = new TrgEclMapping();
65
66
68 // fampara.construct();
69
70 std::vector<int> FPGAversion;
71 std::vector<int> TCId;
72 std::vector<int> FAMId;
73 std::vector<int> ChannelId;
74 std::vector<int> TEreconstruction;
75 std::vector<int> Threshold;
76 std::vector<double> Conversionfactor;
77 std::vector<int> Toffset;
78 std::vector<int> Wavemean;
79 std::vector<int> Wavesigma;
80 FPGAversion.clear();
81 TCId.clear();
82 FAMId.clear();
83 ChannelId.clear();
84 TEreconstruction.clear();
85 Threshold.clear();
86 Conversionfactor.clear();
87 Toffset.clear();
88 Wavemean.clear();
89 Wavesigma.clear();
90
91 FPGAversion.resize(624, 0);
92 TCId.resize(624, 0);
93 FAMId.resize(624, 0);
94 ChannelId.resize(624, 0);
95 TEreconstruction.resize(624, 0);
96 Threshold.resize(624, 0);
97 Conversionfactor.resize(624, 0);
98 Toffset.resize(624, 0);
99
100 Wavemean.resize(624, 0);
101 Wavesigma.resize(624, 0);
102
103
104 std::vector<std::vector<double> > SignalPDF;
105 SignalPDF.clear();
106 std::vector<std::vector<double> > NoiseCovarianceMatrix;
107 NoiseCovarianceMatrix.clear();
108 SignalPDF.resize(624, std::vector<double>(8, 0));
109 NoiseCovarianceMatrix.resize(624, std::vector<double>(78, 0));
110
111 int Id = 0;
112 while (!stream.eof()) {
113 stream >> FAMId[Id] >> ChannelId[Id] >> FPGAversion [Id] >> TEreconstruction[Id] >> Threshold[Id] >> Conversionfactor[Id] >>
114 Toffset[Id] >> Wavemean[Id] >> Wavesigma[Id];
115 TCId[Id] = _map -> getTCIdFromFAMChannel(FAMId[Id], ChannelId[Id]);
116 Id++;
117 }
118 stream.close();
119 Id = 0;
120 int line = 0;
121
122 while (!stream1.eof()) {
123 stream1 >> SignalPDF[Id][line];
124 line++;
125 if (line == 8) {
126 line = 0;
127 Id++;
128 }
129
130 }
131 stream1.close();
132
133 Id = 0;
134 line = 0;
135 while (!stream2.eof()) {
136 stream2 >> NoiseCovarianceMatrix[Id][line];
137 line++;
138 if (line == 78) {
139 line = 0;
140 Id++;
141 }
142
143 }
144 stream2.close();
145
146
147 //Import to DB
148 for (int iTCId = 0; iTCId < 624; iTCId++) {
149 fampara.appendNew(FPGAversion[iTCId],
150 TCId[iTCId],
151 FAMId[iTCId],
152 ChannelId[iTCId],
153 TEreconstruction[iTCId],
154 Conversionfactor[iTCId],
155 Toffset[iTCId],
156 Threshold[iTCId],
157 Wavemean[iTCId],
158 Wavesigma[iTCId],
159 SignalPDF[iTCId],
160 NoiseCovarianceMatrix[iTCId]
161 );
162 }
163
165
166 fampara.import(iov);
167
168 delete _map ;
169 B2RESULT("FAM parameters are imported to database.");
170
171 }
172 //
173 //
174 void TrgEclDatabaseImporter::importTMMParameter(std::string InputFileName)
175 {
176 std::ifstream stream;
177 stream.open(InputFileName.c_str());
178 if (!stream) {
179 B2ERROR("openFile: " << InputFileName << " *** failed to open");
180 return;
181 }
182
184
185 int FPGAversion;
186 stream >> FPGAversion ;
187 tmmpara.appendNew(FPGAversion);
188 stream.close();
189 //Import to DB
191
192 tmmpara.import(iov);
193
194 B2RESULT("TMM parameters are imported to database.");
195
196 }
197
198
199 void TrgEclDatabaseImporter::importETMParameter(std::string InputFileName)
200 {
201 std::ifstream stream;
202 stream.open(InputFileName.c_str());
203 if (!stream) {
204 B2ERROR("openFile: " << InputFileName << " *** failed to open");
205 return;
206 }
207
209
210 int FPGAversion;
211 double ADCto100MeV;
212 int ELow;
213 int EHigh;
214 int ELum;
215 int FWD2DBhabha[14];
216 int BWD2DBhabha[14];
217 int Bhabha3DSelectionThreshold[2];
218 int Bhabha3DVetoThreshold[2];
219 int Bhabha3DSelectionAngle[4];
220 int Bhabha3DVetoAngle[4];
221 int mumuThreshold;
222 int mumuAngle[4];
223 int LowMultiThreshold[4];
224 int Prescalefactor[3];
225 int TriggerLatency;
226 int ETMDelay;
227 int n300MeVCluster;
228 int ECLBurstThreshold;
229
230 stream >> FPGAversion
231 >> ADCto100MeV
232 >> ELum
233 >> EHigh
234 >> ELow
235 >> FWD2DBhabha[0] >> BWD2DBhabha[0]
236 >> FWD2DBhabha[1] >> BWD2DBhabha[1]
237 >> FWD2DBhabha[2] >> BWD2DBhabha[2]
238 >> FWD2DBhabha[3] >> BWD2DBhabha[3]
239 >> FWD2DBhabha[4] >> BWD2DBhabha[4]
240 >> FWD2DBhabha[5] >> BWD2DBhabha[5]
241 >> FWD2DBhabha[6] >> BWD2DBhabha[6]
242 >> FWD2DBhabha[7] >> BWD2DBhabha[7]
243 >> FWD2DBhabha[8] >> BWD2DBhabha[8]
244 >> FWD2DBhabha[9] >> BWD2DBhabha[9]
245 >> FWD2DBhabha[10] >> BWD2DBhabha[10]
246 >> FWD2DBhabha[11] >> BWD2DBhabha[11]
247 >> FWD2DBhabha[12] >> BWD2DBhabha[12]
248 >> FWD2DBhabha[13] >> BWD2DBhabha[13]
249 >> Bhabha3DSelectionThreshold[0]
250 >> Bhabha3DSelectionThreshold[1]
251 >> Bhabha3DVetoThreshold[0]
252 >> Bhabha3DVetoThreshold[1]
253 >> Bhabha3DSelectionAngle[0]
254 >> Bhabha3DSelectionAngle[1]
255 >> Bhabha3DSelectionAngle[2]
256 >> Bhabha3DSelectionAngle[3]
257 >> Bhabha3DVetoAngle[0]
258 >> Bhabha3DVetoAngle[1]
259 >> Bhabha3DVetoAngle[2]
260 >> Bhabha3DVetoAngle[3]
261 >> mumuThreshold
262 >> mumuAngle[0]
263 >> mumuAngle[1]
264 >> mumuAngle[2]
265 >> mumuAngle[3]
266 >> LowMultiThreshold[0]
267 >> LowMultiThreshold[1]
268 >> LowMultiThreshold[2]
269 >> LowMultiThreshold[3]
270 >> Prescalefactor[0]
271 >> Prescalefactor[1]
272 >> Prescalefactor[2]
273 >> TriggerLatency
274 >> ETMDelay
275 >> n300MeVCluster
276 >> ECLBurstThreshold;
277
278
279 etmpara.appendNew(FPGAversion, ADCto100MeV, ELow, EHigh, ELum, FWD2DBhabha, BWD2DBhabha, Bhabha3DSelectionThreshold,
280 Bhabha3DVetoThreshold, Bhabha3DSelectionAngle, Bhabha3DVetoAngle, mumuThreshold, mumuAngle, LowMultiThreshold,
281 Prescalefactor, TriggerLatency, ETMDelay, n300MeVCluster, ECLBurstThreshold);
282
283 stream.close();
284 //Import to DB
286
287 etmpara.import(iov);
288
289 B2RESULT("ETM Parameters are imported to database.");
290
291 }
292
293 void TrgEclDatabaseImporter::importBadRunNumber(std::string InputFileName)
294 {
295 std::ifstream stream;
296 stream.open(InputFileName.c_str());
297 if (!stream) {
298 B2ERROR("openFile: " << InputFileName << " *** failed to open");
299 return;
300 }
301
303
304 int BadRunNumber;
305 while (!stream.eof()) {
306
307 stream >> BadRunNumber ;
308 badrun.appendNew(BadRunNumber);
309 }
310 stream.close();
311 //Import to DB
313
314 badrun.import(iov);
315
316 B2RESULT("BadRunList are imported to database.");
317
318 }
319
321 {
322
324
325 para->Dump();
326
327 }
329}
Class for importing array of objects to the database.
Definition: DBImportArray.h:25
T * appendNew()
Construct a new T object at the end of the array.
Definition: DBImportArray.h:67
void clear() override
Clear the content, e.g.
bool import(const IntervalOfValidity &iov)
Import the object to database.
Definition: DBImportBase.cc:36
Class for accessing objects in the database.
Definition: DBObjPtr.h:21
A class that describes the interval of experiments/runs for which an object in the database is valid.
Parametrization of signal PDF in a single pixel.
Definition: SignalPDF.h:25
int startExp
Start Experiment Number.
int endExp
End Experiment Number.
A class of TC Mapping.
Definition: TrgEclMapping.h:26
void importETMParameter(std::string)
Import ETM Parameters.
void importTMMParameter(std::string)
Import TMM Parameters.
void importFAMParameter(std::string, std::string, std::string)
Import FAM Parameters.
void printTCThreshold()
Print TC energy Threshold.
TrgEclDatabaseImporter()
TrgEclDatabaseImporter Constructor.
void importBadRunNumber(std::string)
Import Bad Run Number.
Abstract base class for different kinds of events.
STL namespace.