Changeset 315 in Sophya for trunk/Poubelle/archTOI.old/toiiter.cc


Ignore:
Timestamp:
Jun 15, 1999, 3:53:04 PM (26 years ago)
Author:
ansari
Message:

Archeops 24, gestion byte-swap

File:
1 edited

Legend:

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

    r310 r315  
    11#include "toiiter.h"
     2#include "toiinterpolator.h"
    23#include <dirent.h>
    34
     
    1718 
    1819 tBlock0 = -1;
     20 
     21 rawIter = NULL;
     22 interp  = NULL;
     23 lastSample = -1;
     24 maxLookAhead = 1000;
    1925
    2026}
     
    3238  infos = x.infos;   
    3339
    34   file = new ArcheopsFile(*x.file);
     40  if (x.file)
     41    file = new ArcheopsFile(*x.file);
     42  else
     43    file = NULL;
     44   
     45  if (x.rawIter) {
     46    rawIter = new TOIIter(*x.rawIter);
     47    interp = new TOIInterpolator[infos.size()];
     48    for (int i=0; i<infos.size(); i++)
     49      interp[i] = x.interp[i];
     50  } else {
     51    rawIter = NULL;
     52    interp  = NULL;
     53  }
     54 
     55  lastSample = x.lastSample;
     56  maxLookAhead = x.maxLookAhead;
    3557}
    3658
    3759TOIIter::~TOIIter() {
    3860  delete file;
     61  delete rawIter;
     62  delete[] interp;
    3963}
    4064
    4165void TOIIter::Init() {
     66
     67  // $CHECK$ a deplacer, pour gerer repertoires...
    4268  if (directory == "") {
    4369    file = new ArcheopsFile(fileName);
     
    6086  // mieux en prenant le min de tous les delta_T.
    6187 
    62     tBlock0 = file->getStartMJD();
    63 #if 0
     88  tBlock0 = file->getStartMJD();
     89
    6490  file->pushMark();
    6591  if (file->lastGPS() || file->nextBlock(block_gps_mask)) {
     
    7197  }
    7298  file->popMark();
    73 #endif 
     99
     100  bool hasInterp = false;
    74101 
    75102  trigMask = 0;
    76103  for (vector<info>::iterator i = infos.begin(); i != infos.end(); i++) {
     104    if ((*i).interpolated) hasInterp = true;
    77105    if ((*i).triggering) {
    78106      switch ((*i).kind) {
     
    86114          break;
    87115        case azimut:
     116          file->needSSTProcessMask(SSTHandler::findPeriod);
    88117          trigMask |= block_sst_mask;
    89118          break;
    90         case alpha:
    91         case delta:
     119        case sstStarZ:
     120        case sstStarF:
     121          file->needSSTProcessMask(SSTHandler::findStars);
     122          trigMask |= block_sst_mask;
     123          break;
     124        case sstSignal:
     125          file->needSSTProcessMask(SSTHandler::rmveOffset);
     126          trigMask |= block_sst_mask;
     127          break;
     128        case alphaAxis:
     129        case deltaAxis:
     130        case alphaBolo:
     131        case deltaBolo:
     132          file->needSSTProcessMask(SSTHandler::findAxis);
    92133          trigMask |= block_sst_mask;
    93134          break;
     
    101142    imes = 0;
    102143  }
     144 
     145  if (hasInterp) {
     146    rawIter = new TOIIter(*this);
     147    interp = new TOIInterpolator[infos.size()];
     148    for (int i=0; i<infos.size(); i++) {
     149      rawIter->infos[i].interpolated = false;
     150    }
     151    delete file; file = NULL; // on ne travaille plus sur le fichier directement...
     152  }
    103153}
    104154
    105155bool TOIIter::NextFile() {
     156  if (rawIter)
     157    return rawIter->NextFile();
     158   
    106159  if (directory == "") {
    107160    return false;
     
    119172
    120173bool TOIIter::Next() {
    121 
     174  if (rawIter) {  // Delegation pour interpolation
     175    // Trouve prochain sample disponible
     176    for (int k=0; k<2; k++) {
     177      long smp = 2147483647L;
     178      for (int i=0; i<infos.size(); i++) {
     179        long ss = interp[i].nextSample(lastSample+1);
     180        if (ss > 0 && ss < smp) smp=ss;
     181      }
     182      if (smp != 2147483647L) {
     183        lastSample = smp;
     184        break;
     185      }
     186      if (!fetchAhead())  // tout le monde etait en bout de course,
     187        return false;     // on lit un echantillon, ca suffit, d'ou le k<2
     188    }
     189    // Verifie que tous les interpolateurs ont assez de donnees pour
     190    // trouver la valeur correspondante
     191    for (int i=0; i<infos.size(); i++) {
     192      //rif (infos[i].interpolated)
     193        while (interp[i].needMoreDataFor(lastSample) &&
     194               rawIter->getSampleIndex() - lastSample < maxLookAhead)
     195          if (!fetchAhead()) return false;
     196    }
     197   
     198    // On est pret...
     199    return true;
     200  }
    122201
    123202  // trigger sur info indexee dans bloc bolo ou bloc sst ?
     
    129208 
    130209  // soit pas d'info indexee, soit fin bloc courant...
    131  
    132   if (file->nextBlock(trigMask)) {
    133     return true;
    134   }
    135   if (!NextFile()) return false;
    136   return file->nextBlock(trigMask);
    137 }
    138 
    139  double TOIIter::getTime() {                // MJD
     210  while (1) {
     211    if (file->nextBlock(trigMask)) {
     212      while (file->sameBlockNumAhead()) {  // tant que meme numero de bloc, on lit
     213        if (!file->nextBlock()) {          // fin de fichier ?
     214          if (NextFile()) file->nextBlock();
     215          else break;
     216        }
     217      }
     218      return true;
     219    }
     220    if (!NextFile()) return false;
     221  }
     222}
     223
     224/* double TOIIter::getTime() {                // MJD
    140225   // le temps du bloc courant, en secondes
    141226   double dt = file->blockNum() * file->perBlock();
    142227   return tBlock0 + dt/86400. + imes*file->perEchant()/86400.;
    143228 }
    144  
    145  double TOIIter::getValue(int column) {
    146    if (column < 0 || column >= infos.size()) return -1;
     229 */
     230 
     231bool TOIIter::canGetValue(int column) {
     232   if (column < 0 || column >= infos.size()) return false;
     233   if (rawIter) {
     234       return interp[column].canGet(lastSample);
     235   }
    147236   TOIKind kind = infos[column].kind;
    148237   int index = infos[column].index;
    149238   switch (kind) {
     239     case sampleNum:
     240     case internalTime:
     241     case utc:
     242       return true;
     243     case boloTens:
     244     case boloRaw:
     245       return file->lastBolo() != NULL;
     246     case sstSignal:
     247       return file->lastSST() != NULL;
     248     case longitude:
     249     case latitude:
     250       return file->lastGPS() != NULL;
     251     case azimut:
     252     case alphaAxis:
     253     case deltaAxis:
     254       return (file->lastGPS() != NULL && file->lastSST() != NULL);
     255   }
     256   return false;
     257}
     258 
     259double TOIIter::getValue(int column) {
     260   if (column < 0 || column >= infos.size()) return -1;
     261   if (rawIter) {
     262     if (infos[column].interpolated)
     263       return interp[column].getIValue(lastSample);
     264     else
     265       return interp[column].getEValue(lastSample);
     266   }
     267   TOIKind kind = infos[column].kind;
     268   int index = infos[column].index;
     269   switch (kind) {
     270     case sampleNum:
     271       return file->blockNum() * file->nEchBlock() + imes;
     272     case internalTime:
     273       return (file->blockNum() * file->nEchBlock() + imes) * file->perEchant();
     274     case utc:
     275      /* printf("utc: %d %d %g %g %g\n",file->blockNum(),
     276         (file->blockNum() * file->nEchBlock() + imes),
     277         file->perEchant(),
     278         (file->blockNum() * file->nEchBlock() + imes) * file->perEchant()/86400.,
     279         tBlock0+(file->blockNum() * file->nEchBlock() + imes) * file->perEchant()/86400.); */
     280       return tBlock0+(file->blockNum() * file->nEchBlock() + imes) * file->perEchant()/86400.;
    150281     case boloTens:
    151282       return file->getMuVBolo(index, imes);
    152283     case boloRaw:
    153284       return file->getRawBolo(index, imes);
     285     case sstSignal:
     286       return file->getSSTSignal(index, imes);
    154287     case longitude:
    155288       return file->getGPSLong(); // $CHECK$ TBD gerer interpolation (dans file)
    156289     case latitude:
    157290       return file->getGPSLat();  // $CHECK$ TBD gerer interpolation (dans file)
    158       case azimut:
     291     case azimut:
    159292       return file->getAzimut(imes);
    160       case alpha:
     293     case alphaAxis:
    161294       return file->getAlpha(imes);
    162       case delta:
     295     case deltaAxis:
    163296       return file->getDelta(imes);
    164297   }
    165298   return -1;
    166  }
    167  
    168  bool   TOIIter::newValue(int column) {
     299}
     300 
     301bool   TOIIter::newValue(int column) {
    169302   if (column < 0 || column >= infos.size()) return false;
    170303   TOIKind kind = infos[column].kind;
    171304   switch (kind) {
     305     case sampleNum:
     306     case internalTime:
     307     case utc:
     308       return true;
    172309     case boloTens:
    173        return file->blockKind() == block_bolo;
     310       return file->blockNum() == file->getBoloBlockNum();
    174311     case boloRaw:
    175        return file->blockKind() == block_bolo;
     312       return file->blockNum() == file->getBoloBlockNum();
     313     case sstSignal:
     314       return file->blockNum() == file->getSSTBlockNum();
    176315     case longitude:
    177        return file->blockKind() == block_gps;
     316       return file->blockNum() == file->getGPSBlockNum() && imes==0;
    178317     case latitude:
    179        return file->blockKind() == block_gps;
    180       case azimut:
    181        return file->blockKind() == block_sst || file->blockKind() == block_bolo;
    182       case alpha:
    183        return file->blockKind() == block_sst || file->blockKind() == block_bolo;
    184       case delta:
    185        return file->blockKind() == block_sst || file->blockKind() == block_bolo;
     318       return file->blockNum() == file->getGPSBlockNum() && imes==0;
     319     case azimut:
     320       return true; // $CHECK$ with SSTHandler
     321     case alphaAxis:
     322       return true; // $CHECK$ with SSTHandler
     323     case deltaAxis:
     324       return true; // $CHECK$ with SSTHandler
    186325   }
    187326   return false;
    188  }
    189  
    190  bool   TOIIter::extendValue(int column) {
    191    return !newValue(column);
    192  }
    193  
    194  bool   TOIIter::interpValue(int /*column*/) {
    195    return false; // $CHECK$ TBD gerer interpolation
    196  }
    197  
    198  TOIKind TOIIter::getKind(int column) {
     327}
     328 
     329bool   TOIIter::extendValue(int column) {
     330   return (!infos[column].interpolated && !newValue(column));
     331}
     332 
     333bool   TOIIter::interpValue(int column) {
     334   return (infos[column].interpolated && !newValue(column));
     335}
     336 
     337TOIKind TOIIter::getKind(int column) {
    199338   if (column < 0 || column >= infos.size()) return (TOIKind)-1;
    200339   return infos[column].kind;
    201  }
    202  
    203  int TOIIter::getIndex(int column) {
     340}
     341 
     342int TOIIter::getIndex(int column) {
    204343   if (column < 0 || column >= infos.size()) return (TOIKind)-1;
    205344   return infos[column].index;
    206  }
     345}
     346
     347int TOIIter::getColTOI(TOIKind kind, int index) {
     348   for (int i=0; i<infos.size(); i++)
     349     if (infos[i].kind == kind && infos[i].index == index)
     350       return i;
     351   return -1;
     352}
     353
     354bool TOIIter::canGetTOI(TOIKind kind, int index) {
     355   int col = getColTOI(kind, index);
     356   if (col<0) return false;
     357   return canGetValue(col);
     358}
     359
     360double TOIIter::getTOI(TOIKind kind, int index) {
     361   int col = getColTOI(kind, index);
     362   if (col<0) return -9.e99;
     363   return getValue(col);
     364}
     365
    207366   
    208  int TOIIter::getSampleIndex() {
     367int TOIIter::getBlockSampleIndex() {
    209368   return imes;
    210  }
     369}
     370 
     371int TOIIter::getSampleIndex() {
     372   return file->blockNum() * file->nEchBlock() + imes;
     373}
     374 
     375bool TOIIter::fetchAhead() { // Seulement si delegation
     376  if (!rawIter) return false;
     377  if (!rawIter->Next()) return false;
     378  long sample = rawIter->getSampleIndex();
     379  for (int i=0; i<infos.size(); i++) {
     380    if (rawIter->canGetValue(i) && rawIter->newValue(i))
     381      interp[i].enterValue(rawIter->getValue(i), sample);
     382  }
     383  return true;
     384}
     385
Note: See TracChangeset for help on using the changeset viewer.