-
Notifications
You must be signed in to change notification settings - Fork 0
/
STMDataPacketInput.cc
84 lines (72 loc) · 2.38 KB
/
STMDataPacketInput.cc
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
//Author: S Middleton
//Date : 07 Jun2019
//Purpose : This file is meant to create "fake data packets" from a sample CSV file for validation of the algorithms
//Note : to run you need to invoke c++11, to compile type:
// "g++ -std=c++11 CVSReader.cc"
// then "./a.out" as usual.
#include <iostream>
#include <fstream>
#include <vector>
#include <iterator>
#include <string>
#include <algorithm>
#include <boost/algorithm/string.hpp>
#include "STMDataPacket.hpp"
using namespace std;
using namespace boost;
class CSVReaderUpdatedStructure
{
std::string FileName;
std::string LineDelimeter;
public:
CSVReaderUpdatedStructure(std::string filename, std::string delm = ";") : FileName(filename), LineDelimeter(delm)
{ }
std::vector<STMDataPacket> GetData();
};
std::vector<STMDataPacket> CSVReaderUpdatedStructure::GetData()
{
std::ifstream file(FileName);
std::vector<std::vector<std::string> > DataList;
std::vector<STMDataPacket> Data;
std::string line = "";
int i = 0;
while (getline(file, line))
{
i+=1;
if(i>1){ //Skips first row as this is just titles
std::vector<std::string> vec;
boost::algorithm::split(vec, line, boost::is_any_of(LineDelimeter));
DataList.push_back(vec);
}
}
for(unsigned i=0; i < DataList.size(); i++){
STMDataPacket d;
// STMDataPacket::DataSample d.DataSample;
d.datasample.GlobalTimeStamp = (atof (DataList[i][0].c_str()));
d.datasample.RequestPacketTime = (atof (DataList[i][0].c_str()));
for(unsigned ch=0; ch<1;ch++){//loop 4 channels - here assume just 1
//STMDataPacket::ChannelHeader ;
// STMDataPacket::ChannelPacket d.ChannelPacket;
d.channelheader.ChannelID = ch;
d.channelpacket.ChannelID = ch;
d.channelpacket.CountLength = (DataList[i].size());
d.channelheader.Status = true;
for(unsigned j=2; j< (DataList[i]).size();j++){
float isample= atof (DataList[i][j].c_str());
d.channelpacket.ADCList.push_back(isample);
}
d.datasample.channel.push_back(d.channelpacket);
}
Data.push_back(d);
}
DataList.clear();
file.close();
return Data;
}
int read()
{
std::cout<<"In Main...Extracting Data..."<<std::endl;
CSVReaderUpdatedStructure reader("DT5725-2-14-1694_Data_run_co60_waveforms_hpge_06042019.csv");
std::vector<STMDataPacket> DataList = reader.GetData();
return 0;
}