1 |
buchmann |
1.1 |
#include <iostream>
|
2 |
|
|
#include <fstream>
|
3 |
|
|
#include <vector>
|
4 |
|
|
#include <algorithm>
|
5 |
|
|
|
6 |
|
|
class LimitDroplet{
|
7 |
|
|
public:
|
8 |
|
|
std::string LimitName;
|
9 |
|
|
float JZB;
|
10 |
|
|
float upper68;
|
11 |
|
|
float lower68;
|
12 |
|
|
float expected;
|
13 |
|
|
float observed;
|
14 |
|
|
float upper95;
|
15 |
|
|
float lower95;
|
16 |
|
|
void saveDroplet(std::string filename);//save droplet to file
|
17 |
|
|
void readDroplet(std::string filename);//get droplet from file
|
18 |
|
|
void fill_limit_vector(std::string line, std::vector<float> &res);
|
19 |
|
|
LimitDroplet();
|
20 |
|
|
};
|
21 |
|
|
|
22 |
|
|
LimitDroplet::LimitDroplet() {
|
23 |
|
|
JZB=-1;upper68=-1;lower68=-1;expected=-1;observed=-1;upper95=-1;lower95=-1;
|
24 |
|
|
}
|
25 |
|
|
|
26 |
|
|
std::ostream &operator<<(std::ostream &ostr, LimitDroplet v)
|
27 |
|
|
{
|
28 |
|
|
return ostr << "JZB>" << v.JZB << std::endl << " 68 % interval is: [ " << v.lower68 << " : " << v.upper68 << " ]" << std::endl << " 95 % interval is: [" << v.lower95 << " : " << v.upper95 << " ]" << std::endl << " Expected limit is " << v.expected << std::endl << " Observed limit is " << v.observed << std::endl;
|
29 |
|
|
}
|
30 |
|
|
|
31 |
|
|
void LimitDroplet::saveDroplet(std::string filename) {
|
32 |
|
|
std::ofstream myreport(filename.c_str());
|
33 |
|
|
myreport<<JZB<<";"<<this->upper68<<";"<<this->lower68<<";"<<this->expected<<";"<<this->observed<<";"<<this->upper95<<";"<<this->lower95<<";";
|
34 |
|
|
myreport.close();
|
35 |
|
|
}
|
36 |
|
|
|
37 |
|
|
void LimitDroplet::fill_limit_vector(std::string line, std::vector<float> &res) {
|
38 |
|
|
if(line=="") return;
|
39 |
|
|
while((int)line.find(";")>-1) {
|
40 |
|
|
int pos=(int)line.find(";");
|
41 |
|
|
std::string thisentry=line.substr(0,pos);
|
42 |
|
|
res.push_back(atof(thisentry.c_str()));
|
43 |
|
|
line=line.substr(pos+1,line.size()-pos);
|
44 |
|
|
}
|
45 |
|
|
}
|
46 |
|
|
void LimitDroplet::readDroplet(std::string filename) {
|
47 |
|
|
std::ifstream myreport;
|
48 |
|
|
myreport.open(filename.c_str());
|
49 |
|
|
if(!myreport) {
|
50 |
|
|
std::cerr << "Watch out, cannot fill limit droplet using " << filename << std::endl;
|
51 |
|
|
} else {
|
52 |
|
|
std::vector<float> lresults;
|
53 |
|
|
char c[255];
|
54 |
|
|
while(myreport) {
|
55 |
|
|
myreport.getline(c,255);
|
56 |
|
|
this->fill_limit_vector((std::string)c,lresults);
|
57 |
|
|
}
|
58 |
|
|
if(lresults.size()<7) std::cerr << "Watch out, stored limit droplet from " << filename << " does not contain sufficient information" << std::endl;
|
59 |
|
|
else {
|
60 |
|
|
this->JZB=lresults[0];
|
61 |
|
|
this->upper68=lresults[1];
|
62 |
|
|
this->lower68=lresults[2];
|
63 |
|
|
this->expected=lresults[3];
|
64 |
|
|
this->observed=lresults[4];
|
65 |
|
|
this->upper95=lresults[5];
|
66 |
|
|
this->lower95=lresults[6];
|
67 |
|
|
}//result vector is of right size
|
68 |
|
|
}//report exists
|
69 |
|
|
myreport.close();
|
70 |
|
|
}
|
71 |
|
|
|
72 |
|
|
/*int main() {
|
73 |
|
|
std::cout << "Limit Droplet Class !" << std::endl;
|
74 |
|
|
LimitDroplet alpha;
|
75 |
|
|
alpha.fillDroplet("report_999741748.txt");
|
76 |
|
|
return 0;
|
77 |
|
|
}
|
78 |
|
|
*/
|