Changeset 407 in Sophya


Ignore:
Timestamp:
Sep 18, 1999, 2:08:23 PM (26 years ago)
Author:
ansari
Message:

apres grenoble

Location:
trunk/Poubelle/archTOI.old
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Poubelle/archTOI.old/archeopsfile.cc

    r405 r407  
    55#define utilitaires_de_block_archeops
    66#include "archeopsfile.h"
     7#include "gyrohandler.h"
     8
    79extern "C" {
    810#include "compress.h"
     
    4143  block_type_modele         peekBlock;
    4244 
    43   SSTHandler sstHandler;
    44   GPSParser  gpsParser;
     45  SSTHandler   sstHandler;
     46  GyroHandler  gyroHandler;
     47  GPSParser    gpsParser;
    4548};
    4649
     
    8588
    8689BlockSet::BlockSet(BlockSet const& x)
    87 : sstHandler(x.sstHandler)
     90: sstHandler(x.sstHandler), gyroHandler(x.gyroHandler)
    8891{
    8992  lastParam      = NULL;
     
    567570       blockSet->sstHandler.ProcessBlock((block_type_sst*)&blockSet->curBlock);
    568571     }
     572     case block_gyro : {
     573       blockSet->gyroHandler.ProcessBlock((block_type_gyro*)&blockSet->curBlock);
     574     }
    569575     case block_gps : {
    570576       blockSet->gpsParser.ProcessBlock((block_type_gps*)&blockSet->curBlock);
     
    673679  static char* buffer = 0;
    674680  static int4  debswp = debut_block_mesure;
    675   static int4  longmax = taille_maxi_block_archeops*20;
     681  static int4  longmax = taille_maxi_block_archeops*20; 
    676682  if (!buffer) {
    677683    buffer = new char[longmax];
     
    680686#endif
    681687  }
    682   fseek(f,pos,SEEK_SET);
    683   size_t read = fread(buffer,1,taille_maxi_block_archeops*2,f);
    684   //if (read<taille_maxi_block_archeops*2) return -1;
    685   for (int i=4; i<read; i+=4) {
    686     if (*(int4*)(buffer+i) == debswp) {
    687       cout << "trying to skip " << i << " bytes to pos="<<pos+i << endl;
    688       return pos+i;
     688  size_t read = longmax;
     689  while (read == longmax) {
     690    fseek(f,pos,SEEK_SET);
     691    read = fread(buffer,1,longmax,f);
     692    //if (read<taille_maxi_block_archeops*2) return -1;
     693    // EA 150999 changed i+=4 to i++ -> unaligned, but can lose bytes in flight recorder
     694    for (size_t i=4; i<read; i++) {
     695      if (*(int4*)(buffer+i) == debswp) {
     696        cout << "trying to skip " << i << " bytes to pos="<<pos+i << endl;
     697        return pos+i;
     698      }
    689699    }
     700    pos += read;
    690701  }
    691702  cout << "cannot find block start" << endl;
     
    758769}
    759770
     771int ArcheopsFile::getReglageBlockNum() {
     772  if (!lastReglage()) return -1;
     773  return numero_block(lastReglage());
     774}
     775
     776
    760777int ArcheopsFile::getSSTBlockNum() {
    761778  if (!lastSST()) return -1;
     
    864881}
    865882
     883double ArcheopsFile::getGainAmpli(int ibolo) {
     884     return gain_ampli(lastReglage()->reglage.bolo[ibolo]);
     885}
    866886
    867887// SST, gyros...
     
    895915}
    896916
    897 long ArcheopsFile::getGyro(int igyro, int imesure) {   
    898   if (igyro<0 || igyro>2) return 0;
    899   if (imesure<0 || imesure>= nb_per_block*2) return 0;
    900   block_type_gyro* blk = lastGyro() ;
    901   if (!blk) return 0;
    902 #if version_num<=25
    903   return blk->gyros[igyro][imesure]-32768.;
    904 #else
    905   return blk->gyro[igyro][imesure]-32768.;
    906 #endif
    907 }
     917long ArcheopsFile::getGyroRaw(int igyro, int imesure) {   
     918  return blockSet->gyroHandler.getRawSignal(imesure, igyro);
     919}
     920
     921double ArcheopsFile::getGyroTens(int igyro, int imesure) {   
     922  return blockSet->gyroHandler.getSignal(imesure, igyro);
     923}
     924
     925double ArcheopsFile::getGyroSpeed(int igyro, int imesure) {   
     926  return blockSet->gyroHandler.getSpeed(imesure, igyro);
     927}
     928
     929
    908930
    909931
  • trunk/Poubelle/archTOI.old/archeopsfile.h

    r394 r407  
    127127   
    128128  // Bolo
     129  int getReglageBlockNum();
    129130  int getBoloBlockNum();
    130131  long getRawBolo(int ibolo, int imesure);   // donnee brute, avec seulement soustraction offset
    131132  double getMuVBolo(int ibolo, int imesure); // microvolts, filtre avec filtre carre
     133  double getGainAmpli(int ibolo);
    132134 
    133135  // SST, gyros, etc
     
    142144 
    143145  int getGyroBlockNum();
    144   long getGyro(int iGyro, int imesure);
     146  long getGyroRaw(int iGyro, int imesure);
     147  double getGyroTens(int iGyro, int imesure);
     148  double getGyroSpeed(int iGyro, int imesure);
    145149 
    146150  double getAzimut(int imesure);
  • trunk/Poubelle/archTOI.old/archtoi.cc

    r406 r407  
    1212#include "archtoi.h"
    1313#include "archparam.h"
    14 #include "asigps.h"
    1514
    1615using namespace std;
     
    3938{
    4039  init();
    41   readReq(str);
     40  svr.readReq(str);
    4241}
    4342
     
    4746  init();
    4847  ifstream str(filename.c_str());
    49   readReq(str);
     48  svr.readReq(str);
    5049}
    5150
     
    5756  fptr = NULL;
    5857  ostr = NULL;
    59 }
    60 
    61 void ArchTOI::readReq(istream& str)
    62 {
    63    string line;
    64    while (str) {
    65      getline(str,line);
    66      if (!str) break;
    67      if (line[0] == '@') processTOIReq(line);
    68      else if (line[0] == '#')
    69        if (!processOption(line)) break;
    70    }
    71 }
    72 
    73 #define tsttoi(toi)   if (key == "@"#toi) kind = toi;
    74 
    75 void ArchTOI::processTOIReq(string line)
    76 {
    77   // find TOI kind, index and options
    78   TOIKind kind= (TOIKind)-1;
    79   int index=-1;
    80   bool interp=false;
    81   bool repet =false;
    82   bool flag  =false;
    83   bool notrig=false;
    84   int x = line.find(' ');
    85   string key = line.substr(0, x);
    86   string opts = (x>0) ? line.substr(x) : string("");
    87   tsttoi(sampleNum)
    88   else tsttoi(internalTime)
    89   else tsttoi(mjd)
    90   else tsttoi(boloTens)
    91   else tsttoi(boloRaw)
    92   else tsttoi(sstDiode)
    93   else tsttoi(sstChannel)
    94   else tsttoi(sstStarCnt)
    95   else tsttoi(sstStarZ)
    96   else tsttoi(sstStarF)
    97   else tsttoi(sstStarT)
    98   else tsttoi(gyroRaw)
    99   else tsttoi(gpsTime)
    100   else tsttoi(longitude)
    101   else tsttoi(latitude)
    102   else tsttoi(altitude)
    103   else tsttoi(tsid)
    104   else tsttoi(azimut)
    105   else tsttoi(alphaAxis)
    106   else tsttoi(deltaAxis)
    107   else tsttoi(alphaBolo)
    108   else tsttoi(deltaBolo)
    109   else {
    110     cerr << "*Warning, unrecognized TOI " << line << endl;
    111     return;
    112   }
    113   if (kind  == sampleNum) notrig = true;
    114   while (opts != "") {
    115     if (opts[0] == ' ') {
    116       opts = opts.substr(opts.find_first_not_of(' '));
    117       if (opts == "") break;
    118     }
    119     x = opts.find(' ');
    120     string opt = opts.substr(0, x);
    121     opts = (x>0) ? opts.substr(x) : string("");
    122     if (opt[0]>='0' && opt[0]<='9') {
    123       index = atoi(opt.c_str());
    124     } else if (opt == "notrig") {
    125       notrig = true;
    126     } else if (opt == "repet") {
    127       repet = true; interp = false;
    128     } else if (opt == "interp") {
    129       interp = true; repet = false;
    130     } else if (opt == "flag") {
    131       flag = true;
    132     }
    133   }
     58  requestVersion = "";
     59  svr.registerReqHandler(this);
     60}
     61
     62
     63bool ArchTOI::processTOIReq(string line, string toiname, TOIKind /*kind*/, int index,
     64                            bool interp, bool repet, bool flag, bool /*notrig*/)
     65{
    13466  headertoi.push_back(line);
    135   string toiname = key.substr(1);
    13667  if (index>=0) {
    13768    char idx[10];
     
    14475  toinames.push_back(toiname);
    14576  toiflags.push_back(flg((flag?hasflag:0)+((!repet&&!interp)?useNA:0)));
    146   if (index<0) index=0;
    147   svr.AddInfo(kind, index, !notrig, interp);
     77  return true;
    14878}
    14979
    150 bool ArchTOI::processOption(string line)
    151 {
    152   int x = line.find(' ');
    153   string key = line.substr(0, x);
    154   string arg = (x>0) ? line.substr(x) : string("");
     80bool ArchTOI::processOption(string key, string arg)
     81{
     82  string line=key; if (arg != "") line = line + " " + arg;
     83  headeropt.push_back(line);
    15584  if (arg.length()>0 && arg[0] == ' ') {
    15685    arg = arg.substr(arg.find_first_not_of(' '));
     
    16089  } else if (key == "#FITS") {
    16190    format = fits_fmt;
    162   } else if (key == "#TRANGE") {
    163     double tmin, tmax;
    164     sscanf(arg.c_str(), "%lg %lg", &tmin, &tmax);
    165     svr.SetTimeInterval(tmin, tmax);
    166   } else if (key == "#PATH") {
    167     svr.SetDirectory(arg);
    168   } else if (key == "#FILE") {
    169     svr.AddFile(arg);
    17091  } else if (key == "#UNDEF") {
    17192    undef=arg;
    17293  } else if (key == "#ALLBOLOS") {
    17394    allBolos=true;
    174   } else if (key == "#RECORDER") {
    175     svr.OnBoardRecorderFiles(true);
    176   } else if (key == "#MJD0") {
    177     double t0;
    178     sscanf(arg.c_str(), "%lg", &t0);
    179     archParam.acq.tBlock0 = t0;
    180   } else if (key == "#PERECH") {
    181     double t0;
    182     sscanf(arg.c_str(), "%lg", &t0);
    183     archParam.acq.perEch = t0;
    184   } else if (key == "#ASIGPS") {
    185     ASIGPS* gps = new ASIGPS(arg);
    186     gps->FitsDump("GPSDump.fits");
    187     svr.UseAuxGPS(gps);
    188   } else if (key == "#END") {
     95  } else if (key == "#REQVERSION") {
     96    requestVersion = arg;
     97  } else if (key == "#COMMENT") {
     98    comments.push_back(arg);
     99  } else {
    189100    return false;
    190   } else {
    191     cerr << "*Warning, unrecognized option " << line << endl;
    192     return true;
    193   }
    194  
    195   headeropt.push_back(line);
     101  }
     102 
    196103  return true;
    197104}
     
    215122 
    216123  cout << "starting query" << endl;
    217   TOIIter iter = svr.DoQuery();
     124  TOIIter iter = svr.doQuery();
    218125  (this->*openFile)(outfilename);
    219126  (this->*outHeader)(iter);
     
    388295    //fits_write_key(fptr, TINT, "BOLO", &j, NULL, &fitsStatus);
    389296  }
     297  fits_write_key_str(fptr, "TOIVERS", ARCHTOI_VERS, "Archtoi version",&fitsStatus);
     298  fits_write_key_str(fptr, "TOITAG", ARCHTOI_TAG, "Archtoi cvs tag",&fitsStatus);
     299  if (requestVersion != "")
     300    fits_write_key_str(fptr, "REQVERS", (char*) requestVersion.c_str(),
     301                       "Request options version",&fitsStatus);
    390302  fits_write_comment(fptr, "Generated with archtoi " ARCHTOI_VERS, &fitsStatus);
    391303  char line[80];
    392304  sprintf(line, "using archeops.h %d", version_num);
    393305  fits_write_comment(fptr, line, &fitsStatus);
     306  for (list<string>::iterator i = comments.begin(); i!=comments.end(); i++)
     307    fits_write_comment(fptr, (char*)((*i).c_str()), &fitsStatus);
    394308 
    395309  fitsLine = 1;
  • trunk/Poubelle/archTOI.old/archtoi.h

    r359 r407  
    1414using namespace std;
    1515
    16 class ArchTOI {
     16class ArchTOI : public RequestHandler {
    1717public:
    1818  ArchTOI(istream& str);
     
    2424  enum flg {hasflag = 1,
    2525            useNA   = 2};
     26           
     27  virtual bool processTOIReq(string line, string toiname, TOIKind toi, int index,
     28                             bool interp, bool repet, bool flag, bool notrig);
     29  virtual bool processOption(string keyw, string args);
    2630 
    2731protected:
    2832  void init();
    29   void readReq(istream& str);
    30   bool processOption(string line); // false when #END : stop processing...
    31   void processTOIReq(string line);
    3233  TOISvr svr;
    3334  list<string> headertoi;
     
    6162  int fitsLine;
    6263  ostream* ostr;
     64 
     65  string requestVersion;
     66  list<string> comments;
    6367};
    6468
    65 #define ARCHTOI_VERS "1.0"
     69#define ARCHTOI_VERS "1.1"
     70#define ARCHTOI_TAG  "notag"
    6671
    6772#endif
  • trunk/Poubelle/archTOI.old/toiiter.cc

    r406 r407  
    11// toiiter.cc
    22// Eric Aubourg         CEA/DAPNIA/SPP   juillet 1999
     3
     4#ifndef nb_max_bolo
     5#define _archeops               //  Acquisition Archeops (avec transputer)
     6#define programme
     7extern "C" {
     8#include "archeops.h"
     9}
     10#endif
    311
    412
     
    204212      switch ((*i).kind) {
    205213      case boloTens:
     214      case boloTens2:
    206215      case boloRaw:
    207         trigMask |= block_bolo_mask;
    208         break;
     216      case boloRes:
     217      case boloTemp:
     218      case boloRawCN:
     219      case boloTens2T:
     220        trigMask |= block_bolo_mask;
     221        break;
     222      case boloGainAmpli:
     223        trigMask |= block_reglage_mask;
     224        break;
    209225      case gpsTime:
    210226      case longitude:
    211227      case latitude:
    212228      case altitude:
    213         trigMask |= block_gps_mask;
    214         break;
     229        trigMask |= block_gps_mask;
     230        break;
    215231      case azimut:
    216         file->needSSTProcessMask(SSTHandler::findPeriod);
    217         trigMask |= block_sst_mask;
    218         break;
     232        file->needSSTProcessMask(SSTHandler::findPeriod);
     233        trigMask |= block_sst_mask;
     234        break;
    219235      case sstStarCnt:
    220236      case sstStarZ:
    221237      case sstStarF:
    222238      case sstStarT:
    223         file->needSSTProcessMask(SSTHandler::findStars);
    224         trigMask |= block_sst_mask;
    225         break;
     239        file->needSSTProcessMask(SSTHandler::findStars);
     240        trigMask |= block_sst_mask;
     241        break;
    226242      case sstDiode:
    227         file->needSSTProcessMask(SSTHandler::permDiode);
    228         trigMask |= block_sst_mask;
    229         break;
     243      case sstDiodeCN:
     244        file->needSSTProcessMask(SSTHandler::permDiode);
     245        trigMask |= block_sst_mask;
     246        break;
    230247      case sstChannel:
    231         trigMask |= block_sst_mask;
    232         break;
     248      case sstChannelCN:
     249        trigMask |= block_sst_mask;
     250        break;
    233251      case gyroRaw:
    234         trigMask |= block_gyro_mask;
    235         break;
     252      case gyroTens:
     253        trigMask |= block_gyro_mask;
     254        break;
     255      case gyroSpeed:
     256        trigMask |= block_gyro_mask; // $CHECK$ + info to calibrate gyros
     257        break;
    236258      case alphaAxis:
    237259      case deltaAxis:
     260      case alphaSst:
     261      case deltaSst:
    238262      case alphaBolo:
    239263      case deltaBolo:
    240         file->needSSTProcessMask(SSTHandler::findAxis);
    241         trigMask |= block_sst_mask;
    242         break;
     264        file->needSSTProcessMask(SSTHandler::findAxis);
     265        trigMask |= block_sst_mask;
     266        break;
    243267      }
    244268    }
     
    407431     return true;
    408432   case boloTens:
     433   case boloTens2:
     434   case boloTens2T:
     435   case boloRes:
     436   case boloRawCN:
    409437     if (imes==0 && file->llastBolo()==NULL) return false;
    410438     return file->lastBolo() != NULL;
    411439   case boloRaw:
    412440     return file->lastBolo() != NULL;
     441   case boloGainAmpli:
     442     return file->lastReglage() != NULL;
    413443   case sstDiode:
    414444   case sstChannel:
     445   case sstDiodeCN:
     446   case sstChannelCN:
    415447     return file->lastSST() != NULL;
    416448   case sstStarCnt:
     
    423455   }
    424456   case gyroRaw:
     457   case gyroTens:
     458   case gyroSpeed:
    425459     return (file->lastGyro() != NULL);
    426460   case gpsTime:
     
    450484}
    451485
     486
    452487double TOIIter::getValue(int column) {
    453488  if (!initDone) Init();
     
    484519   case boloRaw:
    485520     return file->getRawBolo(index, imes);
     521   case boloGainAmpli:
     522     return file->getGainAmpli(index);
    486523   case sstDiode:
    487524     return file->getSSTSignal(index, imes);
     
    497534     return file->getSSTStarT(index, imes);
    498535   case gyroRaw:
    499      return file->getGyro(index, imes);
     536     return file->getGyroRaw(index, imes);
     537   case gyroTens:
     538     return file->getGyroTens(index, imes);
     539   case gyroSpeed:
     540     return file->getGyroSpeed(index, imes);
    500541   case gpsTime:
    501542     return file->getGPSUTC();
     
    540581     case boloRaw:
    541582       return file->blockNum() == file->getBoloBlockNum();
     583     case boloGainAmpli:
     584       return file->blockNum() == file->getReglageBlockNum() && imes==0;
    542585     case sstChannel:
    543586     case sstDiode:
     
    548591       return file->blockNum() == file->getSSTBlockNum();
    549592     case gyroRaw:
     593     case gyroTens:
     594     case gyroSpeed:
    550595       return file->blockNum() == file->getGyroBlockNum();
    551596     case gpsTime:
  • trunk/Poubelle/archTOI.old/toiiter.h

    r401 r407  
    1515
    1616enum TOIKind {
    17   sampleNum,  // Numero d''echantillon (timer interne transputer)
    18   internalTime, // temps transputer depuis debut manip, en secondes.
    19   mjd,        // UTC (en jours, MJD = JD - 2450000). index=0 : premier bloc GPS. 1: + sioux.
    20   boloTens,   // tension en microVolts, filtree avec filtre carre indexe par bolometre
    21   boloRaw,    // tension brute, non filtree indexe par bolometre
    22   boloTemp,   // Kelvins
    23   sstDiode,   // signal brut SST, indice = diode, 0-45
    24   sstChannel, // signal brut SST, indice = canal, 0-47
    25   sstStarCnt, // nombre d''etoiles detectees durant ce sample
    26   sstStarZ,   // numero de diode d''une eventuelle etoile,   i=etoile 0..n
    27   sstStarF,   // flux d''une eventuelle etoile,             <0 si moins de i+1 etoiles
    28   sstStarT,   // temps d''une eventuelle etoile,            <0 si moins de i+1 etoiles
    29   gyroRaw,    // valeur brute du gyro, index = 0,1,2
    30   gpsTime,    // temps fourni par GPS
    31   longitude,  // position ballon
    32   latitude,   // position ballon
    33   altitude,   // position ballon
    34   tsid,       // temps sideral en secondes
    35   azimut,     // a preciser, reconstruit SST, magneto, autres...
    36   alphaAxis,  //
    37   deltaAxis,  //
    38   alphaSst,  //
    39   deltaSst,  //
    40   alphaBolo,  // sur le ciel, indexe par bolometre
    41   deltaBolo   // sur le ciel, indexe par bolometre
    42 };
     17  sampleNum,     // Numero d''echantillon (timer interne transputer)
     18  internalTime,  // temps transputer depuis debut manip, en secondes.
     19  mjd,           // UTC (en jours, MJD = JD - 2450000). index=0 : premier bloc GPS. 1: + sioux.
     20  boloTens,      // tension en microVolts, filtree avec filtre carre indexe par bolometre
     21  boloTens2,     // tension en microVolts, avec soustraction offset filtre
     22  boloRaw,       // tension brute en microVolts, non filtree indexe par bolometre, sans chgt signe
     23  boloRes,       // Resistance, ohms
     24  boloTemp,      // Kelvins, need R(T) -> N/A
     25  boloGainAmpli, // gain de l'ampli du bolo
     26  boloRawCN,     // compression noise on bolo raw
     27  boloTens2T,    // total, microVolts, avec consigne DAC
     28  sstDiode,      // signal brut SST, indice = diode, 0-45
     29  sstChannel,    // signal brut SST, indice = canal, 0-47
     30  sstDiodeCN,    // compression noise
     31  sstChannelCN,  // compression noise
     32  sstStarCnt,    // nombre d''etoiles detectees durant ce sample
     33  sstStarZ,      // numero de diode d''une eventuelle etoile,   i=etoile 0..n
     34  sstStarF,      // flux d''une eventuelle etoile,             <0 si moins de i+1 etoiles
     35  sstStarT,      // temps d''une eventuelle etoile,            <0 si moins de i+1 etoiles
     36  gyroRaw,       // valeur brute du gyro, index = 0,1,2
     37  gyroTens,      // tension gyro, V, index = 0,1,2
     38  gyroSpeed,     // vitesse gyro, deg/s, index = 0,1,2, calibree...
     39  gpsTime,       // temps fourni par GPS
     40  longitude,     // position ballon, degrees
     41  latitude,      // position ballon, degrees
     42  altitude,      // position ballon, m
     43  tsid,          // temps sideral en secondes
     44  azimut,        // azimut centre optique ???
     45  alphaAxis,     //
     46  deltaAxis,     //
     47  alphaSst,      //
     48  deltaSst,      //
     49  alphaBolo,     // sur le ciel, indexe par bolometre
     50  deltaBolo      // sur le ciel, indexe par bolometre
     51};
    4352
    4453class TOIInterpolator;
  • trunk/Poubelle/archTOI.old/toisvr.cc

    r394 r407  
    22// Eric Aubourg         CEA/DAPNIA/SPP   juillet 1999
    33
    4 
     4#include <iostream.h>
    55#include "toisvr.h"
     6#include "archparam.h"
     7#include "asigps.h"
    68
    79TOISvr::TOISvr()
    810{}
    911
    10 void TOISvr::SetDirectory(string d) {
     12// To avoid special copy constructor handling, we will not
     13// register ourself to us... Special dealing in readReq.
     14
     15void TOISvr::setDirectory(string d) {
    1116  iter.directory = d;
    1217}
    1318
    14 void TOISvr::AddFile(string f) {
     19void TOISvr::addFile(string f) {
    1520  iter.files.insert(f);
    1621}
    1722
    18 void TOISvr::UseAuxGPS(AuxGPS* gps) {
     23void TOISvr::useAuxGPS(AuxGPS* gps) {
    1924  if (iter.auxGPS) delete iter.auxGPS;
    2025  iter.auxGPS = gps;
     
    2227
    2328
    24 void TOISvr::OnBoardRecorderFiles(bool x) {
     29void TOISvr::onBoardRecorderFiles(bool x) {
    2530  iter.isOnBoardRecorder = x;
    2631}
    2732
    2833 
    29 void TOISvr::SetTimeInterval(double tStart, double tEnd) {
     34void TOISvr::setTimeInterval(double tStart, double tEnd) {
    3035  if (tStart>0) iter.tStart = tStart;
    3136  if (tEnd>0)   iter.tEnd = tEnd;
    3237}
    3338 
    34 void TOISvr::AddInfo(TOIKind kind, int index, bool triggering, bool interp) {
     39void TOISvr::addInfo(TOIKind kind, int index, bool triggering, bool interp) {
    3540  TOIIter::info i;
    3641  i.kind = kind;
     
    4146}
    4247
    43 void TOISvr::AddInfo(TOIKind kind, bool triggering, bool interp) {
    44   AddInfo(kind,0,triggering,interp);
     48void TOISvr::addInfo(TOIKind kind, bool triggering, bool interp) {
     49  addInfo(kind,0,triggering,interp);
    4550}
    4651 
    47 TOIIter TOISvr::DoQuery() {
     52TOIIter TOISvr::doQuery() {
    4853  //iter.Init();
    4954  return iter;
    5055}
     56
     57void TOISvr::registerReqHandler(RequestHandler* h) {
     58  handlers.push_back(h);
     59}
     60
     61
     62void 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
     78bool 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(boloTens2T)
     108    else tsttoi(boloRawCN)
     109    else tsttoi(sstDiode)
     110    else tsttoi(sstChannel)
     111    else tsttoi(sstDiodeCN)
     112    else tsttoi(sstChannelCN)
     113    else tsttoi(sstStarCnt)
     114    else tsttoi(sstStarZ)
     115    else tsttoi(sstStarF)
     116    else tsttoi(sstStarT)
     117    else tsttoi(gyroRaw)
     118    else tsttoi(gyroTens)
     119    else tsttoi(gyroSpeed)
     120    else tsttoi(gpsTime)
     121    else tsttoi(longitude)
     122    else tsttoi(latitude)
     123    else tsttoi(altitude)
     124    else tsttoi(tsid)
     125    else tsttoi(azimut)
     126    else tsttoi(alphaAxis)
     127    else tsttoi(deltaAxis)
     128    else tsttoi(alphaSst)
     129    else tsttoi(deltaSst)
     130    else tsttoi(alphaBolo)
     131    else tsttoi(deltaBolo)
     132    else {
     133      // cerr << "*Warning, unrecognized TOI " << line << endl;
     134      return false;
     135    }
     136    if (kind  == sampleNum || kind == mjd) notrig = true;
     137    string toiname = keyw.substr(1);
     138    while (args != "") {
     139      if (args[0] == ' ') {
     140        args = args.substr(args.find_first_not_of(' '));
     141        if (args == "") break;
     142      }
     143      x = args.find(' ');
     144      string opt = args.substr(0, x);
     145      args = (x>0) ? args.substr(x) : string("");
     146      if (opt[0]>='0' && opt[0]<='9') {
     147        index = atoi(opt.c_str());
     148      } else if (opt == "notrig") {
     149        notrig = true;
     150      } else if (opt == "repet") {
     151        repet = true; interp = false;
     152      } else if (opt == "interp") {
     153        interp = true; repet = false;
     154      } else if (opt == "flag") {
     155        flag = true;
     156      }
     157    }
     158    bool handled = processTOIReq(line, toiname, kind, index, interp, repet, flag, notrig);
     159    for (list<RequestHandler*>::iterator i = handlers.begin();
     160         i != handlers.end(); i++) {
     161      handled |= (*i)->processTOIReq(line, toiname, kind, index, interp, repet, flag, notrig);
     162    }
     163    return handled;
     164  }
     165  return false;
     166}
     167
     168
     169bool TOISvr::processTOIReq(string /*line*/, string /*toiname*/, TOIKind kind, int index,
     170                           bool interp, bool /*repet*/, bool /*flag*/, bool notrig)
     171{
     172  if (index<0) index=0;
     173  addInfo(kind, index, !notrig, interp);
     174  return true;
     175}
     176
     177bool TOISvr::processOption(string key, string arg)
     178{
     179  if (arg.length()>0 && arg[0] == ' ') {
     180    arg = arg.substr(arg.find_first_not_of(' '));
     181  }
     182  if (key == "#TRANGE") {
     183    double tmin, tmax;
     184    sscanf(arg.c_str(), "%lg %lg", &tmin, &tmax);
     185    setTimeInterval(tmin, tmax);
     186  } else if (key == "#PATH") {
     187    setDirectory(arg);
     188  } else if (key == "#FILE") {
     189    addFile(arg);
     190  } else if (key == "#RECORDER") {
     191    onBoardRecorderFiles(true);
     192  } else if (key == "#MJD0") {
     193    double t0;
     194    sscanf(arg.c_str(), "%lg", &t0);
     195    archParam.acq.tBlock0 = t0;
     196  } else if (key == "#PERECH") {
     197    double t0;
     198    sscanf(arg.c_str(), "%lg", &t0);
     199    archParam.acq.perEch = t0;
     200  } else if (key == "#ASIGPS") {
     201    ASIGPS* gps = new ASIGPS(arg);
     202    gps->FitsDump("GPSDump.fits");
     203    useAuxGPS(gps);
     204  } else {
     205    // cerr << "*Warning, unrecognized option " << line << endl;
     206    return false;
     207  }
     208  return true;
     209}
  • trunk/Poubelle/archTOI.old/toisvr.h

    r394 r407  
    77
    88#include "toiiter.h"
     9#include <list>
    910
    1011class AuxGPS;
    1112
    12 class TOISvr {
     13class RequestHandler {
     14public:
     15  virtual bool processTOIReq(string line, string toiname, TOIKind toi, int index,
     16                             bool interp, bool repet, bool flag, bool notrig)=0;
     17  virtual bool processOption(string keyw, string args)=0;
     18};
     19
     20class TOISvr : public RequestHandler {
    1321public:
    1422  TOISvr();
    1523 
    16   void SetDirectory(string);
    17   void AddFile(string);
    18   void OnBoardRecorderFiles(bool);
    19   void UseAuxGPS(AuxGPS* gps);
     24  void setDirectory(string);
     25  void addFile(string);
     26  void onBoardRecorderFiles(bool);
     27  void useAuxGPS(AuxGPS* gps);
    2028 
    21   void SetTimeInterval(double tStart, double tEnd);
     29  void setTimeInterval(double tStart, double tEnd);
    2230 
    23   void AddInfo(TOIKind kind, int index, bool triggering=true, bool interp=false);
    24   void AddInfo(TOIKind kind, bool triggering=true, bool interp=false);
     31  void addInfo(TOIKind kind, int index, bool triggering=true, bool interp=false);
     32  void addInfo(TOIKind kind, bool triggering=true, bool interp=false);
    2533 
    26   TOIIter DoQuery();
     34  void readReq(istream& s);
    2735 
     36  TOIIter doQuery();
     37
     38  bool processRequest(string line);
     39  void registerReqHandler(RequestHandler*);
     40  virtual bool processTOIReq(string line, string toiname, TOIKind toi, int index,
     41                             bool interp, bool repet, bool flag, bool notrig);
     42  virtual bool processOption(string keyw, string args);
    2843 
    2944protected:
    3045  TOIIter iter;
     46  list<RequestHandler*> handlers;
    3147};
    3248
Note: See TracChangeset for help on using the changeset viewer.