DB_Track/source/TrackFinder.cpp

111 lines
2.6 KiB
C++

//
// TrackFinder.cpp
// DB_Track
//
// Created by Baranyai David on 2018. 06. 05..
//
#include "TrackFinder.hpp"
#include <iostream>
TrackFinder::TrackFinder()
{
try
{
file.open("data.txt");
if(!file.is_open())
{
throw "File opening error";
}
getline(file, line);
std::istringstream is(line);
for(int i = 0; i < 4; i++)
{
is >> line_data[i];
}
ch_id_1 = line_data[0];
sec_1 = line_data[1];
nsec_1 = line_data[2];
amp_1 = line_data[3];
ch_id.push_back(ch_id_1);
sec.push_back(sec_1);
nsec.push_back(nsec_1);
amp.push_back(amp_1);
}
catch(char param)
{
std::cout << param << std::endl;
}
}
TrackFinder::~TrackFinder()
{
file.close();
}
bool TrackFinder::FindTrack()
{
ch_id.erase(ch_id.begin(), ch_id.end());
sec.erase(sec.begin(), sec.end());
nsec.erase(nsec.begin(), nsec.end());
amp.erase(amp.begin(), amp.end());
while(!file.eof())
{
getline(file, line);
std::istringstream is(line);
for(int i = 0; i < 4; i++)
{
is >> line_data[i];
}
long old = ((line_data[1]*1000000)+line_data[2]);
long nw = ((sec_1*1000000)+nsec_1);
if( old - nw < interval)
{
ch_id_1 = line_data[0];
sec_1 = line_data[1];
nsec_1 = line_data[2];
amp_1 = line_data[3];
ch_id.push_back(ch_id_1);
sec.push_back(sec_1);
nsec.push_back(nsec_1);
amp.push_back(amp_1);
}
else if(ch_id.size() < 4) //ha négynél kevesebb szál szólalt meg
{
ch_id_1 = line_data[0];
sec_1 = line_data[1];
nsec_1 = line_data[2];
amp_1 = line_data[3];
ch_id.erase(ch_id.begin(), ch_id.end());
sec.erase(sec.begin(), sec.end());
nsec.erase(nsec.begin(), nsec.end());
amp.erase(amp.begin(), amp.end());
ch_id.push_back(ch_id_1);
sec.push_back(sec_1);
nsec.push_back(nsec_1);
amp.push_back(amp_1);
}
else if(ch_id.size() >= 4) //ha négynél több
{
istrackavailable = true;
return true;
}
}
return false;
}
void TrackFinder::GetTrack(std::vector<int> &ch, std::vector<int> &s, std::vector<int> &ns, std::vector<int> &a)
{
if(istrackavailable)
{
ch = ch_id;
s = sec;
ns = nsec;
a = amp;
}
}