| 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 { | 
|---|
| 165 | // cerr << "*Warning, unrecognized TOI " << line << endl; | 
|---|
| 166 | return false; | 
|---|
| 167 | } | 
|---|
| 168 | if (kind  == sampleNum || kind == mjd || kind == mutc) notrig = true; | 
|---|
| 169 | string toiname = keyw.substr(1); | 
|---|
| 170 | while (args != "") { | 
|---|
| 171 | if (args[0] == ' ') { | 
|---|
| 172 | x = args.find_first_not_of(' '); | 
|---|
| 173 | if (x==string::npos) break; | 
|---|
| 174 | args = args.substr(x); | 
|---|
| 175 | if (args == "") break; | 
|---|
| 176 | } | 
|---|
| 177 | x = args.find(' '); | 
|---|
| 178 | string opt = args.substr(0, x); | 
|---|
| 179 | args = (x>0) ? args.substr(x) : string(""); | 
|---|
| 180 | if (opt[0]>='0' && opt[0]<='9') { | 
|---|
| 181 | index = atoi(opt.c_str()); | 
|---|
| 182 | } else if (opt == "notrig") { | 
|---|
| 183 | notrig = true; | 
|---|
| 184 | } else if (opt == "repet") { | 
|---|
| 185 | repet = true; interp = false; | 
|---|
| 186 | } else if (opt == "interp") { | 
|---|
| 187 | interp = true; repet = false; | 
|---|
| 188 | } else if (opt == "flag") { | 
|---|
| 189 | flag = true; | 
|---|
| 190 | } | 
|---|
| 191 | } | 
|---|
| 192 | bool handled = processTOIReq(line, toiname, kind, index, interp, repet, flag, notrig); | 
|---|
| 193 | for (list<RequestHandler*>::iterator i = handlers.begin(); | 
|---|
| 194 | i != handlers.end(); i++) { | 
|---|
| 195 | handled |= (*i)->processTOIReq(line, toiname, kind, index, interp, repet, flag, notrig); | 
|---|
| 196 | } | 
|---|
| 197 | return handled; | 
|---|
| 198 | } | 
|---|
| 199 | return false; | 
|---|
| 200 | } | 
|---|
| 201 |  | 
|---|
| 202 |  | 
|---|
| 203 | bool TOISvr::processTOIReq(string /*line*/, string /*toiname*/, TOIKind kind, int index, | 
|---|
| 204 | bool interp, bool /*repet*/, bool /*flag*/, bool notrig) | 
|---|
| 205 | { | 
|---|
| 206 | if (index<0) index=0; | 
|---|
| 207 | addInfo(kind, index, !notrig, interp); | 
|---|
| 208 | return true; | 
|---|
| 209 | } | 
|---|
| 210 |  | 
|---|
| 211 | bool TOISvr::processOption(string key, string arg) | 
|---|
| 212 | { | 
|---|
| 213 | if (arg.length()>0 && arg[0] == ' ') { | 
|---|
| 214 | arg = arg.substr(arg.find_first_not_of(' ')); | 
|---|
| 215 | } | 
|---|
| 216 | if (key == "#MJDRANGE") { | 
|---|
| 217 | double tmin, tmax; | 
|---|
| 218 | sscanf(arg.c_str(), "%lg %lg", &tmin, &tmax); | 
|---|
| 219 | setMJDInterval(tmin, tmax); | 
|---|
| 220 | } else if (key == "#UTCRANGE") { | 
|---|
| 221 | double tmin, tmax; | 
|---|
| 222 | sscanf(arg.c_str(), "%lg %lg", &tmin, &tmax); | 
|---|
| 223 | setUTCInterval(tmin, tmax); | 
|---|
| 224 | } else if (key == "#SNRANGE") { | 
|---|
| 225 | long tmin, tmax; | 
|---|
| 226 | sscanf(arg.c_str(), "%ld %ld", &tmin, &tmax); | 
|---|
| 227 | setSNInterval(tmin, tmax); | 
|---|
| 228 | } else if (key == "#PATH") { | 
|---|
| 229 | setDirectory(arg); | 
|---|
| 230 | } else if (key == "#FILE") { | 
|---|
| 231 | addFile(arg); | 
|---|
| 232 | } else if (key == "#UNDERSAMPLE") { | 
|---|
| 233 | setUnderSample(atoi(arg.c_str())); | 
|---|
| 234 | } else if (key == "#RECORDER") { | 
|---|
| 235 | onBoardRecorderFiles(true); | 
|---|
| 236 | } else if (key == "#MJD0") { | 
|---|
| 237 | double t0; | 
|---|
| 238 | sscanf(arg.c_str(), "%lg", &t0); | 
|---|
| 239 | archParam.acq.tBlock0 = t0; | 
|---|
| 240 | } else if (key == "#UTCORIGIN") { | 
|---|
| 241 | double t0; | 
|---|
| 242 | sscanf(arg.c_str(), "%lg", &t0); | 
|---|
| 243 | archParam.acq.utcOrigin = t0; | 
|---|
| 244 | } else if (key == "#PERECH") { | 
|---|
| 245 | double t0; | 
|---|
| 246 | sscanf(arg.c_str(), "%lg", &t0); | 
|---|
| 247 | archParam.acq.perEch = t0; | 
|---|
| 248 | } else if (key == "#ASIGPS") { | 
|---|
| 249 | ASIGPS* gps = new ASIGPS(arg); | 
|---|
| 250 | gps->FitsDump("GPSDump.fits"); | 
|---|
| 251 | useAuxGPS(gps); | 
|---|
| 252 | } else if (key == "#INCLUDE") { | 
|---|
| 253 | ifstream f(arg.c_str()); | 
|---|
| 254 | readReq(f); | 
|---|
| 255 | } else { | 
|---|
| 256 | // cerr << "*Warning, unrecognized option " << line << endl; | 
|---|
| 257 | return false; | 
|---|
| 258 | } | 
|---|
| 259 | return true; | 
|---|
| 260 | } | 
|---|
| 261 |  | 
|---|
| 262 | void TOISvr::defaultInclude() { | 
|---|
| 263 | initDone = true; | 
|---|
| 264 | processRequest("#REQVERSION V_270999"); | 
|---|
| 265 | processRequest("#MJD0 1376.8358818"); | 
|---|
| 266 | processRequest("#PERECH 0.005836818076"); | 
|---|
| 267 | processRequest("#UTCORIGIN 1376.5"); | 
|---|
| 268 | processRequest("#ASIGPS ASI_GPS_archeops1999.ascii"); | 
|---|
| 269 | processRequest("#COMMENT Archtoi -- 27 september 1999 -- Eric Aubourg CEA/DAPNIA"); | 
|---|
| 270 | processRequest("#COMMENT ***WARNING***"); | 
|---|
| 271 | processRequest("#COMMENT ***SOME TOI'S ARE PRELIMINARY***"); | 
|---|
| 272 | processRequest("#COMMENT gyroSpeed is not calibrated"); | 
|---|
| 273 | processRequest("#COMMENT azimut/alpha/delta use galaxy crossings and ASI GPS data"); | 
|---|
| 274 | processRequest("#COMMENT   and assume no pendulation"); | 
|---|
| 275 | processRequest("#COMMENT Focal plane center elevation found at 41.5 deg"); | 
|---|
| 276 | processRequest("#COMMENT   with Jupiter"); | 
|---|
| 277 | processRequest("#COMMENT boloMuV2 is not protected against glitches"); | 
|---|
| 278 | processRequest("#COMMENT sst software has not been updated to last DY code"); | 
|---|
| 279 | processRequest("#COMMENT trajectory info only while italian TM got GPS info"); | 
|---|
| 280 |  | 
|---|
| 281 | } | 
|---|