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/TRGECLTMMPara.h"
24#include "trg/ecl/dbobjects/TRGECLETMParameters.h"
25#include "trg/ecl/dbobjects/TRGECLBadRun.h"
26
27#include "trg/ecl/TrgEclMapping.h"
28
29#include <iostream>
30#include <fstream>
31#include <map>
32
33using namespace std;
34using namespace Belle2;
35
39
40void TrgEclDatabaseImporter::importFAMParameter(std::string InputFileName,
41 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* m_map = new TrgEclMapping();
65
67 // fampara.construct();
68
69 std::vector<int> FPGAversion;
70 std::vector<int> TCId;
71 std::vector<int> FAMId;
72 std::vector<int> ChannelId;
73 std::vector<int> TEreconstruction;
74 std::vector<int> Threshold;
75 std::vector<double> Conversionfactor;
76 std::vector<int> Toffset;
77 std::vector<int> Wavemean;
78 std::vector<int> Wavesigma;
79 FPGAversion.clear();
80 TCId.clear();
81 FAMId.clear();
82 ChannelId.clear();
83 TEreconstruction.clear();
84 Threshold.clear();
85 Conversionfactor.clear();
86 Toffset.clear();
87 Wavemean.clear();
88 Wavesigma.clear();
89
90 FPGAversion.resize(624, 0);
91 TCId.resize(624, 0);
92 FAMId.resize(624, 0);
93 ChannelId.resize(624, 0);
94 TEreconstruction.resize(624, 0);
95 Threshold.resize(624, 0);
96 Conversionfactor.resize(624, 0);
97 Toffset.resize(624, 0);
98
99 Wavemean.resize(624, 0);
100 Wavesigma.resize(624, 0);
101
102
103 std::vector<std::vector<double> > SignalPDF;
104 SignalPDF.clear();
105 std::vector<std::vector<double> > NoiseCovarianceMatrix;
106 NoiseCovarianceMatrix.clear();
107 SignalPDF.resize(624, std::vector<double>(8, 0));
108 NoiseCovarianceMatrix.resize(624, std::vector<double>(78, 0));
109
110 int Id = 0;
111 while (!stream.eof()) {
112 stream >> FAMId[Id] >> ChannelId[Id] >> FPGAversion [Id]
113 >> TEreconstruction[Id] >> Threshold[Id] >> Conversionfactor[Id]
114 >> Toffset[Id] >> Wavemean[Id] >> Wavesigma[Id];
115 TCId[Id] = m_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 m_map ;
169 B2RESULT("FAM parameters are imported to database.");
170
171}
172//
173//
174//
175void TrgEclDatabaseImporter::importTMMParameter(std::string InputFileName)
176{
177 std::ifstream stream;
178 stream.open(InputFileName.c_str());
179 if (!stream) {
180 B2ERROR("openFile: " << InputFileName << " *** failed to open");
181 return;
182 }
183
185
186 int FPGAversion;
187 stream >> FPGAversion ;
188 tmmpara.appendNew(FPGAversion);
189 stream.close();
190 //Import to DB
192
193 tmmpara.import(iov);
194
195 B2RESULT("TMM parameters are imported to database.");
196
197}
198//
199//
200//
201void TrgEclDatabaseImporter::importETMParameter(std::string InputFileName)
202{
203
204 std::ifstream stream;
205 stream.open(InputFileName.c_str());
206 if (!stream) {
207 B2ERROR("openFile: " << InputFileName << " *** failed to open");
208 return;
209 }
210
211 // get data from InputFileName
212 std::vector<string> v_par_name;
213 std::vector<double> v_par_value;
214 string str_line;
215 int cnt_par = 0;
216 while (getline(stream, str_line)) {
217 if (str_line.find("#")) {
218 std::stringstream sss;
219 sss << str_line;
220 int tmp_id;
221 char tmp_name[100];
222 double tmp_value;
223 if (sscanf(sss.str().data(),
224 "%i%99s%lf",
225 &tmp_id, tmp_name, &tmp_value) == 3) {
226 string str_tmp_name = string(tmp_name);
227 v_par_name.push_back(str_tmp_name);
228 v_par_value.push_back(tmp_value);
229 cnt_par++;
230 }
231 }
232 }
233 stream.close();
234
235 B2INFO("[TrgEclDatabaseImporter] The number of parameters in "
236 << InputFileName
237 << " = "
238 << cnt_par);
239
241 etmpara.construct();
242
243 etmpara->setnpar(cnt_par);
244
245 for (int iii = 0; iii < cnt_par; iii++) {
246 etmpara->setparMap(v_par_name[iii], v_par_value[iii]);
247 }
248
249 //Import to DB
251
252 etmpara.import(iov);
253
254 B2RESULT("ETM Parameters are imported to database.");
255
256}
257//
258//
259//
260void TrgEclDatabaseImporter::importBadRunNumber(std::string InputFileName)
261{
262 std::ifstream stream;
263 stream.open(InputFileName.c_str());
264 if (!stream) {
265 B2ERROR("openFile: " << InputFileName << " *** failed to open");
266 return;
267 }
268
270
271 int BadRunNumber;
272 while (!stream.eof()) {
273
274 stream >> BadRunNumber ;
275 badrun.appendNew(BadRunNumber);
276 }
277 stream.close();
278
279 //Import to DB
281
282 badrun.import(iov);
283
284 B2RESULT("BadRunList are imported to database.");
285
286}
287//
288//
289//
291{
292
294
295 para->Dump();
296
297}
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.
int m_startExp
Start Experiment Number.
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.