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