-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTLogFileReader.cpp
More file actions
113 lines (99 loc) · 3.4 KB
/
TLogFileReader.cpp
File metadata and controls
113 lines (99 loc) · 3.4 KB
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
/*
* TLogFileReader.cpp
*
* Created on: Feb 28, 2019
* Author: mss
*/
#include "TLogFileReader.h"
namespace std {
TLogFileReader::TLogFileReader() {
// Nothing here
}
TLogFileReader::~TLogFileReader() {
// Nothing here
}
int16_t TLogFileReader::ReadLine(const string& sLine, const int32_t iLine){
stringstream ssLine(sLine);
int16_t iCol=0;
if(sLine.find_first_of("#")!=0){ //if not a comment
string sWord;
while(!ssLine.eof()){ // first parsing to count the number of columns
ssLine >> sWord;
iCol++;
}
if(iCol != nCols+1){
cerr << "<E> TLogFileReader::ReadLine(): Wrong number of columns when parsing line " << iLine << ": " << iCol << " != " << nCols << endl;
cerr << " -> " << ssLine.str() << endl;
return -1;
}
else{
ssLine.clear();
ssLine.seekg(ios_base::beg); // go back to the beginning of the line
TSingleLogLine singleLogLine; // temp object to store read line in
string sTimeStamp, sBoardName, sParName, tmp, sCh, sVal;
int iCh;
float fVal;
ssLine >> sTimeStamp;
singleLogLine.SetTimeStamp(sTimeStamp.substr(1, sTimeStamp.size()-3)); // remove the brackets and colon at the end
ssLine >> sBoardName;
singleLogLine.SetBoardName(sBoardName.substr(1, sBoardName.size()-2)); // remove the surrounding brackets
ssLine >> tmp;
ssLine >> tmp;
ssLine >> tmp;
if(tmp != "ch"){
cerr << "<E> TLogFileReader::ReadLine(): Consistency problems (column 'ch' missing) at line " << iLine << endl;
cerr << sLine << endl;
return -3;
}
// Extraction of channel int from string with brackets
ssLine >> sCh;
sCh = sCh.substr(1, sCh.size()-2);
stringstream ssCh(sCh);
ssCh >> iCh;
if(!(ssCh.good() || ssCh.eof())){ // check if there were stringstream conversion errors
vStorage.clear();
cerr << "<E> TLogFileReader::ReadLine(): Channel conversion problems at line " << iLine;
cerr << " (eof,fail,bad)=(" << ssCh.eof() << "," << ssCh.fail() << "," << ssCh.bad() << ")" << endl;
cerr << sCh << endl;
return -4;
}
singleLogLine.SetChannel(iCh);
ssLine >> tmp; // should be 'par' but no more checks at this point
ssLine >> sParName;
singleLogLine.SetParName(sParName.substr(1, sParName.size()-2)); // remove the surrounding brackets
ssLine >> tmp; // should be 'val' but no more checks at this point
// Extraction of value float from string with brackets and semicolon at the end
ssLine >> sVal;
sVal = sVal.substr(1, sVal.size()-3);
stringstream ssVal(sVal);
ssVal >> fVal;
if(!(ssVal.good() || ssVal.eof())){ // check if there were stringstream conversion errors
vStorage.clear();
cerr << "<E> TLogFileReader::ReadLine(): Value conversion problems at line " << iLine;
cerr << " (eof,fail,bad)=(" << ssVal.eof() << "," << ssVal.fail() << "," << ssVal.bad() << ")" << endl;
cerr << sVal << endl;
return -4;
}
singleLogLine.SetValue(fVal);
vStorage.push_back(singleLogLine);
}
}
return 0;
}
int16_t TLogFileReader::Print(ostream &out){
cout << "Printing file contents: " << GetFilePath() << endl;
for(uint32_t iline=0; iline<vStorage.size(); iline++){
vStorage.at(iline).Print(out);
}
return 0;
}
void TLogFileReader::ResetData(){
// Nothing to delete additionally to what base class handles
}
void TLogFileReader::InitLutVectors(){
// Nothing to init
}
void TLogFileReader::FillLutVectors(){
// Nothing to fill
}
} /* namespace std */