| 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::setMJDInterval(double tStart, double tEnd) { | 
|---|
| 39 | if (tStart>0) iter.tStart = tStart; | 
|---|
| 40 | if (tEnd>0)   iter.tEnd = tEnd; | 
|---|
| 41 | } | 
|---|
| 42 |  | 
|---|
| 43 | void TOISvr::setUTCInterval(double tStart, double tEnd) { | 
|---|
| 44 | if (tStart>0) iter.utcStart = tStart; | 
|---|
| 45 | if (tEnd>0)   iter.utcEnd = tEnd; | 
|---|
| 46 | } | 
|---|
| 47 |  | 
|---|
| 48 | void TOISvr::setSNInterval(long tStart, long tEnd) { | 
|---|
| 49 | if (tStart>0) iter.sStart = tStart; | 
|---|
| 50 | if (tEnd>0)   iter.sEnd = tEnd; | 
|---|
| 51 | } | 
|---|
| 52 |  | 
|---|
| 53 |  | 
|---|
| 54 | void TOISvr::setUnderSample(int n) { | 
|---|
| 55 | if (n<=1) n=1; | 
|---|
| 56 | iter.underSample = n; | 
|---|
| 57 | } | 
|---|
| 58 |  | 
|---|
| 59 |  | 
|---|
| 60 | void TOISvr::addInfo(TOIKind kind, int index, bool triggering, bool interp) { | 
|---|
| 61 | TOIIter::info i; | 
|---|
| 62 | i.kind = kind; | 
|---|
| 63 | i.index = index; | 
|---|
| 64 | i.triggering = triggering; | 
|---|
| 65 | i.interpolated= interp; | 
|---|
| 66 | iter.infos.push_back(i); | 
|---|
| 67 | } | 
|---|
| 68 |  | 
|---|
| 69 | void TOISvr::addInfo(TOIKind kind, bool triggering, bool interp) { | 
|---|
| 70 | addInfo(kind,0,triggering,interp); | 
|---|
| 71 | } | 
|---|
| 72 |  | 
|---|
| 73 | TOIIter TOISvr::doQuery() { | 
|---|
| 74 | //iter.Init(); | 
|---|
| 75 | return iter; | 
|---|
| 76 | } | 
|---|
| 77 |  | 
|---|
| 78 | void TOISvr::registerReqHandler(RequestHandler* h) { | 
|---|
| 79 | handlers.push_back(h); | 
|---|
| 80 | } | 
|---|
| 81 |  | 
|---|
| 82 |  | 
|---|
| 83 | void TOISvr::readReq(istream& str) { | 
|---|
| 84 | if (!initDone) defaultInclude(); | 
|---|
| 85 | string line; | 
|---|
| 86 | while (str) { | 
|---|
| 87 | getline(str,line); | 
|---|
| 88 | if (!str) break; | 
|---|
| 89 | if (line.substr(0,4)=="#END") break; | 
|---|
| 90 | if (line[0] != '@' && line[0] != '#') continue; | 
|---|
| 91 | bool handled=processRequest(line); | 
|---|
| 92 | if (!handled) { | 
|---|
| 93 | cerr << "*Warning, unrecognized directive " << line << endl; | 
|---|
| 94 | } | 
|---|
| 95 | } | 
|---|
| 96 | } | 
|---|
| 97 |  | 
|---|
| 98 | #define tsttoi(toi)   if (keyw == "@"#toi) kind = toi; | 
|---|
| 99 |  | 
|---|
| 100 | bool TOISvr::processRequest(string line) { | 
|---|
| 101 | int x = line.find(' '); | 
|---|
| 102 | string keyw = line.substr(0, x); | 
|---|
| 103 | string args = (x>0) ? line.substr(x) : string(""); | 
|---|
| 104 | if (keyw[0] == '#') { | 
|---|
| 105 | bool handled = processOption(keyw,args); | 
|---|
| 106 | for (list<RequestHandler*>::iterator i = handlers.begin(); | 
|---|
| 107 | i != handlers.end(); i++) { | 
|---|
| 108 | handled |= (*i)->processOption(keyw,args); | 
|---|
| 109 | } | 
|---|
| 110 | return handled; | 
|---|
| 111 | } | 
|---|
| 112 | if (keyw[0] == '@') { | 
|---|
| 113 | // find TOI kind, index and options | 
|---|
| 114 | TOIKind kind= (TOIKind)-1; | 
|---|
| 115 | int index=-1; | 
|---|
| 116 | bool interp=false; | 
|---|
| 117 | bool repet =false; | 
|---|
| 118 | bool flag  =false; | 
|---|
| 119 | bool notrig=false; | 
|---|
| 120 | tsttoi(sampleNum) | 
|---|
| 121 | else tsttoi(internalTime) | 
|---|
| 122 | else tsttoi(mjd) | 
|---|
| 123 | else tsttoi(mutc) | 
|---|
| 124 | else tsttoi(boloMuV) | 
|---|
| 125 | else tsttoi(boloMuV2) | 
|---|
| 126 | else tsttoi(boloRawMuV) | 
|---|
| 127 | else tsttoi(boloRes) | 
|---|
| 128 | else tsttoi(boloTemp) | 
|---|
| 129 | else tsttoi(boloGainAmpli) | 
|---|
| 130 | else tsttoi(boloDACV) | 
|---|
| 131 | else tsttoi(boloDACI) | 
|---|
| 132 | else tsttoi(boloMuV2T) | 
|---|
| 133 | else tsttoi(boloRawMuVCN) | 
|---|
| 134 | else tsttoi(dilDAC) | 
|---|
| 135 | else tsttoi(dilSwitch) | 
|---|
| 136 | else tsttoi(serviceTemp) | 
|---|
| 137 | else tsttoi(sstDiode) | 
|---|
| 138 | else tsttoi(sstChannel) | 
|---|
| 139 | else tsttoi(sstDiodeCN) | 
|---|
| 140 | else tsttoi(sstChannelCN) | 
|---|
| 141 | else tsttoi(sstStarCnt) | 
|---|
| 142 | else tsttoi(sstStarZ) | 
|---|
| 143 | else tsttoi(sstStarF) | 
|---|
| 144 | else tsttoi(sstStarT) | 
|---|
| 145 | else tsttoi(gyroRaw) | 
|---|
| 146 | else tsttoi(gyroV) | 
|---|
| 147 | else tsttoi(gyroSpeed) | 
|---|
| 148 | else tsttoi(gpsTime) | 
|---|
| 149 | else tsttoi(longitude) | 
|---|
| 150 | else tsttoi(latitude) | 
|---|
| 151 | else tsttoi(altitude) | 
|---|
| 152 | else tsttoi(tsid) | 
|---|
| 153 | else tsttoi(azimuthBolo) | 
|---|
| 154 | else tsttoi(alphaRotAxis) | 
|---|
| 155 | else tsttoi(deltaRotAxis) | 
|---|
| 156 | else tsttoi(alphaSst) | 
|---|
| 157 | else tsttoi(deltaSst) | 
|---|
| 158 | else tsttoi(alphaZenith) | 
|---|
| 159 | else tsttoi(deltaZenith) | 
|---|
| 160 | else tsttoi(alphaFPAxis) | 
|---|
| 161 | else tsttoi(deltaFPAxis) | 
|---|
| 162 | else tsttoi(alphaBolo) | 
|---|
| 163 | else tsttoi(deltaBolo) | 
|---|
| 164 | else tsttoi(voyantEVO) | 
|---|
| 165 | else tsttoi(voyantEVF) | 
|---|
| 166 | else tsttoi(commandeEV0) | 
|---|
| 167 | else tsttoi(commandeEVF) | 
|---|
| 168 | else tsttoi(commandeEVB) | 
|---|
| 169 | else tsttoi(commandeEVV) | 
|---|
| 170 | else tsttoi(pressEnt3He) | 
|---|
| 171 | else tsttoi(debit3He) | 
|---|
| 172 | else tsttoi(pressSor3He) | 
|---|
| 173 | else tsttoi(pressEnt4He) | 
|---|
| 174 | else tsttoi(debit4He) | 
|---|
| 175 | else tsttoi(pressSor4He) | 
|---|
| 176 | else tsttoi(pressAirVanne) | 
|---|
| 177 | else tsttoi(pressPompChar) | 
|---|
| 178 | else tsttoi(pressMembrane) | 
|---|
| 179 | else tsttoi(pressExterne) | 
|---|
| 180 | else tsttoi(tensPile10T) | 
|---|
| 181 | else tsttoi(tensPileP18D) | 
|---|
| 182 | else tsttoi(tensPileM18D) | 
|---|
| 183 | else tsttoi(tensPile10B) | 
|---|
| 184 | else tsttoi(tensPileP18B) | 
|---|
| 185 | else tsttoi(tensPileM18B) | 
|---|
| 186 | else tsttoi(tensPileCh) | 
|---|
| 187 | else tsttoi(swPile5) | 
|---|
| 188 | else tsttoi(swPile15) | 
|---|
| 189 | else tsttoi(tempCaissH1) | 
|---|
| 190 | else tsttoi(tempCaissH2) | 
|---|
| 191 | else tsttoi(tempCaissB1) | 
|---|
| 192 | else tsttoi(tempCaissB2) | 
|---|
| 193 | else tsttoi(tempCaissTHe) | 
|---|
| 194 | else tsttoi(tempCaissPiles) | 
|---|
| 195 | else tsttoi(tempCaissDrv) | 
|---|
| 196 | else tsttoi(pressHeBain) | 
|---|
| 197 | else tsttoi(pressPirani) | 
|---|
| 198 | else { | 
|---|
| 199 | // cerr << "*Warning, unrecognized TOI " << line << endl; | 
|---|
| 200 | return false; | 
|---|
| 201 | } | 
|---|
| 202 | if (kind  == sampleNum || kind == mjd || kind == mutc) notrig = true; | 
|---|
| 203 | string toiname = keyw.substr(1); | 
|---|
| 204 | while (args != "") { | 
|---|
| 205 | if (args[0] == ' ') { | 
|---|
| 206 | x = args.find_first_not_of(' '); | 
|---|
| 207 | if (x==string::npos) break; | 
|---|
| 208 | args = args.substr(x); | 
|---|
| 209 | if (args == "") break; | 
|---|
| 210 | } | 
|---|
| 211 | x = args.find(' '); | 
|---|
| 212 | string opt = args.substr(0, x); | 
|---|
| 213 | args = (x>0) ? args.substr(x) : string(""); | 
|---|
| 214 | if (opt[0]>='0' && opt[0]<='9') { | 
|---|
| 215 | index = atoi(opt.c_str()); | 
|---|
| 216 | } else if (opt == "notrig") { | 
|---|
| 217 | notrig = true; | 
|---|
| 218 | } else if (opt == "repet") { | 
|---|
| 219 | repet = true; interp = false; | 
|---|
| 220 | } else if (opt == "interp") { | 
|---|
| 221 | interp = true; repet = false; | 
|---|
| 222 | } else if (opt == "flag") { | 
|---|
| 223 | flag = true; | 
|---|
| 224 | } | 
|---|
| 225 | } | 
|---|
| 226 | bool handled = processTOIReq(line, toiname, kind, index, interp, repet, flag, notrig); | 
|---|
| 227 | for (list<RequestHandler*>::iterator i = handlers.begin(); | 
|---|
| 228 | i != handlers.end(); i++) { | 
|---|
| 229 | handled |= (*i)->processTOIReq(line, toiname, kind, index, interp, repet, flag, notrig); | 
|---|
| 230 | } | 
|---|
| 231 | return handled; | 
|---|
| 232 | } | 
|---|
| 233 | return false; | 
|---|
| 234 | } | 
|---|
| 235 |  | 
|---|
| 236 |  | 
|---|
| 237 | bool TOISvr::processTOIReq(string /*line*/, string /*toiname*/, TOIKind kind, int index, | 
|---|
| 238 | bool interp, bool /*repet*/, bool /*flag*/, bool notrig) | 
|---|
| 239 | { | 
|---|
| 240 | if (index<0) index=0; | 
|---|
| 241 | addInfo(kind, index, !notrig, interp); | 
|---|
| 242 | return true; | 
|---|
| 243 | } | 
|---|
| 244 |  | 
|---|
| 245 | bool TOISvr::processOption(string key, string arg) | 
|---|
| 246 | { | 
|---|
| 247 | if (arg.length()>0 && arg[0] == ' ') { | 
|---|
| 248 | arg = arg.substr(arg.find_first_not_of(' ')); | 
|---|
| 249 | } | 
|---|
| 250 | if (key == "#MJDRANGE") { | 
|---|
| 251 | double tmin, tmax; | 
|---|
| 252 | sscanf(arg.c_str(), "%lg %lg", &tmin, &tmax); | 
|---|
| 253 | setMJDInterval(tmin, tmax); | 
|---|
| 254 | } else if (key == "#UTCRANGE") { | 
|---|
| 255 | double tmin, tmax; | 
|---|
| 256 | sscanf(arg.c_str(), "%lg %lg", &tmin, &tmax); | 
|---|
| 257 | setUTCInterval(tmin, tmax); | 
|---|
| 258 | } else if (key == "#SNRANGE") { | 
|---|
| 259 | long tmin, tmax; | 
|---|
| 260 | sscanf(arg.c_str(), "%ld %ld", &tmin, &tmax); | 
|---|
| 261 | setSNInterval(tmin, tmax); | 
|---|
| 262 | } else if (key == "#PATH") { | 
|---|
| 263 | setDirectory(arg); | 
|---|
| 264 | } else if (key == "#FILE") { | 
|---|
| 265 | addFile(arg); | 
|---|
| 266 | } else if (key == "#UNDERSAMPLE") { | 
|---|
| 267 | setUnderSample(atoi(arg.c_str())); | 
|---|
| 268 | } else if (key == "#RECORDER") { | 
|---|
| 269 | onBoardRecorderFiles(true); | 
|---|
| 270 | } else if (key == "#MJD0") { | 
|---|
| 271 | double t0; | 
|---|
| 272 | sscanf(arg.c_str(), "%lg", &t0); | 
|---|
| 273 | archParam.acq.tBlock0 = t0; | 
|---|
| 274 | } else if (key == "#UTCORIGIN") { | 
|---|
| 275 | double t0; | 
|---|
| 276 | sscanf(arg.c_str(), "%lg", &t0); | 
|---|
| 277 | archParam.acq.utcOrigin = t0; | 
|---|
| 278 | } else if (key == "#PERECH") { | 
|---|
| 279 | double t0; | 
|---|
| 280 | sscanf(arg.c_str(), "%lg", &t0); | 
|---|
| 281 | archParam.acq.perEch = t0; | 
|---|
| 282 | } else if (key == "#ASIGPS") { | 
|---|
| 283 | ASIGPS* gps = new ASIGPS(arg); | 
|---|
| 284 | gps->FitsDump("GPSDump.fits"); | 
|---|
| 285 | useAuxGPS(gps); | 
|---|
| 286 | } else if (key == "#INCLUDE") { | 
|---|
| 287 | ifstream f(arg.c_str()); | 
|---|
| 288 | readReq(f); | 
|---|
| 289 | } else { | 
|---|
| 290 | // cerr << "*Warning, unrecognized option " << line << endl; | 
|---|
| 291 | return false; | 
|---|
| 292 | } | 
|---|
| 293 | return true; | 
|---|
| 294 | } | 
|---|
| 295 |  | 
|---|
| 296 | void TOISvr::defaultInclude() { | 
|---|
| 297 | initDone = true; | 
|---|
| 298 | processRequest("#REQVERSION V_270999"); | 
|---|
| 299 | processRequest("#MJD0 1376.8358818"); | 
|---|
| 300 | processRequest("#PERECH 0.005836818076"); | 
|---|
| 301 | processRequest("#UTCORIGIN 1376.5"); | 
|---|
| 302 | processRequest("#ASIGPS ASI_GPS_archeops1999.ascii"); | 
|---|
| 303 | processRequest("#COMMENT Archtoi -- 27 september 1999 -- Eric Aubourg CEA/DAPNIA"); | 
|---|
| 304 | processRequest("#COMMENT ***WARNING***"); | 
|---|
| 305 | processRequest("#COMMENT ***SOME TOI'S ARE PRELIMINARY***"); | 
|---|
| 306 | processRequest("#COMMENT gyroSpeed is not calibrated"); | 
|---|
| 307 | processRequest("#COMMENT azimut/alpha/delta use galaxy crossings and ASI GPS data"); | 
|---|
| 308 | processRequest("#COMMENT   and assume no pendulation"); | 
|---|
| 309 | processRequest("#COMMENT Focal plane center elevation found at 41.5 deg"); | 
|---|
| 310 | processRequest("#COMMENT   with Jupiter"); | 
|---|
| 311 | processRequest("#COMMENT boloMuV2 is not protected against glitches"); | 
|---|
| 312 | processRequest("#COMMENT sst software has not been updated to last DY code"); | 
|---|
| 313 | processRequest("#COMMENT trajectory info only while italian TM got GPS info"); | 
|---|
| 314 |  | 
|---|
| 315 | } | 
|---|