forked from GooFit/GooFit
-
Notifications
You must be signed in to change notification settings - Fork 1
/
FunctorWriter.cc
82 lines (69 loc) · 1.79 KB
/
FunctorWriter.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
#include "FunctorWriter.hh"
#include <fstream>
#include <map>
#include "PdfBase.hh"
void writeToFile (PdfBase* pdf, const char* fname) {
PdfBase::parCont params;
pdf->getParameters(params);
std::ofstream writer;
writer.open(fname);
for (PdfBase::parIter p = params.begin(); p != params.end(); ++p) {
writer << (*p)->name << " "
<< (*p)->value << " "
<< (*p)->error << " "
<< (*p)->numbins << " "
<< (*p)->lowerlimit << " "
<< (*p)->upperlimit
<< std::endl;
}
writer.close();
}
void readFromFile (PdfBase* pdf, const char* fname) {
PdfBase::parCont params;
pdf->getParameters(params);
std::map<string, Variable*> tempMap;
for (PdfBase::parIter p = params.begin(); p != params.end(); ++p) {
tempMap[(*p)->name] = (*p);
}
std::ifstream reader;
reader.open(fname);
std::string buffer;
char discard[1000];
int numSet = 0;
while (true) {
reader >> buffer;
if (reader.eof()) break;
Variable* var = tempMap[buffer];
if (var) {
reader >> var->value
>> var->error
>> var->numbins
>> var->lowerlimit
>> var->upperlimit;
if (++numSet == tempMap.size()) break;
}
else {
reader.getline(discard, 1000);
}
}
reader.close();
}
void readListOfNumbers (thrust::host_vector<fptype>& target, const char* fname) {
std::ifstream reader;
reader.open(fname);
fptype buffer = 0;
while (true) {
reader >> buffer;
if (reader.eof()) break;
target.push_back(buffer);
}
reader.close();
}
void writeListOfNumbers (thrust::host_vector<fptype>& target, const char* fname) {
std::ofstream writer;
writer.open(fname);
for (thrust::host_vector<fptype>::iterator t = target.begin(); t != target.end(); ++t) {
writer << (*t) << " ";
}
writer.close();
}