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