1 | // toisvr.cc
|
---|
2 | // Eric Aubourg CEA/DAPNIA/SPP juillet 1999
|
---|
3 |
|
---|
4 | #include <iostream.h>
|
---|
5 | #include "toisvr.h"
|
---|
6 | #include "archparam.h"
|
---|
7 | #include "asigps.h"
|
---|
8 |
|
---|
9 |
|
---|
10 |
|
---|
11 | TOISvr::TOISvr()
|
---|
12 | {
|
---|
13 | initDone = false;
|
---|
14 | }
|
---|
15 |
|
---|
16 | // To avoid special copy constructor handling, we will not
|
---|
17 | // register ourself to us... Special dealing in readReq.
|
---|
18 |
|
---|
19 | void TOISvr::setDirectory(string d) {
|
---|
20 | iter.directory = d;
|
---|
21 | }
|
---|
22 |
|
---|
23 | void TOISvr::addFile(string f) {
|
---|
24 | iter.files.insert(f);
|
---|
25 | }
|
---|
26 |
|
---|
27 | void TOISvr::useAuxGPS(AuxGPS* gps) {
|
---|
28 | if (iter.auxGPS) delete iter.auxGPS;
|
---|
29 | iter.auxGPS = gps;
|
---|
30 | }
|
---|
31 |
|
---|
32 |
|
---|
33 | void TOISvr::onBoardRecorderFiles(bool x) {
|
---|
34 | iter.isOnBoardRecorder = x;
|
---|
35 | }
|
---|
36 |
|
---|
37 |
|
---|
38 | void TOISvr::setTimeInterval(double tStart, double tEnd) {
|
---|
39 | if (tStart>0) iter.tStart = tStart;
|
---|
40 | if (tEnd>0) iter.tEnd = tEnd;
|
---|
41 | }
|
---|
42 |
|
---|
43 | void TOISvr::addInfo(TOIKind kind, int index, bool triggering, bool interp) {
|
---|
44 | TOIIter::info i;
|
---|
45 | i.kind = kind;
|
---|
46 | i.index = index;
|
---|
47 | i.triggering = triggering;
|
---|
48 | i.interpolated= interp;
|
---|
49 | iter.infos.push_back(i);
|
---|
50 | }
|
---|
51 |
|
---|
52 | void TOISvr::addInfo(TOIKind kind, bool triggering, bool interp) {
|
---|
53 | addInfo(kind,0,triggering,interp);
|
---|
54 | }
|
---|
55 |
|
---|
56 | TOIIter TOISvr::doQuery() {
|
---|
57 | //iter.Init();
|
---|
58 | return iter;
|
---|
59 | }
|
---|
60 |
|
---|
61 | void TOISvr::registerReqHandler(RequestHandler* h) {
|
---|
62 | handlers.push_back(h);
|
---|
63 | }
|
---|
64 |
|
---|
65 |
|
---|
66 | void TOISvr::readReq(istream& str) {
|
---|
67 | if (!initDone) defaultInclude();
|
---|
68 | string line;
|
---|
69 | while (str) {
|
---|
70 | getline(str,line);
|
---|
71 | if (!str) break;
|
---|
72 | if (line.substr(0,4)=="#END") break;
|
---|
73 | if (line[0] != '@' && line[0] != '#') continue;
|
---|
74 | bool handled=processRequest(line);
|
---|
75 | if (!handled) {
|
---|
76 | cerr << "*Warning, unrecognized directive " << line << endl;
|
---|
77 | }
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 | #define tsttoi(toi) if (keyw == "@"#toi) kind = toi;
|
---|
82 |
|
---|
83 | bool TOISvr::processRequest(string line) {
|
---|
84 | int x = line.find(' ');
|
---|
85 | string keyw = line.substr(0, x);
|
---|
86 | string args = (x>0) ? line.substr(x) : string("");
|
---|
87 | if (keyw[0] == '#') {
|
---|
88 | bool handled = processOption(keyw,args);
|
---|
89 | for (list<RequestHandler*>::iterator i = handlers.begin();
|
---|
90 | i != handlers.end(); i++) {
|
---|
91 | handled |= (*i)->processOption(keyw,args);
|
---|
92 | }
|
---|
93 | return handled;
|
---|
94 | }
|
---|
95 | if (keyw[0] == '@') {
|
---|
96 | // find TOI kind, index and options
|
---|
97 | TOIKind kind= (TOIKind)-1;
|
---|
98 | int index=-1;
|
---|
99 | bool interp=false;
|
---|
100 | bool repet =false;
|
---|
101 | bool flag =false;
|
---|
102 | bool notrig=false;
|
---|
103 | tsttoi(sampleNum)
|
---|
104 | else tsttoi(internalTime)
|
---|
105 | else tsttoi(mjd)
|
---|
106 | else tsttoi(boloTens)
|
---|
107 | else tsttoi(boloTens2)
|
---|
108 | else tsttoi(boloRaw)
|
---|
109 | else tsttoi(boloRes)
|
---|
110 | else tsttoi(boloTemp)
|
---|
111 | else tsttoi(boloGainAmpli)
|
---|
112 | else tsttoi(boloDACV)
|
---|
113 | else tsttoi(boloDACI)
|
---|
114 | else tsttoi(boloTens2T)
|
---|
115 | else tsttoi(boloRawCN)
|
---|
116 | else tsttoi(boloTensCN)
|
---|
117 | else tsttoi(dilDAC)
|
---|
118 | else tsttoi(dilSwitch)
|
---|
119 | else tsttoi(sstDiode)
|
---|
120 | else tsttoi(sstChannel)
|
---|
121 | else tsttoi(sstDiodeCN)
|
---|
122 | else tsttoi(sstChannelCN)
|
---|
123 | else tsttoi(sstStarCnt)
|
---|
124 | else tsttoi(sstStarZ)
|
---|
125 | else tsttoi(sstStarF)
|
---|
126 | else tsttoi(sstStarT)
|
---|
127 | else tsttoi(gyroRaw)
|
---|
128 | else tsttoi(gyroTens)
|
---|
129 | else tsttoi(gyroSpeed)
|
---|
130 | else tsttoi(gpsTime)
|
---|
131 | else tsttoi(longitude)
|
---|
132 | else tsttoi(latitude)
|
---|
133 | else tsttoi(altitude)
|
---|
134 | else tsttoi(tsid)
|
---|
135 | else tsttoi(azimut)
|
---|
136 | else tsttoi(alphaAxis)
|
---|
137 | else tsttoi(deltaAxis)
|
---|
138 | else tsttoi(alphaSst)
|
---|
139 | else tsttoi(deltaSst)
|
---|
140 | else tsttoi(alphaBolo)
|
---|
141 | else tsttoi(deltaBolo)
|
---|
142 | else {
|
---|
143 | // cerr << "*Warning, unrecognized TOI " << line << endl;
|
---|
144 | return false;
|
---|
145 | }
|
---|
146 | if (kind == sampleNum || kind == mjd) notrig = true;
|
---|
147 | string toiname = keyw.substr(1);
|
---|
148 | while (args != "") {
|
---|
149 | if (args[0] == ' ') {
|
---|
150 | args = args.substr(args.find_first_not_of(' '));
|
---|
151 | if (args == "") break;
|
---|
152 | }
|
---|
153 | x = args.find(' ');
|
---|
154 | string opt = args.substr(0, x);
|
---|
155 | args = (x>0) ? args.substr(x) : string("");
|
---|
156 | if (opt[0]>='0' && opt[0]<='9') {
|
---|
157 | index = atoi(opt.c_str());
|
---|
158 | } else if (opt == "notrig") {
|
---|
159 | notrig = true;
|
---|
160 | } else if (opt == "repet") {
|
---|
161 | repet = true; interp = false;
|
---|
162 | } else if (opt == "interp") {
|
---|
163 | interp = true; repet = false;
|
---|
164 | } else if (opt == "flag") {
|
---|
165 | flag = true;
|
---|
166 | }
|
---|
167 | }
|
---|
168 | bool handled = processTOIReq(line, toiname, kind, index, interp, repet, flag, notrig);
|
---|
169 | for (list<RequestHandler*>::iterator i = handlers.begin();
|
---|
170 | i != handlers.end(); i++) {
|
---|
171 | handled |= (*i)->processTOIReq(line, toiname, kind, index, interp, repet, flag, notrig);
|
---|
172 | }
|
---|
173 | return handled;
|
---|
174 | }
|
---|
175 | return false;
|
---|
176 | }
|
---|
177 |
|
---|
178 |
|
---|
179 | bool TOISvr::processTOIReq(string /*line*/, string /*toiname*/, TOIKind kind, int index,
|
---|
180 | bool interp, bool /*repet*/, bool /*flag*/, bool notrig)
|
---|
181 | {
|
---|
182 | if (index<0) index=0;
|
---|
183 | addInfo(kind, index, !notrig, interp);
|
---|
184 | return true;
|
---|
185 | }
|
---|
186 |
|
---|
187 | bool TOISvr::processOption(string key, string arg)
|
---|
188 | {
|
---|
189 | if (arg.length()>0 && arg[0] == ' ') {
|
---|
190 | arg = arg.substr(arg.find_first_not_of(' '));
|
---|
191 | }
|
---|
192 | if (key == "#TRANGE") {
|
---|
193 | double tmin, tmax;
|
---|
194 | sscanf(arg.c_str(), "%lg %lg", &tmin, &tmax);
|
---|
195 | setTimeInterval(tmin, tmax);
|
---|
196 | } else if (key == "#PATH") {
|
---|
197 | setDirectory(arg);
|
---|
198 | } else if (key == "#FILE") {
|
---|
199 | addFile(arg);
|
---|
200 | } else if (key == "#RECORDER") {
|
---|
201 | onBoardRecorderFiles(true);
|
---|
202 | } else if (key == "#MJD0") {
|
---|
203 | double t0;
|
---|
204 | sscanf(arg.c_str(), "%lg", &t0);
|
---|
205 | archParam.acq.tBlock0 = t0;
|
---|
206 | } else if (key == "#PERECH") {
|
---|
207 | double t0;
|
---|
208 | sscanf(arg.c_str(), "%lg", &t0);
|
---|
209 | archParam.acq.perEch = t0;
|
---|
210 | } else if (key == "#ASIGPS") {
|
---|
211 | ASIGPS* gps = new ASIGPS(arg);
|
---|
212 | gps->FitsDump("GPSDump.fits");
|
---|
213 | useAuxGPS(gps);
|
---|
214 | } else if (key == "#INCLUDE") {
|
---|
215 | ifstream f(arg.c_str());
|
---|
216 | readReq(f);
|
---|
217 | } else {
|
---|
218 | // cerr << "*Warning, unrecognized option " << line << endl;
|
---|
219 | return false;
|
---|
220 | }
|
---|
221 | return true;
|
---|
222 | }
|
---|
223 |
|
---|
224 | void TOISvr::defaultInclude() {
|
---|
225 | initDone = true;
|
---|
226 | processRequest("#REQVERSION V_230999");
|
---|
227 | processRequest("#MJD0 1376.8358818");
|
---|
228 | processRequest("#PERECH 0.005836818076");
|
---|
229 | processRequest("#COMMENT ***WARNING***");
|
---|
230 | processRequest("#COMMENT ***SOME TOI'S ARE PRELIMINARY***");
|
---|
231 | processRequest("#COMMENT gyroSpeed is not calibrated");
|
---|
232 | processRequest("#COMMENT azimut/alpha/delta use galaxy crossings");
|
---|
233 | processRequest("#COMMENT and assume no pendulation");
|
---|
234 |
|
---|
235 | }
|
---|