forked from amissert/atmFitTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeyread.cxx
102 lines (94 loc) · 2.07 KB
/
keyread.cxx
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
#include "keyread.h"
keyread::keyread(const char* afile){
fname = afile;
}
double keyread::getKeyD(string key){
return dmap[key];
}
float keyread::getKeyF(string key){
return fmap[key];
}
int keyread::getKeyI(string key){
return imap[key];
}
TString keyread::getKeyS(string key){
return smap[key];
}
void keyread::readFile(){
ifstream file(fname);
if (!file.is_open()){
cout<<fname<<" is not a good file "<<endl;
return;
}
char line[LINESIZEMAX];
int nread;
TString sline;
int nline=0;
while(!file.eof()){
// cout<<"reading line: "<<nline<<endl;
nline++;
file.getline(line,LINESIZEMAX);
for (int i=0;i<file.gcount();i++){
//cout<<"appending "<<line[i]<<" to tstring"<<endl;
sline.Append(line[i]);
}
//cout<<"processing line: "<<endl;
processLine(sline);
sline.Clear();
}
}
void keyread::processLine(TString sline){
TString stype;
TString skey;
TString sval;
int ival;
float fval;
double dval;
///get key type
if (sline(0)=='i') stype="i";
else if (sline(0)=='f') stype="f";
else if (sline(0)=='d') stype="d";
else if (sline(0)=='s') stype="s";
else if (sline(0)=='$'){
return;
}
else if (sline(0)==' ' || sline(0)=='\n'){
return;
}
else {
cout<<sline(0)<<" is not a valid type!!"<<endl;
return;
}
///get key name
int ichar=2;
while (sline(ichar)!='='){
skey.Append(sline(ichar));
ichar++;
}
///get key value
int jchar=ichar+1;
while (sline(jchar)!=';'){
sval.Append(sline(jchar));
jchar++;
}
//place key value in appropriate map
if (stype(0)=='i'){
ival = sval.Atoi();
cout<<"mapping "<<skey.Data()<<" to "<<ival<<endl;
imap[skey.Data()] = ival;
}
if (stype(0)=='f'){
fval = sval.Atof();
cout<<"mapping "<<skey.Data()<<" to "<<fval<<endl;
fmap[skey.Data()]=fval;
}
if (stype(0)=='d'){
dval=sval.Atof();
cout<<"mapping "<<skey.Data()<<" to "<<dval<<endl;
dmap[skey.Data()]=dval;
}
if (stype(0)=='s'){
cout<<"mapping "<<skey.Data()<<" to "<<sval.Data()<<endl;
smap[skey.Data()]=sval;
}
}