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#include <framework/database/DBImportObjPtr.h>
17
18// framework aux
19#include <framework/logging/Logger.h>
20
21// DB objects
22#include "trg/ecl/dbobjects/TRGECLFAMPara.h"
23#include "trg/ecl/dbobjects/TRGECLFAMTCADCThreshold.h"
24#include "trg/ecl/dbobjects/TRGECLTMMPara.h"
25#include "trg/ecl/dbobjects/TRGECLETMParameters.h"
26#include "trg/ecl/dbobjects/TRGECLBadRun.h"
27
28#include "trg/ecl/TrgEclMapping.h"
29
30#include <iostream>
31#include <fstream>
32#include <map>
33
34using namespace std;
35using namespace Belle2;
36
40
41void TrgEclDatabaseImporter::importFAMParameter(std::string InputFileName,
42 std::string InputFileSignalPDF,
43 std::string InputFileNoise)
44{
45 std::ifstream stream;
46 stream.open(InputFileName.c_str());
47 if (!stream) {
48 B2ERROR("openFile: " << InputFileName << " *** failed to open");
49 return;
50 }
51 std::ifstream stream1;
52 stream1.open(InputFileSignalPDF.c_str());
53 if (!stream1) {
54 B2ERROR("openFile: " << InputFileSignalPDF << " *** failed to open");
55 return;
56 }
57
58 std::ifstream stream2;
59 stream2.open(InputFileNoise.c_str());
60 if (!stream2) {
61 B2ERROR("openFile: " << InputFileNoise << " *** failed to open");
62 return;
63 }
64
65 TrgEclMapping* m_map = new TrgEclMapping();
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]
114 >> ChannelId[Id]
115 >> FPGAversion [Id]
116 >> TEreconstruction[Id]
117 >> Threshold[Id]
118 >> Conversionfactor[Id]
119 >> Toffset[Id]
120 >> Wavemean[Id]
121 >> Wavesigma[Id];
122 TCId[Id] = m_map->getTCIdFromFAMChannel(FAMId[Id], ChannelId[Id]);
123 Id++;
124 if (Id == 624) {
125 break;
126 }
127 }
128 stream.close();
129 //-----------------------------------------------------------------
130
131 Id = 0;
132 int line = 0;
133
134 while (!stream1.eof()) {
135 stream1 >> SignalPDF[Id][line];
136 line++;
137 if (line == 8) {
138 line = 0;
139 Id++;
140 }
141
142 }
143 stream1.close();
144
145 Id = 0;
146 line = 0;
147 while (!stream2.eof()) {
148 stream2 >> NoiseCovarianceMatrix[Id][line];
149 line++;
150 if (line == 78) {
151 line = 0;
152 Id++;
153 }
154
155 }
156 stream2.close();
157
158
159 //Import to DB
160 for (int iTCId = 0; iTCId < 624; iTCId++) {
161 fampara.appendNew(FPGAversion[iTCId],
162 TCId[iTCId],
163 FAMId[iTCId],
164 ChannelId[iTCId],
165 TEreconstruction[iTCId],
166 Conversionfactor[iTCId],
167 Toffset[iTCId],
168 Threshold[iTCId],
169 Wavemean[iTCId],
170 Wavesigma[iTCId],
171 SignalPDF[iTCId],
172 NoiseCovarianceMatrix[iTCId]
173 );
174 }
175
177
178 fampara.import(iov);
179
180 delete m_map ;
181 B2RESULT("FAM parameters are imported to database.");
182
183}
184//
185//
186//
188{
189 std::ifstream stream;
190 stream.open(InputFileName.c_str());
191 if (!stream) {
192 B2ERROR("openFile: " << InputFileName << " *** failed to open");
193 return;
194 }
195
197
198 // parameters to be imported to conditionDB
199 std::vector<int> TCId(c_NTC, 0);
200 std::vector<int> TCADCThreshold(c_NTC, 0);
201
202 int id = 0;
203 while (!stream.eof()) {
204 stream >> TCId[id]
205 >> TCADCThreshold[id];
206 id++;
207 }
208 stream.close();
209
210 //Import to DB
211 for (int iTCId = 0; iTCId < c_NTC; iTCId++) {
212 DbTCADCThreshold.appendNew(TCId[iTCId],
213 TCADCThreshold[iTCId]);
214 }
215
217
218 DbTCADCThreshold.import(iov);
219
220 B2RESULT("FAM TCADCThresholds are imported to database.");
221
222}
223//
224//
225//
226void TrgEclDatabaseImporter::importTMMParameter(std::string InputFileName)
227{
228 std::ifstream stream;
229 stream.open(InputFileName.c_str());
230 if (!stream) {
231 B2ERROR("openFile: " << InputFileName << " *** failed to open");
232 return;
233 }
234
236
237 int FPGAversion;
238 stream >> FPGAversion ;
239 tmmpara.appendNew(FPGAversion);
240 stream.close();
241 //Import to DB
243
244 tmmpara.import(iov);
245
246 B2RESULT("TMM parameters are imported to database.");
247
248}
249//
250//
251//
252void TrgEclDatabaseImporter::importETMParameter(std::string InputFileName)
253{
254
255 std::ifstream stream;
256 stream.open(InputFileName.c_str());
257 if (!stream) {
258 B2ERROR("openFile: " << InputFileName << " *** failed to open");
259 return;
260 }
261
262 // get data from InputFileName
263 std::vector<string> v_par_name;
264 std::vector<double> v_par_value;
265 string str_line;
266 int cnt_par = 0;
267 while (getline(stream, str_line)) {
268 if (str_line.find("#")) {
269 std::stringstream sss;
270 sss << str_line;
271 int tmp_id;
272 char tmp_name[100];
273 double tmp_value;
274 if (sscanf(sss.str().data(),
275 "%i%99s%lf",
276 &tmp_id, tmp_name, &tmp_value) == 3) {
277 string str_tmp_name = string(tmp_name);
278 v_par_name.push_back(str_tmp_name);
279 v_par_value.push_back(tmp_value);
280 cnt_par++;
281 }
282 }
283 }
284 stream.close();
285
286 B2INFO("[TrgEclDatabaseImporter] The number of parameters in "
287 << InputFileName
288 << " = "
289 << cnt_par);
290
292 etmpara.construct();
293
294 etmpara->setnpar(cnt_par);
295
296 for (int iii = 0; iii < cnt_par; iii++) {
297 etmpara->setparMap(v_par_name[iii], v_par_value[iii]);
298 }
299
300 //Import to DB
302
303 etmpara.import(iov);
304
305 B2RESULT("ETM Parameters are imported to database.");
306
307}
308//
309//
310//
311void TrgEclDatabaseImporter::importBadRunNumber(std::string InputFileName)
312{
313 std::ifstream stream;
314 stream.open(InputFileName.c_str());
315 if (!stream) {
316 B2ERROR("openFile: " << InputFileName << " *** failed to open");
317 return;
318 }
319
321
322 int BadRunNumber;
323 while (!stream.eof()) {
324
325 stream >> BadRunNumber ;
326 badrun.appendNew(BadRunNumber);
327 }
328 stream.close();
329
330 //Import to DB
332
333 badrun.import(iov);
334
335 B2RESULT("BadRunList are imported to database.");
336
337}
338//
339//
340//
342{
343
345
346 para->Dump();
347
348}
Class for importing array of objects to the database.
T * appendNew()
Construct a new T object at the end of the array.
bool import(const IntervalOfValidity &iov)
Import the object to database.
Class for importing a single object to the database.
void construct(Args &&... params)
Construct an object of type T in this DBImportObjPtr using the provided constructor arguments.
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
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.
const int c_NTC
the number of total TC
int m_startExp
Start Experiment Number.
void importFAMTCADCThreshold(std::string)
Import FAM TC ADC Threshold.
int m_endExp
End Experiment Number.
TrgEclDatabaseImporter()
TrgEclDatabaseImporter Constructor.
void importBadRunNumber(std::string)
Import Bad Run Number.
A class of TC Mapping.
int getTCIdFromFAMChannel(int, int)
Get TC from FAM # and Channel #.
Abstract base class for different kinds of events.
STL namespace.