-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTLogStorage.cpp
364 lines (328 loc) · 10.3 KB
/
TLogStorage.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
/*
* TLogStorage.cpp
*
* Created on: Feb 28, 2019
* Author: mss
*/
#include "TLogStorage.h"
namespace std {
TLogStorage::TLogStorage(vector<TSingleLogLine> *vRawLog) {
globalMinTime = -1;
globalMaxTime = -1;
this->vRawLog = vRawLog;
if(GenerateStructure() < 0){
return;
}
SortStructure();
}
TLogStorage::~TLogStorage() {
// TODO Auto-generated destructor stub
}
void TLogStorage::GenerateListOfUniques(){
if(vRawLog->size()>0){
vUniqueBoardName.push_back(vRawLog->at(0).GetBoardName());
vUniqueChannelNumber.push_back(vRawLog->at(0).GetChannel());
vUniqueParamName.push_back(vRawLog->at(0).GetParName());
}
else{
cerr << "<E> TLogStorage::GenerateListOfUniques: No entries in raw log." << endl;
return;
}
for(uint32_t iraw=1; iraw<vRawLog->size(); iraw++){
string rawboardname = vRawLog->at(iraw).GetBoardName();
int rawchannel = vRawLog->at(iraw).GetChannel();
string rawparname = vRawLog->at(iraw).GetParName();
bool isTripletSame = false;
for(uint32_t i=0; i<vUniqueBoardName.size(); i++){
string *uboardname = &(vUniqueBoardName.at(i));
int uchannel = vUniqueChannelNumber.at(i);
string *uparname = &(vUniqueParamName.at(i));
if((rawboardname.compare(*uboardname) == 0) && (rawchannel == uchannel) && (rawparname.compare(*uparname) == 0)){
isTripletSame = true;
}
}
if(!isTripletSame){
vUniqueBoardName.push_back(rawboardname);
vUniqueChannelNumber.push_back(rawchannel);
vUniqueParamName.push_back(rawparname);
}
}
}
// Sort the structure
void TLogStorage::SortStructure(){
sort(vLog.begin(), vLog.end(), LogChannel::compare);
for(uint32_t ilog=0; ilog<vLog.size(); ilog++){
vector<LogParam>* vParam = &(vLog.at(ilog).vParam);
sort(vParam->begin(), vParam->end(), LogParam::compare);
}
}
int TLogStorage::GenerateStructure() {
GenerateListOfUniques();
// Fill vLog structure
for(uint32_t i=0; i<vUniqueBoardName.size(); i++){
string *ubn = &(vUniqueBoardName.at(i));
int *ucn = &(vUniqueChannelNumber.at(i));
string *upn = &(vUniqueParamName.at(i));
if(i==0){
LogChannel *lch = new LogChannel;
lch->boardName = *ubn;
lch->channel = *ucn;
LogParam *lp = new LogParam;
lp->parName = *upn;
lch->vParam.push_back(*lp);
vLog.push_back(*lch);
}
else{
int loopSafetyCnt=0;
while(true){
loopSafetyCnt++;
bool boardChannelPresent = false;
bool paramPresent = false;
vector<LogParam>* vParam = NULL;
for(uint16_t ilog=0; ilog<vLog.size(); ilog++){
//cout << i << "/" << vUniqueBoardName.size() << " - " << ilog << " " << vLog.at(ilog).boardName << " -- " << (*ubn) << " \t| ";
//cout << vLog.at(ilog).channel << " -- " << (*ucn) << endl;
if((vLog.at(ilog).boardName.compare(*ubn) == 0) && (vLog.at(ilog).channel == (*ucn))){
boardChannelPresent = true;
// If board channel is found then try to find a corresponding parameter within this board-channel
vParam = &(vLog.at(ilog).vParam);
for(uint16_t ipar=0; ipar<vParam->size(); ipar++){
if(vParam->at(ipar).parName.compare(*upn) == 0){
paramPresent = true;
break;
}
}
break;
}
}
// For debugging uncomment to see how adding proceeds
/*cout << i << "-" << loopSafetyCnt << " " << true << boardChannelPresent << endl;
cout << " Unique: " << *ubn << " " << *ucn << " " << *upn << endl;
for(int ilog=0; ilog<vLog.size(); ilog++){
cout << " " << vLog.at(ilog).boardName << " " << vLog.at(ilog).channel;
for(int ipar=0; ipar<vLog.at(ilog).vParam.size(); ipar++){
cout << " " << vLog.at(ilog).vParam.at(ipar).parName << " ";
}
cout << endl;
}
cout << endl;
*/
if(!boardChannelPresent){
LogChannel *lch = new LogChannel;
lch->boardName = *ubn;
lch->channel = *ucn;
LogParam *lp = new LogParam;
lp->parName = *upn;
lch->vParam.push_back(*lp);
vLog.push_back(*lch);
}
else if(!paramPresent){
if(vParam == NULL){
cerr << "<E> TLogStorage::TLogStorage(): vParam pointer was not assigned an object!" << endl;
return -1;
}
LogParam *lp = new LogParam;
lp->parName = *upn;
vParam->push_back(*lp);
}
else{ // all info was added in the structure, end infinite loop
break;
}
if(loopSafetyCnt > 1e3){
cerr << "<E> TLogStorage::TLogStorage(): Something went wrong and probably infinite loop started..." << endl;
return -2;
}
}
}
}
return 0;
}
time_t TLogStorage::GetTime(string& rawTimeStamp){
// year
int iyear0 = 0;
int iyear1 = rawTimeStamp.find_first_of('-');
int imonth0 = iyear1+1;
int imonth1 = rawTimeStamp.find_first_of('-', imonth0);
int iday0 = imonth1+1;
int iday1 = rawTimeStamp.find_first_of('T', iday0);
int ihour0 = iday1+1;
int ihour1 = rawTimeStamp.find_first_of(':', ihour0);
int imin0 = ihour1+1;
int imin1 = rawTimeStamp.find_first_of(':', imin0);
int isec0 = imin1+1;
struct tm timestamp;
stringstream ss;
ss << rawTimeStamp.substr(iyear0, iyear1-iyear0);
ss >> timestamp.tm_year;
timestamp.tm_year -= 1900;
ss.clear();
ss << rawTimeStamp.substr(imonth0, imonth1-imonth0);
ss >> timestamp.tm_mon;
timestamp.tm_mon -= 1;
ss.clear();
ss << rawTimeStamp.substr(iday0, iday1-iday0);
ss >> timestamp.tm_mday;
ss.clear();
ss << rawTimeStamp.substr(ihour0, ihour1-ihour0);
ss >> timestamp.tm_hour;
ss.clear();
ss << rawTimeStamp.substr(imin0, imin1-imin0);
ss >> timestamp.tm_min;
ss.clear();
ss << rawTimeStamp.substr(isec0);
ss >> timestamp.tm_sec;
ss.clear();
time_t t = mktime(×tamp);
return t;
}
void TLogStorage::FillStructure(){
for(uint32_t iraw=0; iraw<vRawLog->size(); iraw++){
string rawBoardName = vRawLog->at(iraw).GetBoardName();
int rawChannel = vRawLog->at(iraw).GetChannel();
string rawParName = vRawLog->at(iraw).GetParName();
string rawTimeStamp = vRawLog->at(iraw).GetTimeStamp();
float rawValue = vRawLog->at(iraw).GetValue();
for(uint32_t ilog=0; ilog<vLog.size(); ilog++){
LogChannel* lc = &(vLog.at(ilog));
if((rawBoardName.compare(lc->boardName) == 0) && (rawChannel == lc->channel)){
for(uint32_t ipar=0; ipar<vLog.at(ilog).vParam.size(); ipar++){
LogParam* lp = &(lc->vParam.at(ipar));
if(rawParName.compare(lp->parName) == 0){
LogInfo* li = new LogInfo();
li->timeStamp = GetTime(rawTimeStamp);
li->value = rawValue;
if(li->timeStamp>0){
lp->vVal.push_back(li);
}
break;
}
}
break;
}
}
}
}
void TLogStorage::AnalyseMinMax(){
for(uint32_t ilog=0; ilog<vLog.size(); ilog++){
LogChannel* lc = &(vLog.at(ilog));
for(uint32_t ipar=0; ipar<vLog.at(ilog).vParam.size(); ipar++){
LogParam* lp = &(lc->vParam.at(ipar));
for(uint32_t ival=0; ival<lp->vVal.size(); ival++){
LogInfo* li = lp->vVal.at(ival);
if((lp->minTime > li->timeStamp) || (lp->minTime == -999)){
lp->minTime = li->timeStamp;
}
if((lp->maxTime < li->timeStamp) || (lp->maxTime == -999)){
lp->maxTime = li->timeStamp;
}
if((lp->minValue > li->value) || (lp->minValue == -999)){
lp->minValue = li->value;
}
if((lp->maxValue < li->value) || (lp->maxValue == -999)){
lp->maxValue = li->value;
}
}
if(lp->minTime < 0){
cout << "<E> TLogStorage::AnalyseMinMax(): " << ilog << "-" << ipar << ":" << lp->parName << endl;
return;
}
}
}
// Initialize time global min and global max
if(vLog.size()>0){
if(vLog.at(0).vParam.size()>0){
globalMaxTime = vLog.at(0).vParam.at(0).maxTime;
globalMinTime = vLog.at(0).vParam.at(0).minTime;
}
}
for(uint32_t ilog=0; ilog<vLog.size(); ilog++){
LogChannel* lc = &(vLog.at(ilog));
for(uint32_t ipar=0; ipar<vLog.at(ilog).vParam.size(); ipar++){
LogParam* lp = &(lc->vParam.at(ipar));
if(globalMaxTime < lp->maxTime){
globalMaxTime = lp->maxTime;
}
if(globalMinTime > lp->minTime){
globalMinTime = lp->minTime;
}
}
}
}
void TLogStorage::CreateGraphs(){
for(uint32_t ilog=0; ilog<vLog.size(); ilog++){
LogChannel* lc = &(vLog.at(ilog));
for(uint32_t ipar=0; ipar<vLog.at(ilog).vParam.size(); ipar++){
LogParam* lp = &(lc->vParam.at(ipar));
stringstream ssname;
ssname << lc->boardName << "_" << lc->channel << "_" << lp->parName;
lp->gr = new TGraph(lp->vVal.size());
lp->gr->SetName(ssname.str().c_str());
lp->gr->SetTitle(ssname.str().c_str());
}
}
}
int TLogStorage::Fill(){
FillStructure();
CreateGraphs();
//Fill histos
for(uint32_t ilog=0; ilog<vLog.size(); ilog++){
LogChannel* lc = &(vLog.at(ilog));
for(uint32_t ipar=0; ipar<vLog.at(ilog).vParam.size(); ipar++){
LogParam* lp = &(lc->vParam.at(ipar));
for(uint32_t ival=0; ival<lp->vVal.size(); ival++){
LogInfo* li = lp->vVal.at(ival);
lp->gr->SetPoint(ival, li->timeStamp, li->value);
}
}
}
return 0;
}
void TLogStorage::PrintStructure(){
cout << " <I> TLogStorage::PrintStructure(): vLog structure" << endl;
for(uint32_t ilog=0; ilog<vLog.size(); ilog++){
LogChannel* lc = &(vLog.at(ilog));
cout << " " << lc->boardName << " " << lc->channel << " ";
for(uint32_t ipar=0; ipar<vLog.at(ilog).vParam.size(); ipar++){
cout << lc->vParam.at(ipar).parName << " ";
}
cout << endl;
}
}
void TLogStorage::PrintContents(){
cout << " <I> TLogStorage::PrintContents(): vLog content" << endl;
for(uint32_t ilog=0; ilog<vLog.size(); ilog++){
LogChannel* lc = &(vLog.at(ilog));
lc->PrintContents();
}
}
vector<LogChannel>* TLogStorage::GetLog(){
return &vLog;
}
void TLogStorage::GetUniques(vector<string> &vUniqueBoardName, vector<int> &vUniqueChannelNumber, vector<string> &vUniqueParamName){
vUniqueBoardName = this->vUniqueBoardName;
vUniqueChannelNumber = this->vUniqueChannelNumber;
vUniqueParamName = this->vUniqueParamName;
}
time_t TLogStorage::GetGlobalMaxTime(){
if(globalMaxTime == -1){
AnalyseMinMax();
}
return globalMaxTime;
}
time_t TLogStorage::GetGlobalMinTime(){
if(globalMinTime == -1){
AnalyseMinMax();
}
return globalMinTime;
}
void LogChannel::PrintContents(){
cout << " " << boardName << " " << channel << " " << endl;
for(uint32_t ipar=0; ipar<vParam.size(); ipar++){
LogParam* lp = &(vParam.at(ipar));
cout << " " << lp->parName << endl;
for(uint32_t ival=0; ival<lp->vVal.size(); ival++){
cout << " " << lp->vVal.at(ival)->timeStamp << ": " << lp->vVal.at(ival)->value << endl;
}
}
}
} /* namespace std */