Index: trunk/Poubelle/archTOI.old/archeopsfile.cc
===================================================================
--- trunk/Poubelle/archTOI.old/archeopsfile.cc	(revision 533)
+++ trunk/Poubelle/archTOI.old/archeopsfile.cc	(revision 534)
@@ -5,5 +5,4 @@
 #define utilitaires_de_block_archeops
 #include "archeopsfile.h"
-#include "gyrohandler.h"
 
 extern "C" {
@@ -43,8 +42,4 @@
   block_type_modele         curBlock;
   block_type_modele         peekBlock;
-  
-  SSTHandler   sstHandler;
-  GyroHandler  gyroHandler;
-  GPSParser    gpsParser;
 };
 
@@ -89,5 +84,4 @@
 
 BlockSet::BlockSet(BlockSet const& x) 
-: sstHandler(x.sstHandler), gyroHandler(x.gyroHandler)
 {
   lastParam      = NULL;
@@ -255,4 +249,12 @@
   }
 }
+
+#ifdef __MWERKS__
+#pragma mark -
+#endif
+#ifdef __MWERKS__
+#pragma mark -
+#endif
+
 
 ArcheopsFile::ArcheopsFile(string const& fname) {
@@ -404,23 +406,4 @@
 }
 
-#define	 bitmot			24		// nb de bit horloge dans un mot ADC
-
-double ArcheopsFile::perEchant() { // periode d'echantillonage pour le dernier bloc reglage
-  double p,f1,f2,f3;
-  int pp;
-  if (!lastReglage()) return -1;
-  pp=lastReglage()->reglage.horloge.periode;
-  p=pp/5.;
-  f1=1000/p;f2=f1/bitmot;f3=f2*1000./(double)(lastReglage()->reglage.horloge.nb_mesures);
-  return 0.5/f3;					//  2 fois la frequence de modulation
-}
-
-double ArcheopsFile::perBlock() {  // duree (en secondes) correspondant a un bloc bolo
-  return perEchant() * (double)lastParam()->param.n_per_block*2.;
-}
-
-int ArcheopsFile::nEchBlock() {  // Nb d'echantillons dans un bloc
-  return lastParam()->param.n_per_block*2;
-}
 
 string  ArcheopsFile::blockKdName() {
@@ -448,53 +431,37 @@
 }
 
-
-block_type_param* ArcheopsFile::lastParam() {
-  return blockSet->lastParam;
-}
-block_type_journal* ArcheopsFile::lastJournal() {
-  return blockSet->lastJournal;
-}
-block_type_reglage* ArcheopsFile::lastReglage() {
-  return blockSet->lastReglage;
-}
-block_type_dilution* ArcheopsFile::lastDilution() {
-  return blockSet->lastDilution;
-}
-block_type_gps* ArcheopsFile::lastGPS() {
-  return blockSet->lastGPS;
-}
-block_type_une_periode* ArcheopsFile::lastUnePeriode() {
-  return blockSet->lastUnePeriode;
-}
-block_type_synchro_sol* ArcheopsFile::lastSynchroSol() {
-  return blockSet->lastSynchroSol;
-}
-block_type_pointage_sol* ArcheopsFile::lastPointageSol() {
-  return blockSet->lastPointageSol;
-}
-block_type_bolo* ArcheopsFile::lastBolo() {
-  return blockSet->lastBolo;
-} 
-block_type_bolo* ArcheopsFile::llastBolo() {
-  return blockSet->llastBolo;
-} 
-block_type_gyro* ArcheopsFile::lastGyro() {
-  return blockSet->lastGyro;
-}
-block_type_sst* ArcheopsFile::lastSST() {
-  return blockSet->lastSST;
-}
-block_type_bolo_comprime* ArcheopsFile::lastBoloComp() {
-  return blockSet->lastBoloComp;
-} 
-block_type_gyro_comprime* ArcheopsFile::lastGyroComp() {
-  return blockSet->lastGyroComp;
-}
-block_type_sst_comprime* ArcheopsFile::lastSSTComp() {
-  return blockSet->lastSSTComp;
-}
-
 void ArcheopsFile::forceBlock(block_type_modele* blk) {
   blockSet->setBloc(*blk);
+}
+
+long ArcheopsFile::searchNextBlock(long pos) {
+  static char* buffer = 0;
+  static int4  debswp = debut_block_mesure;
+  static int4  longmax = taille_maxi_block_archeops*20; 
+  if (!buffer) {
+    buffer = new char[longmax];
+#ifdef SWAP
+    bswap4(&debswp);
+#endif
+  }
+  long read = longmax;
+  while (read == longmax) {
+    fseek(f,pos,SEEK_SET);
+    read = fread(buffer,1,longmax,f);
+    //if (read<taille_maxi_block_archeops*2) return -1; 
+    // EA 150999 changed i+=4 to i++ -> unaligned, but can lose bytes in flight recorder
+#ifndef __DECCXX
+#define __unaligned 
+#endif
+     for (long i=4; i<read; i++) {
+      if (*(__unaligned int4*)(buffer+i) == debswp) {
+        cout << "trying to skip " << i << " bytes to pos="<<pos+i << endl;
+	    return pos+i;
+      }
+    }
+    pos += read;
+  }
+  cout << "cannot find block start" << endl;
+  return -1;
 }
 
@@ -531,9 +498,9 @@
        memcpy(&blockSet->curBlock,&blk2,sizeof(blk2));
        curKind = block_bolo;
+       postProcessBlock();
        break;
      }
      case block_sst_comprime: {  
        blockSet->setRawBloc(blockSet->curBlock);
-       if (!blockSet->sstHandler.NeedBlocks()) break; // inutile de decompresser
        block_type_sst blk2;
        block_type_sst_comprime* blk = (block_type_sst_comprime*) &blockSet->curBlock;
@@ -566,20 +533,68 @@
        memcpy(&blockSet->curBlock,&blk2,sizeof(blk2));
        curKind = block_sst;
-       //       cout << "process " << numero_block(&blockSet->curBlock) << "\n";
-       blockSet->sstHandler.ProcessBlock((block_type_sst*)&blockSet->curBlock);
+       postProcessBlock();
        break;
      }
-     case block_sst : {
-       //       cout << "process " << numero_block(&blockSet->curBlock) << "\n";
-       blockSet->sstHandler.ProcessBlock((block_type_sst*)&blockSet->curBlock);
-     }
-     case block_gyro : {
-       blockSet->gyroHandler.ProcessBlock((block_type_gyro*)&blockSet->curBlock);
-     }
-     case block_gps : {
-       blockSet->gpsParser.ProcessBlock((block_type_gps*)&blockSet->curBlock);
-     }
-  }
-}
+// Delegation a tous les producers qui traitent des blocs bruts
+  }
+}
+
+
+
+#ifdef __MWERKS__
+#pragma mark -
+#endif
+
+block_type_param* ArcheopsFile::lastParam() {
+  return blockSet->lastParam;
+}
+block_type_journal* ArcheopsFile::lastJournal() {
+  return blockSet->lastJournal;
+}
+block_type_reglage* ArcheopsFile::lastReglage() {
+  return blockSet->lastReglage;
+}
+block_type_dilution* ArcheopsFile::lastDilution() {
+  return blockSet->lastDilution;
+}
+block_type_gps* ArcheopsFile::lastGPS() {
+  return blockSet->lastGPS;
+}
+block_type_une_periode* ArcheopsFile::lastUnePeriode() {
+  return blockSet->lastUnePeriode;
+}
+block_type_synchro_sol* ArcheopsFile::lastSynchroSol() {
+  return blockSet->lastSynchroSol;
+}
+block_type_pointage_sol* ArcheopsFile::lastPointageSol() {
+  return blockSet->lastPointageSol;
+}
+block_type_bolo* ArcheopsFile::lastBolo() {
+  return blockSet->lastBolo;
+} 
+block_type_bolo* ArcheopsFile::llastBolo() {
+  return blockSet->llastBolo;
+} 
+block_type_gyro* ArcheopsFile::lastGyro() {
+  return blockSet->lastGyro;
+}
+block_type_sst* ArcheopsFile::lastSST() {
+  return blockSet->lastSST;
+}
+block_type_bolo_comprime* ArcheopsFile::lastBoloComp() {
+  return blockSet->lastBoloComp;
+} 
+block_type_gyro_comprime* ArcheopsFile::lastGyroComp() {
+  return blockSet->lastGyroComp;
+}
+block_type_sst_comprime* ArcheopsFile::lastSSTComp() {
+  return blockSet->lastSSTComp;
+}
+
+#ifdef __MWERKS__
+#pragma mark -
+#endif
+
+
 
 void ArcheopsFile::saveCurBlock() {
@@ -680,36 +695,7 @@
 #endif
 
-long ArcheopsFile::searchNextBlock(long pos) {
-  static char* buffer = 0;
-  static int4  debswp = debut_block_mesure;
-  static int4  longmax = taille_maxi_block_archeops*20; 
-  if (!buffer) {
-    buffer = new char[longmax];
-#ifdef SWAP
-    bswap4(&debswp);
-#endif
-  }
-  size_t read = longmax;
-  while (read == longmax) {
-    fseek(f,pos,SEEK_SET);
-    read = fread(buffer,1,longmax,f);
-    //if (read<taille_maxi_block_archeops*2) return -1; 
-    // EA 150999 changed i+=4 to i++ -> unaligned, but can lose bytes in flight recorder
-#ifndef __DECCXX
-#define __unaligned 
-#endif
-     for (size_t i=4; i<read; i++) {
-      if (*(__unaligned int4*)(buffer+i) == debswp) {
-	cout << "trying to skip " << i << " bytes to pos="<<pos+i << endl;
-	return pos+i;
-      }
-    }
-    pos += read;
-  }
-  cout << "cannot find block start" << endl;
-  return -1;
-}
-
-
+#ifdef __MWERKS__
+#pragma mark -
+#endif
 
 
@@ -762,5 +748,5 @@
 }
 
-void ArcheopsFile::setUTCOffset(int UTCOffset) {
+void ArcheopsFile::setUTCOffset(double UTCOffset) {
   utcOffset = UTCOffset;
   startMJD = rawMJD - utcOffset/24.;
@@ -771,346 +757,2 @@
 }
 
-int ArcheopsFile::getBoloBlockNum() {
-  if (!lastBolo()) return -1;
-  return numero_block(lastBolo());
-}
-
-int ArcheopsFile::getBoloCompBlockNum() {
-  if (!lastBolo()) return -1;
-  return numero_block(lastBoloComp());
-}
-
-int ArcheopsFile::getReglageBlockNum() {
-  if (!lastReglage()) return -1;
-  return numero_block(lastReglage());
-}
-
-int ArcheopsFile::getDilutionBlockNum() {
-  if (!lastDilution()) return -1;
-  return numero_block(lastDilution());
-}
-
-
-int ArcheopsFile::getSSTBlockNum() {
-  if (!lastSST()) return -1;
-  return numero_block(lastSST());
-}
-
-int ArcheopsFile::getSSTCompBlockNum() {
-  if (!lastSST()) return -1;
-  return numero_block(lastSSTComp());
-}
-
-
-
-int ArcheopsFile::getGyroBlockNum() {
-  if (!lastGyro()) return -1;
-  return numero_block(lastGyro());
-}
-
-
-// GPS
-// $GPGGA,hhmmss.ss,ddmm.mmmm,n,dddmm.mmmm,e,q,ss,y.y,a.a,z,
-
-
-int ArcheopsFile::getGPSBlockNum() {
-  if (!lastGPS()) return -1;
-  return numero_block(lastGPS());
-}
-
-double ArcheopsFile::getGPSUTC() {  // en secondes depuis minuit UTC jour courant
-  if (!lastGPS()) return -9.e99;
-  return blockSet->gpsParser.getUTC();
-}
-
-double ArcheopsFile::getGPSMJD() {  // modified julian day du dernier bloc GPS, JD - 2450000
-  double t = getGPSUTC()/86400. - 0.5;
-  if (t<0) return t;
-  if (t > (startMJD - int(startMJD))) {
-    return int(startMJD) + t;
-  } else {
-    return int(startMJD) + 1. + t;
-  }
-}
-
-double ArcheopsFile::getGPSLat() {  // degres, +  = NORD
-  if (!lastGPS()) return -9.e99;
-  return blockSet->gpsParser.getLatitude();
-}
-
-
-double ArcheopsFile::getGPSLong() { // degres, +  = EST
-  if (!lastGPS()) return -9.e99;
-  return blockSet->gpsParser.getLongitude();
-}
-
-double ArcheopsFile::getGPSAlt() { // meters from sea level
-  if (!lastGPS()) return -9.e99;
-  return blockSet->gpsParser.getAltitude();
-}
-
-bool ArcheopsFile::hasGPSTime() { 
-  if (!lastGPS()) return false;
- // return blockSet->gpsParser.hasGPSTime();
-  return blockSet->gpsParser.hasTime();
-}
-
-bool ArcheopsFile::hasGPSPos() { 
-  if (!lastGPS()) return false;
-  return blockSet->gpsParser.hasPosition();
-}
-
-bool ArcheopsFile::hasGPSAlt() { 
-  if (!lastGPS()) return false;
-  return blockSet->gpsParser.hasAltitude();
-}
-
-
-// Bolo
-#define  val_DS(j,i)  (blk->data_bolo[j][i]&0x1fffff)
-
-
-double ArcheopsFile::getBoloRawMuV(int ibolo, int imesure) {    // microvolts bruts
-  block_type_bolo* blk = imesure >= 0 ? lastBolo() : llastBolo();
-  if (imesure < 0) imesure += nEchBlock();
-  block_type_reglage* reglage = lastReglage();
-  block_type_param*   param = lastParam();
-  if (!blk) return 0;
-  if (!reglage) return 0;
-  if (!param) return 0;
-
-  int s = imesure % 2 ? 1 : -1;
-    
-  return s*bolo_muV(&param->param, &reglage->reglage, val_DS(ibolo,imesure), ibolo);
-}
-
-double ArcheopsFile::getBoloRawMuVCN(int ibolo, int imesure) {    
-  // Si pas bloc comprime -> 1 bit
-  int lastbit = 1;
-  if (!(lastBoloComp() == NULL) &&
-      (numero_block(lastBoloComp()) != numero_block(lastBolo()))) {
-    unsigned int4* data = lastBoloComp()->data_bolo[ibolo];
-    // Les deux premieres valeurs sont codees directement...
-    if (imesure>=2) {
-      int iExp = (imesure-2)/4 + 1;
-      int expo = data[iExp] & 0xf;
-      lastbit = 1 << expo;
-    }
-  }
-  block_type_reglage* reglage = lastReglage();
-  block_type_param*   param = lastParam();
-  if (!reglage) return 0;
-  if (!param) return 0;
-  double noise = (
-    bolo_muV(&param->param, &reglage->reglage, lastbit, ibolo) -
-    bolo_muV(&param->param, &reglage->reglage, 0, ibolo)) /2.;
-
-  return noise; 
-}
-
-
-
-def_gains 
-
-double ArcheopsFile::getBoloMuV(int ibolo, int imesure) { // microvolts, filtre avec filtre carre
-  double y = (getBoloRawMuV(ibolo, imesure-1) + getBoloRawMuV(ibolo, imesure))/2.;
-  return y;
-}
-
-double ArcheopsFile::getBoloMuV2(int ibolo, int imesure) { // microvolts, filtre 
-  // On commence par trouver la valeur d'offset, en fittant une droite sur les soustractions
-  if (!lastBolo() || !llastBolo()) return 0;
-  //block_type_reglage* reglage = lastReglage();
-  //block_type_param*   param = lastParam();
-  //if (!reglage) return 0;
-  //if (!param) return 0;
-  double sumx=0, sumy=0, sumxy=0, sumx2=0;
-  int n=20;
-  int s = imesure % 2 ? 1 : -1;
-  for (int i=1; i<=n; i++) {
-    double x = -i;
-    double y = s*(getBoloRawMuV(ibolo, imesure-i+1) - getBoloRawMuV(ibolo, imesure-i))/2;
-    s = -s;
-    sumx += x;
-    sumy += y;
-    sumxy += x*y;
-    sumx2 += x*x;
-  }
-  double a = (sumxy/n - (sumx/n)*(sumy/n)) / (sumx2/n - (sumx/n)*(sumx/n));
-  double b = (sumy/n) - a*(sumx/n);
-  s = imesure % 2 ? 1 : -1;
-  double y = getBoloRawMuV(ibolo, imesure);
-  y = y-s*b;
-  return y;
-}
-
-/*
-double ArcheopsFile::getBoloMuV2(int ibolo, int imesure) { // microvolts, filtre 
-  // On commence par trouver la valeur d'offset, en fittant une droite sur les soustractions
-  if (!lastBolo() || !llastBolo()) return 0;
-  double sumx=0, sumy=0, sumxy=0, sumx2=0;
-  int n=20;
-  int s = (imesure-n) % 2 ? 1 : -1;
-  static double* data = NULL;
-  if (!data) data = new double[n+1];
-  for (int i=0; i<=n; i++) {
-    data[i] = getBoloRawMuV(ibolo, imesure-n+i);
-  }
-  for (int i=0; i<=n; i++) {
-    
-  }
-  for (int i=1; i<=n; i++) {
-    double x = -i;
-    double y = s*(getBoloRawMuV(ibolo, imesure-i+1) - getBoloRawMuV(ibolo, imesure-i))/2;
-    s = -s;
-    sumx += x;
-    sumy += y;
-    sumxy += x*y;
-    sumx2 += x*x;
-  }
-  double a = (sumxy/n - (sumx/n)*(sumy/n)) / (sumx2/n - (sumx/n)*(sumx/n));
-  double b = (sumy/n) - a*(sumx/n);
-  s = imesure % 2 ? 1 : -1;
-  double y = getBoloRawMuV(ibolo, imesure);
-  y = y-s*b;
-  return y;
-}
-*/
-
-
-double ArcheopsFile::getGainAmpli(int ibolo) {
-     return gain_ampli(lastReglage()->reglage.bolo[ibolo]);
-}
-
-
-double ArcheopsFile::getDACV(int ibolo) {
-  block_type_reglage* reglage = lastReglage();
-  block_type_param*   param = lastParam();
-  if (!reglage) return 0;
-  if (!param) return 0;
-  return DAC_muV(&param->param, &reglage->reglage, ibolo);
-}
-
-double ArcheopsFile::getDACI(int ibolo) {
-  block_type_reglage* reglage = lastReglage();
-  block_type_param*   param = lastParam();
-  if (!reglage) return 0;
-  if (!param) return 0;
-  return DAC_muA(&param->param, &reglage->reglage, ibolo);
-}
-
-double ArcheopsFile::getBoloMuV2T(int ibolo, int imesure) {
-  return getDACV(ibolo) - getBoloMuV2(ibolo, imesure) ;
-}
-
-double ArcheopsFile::getBoloRes(int ibolo, int imesure) {
-  double i = getDACI(ibolo); // microAmps
-  double v = getBoloMuV2T(ibolo, imesure); // microVolts
-  double r = v/i; // Ohms
-  return r;
-}
-
-double ArcheopsFile::getBoloTemp(int ibolo, int imesure) {
-  double r = getBoloRes(ibolo, imesure);
-  block_type_reglage* reglage = lastReglage();
-  block_type_param*   param = lastParam();
-  if (!reglage) return 0;
-  if (!param) return 0;
-  return bolo_temp(&param->param, &reglage->reglage, r, ibolo);
-}
-
-
-// Dilution
-
-int4 ArcheopsFile::getADCDil(int iADC) {
-  block_type_dilution* blk = lastDilution();
-  if (!blk) return 0;
-  if (iADC < 0 || iADC > 47) return 0;
-  return blk->ADC_dil[iADC];
-}
-
-int4 ArcheopsFile::getSwitchDil() {
-  block_type_dilution* blk = lastDilution();
-  if (!blk) return 0;
-  return blk->switch_dil;
-}
-
-
-// SST, gyros...
-
-void ArcheopsFile::needSSTProcessMask(int mask) {
-  blockSet->sstHandler.NeedProcess(mask);
-}
-
-long ArcheopsFile::getSSTSignal(int idiode, int imesure) {
-  return blockSet->sstHandler.getSignal(imesure, idiode);
-}
-
-long ArcheopsFile::getSSTRawSignal(int idiode, int imesure) {
-  return blockSet->sstHandler.getRawSignal(imesure, idiode);
-}
-
-double ArcheopsFile::getSSTSignalCN(int idiode, int imesure) {
-  return getSSTRawSignalCN(SSTHandler::getDiodPermut(idiode),imesure);
-}
-
-double ArcheopsFile::getSSTRawSignalCN(int ichannel, int imesure) {
-  // Si pas bloc comprime -> 0.5
-  if (lastSSTComp() == NULL) return .5;
-  if (numero_block(lastSSTComp()) != numero_block(lastSST())) return 0.5;
-  
-  // Attention, on ne transmet pas les canaux 0 et 4....
-  if (ichannel == 0 || ichannel == 4) return 0;
-  int i = ichannel - 1;
-  if (i >= 4) i--;
-  unsigned int4* data = lastSSTComp()->sst[i];
-  // Les deux premieres valeurs sont codees directement...
-  if (imesure<2) return 0.5;
-  int iExp = (imesure-2)/7 + 1;
-  int expo = data[iExp] & 0xf;
-  int noise = 1 << expo;
-  return noise/2.;
-}
-
-
-
-double ArcheopsFile::getSSTStarZ(int istar, int imesure) {
-  return blockSet->sstHandler.getStarZ(imesure+getSSTBlockNum()*nb_per_block*2, istar);
-}
-
-double ArcheopsFile::getSSTStarF(int istar, int imesure) {
-  return blockSet->sstHandler.getStarF(imesure+getSSTBlockNum()*nb_per_block*2, istar);
-}
-
-double ArcheopsFile::getSSTStarT(int istar, int imesure) {
-  return blockSet->sstHandler.getStarTime(imesure+getSSTBlockNum()*nb_per_block*2, istar);
-}
-
-int ArcheopsFile::getNumbStar(int imesure) {
-  return blockSet->sstHandler.getNumbStar(imesure+getSSTBlockNum()*nb_per_block*2);
-}
-
-long ArcheopsFile::getGyroRaw(int igyro, int imesure) {   
-  return blockSet->gyroHandler.getRawSignal(imesure, igyro);
-}
-
-double ArcheopsFile::getGyroTens(int igyro, int imesure) {   
-  return blockSet->gyroHandler.getSignal(imesure, igyro);
-}
-
-double ArcheopsFile::getGyroSpeed(int igyro, int imesure) {   
-  return blockSet->gyroHandler.getSpeed(imesure, igyro);
-}
-
-
-
-
-
-// $CHECK$ TBD
-
-
-double ArcheopsFile::getAzimut(int /*imesure*/) {return 0;}
-double ArcheopsFile::getPendDirect(int /*imesure*/) {return 0;}
-double ArcheopsFile::getPendOrth(int /*imesure*/) {return 0;}
-double ArcheopsFile::getAlphaAxis(int /*imesure*/) {return 0;}
-double ArcheopsFile::getDeltaAxis(int /*imesure*/) {return 0;}
Index: trunk/Poubelle/archTOI.old/archeopsfile.h
===================================================================
--- trunk/Poubelle/archTOI.old/archeopsfile.h	(revision 533)
+++ trunk/Poubelle/archTOI.old/archeopsfile.h	(revision 534)
@@ -9,15 +9,8 @@
 #include <stack>
 
+using namespace std;
 
-#ifndef nb_max_bolo
-#define _archeops		//  Acquisition Archeops (avec transputer) 
-#define programme
-extern "C" {
-#include "archeops.h"
-}
-#endif
-
-#include "ssthandler.h"
-#include "gpsparser.h"
+#include "ark.h"
+#include "archexc.h"
 
 enum {
@@ -50,11 +43,4 @@
 class BlockSet;
 
-class ArchExc {
-public:
-  ArchExc(string s) : msg(s) {}
-  string Msg() {return msg;}
-protected:
-  string msg;
-};
 
 class ArcheopsFile {
@@ -64,5 +50,5 @@
   virtual ~ArcheopsFile();
   
-  void setUTCOffset(int UTCOffset=2); // StartMJD : decodage a partir du nom du bloc...
+  void setUTCOffset(double UTCOffset=2); // StartMJD : decodage a partir du nom du bloc...
   double getStartMJD();
   
@@ -76,9 +62,4 @@
   string blockRawKdName();
   string filename() {return fn;}
-  
-  double perEchant(); // periode d'echantillonage pour le dernier bloc reglage
-  double perBlock();  // duree (en secondes) correspondant a un bloc bolo
-                      // utilise infos dernier bloc param et dernier bloc reglage.
-  int nEchBlock(); // Nb d'echantillons dans un bloc bolo
   
   
@@ -109,66 +90,5 @@
   
   void forceBlock(block_type_modele* blk);
-  
-  // Decodage des derniers blocs..
-  
-  // GPS
-  // On travaille en MJD = JD - 2450000.0, = 9 octobre 1995 midi UTC
-  // 1er juillet 1999 minuit UTC = JD 2451360.5,   MJD 1360.5 
-  // Ces fonctions travaillent sur le dernier bloc GPS 
-  int getGPSBlockNum();
-  bool   hasGPSTime();
-  bool   hasGPSPos();
-  bool   hasGPSAlt();
-  double getGPSUTC();  // en secondes depuis minuit UTC
-  double getGPSMJD();  // modified julian day du dernier bloc GPS, JD - 2450000
-  double getGPSLat();  // degres, +  = NORD
-  double getGPSLong(); // degres, +  = EST
-  double getGPSAlt();  // meters from sea level
     
-  // Bolo
-  int getReglageBlockNum();
-  int getBoloBlockNum();
-  int getBoloCompBlockNum();
-  double getBoloRawMuV(int ibolo, int imesure);   // donnee brute en microvolts et signe change.
-  double getBoloRawMuVCN(int ibolo, int imesure);  // bruit de compression, en microVolts
-  double getBoloMuV(int ibolo, int imesure); // microvolts, filtre avec filtre carre
-  double getBoloMuV2(int ibolo, int imesure); // microvolts, filtre +sioux
-  double getGainAmpli(int ibolo);
-  double getDACV(int ibolo); // offset en microvolt
-  double getDACI(int ibolo); // courant en microAmps
-  double getBoloMuV2T(int ibolo, int imesure); // avec soustraction dacV
-  double getBoloRes(int ibolo, int imesure); // Ohms
-  double getBoloTemp(int ibolo, int imesure); // K
-  
-  // Dilution
-  int getDilutionBlockNum();
-  int4 getADCDil(int iADC);
-  int4 getSwitchDil();
-  
-  // SST, gyros, etc
-  int getSSTBlockNum();
-  int getSSTCompBlockNum();
-  void needSSTProcessMask(int mask);
-  long getSSTRawSignal(int iDiode, int imesure);
-  long getSSTSignal(int iDiode, int imesure);
-  double getSSTRawSignalCN(int iDiode, int imesure);
-  double getSSTSignalCN(int iDiode, int imesure);
-  double getSSTStarZ(int iStar, int imesure);
-  double getSSTStarF(int iStar, int imesure);
-  double getSSTStarT(int iStar, int imesure);
-  int getNumbStar(int imesure);
-  
-  int getGyroBlockNum();
-  long getGyroRaw(int iGyro, int imesure);
-  double getGyroTens(int iGyro, int imesure);
-  double getGyroSpeed(int iGyro, int imesure);
-  
-  double getAzimut(int imesure);
-  double getPendDirect(int imesure);
-  double getPendOrth(int imesure);
-  
-  double getAlphaAxis(int imesure);
-  double getDeltaAxis(int imesure);
-  
   static double decodeMJD(string const& dateString); // sans tenir compte de TU-TLeg
     
@@ -176,5 +96,5 @@
   BlockSet*                 blockSet;
   stack<BlockSet*>          blockStack;
-  stack<size_t>             fposStack;
+  stack<long>               fposStack;
   
   void saveCurBlock();
@@ -193,5 +113,5 @@
   long                      curPos;
   long                      peekPos;
-  size_t                    fLen;
+  long                      fLen;
   FILE* f;
   string fn;
Index: trunk/Poubelle/archTOI.old/archexc.h
===================================================================
--- trunk/Poubelle/archTOI.old/archexc.h	(revision 534)
+++ trunk/Poubelle/archTOI.old/archexc.h	(revision 534)
@@ -0,0 +1,18 @@
+// archexc.h
+// Eric Aubourg         CEA/DAPNIA/SPP   septembre 1999
+
+#ifndef ARCHEXC_H
+#define ARCHEXC_H
+
+#include <string>
+using namespace std;
+
+class ArchExc {
+public:
+  ArchExc(string s) : msg(s) {}
+  string Msg() {return msg;}
+protected:
+  string msg;
+};
+
+#endif
Index: trunk/Poubelle/archTOI.old/archfileset.cc
===================================================================
--- trunk/Poubelle/archTOI.old/archfileset.cc	(revision 534)
+++ trunk/Poubelle/archTOI.old/archfileset.cc	(revision 534)
@@ -0,0 +1,325 @@
+// archfileset.cc
+// Eric Aubourg         CEA/DAPNIA/SPP   septembre 1999
+
+#include <iostream.h>
+#include <dirent.h>
+#include "archfileset.h"
+#include "archparam.h"
+#include "toiproducer.h"
+#include "toimanager.h"
+
+ArchFileSet::ArchFileSet() {
+  file = NULL;
+  
+  trigMask = block_reglage_mask | block_param_mask | TOIManager::trigMask;
+  
+  sStart   = -999999999;
+  sEnd     =  999999999;
+  mjdStart = -999999999;
+  mjdEnd   =  999999999;
+
+  initDone = false;
+  endFound = false;
+}
+
+ArchFileSet::ArchFileSet(ArchFileSet const& x) {
+  directories = x.directories;
+  filenames = x.filenames;
+  if (x.initDone && x.curFile != x.filenames.end()) curFile = filenames.find(*(x.curFile));
+
+  trigMask = x.trigMask;
+
+  sStart   = x.sStart;
+  sEnd     = x.sEnd;
+  mjdStart = x.mjdStart;
+  mjdEnd   = x.mjdEnd;
+  
+  if (x.file)
+    file = new ArcheopsFile(*x.file);
+  else 
+    file = NULL;
+      
+  initDone = x.initDone;
+  endFound = x.endFound;
+}
+
+ArchFileSet::~ArchFileSet() {
+  delete file;
+}
+
+void ArchFileSet::setSNumRange(long start, long end) {
+  sStart = start;
+  sEnd   = end;
+}
+
+void ArchFileSet::setMJDRange(double start, double end) {
+  mjdStart = start;
+  mjdEnd   = end;
+}
+
+void ArchFileSet::addFile(string fn) {
+  filenames.insert(fn);
+}
+
+void ArchFileSet::addDirectory(string fn) {
+  directories.insert(fn);
+}
+
+
+
+#ifdef __MWERKS__
+#pragma mark -
+#endif
+
+#ifdef __MWERKS__
+#define filesep ':'
+#else
+#define filesep '/'
+#endif
+
+void ArchFileSet::init() {
+  if (initDone) return;
+  initDone = true;
+  trigMask |= TOIManager::trigMask;
+  
+  // build files from directories
+  for (set<string>::iterator i = directories.begin(); i != directories.end(); i++) {
+    string directory = *i;
+    if (directory[directory.length()-1] != filesep) 
+      directory += filesep;
+      
+    DIR* dir = opendir(directory.c_str());
+    struct dirent* ent;
+    
+    while ((ent = readdir(dir)) != NULL) {
+      // si c'est un repertoire, avec un nom de jour, il faut l'explorer...
+      if (!strncmp(ent->d_name, "arch-", 5)) {
+        double mjd = ArcheopsFile::decodeMJD(ent->d_name+5) - 2./24.; // ENTIER + .5 en temps local!
+        if (mjd >= mjdStart - 1. && mjd <= mjdEnd) {
+          string direc2 = directory + ent->d_name + filesep;
+          DIR* dir2 = opendir(direc2.c_str());
+          struct dirent* ent2;
+          while ((ent2 = readdir(dir2)) != NULL) {
+            if (*ent2->d_name == 'h') {
+              double mjd2 = ArcheopsFile::decodeMJD(ent->d_name+1) - 2./24.;
+              if (mjd2 >= mjdStart - 1./24. && mjd2 <= mjdEnd) {
+                filenames.insert(direc2 + ent2->d_name);
+              }
+            }
+          }
+        }
+      } // "arch-"
+      else if (*ent->d_name == 'h') {
+        double mjd = ArcheopsFile::decodeMJD(ent->d_name+1) - 2./24.; // $CHECK$ UTCOffset
+        if (mjd >= mjdStart - 1./24. && mjd <= mjdEnd) {
+           filenames.insert(directory + ent->d_name);
+        }
+      } // "h*"
+      else  if (!strncmp(ent->d_name, "ARK", 3) || !strncmp(ent->d_name, "ark", 3)) {
+        char * sfx = ent->d_name + strlen(ent->d_name) - 4;
+        if (!strcmp(sfx, ".DAT") || !strcmp(sfx, ".dat")) {
+          filenames.insert(directory + ent->d_name);
+        }
+      }
+    } // readdir
+    closedir(dir);
+  } // iterate on dirs
+
+  scanFiles();
+  
+  if (filenames.empty()) {
+    throw ArchExc("No files in fileset");
+  }
+  
+  curFile = filenames.begin();
+  file = new ArcheopsFile((*curFile).c_str());
+  cout << "opening file " << (*curFile).c_str() << endl;
+
+  extern param_bolo  parametr;
+  block_type_param block;
+  block.param = parametr;
+  valide_block((block_type_modele*)&block, block_param, 0);
+  file->forceBlock((block_type_modele*)&block);
+
+  if (!file->lastReglage()) file->nextBlock(block_reglage_mask);
+}
+
+void ArchFileSet::scanFiles() {
+  file1stSamp.clear();
+  cout << "Scanning all files" << endl;
+  // Petite astuce pour les STL non conformes comme celles de digital
+  // qui ne supportent pas files.erase(i) suivi de i++....
+  set<string> copy = filenames;
+  for (set<string>::iterator i = copy.begin(); i != copy.end(); i++) {
+    ArcheopsFile fich((*i).c_str());
+    if (fich.nextBlock()) {
+      file1stSamp[*i] = fich.blockNum()*72; // premier numsample
+      cout << "File " << *i << " 1st sample = " << fich.blockNum()*72 << endl;
+    } else {
+      cout << "File " << *i << " unrecoverable, skipping" << endl;
+      filenames.erase(*i);
+    }
+  }
+  cout << "Scan done" << endl;
+  
+  // Et maintenant, on ne garde que ceux qui tombent dans l'intervalle...
+  copy = filenames;
+  string prev="";
+  for (set<string>::iterator i = copy.begin(); i != copy.end(); i++) {
+    double smp = file1stSamp[*i];
+    double t   = archParam.acq.tBlock0 + smp * archParam.acq.perEch/86400.;
+    if (t>mjdEnd || smp>sEnd) {  // premier echantillon apres tEnd
+     filenames.erase(*i);
+     prev = "";
+     continue;
+    }
+    if (t<mjdStart || smp<sStart) { // premier echantillon avant tStart -> on vire le precedent si existe
+      if (prev != "") {
+        filenames.erase(prev);
+      }
+    }
+    prev = *i;
+  }
+}
+
+bool ArchFileSet::nextFile() {    
+  if (filenames.empty()) {
+    return false;
+  } else {
+    if (curFile == filenames.end()) return false;
+    curFile++;
+    if (curFile == filenames.end()) return false;
+    cout << "opening file " << (*curFile).c_str() << endl;
+    ArcheopsFile* newfile = new ArcheopsFile((*curFile).c_str());
+    newfile->grabLastBlocs(*file);
+    delete file;
+    file = newfile;
+    return true;
+  }
+}
+
+bool ArchFileSet::next() {
+  if (endFound) return false;
+  if (!initDone) init();
+  while (1) {
+    long got = nextSample();
+    if (!got) {endFound=true; return false;} // end of files
+    double t = getMJD();
+    if (t < mjdStart) continue;
+    if (t > mjdEnd) {endFound=true; return false;}
+    long s = getSampleIndex();
+    if (s < sStart) continue;
+    if (s > sEnd) {endFound=true; return false;}
+    
+    // On envoie les nouvelles donnees aux producers interesses
+    for (map<TOILowLevProducer*, long>::iterator i = TOIManager::activeLLProducers.begin(); 
+         i != TOIManager::activeLLProducers.end(); i++) {
+      if (got & ((*i).second)) (*i).first->handleBlock(this);
+    }
+    
+    return true;
+  }
+}
+
+long ArchFileSet::getSampleIndex() {
+  if (!initDone) init();
+  return file->blockNum() * nb_per_block*2;
+}
+
+double ArchFileSet::getMJD() {
+  if (!initDone) init();
+  int sample = getSampleIndex();
+  return archParam.acq.SN2MJD(sample);
+}
+
+long ArchFileSet::nextSample() {
+  while (1) {
+    long got = 0;
+    if (file->nextBlock(trigMask)) {
+      got |= 1 << type_block(file->currentBlock());
+      while (file->sameBlockNumAhead()) {  // tant que meme numero de bloc, on lit
+        if (!file->nextBlock()) {          // fin de fichier ?
+          if (nextFile()) file->nextBlock(); // fichier suivant
+          else return 0;    // tout fini
+        }
+      got |= 1 << type_block(file->currentBlock());
+      }
+      return got;
+    }
+    if (!nextFile()) return 0;
+  }
+}
+
+#ifdef __MWERKS__
+#pragma mark -
+#endif
+
+block_type_param*         ArchFileSet::lastParam() {
+  if (!file) return NULL;
+  return file->lastParam();
+}
+
+block_type_journal*       ArchFileSet::lastJournal() {
+  if (!file) return NULL;
+  return file->lastJournal();
+}
+
+block_type_reglage*       ArchFileSet::lastReglage() {
+  if (!file) return NULL;
+  return file->lastReglage();
+}
+
+block_type_dilution*      ArchFileSet::lastDilution() {
+  if (!file) return NULL;
+  return file->lastDilution();
+}
+
+block_type_gps*           ArchFileSet::lastGPS() {
+  if (!file) return NULL;
+  return file->lastGPS();
+}
+
+block_type_une_periode*   ArchFileSet::lastUnePeriode() {
+  if (!file) return NULL;
+  return file->lastUnePeriode();
+}
+
+block_type_synchro_sol*   ArchFileSet::lastSynchroSol() {
+  if (!file) return NULL;
+  return file->lastSynchroSol();
+}
+
+block_type_pointage_sol*  ArchFileSet::lastPointageSol() {
+  if (!file) return NULL;
+  return file->lastPointageSol();
+}
+
+block_type_bolo*          ArchFileSet::lastBolo() {
+  if (!file) return NULL;
+  return file->lastBolo();
+} 
+  
+block_type_gyro*          ArchFileSet::lastGyro() {
+  if (!file) return NULL;
+  return file->lastGyro();
+}
+
+block_type_sst*           ArchFileSet::lastSST() {
+  if (!file) return NULL;
+  return file->lastSST();
+}
+
+block_type_bolo_comprime* ArchFileSet::lastBoloComp() {
+  if (!file) return NULL;
+  return file->lastBoloComp();
+}  
+ 
+block_type_gyro_comprime* ArchFileSet::lastGyroComp() {
+  if (!file) return NULL;
+  return file->lastGyroComp();
+}
+
+block_type_sst_comprime*  ArchFileSet::lastSSTComp() {
+  if (!file) return NULL;
+  return file->lastSSTComp();
+}
Index: trunk/Poubelle/archTOI.old/archfileset.h
===================================================================
--- trunk/Poubelle/archTOI.old/archfileset.h	(revision 534)
+++ trunk/Poubelle/archTOI.old/archfileset.h	(revision 534)
@@ -0,0 +1,65 @@
+// archfileset.h
+// Eric Aubourg         CEA/DAPNIA/SPP   septembre 1999
+
+#ifndef ARCHFILESET_H
+#define ARCHFILESET_H
+
+#include "archeopsfile.h"
+
+#include <set>
+#include <map>
+
+using namespace std;
+
+class TOILowLevProducer;
+
+class ArchFileSet {
+public:
+  ArchFileSet();
+  ArchFileSet(ArchFileSet const&);
+  ~ArchFileSet();
+  
+  void addFile(string);
+  void addDirectory(string);
+  void setSNumRange(long start, long end);
+  void setMJDRange(double start, double end);
+  void init(); // Opens the first file.
+  bool next();
+  
+  block_type_param*         lastParam();  
+  block_type_journal*       lastJournal();
+  block_type_reglage*       lastReglage();
+  block_type_dilution*      lastDilution();
+  block_type_gps*           lastGPS();
+  block_type_une_periode*   lastUnePeriode();
+  block_type_synchro_sol*   lastSynchroSol();
+  block_type_pointage_sol*  lastPointageSol();
+  block_type_bolo*          lastBolo();   
+  block_type_gyro*          lastGyro();
+  block_type_sst*           lastSST();
+  block_type_bolo_comprime* lastBoloComp();   
+  block_type_gyro_comprime* lastGyroComp();
+  block_type_sst_comprime*  lastSSTComp();
+  
+  void   registerProducer(TOILowLevProducer*, int blk_kind);
+  long   getSampleIndex();             // numero d''echantillon 
+  double getMJD();            
+
+protected:
+  set<string> filenames;
+  set<string> directories;
+  map<string, long> file1stSamp; // premier echantillon de chaque fichier
+  set<string>::iterator curFile;
+  ArcheopsFile* file;
+            
+  void scanFiles(); // Parcourt tous les fichiers, cherche le premier echantillon...
+  long nextSample(); // no test of trange
+  bool nextFile();
+  long sStart, sEnd;      // samplenum
+  double mjdStart, mjdEnd;    
+  long trigMask;
+  bool initDone;
+  bool endFound;
+};
+
+#endif
Index: trunk/Poubelle/archTOI.old/archparam.cc
===================================================================
--- trunk/Poubelle/archTOI.old/archparam.cc	(revision 533)
+++ trunk/Poubelle/archTOI.old/archparam.cc	(revision 534)
@@ -38,2 +38,25 @@
   cout << "***END" << endl;
 }
+
+double ArchParam::AcqParam::SN2MJD(double sample) {
+  return tBlock0 + sample*perEch/86400.;
+}
+
+
+double ArchParam::AcqParam::MJD2UTC(double mjd) {
+  return (mjd - utcOrigin)*24. ;
+}
+
+double ArchParam::AcqParam::UTC2MJD(double utc) {
+  return utc/24 + utcOrigin;
+}
+
+double ArchParam::AcqParam::SN2UTC(double sample) {
+  return MJD2UTC(SN2MJD(sample));
+}
+
+
+double ArchParam::AcqParam::MJD2SN(double mjd) {
+  return (mjd - tBlock0)/perEch*86400.;
+}
+
Index: trunk/Poubelle/archTOI.old/archparam.h
===================================================================
--- trunk/Poubelle/archTOI.old/archparam.h	(revision 533)
+++ trunk/Poubelle/archTOI.old/archparam.h	(revision 534)
@@ -11,4 +11,9 @@
     double utcOrigin;
     AcqParam(); 
+    double SN2MJD(double snum);
+    double SN2UTC(double snum);
+    double MJD2UTC(double mjd);
+    double UTC2MJD(double utc);
+    double MJD2SN(double mjd);
   };
   
Index: trunk/Poubelle/archTOI.old/archtoi.cc
===================================================================
--- trunk/Poubelle/archTOI.old/archtoi.cc	(revision 533)
+++ trunk/Poubelle/archTOI.old/archtoi.cc	(revision 534)
@@ -9,5 +9,6 @@
 
 #include "archeopsfile.h"
-#include "toisvr.h"
+#include "toiiter.h"
+#include "toimanager.h"
 #include "archtoi.h"
 #include "archparam.h"
@@ -39,5 +40,5 @@
 {
   init();
-  svr.readReq(str);
+  iter.readReq(str);
 }
 
@@ -47,5 +48,5 @@
   init();
   ifstream str(filename.c_str());
-  svr.readReq(str);
+  iter.readReq(str);
 }
 
@@ -59,22 +60,14 @@
   ostr = NULL;
   requestVersion = "";
-  svr.registerReqHandler(this);
-}
-
-
-bool ArchTOI::processTOIReq(string line, string toiname, TOIKind /*kind*/, int index, 
-                            bool interp, bool repet, bool flag, bool /*notrig*/)
+  iter.registerReqHandler(this);
+  
+  TOIManager::registerDefaultProducers();
+}
+
+
+bool ArchTOI::processTOIReq(TOI const& toi, string line)
 {
   headertoi.push_back(line);
-  if (index>=0) {
-    char idx[10]; 
-    sprintf(idx,"_%d",index);
-    toiname += idx;
-  }
-  if (flag) {
-    toinames.push_back("flg_"+toiname);
-  }
-  toinames.push_back(toiname);
-  toiflags.push_back(flg((flag?hasflag:0)+((!repet&&!interp)?useNA:0)));
+  tois.push_back(toi);
   return true;
 } 
@@ -130,11 +123,11 @@
   
   cout << "starting query" << endl;
-  TOIIter iter = svr.doQuery();
+  iter.init();
   (this->*openFile)(outfilename);
   (this->*outHeader)(iter);
   
   cout << "processing" << endl;
-  while (iter.Next()) {
-    int nn = iter.getSampleIndex() / iter.getUnderSampling(); // Only for tick mark...
+  while (iter.next()) {
+    int nn = iter.getSampleNum() / iter.getUnderSample(); // Only for tick mark...
     #ifdef __MWERKS__
     yield();
@@ -145,21 +138,23 @@
      if (nn%(200*80) == 0) cout << endl;
     // Si rien de dispo parmi les triggering, alors on passe au suivant
-    bool hasValue = false;
-    for (int i=0; i<toiflags.size(); i++) {
-       if (!iter.isTrig(i)) continue;
-       if (iter.canGetValue(i)) {hasValue=true; break;}
-    }
-    if (!hasValue) continue;
+    // normalement, c'est gere par le toiiter...
+    //bool hasValue = false;
+    //for (int i=0; i<toiflags.size(); i++) {
+    //   if (!iter.isTrig(i)) continue;
+    //   if (iter.canGetValue(i)) {hasValue=true; break;}
+    //}
+    //if (!hasValue) continue;
     int icol=0;
-    for (int i=0; i<toiflags.size(); i++) {
+    for (int i=0; i<tois.size(); i++) {
       double value = iter.getValue(i);
       bool   ok    = iter.canGetValue(i);
-      bool   isnew = iter.newValue(i);
-      flg    flag  = toiflags[i];
-      if (flag & hasflag) {
-        (this->*outValue)(icol,  (ok && isnew ? 1 : 0));
-        icol++;
-      }
-      if (((flag & useNA)!=0 && !isnew) || !ok) 
+     // bool   isnew = iter.newValue(i);
+     // flg    flag  = toiflags[i];
+     // if (flag & hasflag) {
+     //   (this->*outValue)(icol,  (ok && isnew ? 1 : 0));
+     //   icol++;
+     // }
+     //if (((flag & useNA)!=0 && !isnew) || !ok) 
+      if (!ok) 
         (this->*outValue)(icol,  0, true);
       else
@@ -184,5 +179,5 @@
   for (list<string>::iterator i = headeropt.begin(); i != headeropt.end(); i++)
     *ostr << (*i) << '\n';;
-  block_type_param* blk = iter.lastParam();
+  block_type_param* blk = iter.getFSet().lastParam();
   if (blk) {
     int nb = blk->param.n_max_bolo;
@@ -227,4 +222,29 @@
 }
 
+list<string> ArchTOI::buildNames() {
+  list<string> toinames;
+  map<string,int> namecount;
+  
+  for (list<TOI>::iterator i = tois.begin(); i != tois.end(); i++) {
+    namecount[(*i).name]++;
+  }
+  
+  map<string,int> curcount;
+  for (list<TOI>::iterator i = tois.begin(); i != tois.end(); i++) {
+    string toiname = (*i).name;
+    if (namecount[(*i).name]>1) {
+      char s[10];
+      sprintf(s,"_%d",curcount[(*i).name]++);
+      toiname += s;
+    }
+    if ((*i).index != TOI::unspec) {
+      char s[10];
+      sprintf(s,"_%d",(*i).index);
+      toiname += s;
+    }
+    toinames.push_back(toiname);
+  }
+  return toinames;
+}
 
 void ArchTOI::openFile_F(string const& filename) {
@@ -237,5 +257,8 @@
 }
 
+
 void ArchTOI::outHeader_F(TOIIter& iter) {  
+  list<string> toinames = buildNames();
+
   int ncols=toinames.size();
   
@@ -244,8 +267,10 @@
   char** colunits = new (char*[ncols]);
   int j=0;
-  for (list<string>::iterator i = toinames.begin(); i != toinames.end(); i++,j++) {
+  list<TOI>::iterator kk = tois.begin();
+  for (list<string>::iterator i = toinames.begin(); i != toinames.end(); i++,j++,kk++) {
     colnames[j] = const_cast<char*>((*i).c_str()); // should work for most STL implementations... Check...
     coltypes[j] = "1D";
-    colunits[j] = " ";
+    colunits[j] = const_cast<char*>((*kk).unit.c_str());
+    cout << (*i).c_str() << " " << ((*kk).unit.c_str()) << endl;
   }
   
@@ -261,9 +286,11 @@
   int ntoireq = headertoi.size();
   fits_write_key(fptr, TINT, "TOIREQ", &ntoireq, NULL, &fitsStatus);
-  for (list<string>::iterator i = headertoi.begin(); i != headertoi.end(); i++,j++) {
+  list<string>::iterator kkk = toinames.begin();
+  for (list<string>::iterator i = headertoi.begin(); i != headertoi.end(); i++,j++,kkk++) {
     char line[80];
     strcpy(line, (*i).c_str());
     char* pline = line;
-    fits_write_keys_str(fptr, "TOIREQ", j, 1, &pline, (char**) NULL, &fitsStatus);
+    char* cmt   = const_cast<char*>((*kkk).c_str());
+    fits_write_keys_str(fptr, "TOIREQ", j, 1, &pline, &cmt, &fitsStatus);
   }
   j=1;
@@ -278,5 +305,5 @@
 
   // Noms des bolos
-  block_type_param* blk = iter.lastParam();
+  block_type_param* blk = iter.getFSet().lastParam();
   if (blk) {
     int nb = blk->param.n_max_bolo;
@@ -338,2 +365,4 @@
   fits_report_error(stderr, fitsStatus);  /* print out any error messages */
 }
+
+
Index: trunk/Poubelle/archTOI.old/archtoi.h
===================================================================
--- trunk/Poubelle/archTOI.old/archtoi.h	(revision 533)
+++ trunk/Poubelle/archTOI.old/archtoi.h	(revision 534)
@@ -9,5 +9,5 @@
 #include <list>
 #include <vector>
-#include "toisvr.h"
+#include "toiiter.h"
 #include "fitsio.h"
 
@@ -25,15 +25,13 @@
             useNA   = 2};
             
-  virtual bool processTOIReq(string line, string toiname, TOIKind toi, int index, 
-                             bool interp, bool repet, bool flag, bool notrig);
+  virtual bool processTOIReq(TOI const& toi, string line);
   virtual bool processOption(string keyw, string args);
   
 protected:
   void init();
-  TOISvr svr;
+  TOIIter iter;
   list<string> headertoi;
   list<string> headeropt;
-  list<string> toinames;
-  vector<flg>  toiflags;
+  list<TOI> tois;
   fmt format;
   string undef;
@@ -46,4 +44,6 @@
   void (ArchTOI::*endLine)();
   void (ArchTOI::*closeFile)();
+  
+  list<string> buildNames();
   
   void openFile_A(string const& filename);
Index: trunk/Poubelle/archTOI.old/archtoimain.cc
===================================================================
--- trunk/Poubelle/archTOI.old/archtoimain.cc	(revision 533)
+++ trunk/Poubelle/archTOI.old/archtoimain.cc	(revision 534)
@@ -7,6 +7,7 @@
 
 #include "archeopsfile.h"
+
 #include "archtoi.h"
-#include "toisvr.h"
+#include "toimanager.h"
 
 //#include <profiler.h>
@@ -23,6 +24,9 @@
     argc = ccommand(&argv);
 #endif
+
+
     if (argc != 3) {
       cerr << "usage: archtoi reqfile datafile" << endl;
+      cerr << "or:    archtoi -h reqfile" << endl;
       return(-1);
     }
@@ -30,9 +34,21 @@
 //   ProfilerInit(collectDetailed, bestTimeBase, 10000, 200);
 
+    if (argv[1] == string("-h")) {
+      ArchTOI toi(argv[2]);
+      TOIManager::dumpAvailTOIs(cout);
+      exit(0);
+    }
+
     
-    ArchTOI toi(argv[1]);
-    toi.run(argv[2]);
+    try {
+      ArchTOI toi(argv[1]);
+      toi.run(argv[2]);
+    } catch (ArchExc exc) {
+      cerr << exc.Msg() << endl; 
+      exit(-1);
+    }
     
 //    ProfilerDump("\pprofiler.data");
     return(0);
 }
+
Index: trunk/Poubelle/archTOI.old/archvers.h
===================================================================
--- trunk/Poubelle/archTOI.old/archvers.h	(revision 533)
+++ trunk/Poubelle/archTOI.old/archvers.h	(revision 534)
@@ -2,6 +2,6 @@
 #define ARCHVERS_H
 
-#define ARCHTOI_VERS "1.3"
-#define ARCHTOI_TAG  "V_241099"
+#define ARCHTOI_VERS "2.0"
+#define ARCHTOI_TAG  "V_011199"
 
 #endif
Index: trunk/Poubelle/archTOI.old/ark.h
===================================================================
--- trunk/Poubelle/archTOI.old/ark.h	(revision 534)
+++ trunk/Poubelle/archTOI.old/ark.h	(revision 534)
@@ -0,0 +1,8 @@
+#ifndef nb_max_bolo
+#define _archeops		//  Acquisition Archeops (avec transputer) 
+#define programme
+extern "C" {
+#include "archeops.h"
+#include "arcunit.h"
+}
+#endif
Index: trunk/Poubelle/archTOI.old/auxgps.h
===================================================================
--- trunk/Poubelle/archTOI.old/auxgps.h	(revision 533)
+++ trunk/Poubelle/archTOI.old/auxgps.h	(revision 534)
@@ -10,4 +10,7 @@
 
   virtual int getLocation(double mjd, double& lat, double& lon, double& alt)=0;
+  virtual bool canGetLocation(double mjd)=0;
+  virtual double getStartMJD()=0;
+  virtual double getEndMJD()=0;
   virtual AuxGPS* clone()=0;
 
Index: trunk/Poubelle/archTOI.old/auxinterpgps.cc
===================================================================
--- trunk/Poubelle/archTOI.old/auxinterpgps.cc	(revision 533)
+++ trunk/Poubelle/archTOI.old/auxinterpgps.cc	(revision 534)
@@ -18,4 +18,16 @@
   ilast = elems.upper_bound(elem(mjd,0,0,0));
   ilastok = (ilast != elems.end() && ilast != elems.begin());
+}
+
+bool AuxInterpGPS::canGetLocation(double mjd) {
+  return (mjd > (*elems.begin()).mjd && mjd < (*--elems.end()).mjd);
+}
+
+double AuxInterpGPS::getStartMJD() {
+  return (*elems.begin()).mjd;
+}
+
+double AuxInterpGPS::getEndMJD() {
+  return (*--elems.end()).mjd;
 }
 
Index: trunk/Poubelle/archTOI.old/auxinterpgps.h
===================================================================
--- trunk/Poubelle/archTOI.old/auxinterpgps.h	(revision 533)
+++ trunk/Poubelle/archTOI.old/auxinterpgps.h	(revision 534)
@@ -15,4 +15,7 @@
   AuxInterpGPS();
   virtual int getLocation(double mjd, double& lat, double& lon, double& alt);
+  virtual bool canGetLocation(double mjd);
+  virtual double getStartMJD();
+  virtual double getEndMJD();
   
   void FitsDump(string const& filename);
Index: trunk/Poubelle/archTOI.old/cmvplgalc.cc
===================================================================
--- trunk/Poubelle/archTOI.old/cmvplgalc.cc	(revision 534)
+++ trunk/Poubelle/archTOI.old/cmvplgalc.cc	(revision 534)
@@ -0,0 +1,43 @@
+#include <iostream.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+
+#include "plgalcross.h"
+
+#define PSCAL2(_v1_,_v2_) (_v1_[0]*_v2_[0]+_v1_[1]*_v2_[1]+_v1_[2]*_v2_[2])
+#define TOCART(_a_,_d_,_v_) \
+        {_v_[0]=cos(_d_)*cos(_a_); _v_[1]=cos(_d_)*sin(_a_); _v_[2]=sin(_d_);}
+
+////////////////////////////////////////////////////////////////////////////////////////
+int main(int narg,char *arg[])
+{
+{
+// test FindPerpEquat
+/*
+cmvplgalc >! toto
+cat toto | awk -v f=1e-10 '{if($1==0&&($9>f||$9<-f||$10>f||$10<-f)) print $0}'
+*/
+double ap,dp,v1[3],v2[3],vp[3],a1,d1,a2,d2;
+int rc;
+for(int aa1=0;aa1<=24;aa1+=1) for(int dd1=-90;dd1<=90;dd1+=15)
+for(int aa2=0;aa2<=24;aa2+=1) for(int dd2=-90;dd2<=90;dd2+=15) {
+  a1 = (double) aa1; d1 = (double) dd1;
+  a2 = (double) aa2; d2 = (double) dd2;
+  rc = FindPerpEquat(a1,d1,a2,d2,ap,dp);
+  printf("%d   %g %g   %g %g   %g %g",rc,a1,d1,a2,d2,ap,dp);
+  a1 /=  HRS_IN_RADIAN; d1 /=  DEG_IN_RADIAN;
+  a2 /=  HRS_IN_RADIAN; d2 /=  DEG_IN_RADIAN;
+  ap /=  HRS_IN_RADIAN; dp /=  DEG_IN_RADIAN;
+  TOCART(a1,d1,v1)
+  TOCART(a2,d2,v2)
+  TOCART(ap,dp,vp)
+  printf("   %g   %g %g\n"
+        ,PSCAL2(vp,vp),PSCAL2(v1,vp),PSCAL2(v2,vp));
+}
+}
+
+exit(0);
+}
+
Index: trunk/Poubelle/archTOI.old/dyffttools.cc
===================================================================
--- trunk/Poubelle/archTOI.old/dyffttools.cc	(revision 533)
+++ trunk/Poubelle/archTOI.old/dyffttools.cc	(revision 534)
@@ -1,4 +1,5 @@
 #include "dyffttools.h"
 
+// D. Yvon, CE Saclay, DAPNIA/SPP, 08/99
 
 //	Librairie FFTMayer enrobée pour etre utilisable facilement en C++
Index: trunk/Poubelle/archTOI.old/dyffttools.h
===================================================================
--- trunk/Poubelle/archTOI.old/dyffttools.h	(revision 533)
+++ trunk/Poubelle/archTOI.old/dyffttools.h	(revision 534)
@@ -1,4 +1,7 @@
 #ifndef DYFFTTOOLS_SEEN
-#define DYFFTTOOLS
+#define DYFFTTOOLS_SEEN
+
+// D. Yvon, CE Saclay, DAPNIA/SPP, 08/99
+
 double DYWindow(double index, double indexMax);
 
Index: trunk/Poubelle/archTOI.old/formepulse.cc
===================================================================
--- trunk/Poubelle/archTOI.old/formepulse.cc	(revision 533)
+++ trunk/Poubelle/archTOI.old/formepulse.cc	(revision 534)
@@ -2,4 +2,5 @@
 #include <fstream.h>
 
+// D. Yvon, CE Saclay, DAPNIA/SPP, 08/99
 
 #include <math.h>
@@ -13,7 +14,6 @@
 #include "ssthardware.h"
 
-
 #define LTab (2048)
-#define LSave (128)
+#define LSave (256)
 #define Tpas (5.e-4)
 //float PulseOptOrigin=LTab/16.*Tpas;
@@ -22,5 +22,12 @@
 //#define DYTestRun
 
-
+/*
+FormePulse::FormePulse() {
+ 	gainElec=0.;
+	FullwidthHalfMax=0;
+	ShapeArr=new double[LSave];
+	for(int i=0; i<LSave; i++)  ShapeArr[i]=0.;
+}
+*/
 
 FormePulse::FormePulse(TransFuncElec TF) {
@@ -129,5 +136,5 @@
 	for(int i=0; i<LSave; i++)  ShapeArr[i]=PulseInReel[i]/Max;
 
-#ifdef DYTestRun	
+//#ifdef DYTestRun	
 		//On ecrit le resultat dans un fichier 
 		char s2[32]="Resultatfiltrage.txt";
@@ -139,6 +146,7 @@
 
 		dlout<<"Impulsion courant de: "<<SSTFPulseCourant<<" Ampères"<<endl;
-		dlout<<"Maximum d'amplitude: "<<max<< " Volts"<<endl;
-		dlout<<" gain chaine preampli: "<<gainElec<<endl<<endl;
+		dlout<<"Maximum d'amplitude: "<<Max<< " Volts"<<endl;
+		dlout<<" gain chaine preampli: "<<gainElec<<endl;
+		dlout<<"largueur a mi hauteur: "<<FullwidthHalfMax<<endl<<endl;
 		dlout<<"Temps"<<"\tPartie Reelle"<<endl;
 
@@ -146,5 +154,5 @@
 			dlout<<k*Tpas<<"\t"<<ShapeArr[k]<<endl;
 		}	
-#endif
+//#endif
 
 
@@ -163,5 +171,5 @@
 	return *this;
 }
-	
+
 FormePulse::~FormePulse() {
 	delete[] ShapeArr;
@@ -174,8 +182,8 @@
 
 double FormePulse::PulseShape(double temps) {
+	double returnValue;
 	int ientier=(int)(temps/Tpas);
-	double returnValue;
 	if (ientier<0) returnValue=0.;
-	else if (ientier>=LSave) returnValue= ShapeArr[127];
+	else if (ientier>=LSave) returnValue= ShapeArr[LSave-1];
 	else {
 		double Min=ShapeArr[ientier];
@@ -193,4 +201,5 @@
 	//en secondes
 	return returnVal;
+//	return returnVal=30.e-3;			//Gros BUGG!!!!!
 }
 	
Index: trunk/Poubelle/archTOI.old/formepulse.h
===================================================================
--- trunk/Poubelle/archTOI.old/formepulse.h	(revision 533)
+++ trunk/Poubelle/archTOI.old/formepulse.h	(revision 534)
@@ -2,4 +2,5 @@
 #define FORMEPULSE_SEEN
 
+// D. Yvon, CE Saclay, DAPNIA/SPP, 08/99
 
 #define  SSTFPulseCourant 1.E-9 	
@@ -11,5 +12,6 @@
 class FormePulse {
 public:
-	FormePulse(TransFuncElec);
+	FormePulse(TransFuncElec TF);
+	FormePulse();						// Cas zero lecture
 	FormePulse& operator =(const FormePulse&);
 	~FormePulse();
Index: trunk/Poubelle/archTOI.old/galcrosslocator.cc
===================================================================
--- trunk/Poubelle/archTOI.old/galcrosslocator.cc	(revision 534)
+++ trunk/Poubelle/archTOI.old/galcrosslocator.cc	(revision 534)
@@ -0,0 +1,114 @@
+// galcrosslocator.cc
+// Eric Aubourg         CEA/DAPNIA/SPP   octobre 1999
+
+#include "galcrosslocator.h"
+#include "archexc.h"
+#include "archparam.h"
+#include "templocator.h"
+
+#define alphaZenith     "alphaZenith"
+#define deltaZenith     "deltaZenith"
+#define rotSpeed        "rotSpeed"
+#define rotSpeedSample1 "rotSpeedSample1"
+#define rotSpeedSample2 "rotSpeedSample2"
+#define lastCrossSample "lastCrossSample"
+#define nextCrossSample "nextCrossSample"
+#define azimuthFPC      "azimuthFPC"
+#define elvFPC          "elvFPC"
+#define alphaFPC        "alphaFPC"
+#define deltaFPC        "deltaFPC"
+#define azimuthBolo     "azimuthBolo"
+#define elvBolo         "elvBolo"
+#define alphaBolo       "alphaBolo"
+#define deltaBolo       "deltaBolo"
+
+
+GalCrossLocator::GalCrossLocator() {
+  possibleTOIs.insert(TOI(alphaZenith,      TOI::unspec, "", "hours",   "galcross0"));  
+  possibleTOIs.insert(TOI(deltaZenith,      TOI::unspec, "", "degrees", "galcross0"));  
+  possibleTOIs.insert(TOI(rotSpeed,         TOI::unspec, "", "deg/s",   "galcross0"));  
+  possibleTOIs.insert(TOI(rotSpeedSample1,  TOI::unspec, "", "integer", "galcross0"));  
+  possibleTOIs.insert(TOI(rotSpeedSample2,  TOI::unspec, "", "integer", "galcross0"));  
+  possibleTOIs.insert(TOI(lastCrossSample,  TOI::unspec, "", "integer", "galcross0"));  
+  possibleTOIs.insert(TOI(lastCrossSample,  TOI::unspec, "", "integer", "galcross0"));  
+  possibleTOIs.insert(TOI(nextCrossSample,  TOI::unspec, "", "integer", "galcross0"));  
+  possibleTOIs.insert(TOI(azimuthFPC,       TOI::unspec, "", "degrees", "galcross0"));  
+  possibleTOIs.insert(TOI(elvFPC,           TOI::unspec, "", "degrees", "galcross0"));  
+  possibleTOIs.insert(TOI(alphaFPC,         TOI::unspec, "", "hours",   "galcross0"));  
+  possibleTOIs.insert(TOI(deltaFPC,         TOI::unspec, "", "degrees", "galcross0"));  
+  possibleTOIs.insert(TOI(azimuthBolo,      TOI::all,    "", "degrees", "galcross0"));  
+  possibleTOIs.insert(TOI(elvBolo,          TOI::all,    "", "degrees", "galcross0"));  
+  possibleTOIs.insert(TOI(alphaBolo,        TOI::all,    "", "hours",   "galcross0"));  
+  possibleTOIs.insert(TOI(deltaBolo,        TOI::all,    "", "degrees", "galcross0"));  
+}
+
+string GalCrossLocator::getName() {
+  return("GalCrossLocator 1.0");
+}
+
+bool GalCrossLocator::canGetValue(long sampleNum, TOI const&) {
+  int dum;
+  return (tempLocator.getCrossSamples(sampleNum, dum, dum) == 0);
+}
+
+
+double GalCrossLocator::getValue(long sampleNum, TOI const& toi) {
+  if (!canGetValue(sampleNum, toi)) return -1;
+
+  map<TOI, TOIProducer*> m = neededTOIs[toi];
+  double lat, lon, ts;
+  
+  for (map<TOI, TOIProducer*>::iterator i = m.begin(); i != m.end(); i++) {
+    TOI inToi = (*i).first;
+    TOIProducer* prod =  (*i).second;
+    if (inToi.name == "latitude")  lat = prod->getValue(sampleNum, inToi);
+    if (inToi.name == "longitude") lon = prod->getValue(sampleNum, inToi);
+    if (inToi.name == "tsid")       ts = prod->getValue(sampleNum, inToi);
+  }
+    
+  tempLocator.setEarthPos(lon,lat);
+  tempLocator.setTSid(ts);
+
+  if (toi.name == alphaZenith)     return tempLocator.getAlphaZenith();
+  if (toi.name == deltaZenith)     return tempLocator.getDeltaZenith();
+  if (toi.name == rotSpeed)        return tempLocator.getRotSpeed(sampleNum);
+
+  if (toi.name == azimuthFPC)      return tempLocator.getAzimutCenter(sampleNum);
+  if (toi.name == elvFPC)          return tempLocator.getElvCenter(sampleNum);
+  if (toi.name == alphaFPC)        return tempLocator.getAlphaCenter(sampleNum);
+  if (toi.name == deltaFPC)        return tempLocator.getDeltaCenter(sampleNum);
+  
+  if (toi.name == azimuthBolo)     return tempLocator.getAzimutBolo(sampleNum, toi.index);
+  if (toi.name == elvBolo)         return tempLocator.getElvBolo(sampleNum, toi.index);
+  if (toi.name == alphaBolo)       return tempLocator.getAlphaBolo(sampleNum, toi.index);
+  if (toi.name == deltaBolo)       return tempLocator.getDeltaBolo(sampleNum, toi.index);
+
+  if (toi.name == lastCrossSample || toi.name == rotSpeedSample1) {
+     int SN1, SN2;
+     tempLocator.getCrossSamples(sampleNum, SN1, SN2);
+     return SN1;
+  } 
+  if (toi.name == nextCrossSample || toi.name == rotSpeedSample2) {
+     int SN1, SN2;
+     tempLocator.getCrossSamples(sampleNum, SN1, SN2);
+     return SN2;
+  } 
+  
+  return -1;
+}
+
+
+set<TOI> GalCrossLocator::reqTOIFor(TOI const&) {
+  set<TOI> t; 
+  t.insert(TOI("latitude",  TOI::unspec, "interp"));
+  t.insert(TOI("longitude", TOI::unspec, "interp"));
+  t.insert(TOI("tsid",      TOI::unspec));
+  return t;
+}
+
+
+
+
+
+
+
Index: trunk/Poubelle/archTOI.old/galcrosslocator.h
===================================================================
--- trunk/Poubelle/archTOI.old/galcrosslocator.h	(revision 534)
+++ trunk/Poubelle/archTOI.old/galcrosslocator.h	(revision 534)
@@ -0,0 +1,21 @@
+// galcrosslocator.h
+// Eric Aubourg         CEA/DAPNIA/SPP   octobre 1999
+
+#ifndef GALCROSSLOCATOR_H
+#define GALCROSSLOCATOR_H
+
+#include "toipullproducer.h"
+
+class GalCrossLocator : public TOIPullProducer {
+public:
+  GalCrossLocator();
+  virtual string getName();
+  virtual double getValue(long sampleNum, TOI const& toi);
+  virtual bool   canGetValue(long sampleNum, TOI const& toi);
+
+protected:
+  virtual set<TOI>     reqTOIFor(TOI const&);
+};
+
+
+#endif
Index: trunk/Poubelle/archTOI.old/gyrocalibrator.cc
===================================================================
--- trunk/Poubelle/archTOI.old/gyrocalibrator.cc	(revision 534)
+++ trunk/Poubelle/archTOI.old/gyrocalibrator.cc	(revision 534)
@@ -0,0 +1,48 @@
+// gyrocalibrator.cc
+// Eric Aubourg         CEA/DAPNIA/SPP   octobre 1999
+
+// assumption : same calibration for all gyros...
+
+
+#include "gyrocalibrator.h"
+
+#define gyroCal    "gyroCal"
+#define gyroSpeed  "gyroSpeed"
+
+GyroCalibrator::GyroCalibrator() {
+  possibleTOIs.insert(TOI(gyroCal,      TOI::unspec, "linearCal", "deg/s/V"));  
+  possibleTOIs.insert(TOI(gyroSpeed,    TOI::all   , "linearCal", "deg/s"));  
+  
+  //needAfter = 3600;  // about one turn...
+  startSample = -1;
+  lastFence1 = lastFence2 = -1;
+}
+
+string GyroCalibrator::getName() {
+  return("GyroCalibrator 1.0");
+}
+
+
+set<TOI> GyroCalibrator::reqTOIFor(TOI const&) {
+  set<TOI> t; 
+  t.insert(TOI("rotSpeed",        TOI::unspec)); // pull only
+  t.insert(TOI("rotSpeedSample1", TOI::unspec)); // pull only
+  t.insert(TOI("rotSpeedSample2", TOI::unspec)); // pull only
+  t.insert(TOI("gyroV", 0));  // push
+  t.insert(TOI("gyroV", 1));  // push
+  t.insert(TOI("gyroV", 2));  // push
+  return t;
+}
+
+void GyroCalibrator::dataFeed(TOIProducer* source, TOI const& toi, long sampleNum, double value) {
+  if (toi.name != "gyroV" || toi.index != 2) return;
+  
+  if (gyro2.empty()) {
+    startSample = sampleNum;
+  }
+  
+  gyro2.push_back(value);
+}
+
+
+
Index: trunk/Poubelle/archTOI.old/gyrocalibrator.h
===================================================================
--- trunk/Poubelle/archTOI.old/gyrocalibrator.h	(revision 534)
+++ trunk/Poubelle/archTOI.old/gyrocalibrator.h	(revision 534)
@@ -0,0 +1,32 @@
+// gyrocalibrator.h
+// Eric Aubourg         CEA/DAPNIA/SPP   octobre 1999
+
+#ifndef GYROCALIBRATOR_H
+#define GYROCALIBRATOR_H
+
+#include "toiderivproducer.h"
+
+#include <vector>
+
+class GyroCalibrator : public TOIDerivProducer {
+public:
+  GyroCalibrator();
+  virtual void dataFeed(TOIProducer* source, TOI const& toi, long sampleNum, double value);
+  virtual string getName();
+
+  virtual bool   canGetValue(long sampleNum, TOI const& toi); // for this samplenum
+  virtual double getValue(long sampleNum, TOI const& toi);
+
+protected:
+  virtual set<TOI>     reqTOIFor(TOI const&);
+  virtual void         propagateLowBound(TOI const&, long sampleNum);
+  
+private:
+  long startSample;
+  vector<double> gyro2; 
+  long lastFence1, lastFence2;
+};
+
+
+
+#endif
Index: trunk/Poubelle/archTOI.old/gyrofftana.cc
===================================================================
--- trunk/Poubelle/archTOI.old/gyrofftana.cc	(revision 534)
+++ trunk/Poubelle/archTOI.old/gyrofftana.cc	(revision 534)
@@ -0,0 +1,90 @@
+#include <iostream.h>
+#include <fstream.h>
+#include <iomanip.h>
+
+#include "archeopsfile.h"
+#include "archtoi.h"
+#include "toisvr.h"
+
+
+#ifdef __MWERKS__
+#include <console.h>
+#endif
+
+using namespace std;  //introduces namespace std
+
+#ifdef __MWERKS__
+#include "Events.h"
+#include "LowMem.h"
+#include "sioux.h"
+static int macSleepTicks = 0;
+static int macRunTicks = 10;
+static void yield()
+{
+    EventRecord theEvent;
+    static long int macLastTicks;
+    long int ticks = LMGetTicks();
+    if (ticks - macLastTicks >= macRunTicks) {
+      if (WaitNextEvent(everyEvent, &theEvent,macSleepTicks,0))
+        SIOUXHandleOneEvent(&theEvent);
+      macLastTicks = LMGetTicks();
+    }
+}
+#endif
+
+int main(int argc, char** argv)
+{	
+
+  TOISvr svr;
+  svr.AddInfo(mjd);
+  svr.AddInfo(gyroRaw,0);
+  svr.AddInfo(gyroRaw,1);
+  svr.AddInfo(gyroRaw,2);
+  
+  svr.SetDirectory("Sans titre");
+  svr.OnBoardRecorderFiles(true);
+  svr.SetTimeInterval(1377.88, 1377.95);
+  
+  // Pour le moment, on sort, en binaire, les points moyennes sur 100
+  
+  ofstream s("gyro.data",ios::binary);
+  ofstream s1("gyro1.data",ios::binary);
+  cout << "starting" << endl;
+  TOIIter iter = svr.DoQuery();
+  const int n=72;
+  int i=0;
+  int ndata=0;
+  double xmjd, gyr0, gyr1, gyr2;
+  double gyr00, gyr01, gyr02;
+  while (iter.Next()) {
+    if (i==0) {
+      xmjd = iter.getValue(0);
+      gyr0=gyr1=gyr2=0;
+      gyr00 = iter.getValue(1);
+      gyr01 = iter.getValue(2);
+      gyr02 = iter.getValue(3);
+    }
+    gyr0 += iter.getValue(1);
+    gyr1 += iter.getValue(2);
+    gyr2 += iter.getValue(3);
+    i++;
+    if (i >= n) {
+      gyr0 /= n;
+      gyr1 /= n;
+      gyr2 /= n;
+      s.write((char*) &xmjd, sizeof(xmjd));
+      s.write((char*) &gyr0, sizeof(gyr0));
+      s.write((char*) &gyr1, sizeof(gyr1));
+      s.write((char*) &gyr2, sizeof(gyr2));
+      s1.write((char*) &xmjd, sizeof(xmjd));
+      s1.write((char*) &gyr00, sizeof(gyr00));
+      s1.write((char*) &gyr01, sizeof(gyr01));
+      s1.write((char*) &gyr02, sizeof(gyr02));
+      ndata++;
+      yield();
+      i=0;
+    }
+  }
+  cout << "Done. " << ndata << " samples written." << endl;
+
+}
Index: trunk/Poubelle/archTOI.old/pisteetoile.cc
===================================================================
--- trunk/Poubelle/archTOI.old/pisteetoile.cc	(revision 533)
+++ trunk/Poubelle/archTOI.old/pisteetoile.cc	(revision 534)
@@ -8,18 +8,17 @@
 FormePulse    PisteEtoile::FPulse(Trapani);
 
-
-
-int SSTnbPasFit= (int) (2*TFExcursion/TPasTFit);
+// D. Yvon, CE Saclay, DAPNIA/SPP, 08/99
 
 PisteEtoile::PisteEtoile(short NoPhotDiod) {
-	PasTempsEch=0.005836818076;			
+	PasTempsEch=archParam.acq.perEch;			
 		//BUGG doit changer	!!!!! Doit etre extrait d'un serveur de param d'acquisition
 	NoPhDiod=NoPhotDiod;
 	DiodVivante=true;
+	
+	SSTnbPasFit= (int) (2*TFExcursion/TPasTFit);
+	
 	AmplNorm=0.;
-//	On echantillonne dix fois plus fin pour avoir une bonne estimation de AmplNorm
-//	Eviter les systematiques
 	for(int i=0; i<SSTLongIndexEvt()*10; i++){
-		AmplNorm+=FPulse.PulseShape(i/10.*TPasTFit)*FPulse.PulseShape(i/10.*TPasTFit);
+		AmplNorm+=FPulse.PulseShape(i*PasTempsEch/10.)*FPulse.PulseShape(i*PasTempsEch/10.);
 	}
 	AmplNorm/=10.;
@@ -39,5 +38,4 @@
 PisteEtoile& PisteEtoile::operator =(PisteEtoile const & x) {
 	PasTempsEch=x.PasTempsEch;		
-		//BUGG doit changer	!!!!! Doit etre extrait d'un serveur de param d'acquisition
 	NoPhDiod=x.NoPhDiod;
 	DiodVivante=x.DiodVivante;
@@ -115,6 +113,6 @@
 void PisteEtoile::fill(int* pData, int InDebutPiste, int nData) {
 //	if(!isAlive()) return;
-	indexDebutPiste=InDebutPiste;
-	int* PhDiod=PhDiodArray;
+	indexDebutPiste=InDebutPiste - PhDiodTabLong + nData;
+	int* PhDiod=PhDiodArray + PhDiodTabLong - nData;
 	int* pDataC=pData;
 	for(int k=0;k<nData;k++,pDataC++, PhDiod++) (*PhDiod)=(*pDataC);
@@ -152,12 +150,19 @@
 	
 		if(testEtoile) {
-		// On emballe une etoile.
+		// On emballe une etoile
+			LastEtoile.InpCurrent= AmplRes/FPulse.GainElectrique();
+			LastEtoile.InpCurFin= AmplFin/FPulse.GainElectrique();
+			LastEtoile.TEchan=TIndex;
+			LastEtoile.TFin=Tfin;
+			LastEtoile.InpCurrNoisRMS=Vrms/FPulse.GainElectrique();
+			LastEtoile.X2Calc=X2Min;
+			LastEtoile.NoDiode=NoPhDiod;
 			LastEtoile.FitForme=SuccesAFine;
-			LastEtoile.X2Calc=X2Min;
-			LastEtoile.InpCurrNoisRMS=Vrms/FPulse.GainElectrique();
-			LastEtoile.TEchan=TIndex;
-			LastEtoile.InpCurrent= AmplRes/FPulse.GainElectrique();
-			LastEtoile.NoDiode=NoPhDiod;
 			LastEtoile.LargMiHauteur=widthHalfMax;
+			
+/*			cout<<setprecision(9);
+			cout<<TIndex<<" "<<Tfin<<" "<<AmplRes<<" "<<AmplFin<<endl;
+			cout<<TIndex-Tfin<<" "<<(AmplRes-AmplFin)/AmplFin<<endl;
+*/
 		}
 	}
@@ -199,6 +204,8 @@
 // On calcule le Vrms sur le prepulse
 	Vrms=0.;
-	for (int i=0; i<Prepulselong; i++) Vrms+=PhDiodPiste[i]*PhDiodPiste[i];
-	Vrms=sqrt(Vrms)/Prepulselong;
+	for (int i=0; i<Prepulselong; i++) {
+		Vrms+=PhDiodPiste[i]*PhDiodPiste[i];
+	}
+	Vrms=sqrt(Vrms/Prepulselong);
 	if(Vrms<SSTLsbVal) Vrms=SSTLsbVal;		// Pour eviter les VRMS=0.
 	
@@ -281,9 +288,7 @@
 // Maintenant que l'on se doute que il y a une etoile 
 // On veut connaitre son flux et son temps de passage
-// Nécessite d'avoir un ordre d'idee de la vitesse de rotation du ballon.
+// Nécessite de connaitre la vitesse de rotation du ballon.
 
 		// BUGG devra etre extrait des headers acquisition. Ca peut changer!!!!!!
-
-	
 			
 	int IndexDebutEvt=MaxIndex-SSTLargEvtIndex();
@@ -292,5 +297,6 @@
 		// Pointeur origine du tableau d'echantillon sur lequel sera calculé le fit
 	double DeltaTemps=0.;
-// Pour chaque decalage en temps, on estime un amplitude et calcule le X2
+	
+// Pour chaque decalage en temps, on estime une amplitude et calcule le X2
 	for(int k=0; k<SSTnbPasFit; k++) {
 		DeltaTemps=TFExcursion-k*TPasTFit;
@@ -314,44 +320,55 @@
 	X2Min=1.e99;
 	int X2MinIndex=-1;
-	for(int k=0; k<SSTnbPasFit; k++) 
+	for(int k=0; k<SSTnbPasFit; k++) { 
 		if (X2[k]<X2Min) {
 			X2Min=X2[k];
 			X2MinIndex=k;
 		}
-
+	}
+	
 	if((X2MinIndex>0)&&(X2MinIndex<(SSTnbPasFit-1))) {
 	
 // On fitte une parabole sur les trois X2 qui encadrent le min
-	double Di;	// Index (non entier) du minimum du X2
+		double Di;	// Index (non entier) du minimum du X2
 		double X=(X2[X2MinIndex+1]-X2Min)/(X2Min-X2[X2MinIndex-1]);		
 		Di=0.5*(X+1)/(X-1);
 
+// Le X2 est mimimum pour le n° de pas de fit X2MinIndex+Di 
 // On calcule l'amplitude estimee a ce temps
 		double Som1=0.; pFitArray=pFitArray0;
 		DeltaTemps=TFExcursion-(X2MinIndex-Di)*TPasTFit;
 		for(int i=0; i<SSTLongIndexEvt(); i++, pFitArray++) 
-			Som1+=(*pFitArray)*FPulse.PulseShape(i*PasTempsEch-DeltaTemps);
-		AmplRes=Som1/AmplNorm;
-		
-//Le X2 est mimimum pour le n° de pas de fit X2MinIndex+Di 
+				Som1+=(*pFitArray)*FPulse.PulseShape(i*PasTempsEch-DeltaTemps);
+		AmplFin=Som1/AmplNorm;
+			
+
 
 #ifdef PEtoileDebug
-		double* PulseTrak=new double [SSTLongIndexEvt()];
+		double *PulseTrak=new double [SSTLongIndexEvt()];
 #endif
-
+// On calcule le X2 correspondant
 		double X2Som1=0.; double dummy=0.;pFitArray=pFitArray0;
 		for(int i=0;i<SSTLongIndexEvt();i++,pFitArray++) {	
+		
 #ifdef PEtoileDebug
 			PulseTrak[i]=FPulse.PulseShape(i*PasTempsEch-DeltaTemps);
 #endif
-			dummy=(*pFitArray)-AmplRes*FPulse.PulseShape(i*PasTempsEch-DeltaTemps); 	// Différence
+			dummy=(*pFitArray)-AmplFin*FPulse.PulseShape(i*PasTempsEch-DeltaTemps); 	// Différence
 			X2Som1+=dummy*dummy;														// Au carré
 		}
-					
+						
 		X2Min=X2Som1/(SSTLongIndexEvt()*Vrms*Vrms);
-	
-		TIndex=indexDebutPiste+IndexDebutEvt+DeltaTemps/PasTempsEch;
-					//Ouff!!!!
+		
+		Tfin= indexDebutPiste+IndexDebutEvt+DeltaTemps/PasTempsEch;
+			//Ouff!!!!
+/*			
+		cout<<setprecision(9)<<endl;			
+		cout<<Tfin<<" "<<indexDebutPiste<<" "<<IndexDebutEvt<<" "<<DeltaTemps/PasTempsEch<<endl;
+*/		
 		SuccesAFine=true;
+		
+#ifdef PEtoileDebug
+		delete[] PulseTrak;
+#endif
 	}
 	else {				// Echec, c'est tres bizarre! On doit etre dans le bruit
Index: trunk/Poubelle/archTOI.old/pisteetoile.h
===================================================================
--- trunk/Poubelle/archTOI.old/pisteetoile.h	(revision 533)
+++ trunk/Poubelle/archTOI.old/pisteetoile.h	(revision 534)
@@ -5,10 +5,10 @@
 #include "formepulse.h"
 
-/*	// D. Yvon, CE Saclay, 08/99
+/*	// D. Yvon, CE Saclay, DAPNIA/SPP, 08/99
 
 	// Analyse the Photodiode track to find star pulse.
 	// Caracterise the time and amplitude of the star Pulse
 
-	We analyse a set of 32 samples. The 16 first are considered as prepulse sample.
+	We analyse a set of 48 samples. The 32 first are considered as prepulse sample.
 	On the prepulse: 
 		We compute baseline and substract it. 
@@ -17,5 +17,9 @@
 		Look for trigger
 	If triggered :
-		Look for maximum. If max found 20< Max< 28
+		Look for maximum. 
+		Compute Full width half maximum
+		Fit a paroabole on max of the pulse
+		return max fitte and time of max fitte
+	if analfine
 		Iterate time fit on pulse area and compute amplitude and X2
 		Find best X2. 
@@ -23,5 +27,5 @@
 		Build SSTStar.
 		
-	That's it. Test code tstpisteetoile.cc can be found in tstroutines folder.
+	That's it. 
 	When  done push the track eigth samples forward and iterate analysis. 
 */
@@ -39,9 +43,9 @@
 // 	Parametrisation du Trigger 
 #define SeuilGachette (6.) 				// On déclenche à SeuilGachette sigmas
-#define SSTLsbVal (10./4096)
+#define SSTLsbVal (10./4096.)
 
 //	Parametrisation Analyse Fine
 #define TFExcursion (15.e-3)			// Secondes: Excursion du fit autour de MaxIndex
-#define TPasTFit (2.5e-3)				// Secondes:
+#define TPasTFit (1.5e-3)				// Secondes:
 			// Secondes:
 
@@ -70,9 +74,12 @@
 	inline int SSTLargEvtIndex(); 
 	inline int SSTLongIndexEvt();
+	static TransFuncElec Trapani;
+	static FormePulse FPulse;
+	
 protected:
 	double PasTempsEch; 	//Secondes 
 // Idendificateur, repères et gestion 
 	short NoPhDiod;
-	int indexDebutPiste; 	// A actualiser dans push() et Fill()! BUGG!!!!
+	long indexDebutPiste; 	// A actualiser dans push() et Fill()
 	bool DiodVivante;		// Si false, On ne fait rien 
 	
@@ -88,11 +95,13 @@
 	double Vrms;
 	short MaxIndex;			// Index de l'amplitude Max en analyse Trig()
+	double TIndex;
 	double AmplMax;
+	double AmplRes;
 	int widthHalfMax;
+	int SSTnbPasFit;
 //	double integ;
 // Variables Resultat d'analyse fine
-	
-	double AmplRes;
-	double TIndex;
+	double AmplFin;
+	double Tfin;
 	double X2Min;
 	bool SuccesAFine;
@@ -109,6 +118,5 @@
 	double* X2;		//Tableau des X2 calculés
 	
-	static TransFuncElec Trapani;
-	static FormePulse FPulse;
+
 	
 };
Index: trunk/Poubelle/archTOI.old/requesthandler.h
===================================================================
--- trunk/Poubelle/archTOI.old/requesthandler.h	(revision 534)
+++ trunk/Poubelle/archTOI.old/requesthandler.h	(revision 534)
@@ -0,0 +1,16 @@
+// requesthandler.h
+// Eric Aubourg         CEA/DAPNIA/SPP   septembre 1999
+
+#ifndef REQUESTHANDLER_H
+#define REQUESTHANDLER_H
+
+#include <string>
+#include "toi.h"
+
+class RequestHandler {
+public:
+  virtual bool processTOIReq(TOI const& toi, string line)=0;
+  virtual bool processOption(string keyw, string args)=0;
+};
+
+#endif
Index: trunk/Poubelle/archTOI.old/skyposition.h
===================================================================
--- trunk/Poubelle/archTOI.old/skyposition.h	(revision 534)
+++ trunk/Poubelle/archTOI.old/skyposition.h	(revision 534)
@@ -0,0 +1,36 @@
+// skyposition.h
+// Eric Aubourg         CEA/DAPNIA/SPP   septembre 1999
+
+#ifndef SKYPOSITION_H
+#define SKYPOSITION_H
+
+class SkyPosition {
+public:
+  SkyPosition();
+  
+  void setEarthLocation(double  latitude, double  longitude);
+  void getEarthLocation(double& latitude, double& longitude) const;
+  
+  void setAltAz(double  altitude, double  azimut);
+  void getAltAz(double& altitude, double& azimut) const;
+  
+  void setEquat(double  ra, double  dec);
+  void getEquat(double& ra, double& dec);
+  
+  void setGalac(double  l, double  b);
+  void getGalav(double& l, double& b) const;
+  
+  void setTSid(double  lst);
+  void getTSid(double& lst) const;
+  
+  // void setMJD(double mjd); Pour faire proprement, garder synchro avec tsid...
+  
+protected:
+  // All this is kept in sync. Recompute from AltAz on location/tsid change.
+  double lat, long;
+  double alt, az;
+  double ra, dec;  
+  double tsid;
+};
+
+#endif
Index: trunk/Poubelle/archTOI.old/sstetoile.cc
===================================================================
--- trunk/Poubelle/archTOI.old/sstetoile.cc	(revision 533)
+++ trunk/Poubelle/archTOI.old/sstetoile.cc	(revision 534)
@@ -1,14 +1,15 @@
 #include "sstetoile.h"
+
+// D. Yvon, CE Saclay, DAPNIA/SPP, 08/99
 
 void SSTEtoile::print(ofstream& str) {
 	str<<setprecision(11);
-	str<<InpCurrent<<'\t'<<TEchan<<'\t'<<NoDiode<<'\t'<<LargMiHauteur;
-	str<<'\t'<<InpCurrNoisRMS<<endl;
-	//	<<'\t'<<X2Calc<<'\t'<<FitForme
+	str<<InpCurrent<<'\t'<<InpCurFin<<'\t'<<TEchan<<'\t'<<TFin<<'\t'<<NoDiode<<'\t'<<LargMiHauteur;
+	str<<'\t'<<InpCurrNoisRMS<<'\t'<<X2Calc<<'\t'<<FitForme<<endl;
 	return;
 }
 
 string SSTEtoile::printHeader() {
-	string a("InpCurrent\tTempsEchan\tNoDiode\tLarMiHauteur\tICurrRMS\tX2Calc\tFitForme");
+	string a("InpCurrent\tInpCurFin\tTempsEchan\tTFin\tNoDiode\tLarMiHauteur\tICurrRMS\tX2Calc\tFitForme");
 	return a;
 }
Index: trunk/Poubelle/archTOI.old/sstetoile.h
===================================================================
--- trunk/Poubelle/archTOI.old/sstetoile.h	(revision 533)
+++ trunk/Poubelle/archTOI.old/sstetoile.h	(revision 534)
@@ -1,4 +1,6 @@
 #ifndef SSTEtoile_H
 #define SSTEtoile_H
+
+// D. Yvon, CE Saclay, DAPNIA/SPP, 08/99
 
 #include <stdio.h>
@@ -11,8 +13,10 @@
 public:
 	double InpCurrent;		// En Ampère
+	double InpCurFin; 		// En ampère, 	Analyse fine
 //	double IInteg;			// En Ampère
-	double TEchan;			// Temps en indexEchantillon
+	double TEchan;			// Temps en indexEchantillon analyse trig
+	double TFin;			// Temps en indexEchantillon analyse fine
 	double InpCurrNoisRMS;	// Bruit en Ampère
-	double X2Calc;			// Sans dimension
+	double X2Calc;			// Sans dimension, analyse fine
 	int NoDiode;
 	bool FitForme;			// Fit de forme?
@@ -20,5 +24,5 @@
 	
 	void print(ofstream& str);
-	string printHeader();
+	static string printHeader();
 };
 
Index: trunk/Poubelle/archTOI.old/ssthandler.cc
===================================================================
--- trunk/Poubelle/archTOI.old/ssthandler.cc	(revision 533)
+++ trunk/Poubelle/archTOI.old/ssthandler.cc	(revision 534)
@@ -12,11 +12,11 @@
 
 #include <math.h>
+#include <iostream>
 #include "ssthandler.h"
 #include "pisteetoile.h"
 
-#ifdef SST_DUMPLOG
+
 ofstream SSTHandler::sstchass("SSTChassLogFile");
 bool     SSTHandler::sstchassinit=false;
-#endif
 
 // diodpermut[i] = channel de la diode i
@@ -180,4 +180,17 @@
 }
 
+
+// D. Yvon, CEA/DAPNIA/SPP Saclay, 08/99
+
+
+#ifdef SSTStatLog
+	static ofstream sststat("SSTStatLog");
+	static int compteurBlock=0;
+	static int nbStar=0;
+	#include "ssthardware.h"
+	#include "archparam.h"
+#endif
+
+
 int SSTHandler::FindStars(block_type_sst* blk) {
 	NbStarInBlock=0;
@@ -224,10 +237,12 @@
 					//On empile sur la map.
 				NbStarInBlock++;
-#ifdef SST_DEBUG			
+#ifdef SSTDUMP			
 			// On écrit les pistes ayant déclénchées
 				int NoDiodeEvt=LastStar.NoDiode;
-				if(pPisteDump[NoDiodeEvt]->is_open())	
-					for(int noSamp=0; noSamp<NbSampleBlock;noSamp++)
-						(*pPisteDump[NoDiodeEvt])<<noStarDet<<'\t'<<NoDiode<<'\t'<<NoFirstSpInBlock+noSamp<<'\t'<<Diodedata[noSamp]<<endl;
+				if(NoDiodeEvt<NbChanDump) {
+					if(pPisteDump[NoDiodeEvt]->is_open())	
+						for(int noSamp=0; noSamp<NbSampleBlock;noSamp++)
+							(*pPisteDump[NoDiodeEvt])<<noStarDet<<'\t'<<NoDiode<<'\t'<<NoFirstSpInBlock+noSamp<<'\t'<<Diodedata[noSamp]<<endl;
+				}
 #endif
 				noStarDet++;
@@ -257,7 +272,6 @@
 		LastBlockStarVec.push_back((*StarHistReIter).second);
 	
-#ifdef SST_DUMPLOG
-	if(NbStarInBlock>0) {
-			
+#ifdef SSTChassLog
+	if(NbStarInBlock>0) {			
 	// On écrit les étoiles detectées
 		vector<SSTEtoile>::reverse_iterator StarVecRevIter;
@@ -266,5 +280,16 @@
 			(*StarVecRevIter).print(sstchass);
 	}
-		
+#endif
+
+#ifdef SSTStatLog
+	int nbBlockincircle=(int) (PeriodRotTeles/(archParam.acq.perEch*72.));
+//	if((compteurBlock%nbBlockincircle)==0) 
+	{
+//	if((compteurBlock%5)==0) {
+  		sststat<<numero_block(blk)<<'\t'<<nbStar<<'\t'<<noStarDet<<endl;
+  		nbStar=0;
+  	}
+  		nbStar+=NbStarInBlock;
+  		compteurBlock++;
 #endif
 
@@ -276,12 +301,10 @@
 	for(int i=0; i<NbPhotDiodBarette; i++) PisteBar[i]=new PisteEtoile(i);
 	StarHistoryMap.clear();
-#ifdef SST_DUMPLOG
 	if (!sstchassinit) {
 	  sstchass<<LastStar.printHeader()<<endl;
 	  sstchassinit = true;
 	}
-#endif
-	
-#ifdef SST_DEBUG	
+	
+#ifdef SSTDUMP	
 	char s[32];
 	string fileName;
@@ -301,5 +324,5 @@
 		}
 */			
-		pPisteDump[pistNumb]=new ofstream(fileName.c_str(),ios::out|ios::trunc);
+		pPisteDump[pistNumb]=new ofstream(fileName.c_str(),ios::out|ios::app);
 		
 		if(!(*pPisteDump[pistNumb]).is_open()) {
@@ -317,10 +340,10 @@
 	delete[] PisteBar;
 		
-#ifdef SST_DEBUG	
+#ifdef SSTDUMP	
 	for (int pistNumb=0; pistNumb<NbChanDump; pistNumb++) {
 		pPisteDump[pistNumb]->close();
 		delete pPisteDump[pistNumb];
 	}
-	delete 	pPisteDump;
+	delete[] pPisteDump;
 #endif
 
@@ -377,8 +400,6 @@
 {
   lastBlkNum = numero_block(blk);
-  if (prcTodo != 0) {
-    for (int i = 0; i<nb_per_block*2; i++) {
-      DecodeTMBlock(blk, i, diodeRaw[i]);
-    }
+  for (int i = 0; i<nb_per_block*2; i++) {
+    DecodeTMBlock(blk, i, diodeRaw[i]);
   }
   if (prcTodo & permDiode) {
Index: trunk/Poubelle/archTOI.old/ssthandler.h
===================================================================
--- trunk/Poubelle/archTOI.old/ssthandler.h	(revision 533)
+++ trunk/Poubelle/archTOI.old/ssthandler.h	(revision 534)
@@ -24,9 +24,11 @@
 
 //#define SST_DEBUG
-//#define SST_DUMPLOG
-#define NbChanDump (10)
+//#define SSTDUMP
+#define SSTChassLog
+//#define SSTStatLog
+
+#define NbChanDump (3)
 #define	NbPhotDiodBarette (46)
 #define NbEtInMapMax 	(100)
-#define SSTChassLog (true)
 #define NbSampleBlock (2*nb_per_block)
 // Fin Zone findStar
@@ -46,5 +48,4 @@
   void NeedProcess(int prcMask);
   void ProcessBlock(block_type_sst*);
-  bool NeedBlocks() {return prcTodo != 0;}
 
   static void Has2Bars(bool, int elecOffset=0); // elecOffset : which wired together
@@ -63,6 +64,4 @@
   double getStarTime(int iSampl, int istar); 
   			// return star time in this sample
-  			
-  static int getDiodPermut(int i) {return diodpermut[i];}
 
 protected:
@@ -92,5 +91,5 @@
   PisteEtoile** PisteBar; 
   	
-#ifdef SST_DEBUG
+#ifdef SSTDUMP
   	ofstream** pPisteDump;
 #endif
@@ -111,4 +110,5 @@
   int noStarDet;
   int FirstSplNb(block_type_sst* blk); // Calcule l'index du premier echantillon du block analysé
+  
   static ofstream sstchass;
   static bool     sstchassinit;
Index: trunk/Poubelle/archTOI.old/ssthardware.h
===================================================================
--- trunk/Poubelle/archTOI.old/ssthardware.h	(revision 533)
+++ trunk/Poubelle/archTOI.old/ssthardware.h	(revision 534)
@@ -1,4 +1,6 @@
 #ifndef SSTHARDWARE_SEEN
 #define SSTHARDWARE_SEEN
+
+// D. Yvon, CE Saclay, DAPNIA/SPP, 08/99
 
 // Telescope SST
@@ -11,6 +13,6 @@
 
 // Paramètres du Vol
-#define PeriodRotTeles (20.)						// Periode de rotation du telescope en seconde
-
+#define PeriodRotTeles (20.)					// Periode de rotation du telescope en seconde
+//#define PeriodRotTeles (30.)					// version Kiruna
 
 #endif
Index: trunk/Poubelle/archTOI.old/sststarfinder.cc
===================================================================
--- trunk/Poubelle/archTOI.old/sststarfinder.cc	(revision 534)
+++ trunk/Poubelle/archTOI.old/sststarfinder.cc	(revision 534)
@@ -0,0 +1,252 @@
+// sststarfinder.cc
+// Eric Aubourg & Dominique Yvon        CEA/DAPNIA/SPP   octobre 1999
+
+#include "sststarfinder.h"
+#include "pisteetoile.h"
+#include "toimanager.h"
+#include "archparam.h"
+
+ofstream SSTStarFinder::sstchass("SSTChassLogFile");
+bool     SSTStarFinder::sstchassinit=false;
+
+#define sstStarCount "sstStarCount"
+#define sstStarZ     "sstStarZ"
+#define sstStarF     "sstStarF"
+#define sstStarSN    "sstStarSN"
+#define sstStarUTC   "sstStarUTC"
+
+
+SSTStarFinder::SSTStarFinder() {
+  lastFedSample = -1;
+  lastAnaSample = -1;
+  lastContSample = -1;
+  lastKeptSample = -1;
+    
+  findStarConstruct();
+  
+  TOIProducer* prod = TOIManager::findTOIProducer(TOI("sstDiode",0));
+  if (!prod) {
+    cerr << "SSTStarFinder : cannot find producer for sstDiode" << endl;
+    exit(-1);
+  }
+  
+  sstprod = dynamic_cast<TOILLSSTProducer*>(prod);
+  if (!sstprod) {
+    cerr << "SSTStarFinder : producer for sstDiode is not a TOILLSSTProducer" << endl;
+    exit(-1);
+  }
+  
+  sstprod->registerProcessor(this);
+
+  possibleTOIs.insert(TOI(sstStarCount,   TOI::all, "", "integer"));  
+  possibleTOIs.insert(TOI(sstStarZ,       TOI::all, "", "integer"));  
+  possibleTOIs.insert(TOI(sstStarF,       TOI::all, "", "ADU"));  
+  possibleTOIs.insert(TOI(sstStarSN,      TOI::all, "", "samplenum"));  
+  possibleTOIs.insert(TOI(sstStarUTC,     TOI::all, "", "hours"));  
+
+}
+
+SSTStarFinder::~SSTStarFinder(){
+  findStarDestruct();
+}
+
+string SSTStarFinder::getName() {
+  return("SSTStarFinder 1.0");
+}
+
+void SSTStarFinder::addTOI(TOI& toi, TOIAbsorber* client) {
+  TOIProducer::addTOI(toi, client);
+  TOIManager::activateLLProducer(sstprod);
+}
+
+void SSTStarFinder::Has2Bars(bool has, int eo)
+{
+  has2bars = has;
+  elecOffset = eo;
+}
+
+#ifdef SSTStatLog
+	static ofstream sststat("SSTStatLog");
+	static int compteurBlock=0;
+	static int nbStar=0;
+	#include "ssthardware.h"
+	#include "archparam.h"
+#endif
+
+void SSTStarFinder::findStarConstruct() {
+	PisteBar=new PisteEtoile*[NbPhotDiodBarette];
+	for(int i=0; i<NbPhotDiodBarette; i++) PisteBar[i]=new PisteEtoile(i);
+	StarHistoryMap.clear();
+	if (!sstchassinit) {
+	  sstchass<<SSTEtoile::printHeader()<<endl;
+	  sstchassinit = true;
+	}
+}
+
+void SSTStarFinder::findStarDestruct() {
+	for(int i=0; i<NbPhotDiodBarette; i++) {
+		delete PisteBar[i];
+	}
+	delete[] PisteBar;
+}
+
+void SSTStarFinder::dataFeed(long sampleNum, int* diodeSignal) {
+  if (producedTOIs.empty()) return;
+  if (sampleNum == lastFedSample+1) {
+	for(int i=0;i<NbPhotDiodBarette; i++) {	
+      PisteBar[i]->push(diodeSignal+i,1);
+    }
+    lastFedSample++;
+  } else {
+	for(int i=0;i<NbPhotDiodBarette; i++) {	
+      PisteBar[i]->fill(diodeSignal+i,sampleNum,1);
+    }
+    lastFedSample = lastContSample = sampleNum;
+  }
+  
+  if ((sampleNum >= lastAnaSample+8) && (sampleNum - lastContSample >= 40)) {
+    lastAnaSample = sampleNum;
+    if (lastKeptSample<0) lastKeptSample = sampleNum-8;
+	for(int i=0;i<NbPhotDiodBarette; i++) {	
+      if (PisteBar[i]->traque()) {				// On a trouve!
+        SSTEtoile star = PisteBar[i]->DonneEtoile();
+        StarHistoryMap[star.TEchan]=star;
+        gotStar(star);
+      }
+    }
+  }
+}
+
+void SSTStarFinder::registerProcessor(SSTStarProcessor* p) {
+  processors.push_back(p);
+  TOIManager::activateLLProducer(sstprod);
+}
+
+int SSTStarFinder::getNumbStar(int iSampl) {
+	StarHistIter IterLow=StarHistoryMap.lower_bound((double)iSampl);
+	StarHistIter IterHigh=StarHistoryMap.upper_bound((double)(iSampl+1.));
+	int Compteur=0;
+	while (!(IterLow==IterHigh)) {IterLow++; Compteur++;}
+	return Compteur;
+}
+
+double SSTStarFinder::getStarF(int iSampl, int istar){ 
+	if( (getNumbStar(iSampl)==0)||(getNumbStar(iSampl)<=istar)) return -1;
+	else {
+		StarHistIter IterLow=StarHistoryMap.lower_bound((double)iSampl);
+		while(!(istar==0)) {
+			IterLow++;
+			istar--;
+		}
+	return (double) ((*IterLow).second).InpCurrent;
+	}
+}
+
+
+int SSTStarFinder::getStarZ(int iSampl, int istar) {
+	if( (getNumbStar(iSampl)==0)||(getNumbStar(iSampl)<=istar)) return -1;
+	StarHistIter IterLow=StarHistoryMap.lower_bound((double)iSampl);
+	while(!(istar==0)) {
+		IterLow++;
+		istar--;
+	}
+	return ((*IterLow).second).NoDiode;
+}
+
+double SSTStarFinder::getStarTime(int iSampl, int istar) {
+	if( (getNumbStar(iSampl)==0)||(getNumbStar(iSampl)<=istar)) return -1;
+	StarHistIter IterLow=StarHistoryMap.lower_bound((double)iSampl);
+	while(!(istar==0)) {
+		IterLow++;
+		istar--;
+	}
+	return ((*IterLow).second).TEchan;
+}
+
+
+void SSTStarFinder::gotStar(SSTEtoile const& star) {
+  for (vector<SSTStarProcessor*>::iterator i = processors.begin(); 
+       i != processors.end(); i++) {
+      (*i)->dataFeed(star);    
+  }
+}
+
+
+// $CHECK$ we handle correctly only the first star
+long SSTStarFinder::firstSampleNum(TOI const&) {
+  if (StarHistoryMap.empty()) return -1;
+  StarHistIter i = StarHistoryMap.begin();
+  return floor((*i).second.TEchan);
+}
+
+long SSTStarFinder::lastSampleNum(TOI const&) {
+  if (StarHistoryMap.empty()) return -1;
+  StarHistIter i = StarHistoryMap.end();
+  i--;
+  return floor((*i).second.TEchan);
+}
+  
+bool SSTStarFinder::canGetValue(long sampleNum, TOI const& toi) {
+  if (sampleNum < lastKeptSample) return false;
+  if (sampleNum > lastAnaSample) return false;
+  if (toi.name == sstStarCount) return true;
+  if (getNumbStar(sampleNum) > toi.index) return true;
+  return false;
+}
+
+// $CHECK$ not done properly, complicated !!!
+bool SSTStarFinder::canGetPrevValue(long sampleNum, TOI const& toi) {
+  return canGetValue(sampleNum-1, toi);
+}
+
+bool SSTStarFinder::canGetNextValue(long sampleNum, TOI const& toi) {
+  return canGetValue(sampleNum+1, toi);
+}
+
+bool SSTStarFinder::canGetValueLater(long sampleNum, TOI const&) {
+  return sampleNum > lastAnaSample;
+}
+  
+double SSTStarFinder::getPrevValue(long& sampleNum, TOI const& toi) {
+  return getValue(--sampleNum, toi);
+}
+
+double SSTStarFinder::getNextValue(long& sampleNum, TOI const& toi) {
+  return getValue(++sampleNum, toi);
+}
+
+double SSTStarFinder::getValue(long sampleNum, TOI const& toi) {
+  if (sampleNum < lastKeptSample) return -1;
+  if (sampleNum > lastAnaSample) return -1;
+  if (toi.name == sstStarCount) {
+    return getNumbStar(sampleNum);
+  }
+  if (toi.name == sstStarF) {
+    return getStarF(sampleNum, toi.index);
+  }
+  if (toi.name == sstStarZ) {
+    return getStarZ(sampleNum, toi.index);
+  }
+  if (toi.name == sstStarSN) {
+    return getStarTime(sampleNum, toi.index);
+  }
+  if (toi.name == sstStarUTC) {
+    return archParam.acq.SN2UTC(getStarTime(sampleNum, toi.index));
+  }
+
+  return -1;
+}
+
+long SSTStarFinder::wontNeedEarlier(TOI const& toi, TOIAbsorber* client, long t) {
+  long oldT = lastNeededSample[toi.ref][client];
+  if (t<oldT) return -1;
+  lastNeededSample[toi.ref][client] = t;
+  map<TOIAbsorber*, long> m = lastNeededSample[toi.ref];
+  long min=999999999L;
+  for (map<TOIAbsorber*, long>::iterator i = m.begin(); i != m.end(); i++) {
+    if ((*i).second < min) min = (*i).second;
+  }
+  while(!StarHistoryMap.empty() && (*StarHistoryMap.begin()).first < min) StarHistoryMap.erase(StarHistoryMap.begin());
+  lastKeptSample=min;
+  return min;
+}
Index: trunk/Poubelle/archTOI.old/sststarfinder.h
===================================================================
--- trunk/Poubelle/archTOI.old/sststarfinder.h	(revision 534)
+++ trunk/Poubelle/archTOI.old/sststarfinder.h	(revision 534)
@@ -0,0 +1,106 @@
+// sststarfinder.h
+// Eric Aubourg & Dominique Yvon        CEA/DAPNIA/SPP   octobre 1999
+
+#ifndef SSTSTARFINDER_H
+#define SSTSTARFINDER_H
+
+#include <math.h>
+#include <vector>
+#include <map>
+
+#ifndef nb_max_bolo
+#define _archeops		//  Acquisition Archeops (avec transputer) 
+#define programme
+extern "C" {
+#include "archeops.h"
+}
+#endif
+
+#include "sstetoile.h"
+#include "pisteetoile.h"
+#include "pisteetoile.h"
+
+
+//#define SST_DEBUG
+//#define SSTDUMP
+#define SSTChassLog
+//#define SSTStatLog
+
+#define NbChanDump (3)
+#define	NbPhotDiodBarette (46)
+#define NbEtInMapMax 	(100)
+#define NbSampleBlock (2*nb_per_block)
+
+#include "toillsstproducer.h"
+
+class SSTStarProcessor {
+public:
+   virtual void dataFeed(SSTEtoile const&)=0; 
+};
+
+class SSTStarFinder : public SSTDataProcessor, public TOIProducer {
+public:
+  SSTStarFinder();
+  ~SSTStarFinder();
+  
+  virtual void dataFeed(long sampleNum, int* diodeSignal); // signal for 46 diodes...
+
+  static void Has2Bars(bool, int elecOffset=0); // elecOffset : which wired together
+  string getName();
+
+  int  getNumbStar(int iSampl);	
+  			// return number of star found in sample number iSampl	
+  int  getStarZ(int iSampl, int istar); 
+  			// return diode number of the star     
+  double getStarF(int iSampl, int istar);  
+  			// return star flux in Ampère
+  double getStarTime(int iSampl, int istar); 
+  			// return star time in this sample
+
+  virtual long   firstSampleNum(TOI const&);
+  virtual long   lastSampleNum(TOI const&);
+  
+  virtual bool   canGetValue(long sampleNum, TOI const& toi); // for this samplenum
+  virtual bool   canGetPrevValue(long sampleNum, TOI const& toi); 
+  virtual bool   canGetNextValue(long sampleNum, TOI const& toi); 
+  virtual bool   canGetValueLater(long sampleNum, TOI const& toi);  // Might, later but not now
+  
+  virtual double getPrevValue(long& sampleNum, TOI const& toi);
+  virtual double getNextValue(long& sampleNum, TOI const& toi);
+  virtual double getValue(long sampleNum, TOI const& toi);
+  virtual long   wontNeedEarlier(TOI const&, TOIAbsorber* client, long);
+
+  void registerProcessor(SSTStarProcessor*);
+  void addTOI(TOI& toi, TOIAbsorber* client);
+
+protected:
+  vector<SSTStarProcessor*> processors;
+  void gotStar(SSTEtoile const& star);
+
+  long lastFedSample; // dernier samplenum vu
+  long lastAnaSample; // dernier samplenum utilise par traque
+  long lastContSample; // dernier samplenum utilise en mode fill
+  
+  PisteEtoile** PisteBar; 
+  
+  	// Are there two photoDiod Arrays and how are they connected?
+  static bool  has2bars;
+  static int   elecOffset;
+
+  map<double,SSTEtoile> StarHistoryMap;	// On stocke les étoiles de manière ordonnée en temps
+  typedef  map<double,SSTEtoile>::iterator StarHistIter;
+  typedef  map<double,SSTEtoile>::const_iterator StarConstHistIter;
+  long lastKeptSample;
+  
+  
+  static ofstream sstchass;
+  static bool     sstchassinit;
+  
+  void findStarConstruct();
+  void findStarDestruct();
+  
+  TOILLSSTProducer* sstprod;
+};
+
+
+#endif
Index: trunk/Poubelle/archTOI.old/starmatcher.cc
===================================================================
--- trunk/Poubelle/archTOI.old/starmatcher.cc	(revision 534)
+++ trunk/Poubelle/archTOI.old/starmatcher.cc	(revision 534)
@@ -0,0 +1,137 @@
+#include "starmatcher.h"
+#include "sststarfinder.h"
+#include "toimanager.h"
+#include "archexc.h"
+
+extern "C" {
+#include "aa_hadec.h"
+}
+
+#include <stdio.h>
+
+StarMatcher::StarMatcher() {
+  possibleTOIs.insert(TOI("dummatcher",      TOI::unspec, "", "blabla"));  
+  
+  FILE* f;
+  
+  f = fopen("gsc7.dat","r");
+  if (!f) throw ArchExc("Error opening gsc7.dat");
+  
+  fread(&nstars, sizeof(long), 1 , f);
+  stars = new gscStar[nstars];
+  fread(stars, sizeof(gscStar), nstars, f);
+  fclose(f);
+
+  TOIProducer* prod = TOIManager::findTOIProducer(TOI("sstStarCount"));
+  if (!prod) {
+    cerr << "StarMatcher : cannot find producer for sstStarCount" << endl;
+    exit(-1);
+  }
+  
+  SSTStarFinder* sprod = dynamic_cast<SSTStarFinder*>(prod);
+  if (!sprod) {
+    cerr << "StarMatcher : producer for sstStarCount is not a SSTStarFinder" << endl;
+    exit(-1);
+  }
+  
+  sprod->registerProcessor(this);
+
+}
+
+string StarMatcher::getName() {
+  return("StarMatcher 1.0");
+}
+
+static ofstream starstream("stars.dat");
+
+void StarMatcher::dataFeed(SSTEtoile const& x) {
+  lastStars[(long)x.TEchan] = x;
+}
+
+
+double StarMatcher::getValue(long sampleNum, TOI const& toi) {
+  if (lastStars.find(sampleNum) == lastStars.end()) return 0;
+  
+  SSTEtoile lastStar = lastStars[sampleNum];
+
+
+  map<TOI, TOIProducer*> m = neededTOIs[toi];
+  double lat, lon, ts, alpha, delta, az;
+  
+  for (map<TOI, TOIProducer*>::iterator i = m.begin(); i != m.end(); i++) {
+    TOI inToi = (*i).first;
+    TOIProducer* prod =  (*i).second;
+    if (inToi.name == "latitude")  lat = prod->getValue(sampleNum, inToi);
+    if (inToi.name == "longitude") lon = prod->getValue(sampleNum, inToi);
+    if (inToi.name == "tsid")       ts = prod->getValue(sampleNum, inToi);
+    if (inToi.name == "alphaFPC")  alpha = prod->getValue(sampleNum, inToi);
+    if (inToi.name == "deltaFPC")  delta = prod->getValue(sampleNum, inToi);
+    if (inToi.name == "azimuthFPC")   az = prod->getValue(sampleNum, inToi);
+  }
+    
+  // find all stars +- 2 deg boresight
+  double dist = 2;
+  double dmin = delta - dist; if (dmin<-90) dmin=-90;
+  double dmax = delta + dist; if (dmax> 90) dmax= 90;
+  double amin = alpha - dist / cos(delta * 3.1415926/180) / 15.;
+  if (amin<0) amin += 24;
+  double amax = alpha + dist / cos(delta * 3.1415926/180) / 15.;
+  if (amax>24) amax -= 24;
+  
+  int a,b,c;
+  a=0; c=nstars-1;
+  while (a+1<c) {
+    b = (a+c)/2;
+    if (stars[b].dec < dmin) a=b; else c=b;
+  }
+  int imin = a;
+  a=0; c=nstars;
+  while (a+1<c) {
+    b = (a+c)/2;
+    if (stars[b].dec < dmax) a=b; else c=b;
+  }
+  int imax = c;
+
+  for (int i=imin; i<=imax; i++) {
+    if (stars[i].ra >= amin && stars[i].ra <= amax) {
+      double ha = (ts/3600. - stars[i].ra) * 15. * 3.1415926/180.;
+      double elv, azim;
+      hadec_aa(lat * 3.1415926/180., ha, stars[i].dec * 3.1415926/180.,
+               &elv, &azim);
+      elv  *= 180/3.1415926;
+      azim *= 180/3.1415926;
+      if (azim<0) azim += 360;
+     
+      starstream << sampleNum << " " << 
+        /*lastStar.TEchan << " " <<*/ lastStar.NoDiode << " " <<
+        alpha << " " << delta << " " <<
+        az << " " << 
+        stars[i].ra << " " << stars[i].dec << " " <<
+        elv << " " << azim << "\n";
+    }
+  }
+  
+  return 1;
+}
+
+
+set<TOI> StarMatcher::reqTOIFor(TOI const&) {
+  set<TOI> t; 
+  t.insert(TOI("latitude",  TOI::unspec, "interp"));
+  t.insert(TOI("longitude", TOI::unspec, "interp"));
+  t.insert(TOI("tsid",      TOI::unspec));
+  t.insert(TOI("alphaFPC",  TOI::unspec, "galcross0"));
+  t.insert(TOI("deltaFPC",  TOI::unspec, "galcross0"));
+  t.insert(TOI("azimuthFPC",  TOI::unspec, "galcross0"));
+  return t;
+}
+
+void StarMatcher::propagateLowBound(TOI const& toi, long sampleNum) {
+  for (map<long,SSTEtoile>::iterator i = lastStars.begin(); i != lastStars.end(); i++)
+    if ((*i).first < sampleNum) lastStars.erase(i);
+}
+
+
+
+
+
Index: trunk/Poubelle/archTOI.old/starmatcher.h
===================================================================
--- trunk/Poubelle/archTOI.old/starmatcher.h	(revision 534)
+++ trunk/Poubelle/archTOI.old/starmatcher.h	(revision 534)
@@ -0,0 +1,35 @@
+#ifndef STARMATCHER_H
+#define STARMATCHER_H
+
+
+#include "sststarfinder.h"
+#include "toipullproducer.h"
+
+class StarMatcher: public SSTStarProcessor, public TOIPullProducer {
+public:
+  StarMatcher();
+  
+  virtual void dataFeed(SSTEtoile const&); 
+
+  virtual string getName();
+  virtual double getValue(long sampleNum, TOI const& toi);
+
+protected:
+  virtual set<TOI>     reqTOIFor(TOI const&);
+  void  propagateLowBound(TOI const& toi, long sampleNum);
+#pragma options align=mac68k
+  struct gscStar {
+    float ra;
+    float dec;
+    short mag; // mag * 100
+  };
+#pragma options align=reset
+  
+  gscStar* stars;
+  long nstars;
+  
+  map<long,SSTEtoile> lastStars;
+};
+
+
+#endif
Index: trunk/Poubelle/archTOI.old/templocator.cc
===================================================================
--- trunk/Poubelle/archTOI.old/templocator.cc	(revision 533)
+++ trunk/Poubelle/archTOI.old/templocator.cc	(revision 534)
@@ -7,4 +7,5 @@
 #include "fitsio.h"
 #include "plgalcross.h"
+#include "archparam.h"
 
 #ifndef M_PI
@@ -78,5 +79,4 @@
   
   // On trouve les croisements juste avant et juste apres notre sampleNum
-  int icross;
   for (icross=0; icross<nGalCross; icross++) {
     if (crossings[icross] > sampleNum) break;
@@ -98,5 +98,5 @@
   if (fabs(azCr2-220) < fabs(azCr1-220)) azCross = azCr2;
   
-  double rotSpeed = 360./(crossings[icross] - crossings[icross-1]); // °/sample
+  rotSpeed = 360./(crossings[icross] - crossings[icross-1]); // °/sample
   
   azimBolGC = azCross - (sampleNum - (crossings[icross-1]+12))*rotSpeed;
@@ -104,4 +104,18 @@
   if (azimBolGC > 360) azimBolGC -= 360;
 }
+
+double TempLocator::getRotSpeed(int sampleNum) {
+  findGeomFromGC(sampleNum);
+  return rotSpeed / archParam.acq.perEch;
+}
+
+int  TempLocator::getCrossSamples(int sampleNum, int& SN1, int& SN2) {
+  findGeomFromGC(sampleNum);
+  if (icross == 0 || icross >= nGalCross) return -1;
+  SN1 = crossings[icross-1];
+  SN2 = crossings[icross];
+  return 0;
+}
+
 
 void TempLocator::getAltAzBolo(int sampleNum, int ibolo, double& elv, double& az) {
@@ -166,4 +180,6 @@
   aa_hadec (lat * M_PI/180, elv * M_PI/180, az * M_PI/180, &ha, &dec);
   ra = - (ha * 180. / M_PI / 15) + (ts/3600.);
+  while (ra>24) ra -= 24;
+  while (ra<0) ra += 24;
   dec = dec * 180. / M_PI;
   return ra;
@@ -187,4 +203,12 @@
 double TempLocator::getDeltaCenter(int sampleNum) {
   return getDeltaBolo(sampleNum, 11);
+}
+
+double TempLocator::getAzimutCenter(int sampleNum) {
+  return getAzimutBolo(sampleNum, 11);
+}
+
+double TempLocator::getElvCenter(int sampleNum) {
+  return getElvBolo(sampleNum, 11);
 }
 
Index: trunk/Poubelle/archTOI.old/templocator.h
===================================================================
--- trunk/Poubelle/archTOI.old/templocator.h	(revision 533)
+++ trunk/Poubelle/archTOI.old/templocator.h	(revision 534)
@@ -19,6 +19,10 @@
   double getAlphaBolo(int sampleNum, int ibolo);
   double getDeltaBolo(int sampleNum, int ibolo);
+  double getAzimutCenter(int sampleNum);
+  double getElvCenter(int sampleNum);
   double getAlphaCenter(int sampleNum);
   double getDeltaCenter(int sampleNum);
+  double getRotSpeed(int sampleNum); // deg/sec
+  int    getCrossSamples(int sampleNum, int& SN1, int& SN2);
   
   void getAltAzBolo(int sampleNum, int ibolo, double& elv, double& az);
@@ -36,4 +40,6 @@
   int xSampleNum; // pour le dernier calcul
   double azimBolGC;
+  double rotSpeed;
+  int icross;
   
   void findGeomFromGC(int sampleNum); // pour le bolo qui voit les xing
Index: trunk/Poubelle/archTOI.old/timetoiproducer.cc
===================================================================
--- trunk/Poubelle/archTOI.old/timetoiproducer.cc	(revision 534)
+++ trunk/Poubelle/archTOI.old/timetoiproducer.cc	(revision 534)
@@ -0,0 +1,73 @@
+// timetoiproducer.cc
+// Eric Aubourg         CEA/DAPNIA/SPP   septembre 1999
+
+#include "timetoiproducer.h"
+#include "archparam.h"
+#include "archexc.h"
+#include "requesthandler.h"
+
+#define sn "sampleNum"
+#define mjd "MJD"
+#define utc "UTC"
+
+
+TimeTOIProducer::TimeTOIProducer()
+{
+  possibleTOIs.insert(TOI(sn,  TOI::unspec, "", "integer"));  
+  possibleTOIs.insert(TOI(mjd, TOI::unspec, "", "days"));
+  possibleTOIs.insert(TOI(utc, TOI::unspec, "", "hours"));
+}
+
+string TimeTOIProducer::getName() {
+  return("TimeTOIProducer 1.0");
+}
+
+
+
+long TimeTOIProducer::firstSampleNum(TOI const& toi) {
+  CHKPROD
+  return -99999999;
+}
+
+long TimeTOIProducer::lastSampleNum(TOI const& toi) {
+  CHKPROD
+  return  99999999;
+}
+
+bool TimeTOIProducer::canGetValue(long /*sampleNum*/, TOI const& toi) {
+  CHKPROD
+  return true;
+}
+
+bool TimeTOIProducer::canGetValueLater(long /*sampleNum*/, TOI const& toi) {
+  CHKPROD
+  return false; // we can always get value NOW
+}
+
+bool TimeTOIProducer::canGetPrevValue(long /*sampleNum*/, TOI const& toi) {
+  CHKPROD
+  return true;
+}
+ 
+bool TimeTOIProducer::canGetNextValue(long /*sampleNum*/, TOI const& toi) {
+  CHKPROD
+  return true;
+}
+
+double TimeTOIProducer::getValue(long sampleNum, TOI const& toi) {
+  CHKPROD
+  if (toi.name == sn) return sampleNum;
+  if (toi.name == mjd) return archParam.acq.SN2MJD(sampleNum);
+  if (toi.name == utc) return archParam.acq.SN2UTC(sampleNum);
+  throw ArchExc("TimeTOIProducer inconsistence " + toi.name);
+}
+
+double TimeTOIProducer::getPrevValue(long& sampleNum, TOI const& toi) {
+  sampleNum--;
+  return getValue(sampleNum, toi);
+}
+
+double TimeTOIProducer::getNextValue(long& sampleNum, TOI const& toi) {
+  sampleNum++;
+  return getValue(sampleNum, toi);
+}
Index: trunk/Poubelle/archTOI.old/timetoiproducer.h
===================================================================
--- trunk/Poubelle/archTOI.old/timetoiproducer.h	(revision 534)
+++ trunk/Poubelle/archTOI.old/timetoiproducer.h	(revision 534)
@@ -0,0 +1,33 @@
+// timetoiproducer.h
+// Eric Aubourg         CEA/DAPNIA/SPP   septembre 1999
+
+#ifndef TIMETOIPRODUCER_H
+#define TIMETOIPRODUCER_H
+
+#include "toiproducer.h"
+#include "ark.h"
+
+
+class TimeTOIProducer : public TOIProducer {
+public:
+  TimeTOIProducer();
+
+  virtual bool   canGetValue(long sampleNum, TOI const& toi); // for this samplenum
+  virtual bool   canGetPrevValue(long sampleNum, TOI const& toi); 
+  virtual bool   canGetNextValue(long sampleNum, TOI const& toi); 
+  virtual bool   canGetValueLater(long sampleNum, TOI const& toi);  // Might, later but not now
+  
+  virtual double getPrevValue(long& sampleNum, TOI const& toi);
+  virtual double getNextValue(long& sampleNum, TOI const& toi);
+  virtual double getValue(long sampleNum, TOI const& toi);
+  
+  virtual long   firstSampleNum(TOI const&);
+  virtual long   lastSampleNum(TOI const&);
+  virtual string getName();
+};
+
+
+
+
+
+#endif
Index: trunk/Poubelle/archTOI.old/toi.cc
===================================================================
--- trunk/Poubelle/archTOI.old/toi.cc	(revision 534)
+++ trunk/Poubelle/archTOI.old/toi.cc	(revision 534)
@@ -0,0 +1,74 @@
+// toi.cc
+// Eric Aubourg         CEA/DAPNIA/SPP   septembre 1999
+
+#include "toi.h"
+#include "tokenizer.h"
+#include "archexc.h"
+
+vector<TOI> TOI::alltois;
+
+TOI::TOI(string n, int i, string opts, string u) 
+: name(n), index(i), unit(u)
+{
+  options = Tokenizer(opts).getTokenSet();
+  findref();
+}
+
+TOI::TOI(string n, int i, string opts, string u, string reqopts) 
+: name(n), index(i), unit(u)
+{
+  options = Tokenizer(opts).getTokenSet();
+  reqOptions = Tokenizer(reqopts).getTokenSet();
+  options.insert(reqOptions.begin(), reqOptions.end());
+  findref();
+}
+
+TOI::TOI(string n, int i, set<string> opts, string u) 
+: name(n), options(opts), index(i), unit(u)
+{
+  findref();
+}
+
+TOI::TOI(string s, string u) 
+: index(unspec), unit(u)
+{
+  vector<string> v = Tokenizer(s).getTokenVector();
+  if (v.empty()) throw ArchExc("TOI::TOI called with empty string");
+  vector<string>::iterator i = v.begin();
+  name = *i;
+  i++;
+  if (i == v.end()) return;
+  string& s1 = *i;
+  if (s1[0]>='0' && s1[0]<='9') {
+    index = atoi(s1.c_str());
+    i++;
+  }
+  options = set<string>(i, v.end());
+  findref();
+}
+
+void TOI::findref() {
+  for (vector<TOI>::iterator i = alltois.begin();
+       i != alltois.end(); i++) {
+    if ((*i).name == name && (*i).index == index && (*i).options == options) {
+       ref = (*i).ref;
+       return;
+    }
+  }
+  ref = alltois.size();
+  alltois.push_back(*this);
+}
+
+string TOI::fullName() {
+ string s = name;
+ if (index == all) { s += " all";}
+ else if (index != unspec) { 
+   char idx[20]; sprintf(idx, "%d", index);
+   s += string(" ")+idx;
+ }
+ for (set<string>::iterator i = options.begin(); i!=options.end(); i++) {
+   s += " " + *i;
+ }
+ if (unit != "") s += " (" + unit + ")";
+ return s;
+}
Index: trunk/Poubelle/archTOI.old/toi.h
===================================================================
--- trunk/Poubelle/archTOI.old/toi.h	(revision 534)
+++ trunk/Poubelle/archTOI.old/toi.h	(revision 534)
@@ -0,0 +1,49 @@
+// toi.h
+// Eric Aubourg         CEA/DAPNIA/SPP   septembre 1999
+
+#ifndef TOI_H
+#define TOI_H
+
+#include<string>
+#include<set>
+#include<vector>
+using namespace std;
+
+struct TOI {
+  TOI() : name(""), index(unspec) {}
+  TOI(string n, int i, string opts="", string u="");
+  TOI(string n, int i, set<string> opts, string u="");
+  TOI(string, string u="");
+  TOI(string n, int i, string opts, string u, string reqopts);
+  
+  string name;
+  set<string> options;
+  set<string> reqOptions; // Used for possibleTOIs... Mandatory options for a producer.
+  int index;   // -1 : unspecified. -2 : all.
+  enum {unspec = -1, all = -2};
+  string unit;
+  inline bool operator == (TOI const&) const;
+  inline bool operator <  (TOI const&) const;
+  
+  int ref;
+  static vector<TOI> alltois;
+  void findref();
+  
+  string fullName();
+};
+
+bool TOI::operator == (TOI const& x) const {
+  return ref == x.ref;
+  //return (name == x.name && options == x.options && index == x.index);
+}
+
+bool TOI::operator < (TOI const& x) const {
+  return ref < x.ref;
+  #if 0
+  return ((name < x.name) ||
+          (name == x.name && options < x.options) ||
+          (name == x.name && options == x.options && index < x.index));
+  #endif
+}
+
+#endif
Index: trunk/Poubelle/archTOI.old/toiabsorber.cc
===================================================================
--- trunk/Poubelle/archTOI.old/toiabsorber.cc	(revision 534)
+++ trunk/Poubelle/archTOI.old/toiabsorber.cc	(revision 534)
@@ -0,0 +1,5 @@
+#include "toiabsorber.h"
+
+void TOIAbsorber::dataFeed(TOIProducer*, TOI const&, long, double)
+{}
+
Index: trunk/Poubelle/archTOI.old/toiabsorber.h
===================================================================
--- trunk/Poubelle/archTOI.old/toiabsorber.h	(revision 534)
+++ trunk/Poubelle/archTOI.old/toiabsorber.h	(revision 534)
@@ -0,0 +1,25 @@
+// toiabsorber.h
+// Eric Aubourg         CEA/DAPNIA/SPP   septembre 1999
+
+#ifndef TOIABSORBER_H
+#define TOIABSORBER_H
+
+#include <set>
+#include <map>
+#include <deque>
+
+using namespace std;
+
+#include "toi.h"
+#include "ark.h"
+
+class TOIProducer;
+
+class TOIAbsorber {
+public:
+  virtual ~TOIAbsorber() {}
+  virtual void dataFeed(TOIProducer* source, TOI const& toi, long sampleNum, double value);
+};
+
+
+#endif
Index: trunk/Poubelle/archTOI.old/toiauxgpsproducer.cc
===================================================================
--- trunk/Poubelle/archTOI.old/toiauxgpsproducer.cc	(revision 534)
+++ trunk/Poubelle/archTOI.old/toiauxgpsproducer.cc	(revision 534)
@@ -0,0 +1,77 @@
+// toiauxgpsproducer.cc
+// Eric Aubourg         CEA/DAPNIA/SPP   octobre 1999
+
+#include "toiauxgpsproducer.h"
+#include "archparam.h"
+#include "archexc.h"
+#include "requesthandler.h"
+
+#define latitude  "latitude"
+#define longitude "longitude"
+#define altitude  "altitude"
+
+
+TOIAuxGPSProducer::TOIAuxGPSProducer(AuxGPS* aux)
+: auxGPS(aux)
+{
+  possibleTOIs.insert(TOI(latitude,     TOI::unspec,   "auxGPS interp", "degrees"));  // + = NORTH
+  possibleTOIs.insert(TOI(longitude,    TOI::unspec,   "auxGPS interp", "degrees"));  // + = EAST
+  possibleTOIs.insert(TOI(altitude,     TOI::unspec,   "auxGPS interp", "meters"));  
+}
+
+string TOIAuxGPSProducer::getName() {
+  return("TOIAuxGPSProducer 1.0");
+}
+
+
+
+long TOIAuxGPSProducer::firstSampleNum(TOI const& toi) {
+  CHKPROD
+  return -99999999;
+}
+
+long TOIAuxGPSProducer::lastSampleNum(TOI const& toi) {
+  CHKPROD
+  return  99999999;
+}
+
+bool TOIAuxGPSProducer::canGetValue(long sampleNum, TOI const& toi) {
+  CHKPROD
+  return auxGPS->canGetLocation(archParam.acq.SN2MJD(sampleNum));
+}
+
+bool TOIAuxGPSProducer::canGetValueLater(long /*sampleNum*/, TOI const& toi) {
+  CHKPROD
+  return false; // we can always get value NOW
+}
+
+bool TOIAuxGPSProducer::canGetPrevValue(long sampleNum, TOI const& toi) {
+  CHKPROD
+  return canGetValue(sampleNum-1,  toi);
+}
+ 
+bool TOIAuxGPSProducer::canGetNextValue(long sampleNum, TOI const& toi) {
+  CHKPROD
+  return canGetValue(sampleNum+1,  toi);
+}
+
+double TOIAuxGPSProducer::getValue(long sampleNum, TOI const& toi) {
+  CHKPROD
+  double lat, lon, alt;
+  auxGPS->getLocation(archParam.acq.SN2MJD(sampleNum), lat, lon, alt);
+  if (toi.name == latitude)  return lat;
+  if (toi.name == longitude) return lon;
+  if (toi.name == altitude)  return alt;
+  throw ArchExc("TOIAuxGPSProducer inconsistence " + toi.name);
+}
+
+double TOIAuxGPSProducer::getPrevValue(long& sampleNum, TOI const& toi) {
+  sampleNum--;
+  return getValue(sampleNum, toi);
+}
+
+double TOIAuxGPSProducer::getNextValue(long& sampleNum, TOI const& toi) {
+  sampleNum++;
+  return getValue(sampleNum, toi);
+}
+
Index: trunk/Poubelle/archTOI.old/toiauxgpsproducer.h
===================================================================
--- trunk/Poubelle/archTOI.old/toiauxgpsproducer.h	(revision 534)
+++ trunk/Poubelle/archTOI.old/toiauxgpsproducer.h	(revision 534)
@@ -0,0 +1,37 @@
+// toiauxgpsproducer.h
+// Eric Aubourg         CEA/DAPNIA/SPP   octobre 1999
+
+#ifndef TOIAUXGPSPRODUCER_H
+#define TOIAUXGPSPRODUCER_H
+
+#include "toiproducer.h"
+#include "ark.h"
+#include "auxgps.h"
+
+
+class TOIAuxGPSProducer : public TOIProducer {
+public:
+  TOIAuxGPSProducer(AuxGPS* aux);
+
+  virtual bool   canGetValue(long sampleNum, TOI const& toi); // for this samplenum
+  virtual bool   canGetPrevValue(long sampleNum, TOI const& toi); 
+  virtual bool   canGetNextValue(long sampleNum, TOI const& toi); 
+  virtual bool   canGetValueLater(long sampleNum, TOI const& toi);  // Might, later but not now
+  
+  virtual double getPrevValue(long& sampleNum, TOI const& toi);
+  virtual double getNextValue(long& sampleNum, TOI const& toi);
+  virtual double getValue(long sampleNum, TOI const& toi);
+  
+  virtual long   firstSampleNum(TOI const&);
+  virtual long   lastSampleNum(TOI const&);  
+  virtual string getName();
+  
+protected:
+  AuxGPS* auxGPS;
+};
+
+
+
+
+
+#endif
Index: trunk/Poubelle/archTOI.old/toiboloproducer.cc
===================================================================
--- trunk/Poubelle/archTOI.old/toiboloproducer.cc	(revision 534)
+++ trunk/Poubelle/archTOI.old/toiboloproducer.cc	(revision 534)
@@ -0,0 +1,52 @@
+// toiboloproducer.cc
+// Eric Aubourg         CEA/DAPNIA/SPP   septembre 1999
+
+#include "toiboloproducer.h"
+#include "archexc.h"
+#include "requesthandler.h"
+
+#define filt2 "boloMuV"
+
+
+TOIBoloProducer::TOIBoloProducer() {
+  possibleTOIs.insert(TOI(filt2, TOI::all, "", "microVolts"));  
+}
+
+string TOIBoloProducer::getName() {
+  return("TOIBoloProducer 1.0");
+}
+
+
+void TOIBoloProducer::dataFeed(TOIProducer* source, TOI const& toi, long sampleNum, double value) {
+  if (source->canGetValue(sampleNum-1, toi)) {
+    value = (value + source->getValue(sampleNum-1, toi))/2.;
+    TOI toi2 = toi;
+    toi2.name = filt2;
+    computedValue(toi2, sampleNum, value);
+  }
+}
+
+set<TOI> TOIBoloProducer::reqTOIFor(TOI const& toi) {
+  TOI toi2 = toi;
+  set<TOI> t; 
+  if (toi.name == filt2) {
+    toi2.name = "boloRawMuV";
+    t.insert(toi2);
+  } else {
+    throw ArchExc("Cannot produce "+toi.name);
+  }
+  return t;
+}
+
+
+void TOIBoloProducer::propagateLowBound(TOI const& toi, long sampleNum) {
+  CHKPROD
+  map<TOI, TOIProducer*> need = neededTOIs[toi];
+  int hlen = 1;
+  for (map<TOI, TOIProducer*>::iterator i = need.begin(); i != need.end(); i++) {
+    (*i).second->wontNeedEarlier((*i).first, this, sampleNum-hlen);
+  }
+}
+
+
+
Index: trunk/Poubelle/archTOI.old/toiboloproducer.h
===================================================================
--- trunk/Poubelle/archTOI.old/toiboloproducer.h	(revision 534)
+++ trunk/Poubelle/archTOI.old/toiboloproducer.h	(revision 534)
@@ -0,0 +1,24 @@
+// toiboloproducer.h
+// Eric Aubourg         CEA/DAPNIA/SPP   septembre 1999
+
+#ifndef TOIBOLOPRODUCER_H
+#define TOIBOLOPRODUCER_H
+
+#include "toiderivproducer.h"
+#include "ark.h"
+
+
+class TOIBoloProducer : public TOIDerivProducer {
+public:
+  TOIBoloProducer();
+  virtual void dataFeed(TOIProducer* source, TOI const& toi, long sampleNum, double value);
+  virtual string getName();
+
+protected:
+  virtual set<TOI>     reqTOIFor(TOI const&);
+  virtual void         propagateLowBound(TOI const&, long sampleNum);
+};
+
+
+
+#endif
Index: trunk/Poubelle/archTOI.old/toiderivproducer.cc
===================================================================
--- trunk/Poubelle/archTOI.old/toiderivproducer.cc	(revision 534)
+++ trunk/Poubelle/archTOI.old/toiderivproducer.cc	(revision 534)
@@ -0,0 +1,123 @@
+// toiderivproducer.cc
+// Eric Aubourg         CEA/DAPNIA/SPP   septembre 1999
+
+#include "toiderivproducer.h"
+#include "toimanager.h"
+#include "archexc.h"
+#include "requesthandler.h"
+
+set<TOI> TOIDerivProducer::reqTOIFor(TOI const&) { 
+  set<TOI> empty;
+  return empty;
+}
+
+void TOIDerivProducer::outManifest(RequestHandler* h) {
+  outVersion(h);
+  h->processOption("#COMMENT", " Producing:");
+  for (set<TOI>::iterator i = producedTOIs.begin(); i != producedTOIs.end(); i++) {
+    h->processOption("#COMMENT", "  " + (*i).fullName());
+    set<TOI> x = reqTOIFor(*i);
+    if (!x.empty()) {
+      h->processOption("#COMMENT", "  from:");
+      for (set<TOI>::iterator j=x.begin(); j!=x.end(); j++) {
+        h->processOption("#COMMENT", "   " + (*j).fullName());
+      }
+    }
+  }
+}
+
+
+bool TOIDerivProducer::canProduce(TOI const& toi) {
+  // 1. Already in cache ?
+  map<TOI, map<TOI, TOIProducer*> >::const_iterator j = neededTOIs.find(toi);
+  if (j != neededTOIs.end()) return true;
+
+  // 2. It should be in our list of possibleTOI's
+  TOI myTOI;
+  for (set<TOI>::const_iterator i = possibleTOIs.begin(); i != possibleTOIs.end(); i++) {
+    if ((toi.name == (*i).name) &&
+        (toi.index == (*i).index || (*i).index == TOI::all)) {
+      myTOI = (*i); 
+      break;
+    }
+  }
+  if (myTOI.name == "") return false; // not in list
+  
+  // 3. Handle options
+  
+  set<string> extraopts = toi.options;
+  
+  // 3a should contain mandatory options
+  for (set<string>::iterator i = myTOI.reqOptions.begin(); 
+       i != myTOI.reqOptions.end(); i++) {
+    if (extraopts.find(*i) == extraopts.end()) return false;
+  }
+  
+  // 3b remove local options
+  
+  for (set<string>::iterator i = myTOI.options.begin();
+       i != myTOI.options.end(); i++) {
+    extraopts.erase(*i);   
+  }
+  
+  // 4. Find producers, distribute remaining options
+  map<TOI, TOIProducer*> fullInputTOI;
+  set<TOI> inputTOIs = reqTOIFor(toi);
+  for (set<TOI>::iterator i = inputTOIs.begin(); i != inputTOIs.end(); i++) {
+    TOI inTOI = *i;
+    TOIProducer* prod = TOIManager::findTOIProducer(inTOI);
+    if (!prod) return false;
+    if (!extraopts.empty()) {
+      set<string> xopts = prod->getAvailOptions(inTOI);
+      for (set<string>::iterator j = xopts.begin(); j != xopts.end(); j++) {
+        if (extraopts.find(*j) != extraopts.end()) {
+          inTOI.options.insert(*j);
+          extraopts.erase(*j);
+        }
+      }
+    }
+    fullInputTOI[inTOI] = prod;
+  }
+  
+  if (!extraopts.empty()) return false;
+  
+  neededTOIs[toi] = fullInputTOI;
+  return true;
+}
+
+set<string> TOIDerivProducer::getAvailOptions(TOI const& toi) {
+ // toi.options.clear();
+ // toi.index = -2;
+ // if (!canProduce(toi)) throw ArchExc("cannot produce " + toi.name);
+  set<string> s = getProperAvailOptions(toi);
+  map<TOI, TOIProducer*> need = neededTOIs[toi];
+  for (map<TOI, TOIProducer*>::iterator i = need.begin(); i != need.end(); i++) {
+    set<string> s1 = (*i).second->getAvailOptions((*i).first);
+    s.insert(s1.begin(), s1.end());
+  }
+  return s;
+}
+
+void TOIDerivProducer::addTOI(TOI& toi, TOIAbsorber* client) {
+  TOIProducer::addTOI(toi, client);
+  map<TOI, TOIProducer*> m = neededTOIs[toi];
+  for (map<TOI, TOIProducer*>::iterator i = m.begin(); i != m.end(); i++) {
+    TOI toi2 = (*i).first;
+    (*i).second->addTOI(toi2,this);
+  }
+}
+
+long TOIDerivProducer::wontNeedEarlier(TOI const& toi, TOIAbsorber* client, long t) {
+  long xt = TOIProducer::wontNeedEarlier(toi, client, t);
+  if (xt>0) propagateLowBound(toi, xt);
+  return xt;
+}
+
+// if no need for past values...
+void TOIDerivProducer::propagateLowBound(TOI const& toi, long sampleNum) {
+  CHKPROD
+  map<TOI, TOIProducer*> need = neededTOIs[toi];
+  for (map<TOI, TOIProducer*>::iterator i = need.begin(); i != need.end(); i++) {
+    (*i).second->wontNeedEarlier((*i).first, this, sampleNum);
+  }
+}
Index: trunk/Poubelle/archTOI.old/toiderivproducer.h
===================================================================
--- trunk/Poubelle/archTOI.old/toiderivproducer.h	(revision 534)
+++ trunk/Poubelle/archTOI.old/toiderivproducer.h	(revision 534)
@@ -0,0 +1,27 @@
+// toiderivproducer.h
+// Eric Aubourg         CEA/DAPNIA/SPP   septembre 1999
+
+#ifndef TOIDERIVPRODUCER_H
+#define TOIDERIVPRODUCER_H
+
+#include "toiproducer.h"
+#include "toiabsorber.h"
+
+class TOIDerivProducer : public TOIProducer, public TOIAbsorber {
+public:
+
+  virtual bool         canProduce(TOI const&);
+  virtual void         addTOI(TOI&, TOIAbsorber* client);     // exception si pas productible
+  virtual set<string>  getAvailOptions(TOI const&);
+  virtual long         wontNeedEarlier(TOI const&, TOIAbsorber* client, long);
+  virtual void outManifest(RequestHandler*);
+
+protected:
+  mutable map<TOI, map<TOI, TOIProducer*> > neededTOIs; // TOI out, TOI in + associated producer, caching.
+
+  virtual set<TOI>     reqTOIFor(TOI const&);
+  virtual void         propagateLowBound(TOI const&, long sampleNum);
+};
+
+
+#endif
Index: trunk/Poubelle/archTOI.old/toiiter.cc
===================================================================
--- trunk/Poubelle/archTOI.old/toiiter.cc	(revision 533)
+++ trunk/Poubelle/archTOI.old/toiiter.cc	(revision 534)
@@ -2,997 +2,320 @@
 // Eric Aubourg         CEA/DAPNIA/SPP   juillet 1999
 
-#ifndef nb_max_bolo
-#define _archeops		//  Acquisition Archeops (avec transputer) 
-#define programme
-extern "C" {
-#include "archeops.h"
-#include "arcunit.h"
-}
+#include "ark.h"
+
+#include "toiiter.h"
+#include "toimanager.h"
+#include "toiproducer.h"
+#include "archparam.h"
+#include "asigps.h"
+#include "toiauxgpsproducer.h"
+#include <iostream.h>
+#include <fstream.h>
+
+#define CHK_INITED if (initDone) \
+        throw ArchExc("Trying to modify TOIIter after init done.");
+
+TOIIter::TOIIter() {
+  mjdStart = -999999999;
+  mjdEnd   =  999999999;
+  utcStart = -999999999;
+  utcEnd   =  999999999;
+  sStart   = -999999999;
+  sEnd     =  999999999;
+
+  underSample = 1;
+  curSample = -1;
+  
+  initDone = false;
+  incDone  = false;
+}
+
+#ifdef __MWERKS__
+#pragma mark -
 #endif
 
-
-#include "toiiter.h"
-#include "toiinterpolator.h"
-#include "archparam.h"
-#include <dirent.h>
-#include <iostream.h>
-#include "templocator.h"
-
-// Format bloc GPS
-// $GPGGA,hhmmss.ss,ddmm.mmmm,n,dddmm.mmmm,e,q,ss,y.y,a.a,z,
-
-TOIIter::TOIIter() {
- // Toutes les valeurs initialisees par defaut. Le TOISvr les positionnera,
- // puis lancera l'initialisation
+void TOIIter::addDirectory(string dir) {
+  CHK_INITED
+  fset.addDirectory(dir);
+}
+
+void TOIIter::addFile(string fn) {
+  CHK_INITED
+  fset.addFile(fn);
+}
+
+void TOIIter::setMJDInterval(double tStart, double tEnd) {
+  CHK_INITED
+  if (tStart>0) mjdStart = tStart;
+  if (tEnd>0)   mjdEnd = tEnd;
+}
+
+void TOIIter::setUTCInterval(double tStart, double tEnd) {
+  CHK_INITED
+  if (tStart>0) utcStart = tStart;
+  if (tEnd>0)   utcEnd = tEnd;
+}
+
+void TOIIter::setSNInterval(long tStart, long tEnd) {
+  CHK_INITED
+  if (tStart>0) sStart = tStart;
+  if (tEnd>0)   sEnd = tEnd;
+}
+
+void TOIIter::setUnderSample(int n) {
+  CHK_INITED
+  if (n<=1) n=1;
+  underSample = n;
+}
+
+int TOIIter::getUnderSample() {
+  return underSample;
+}
+
+void TOIIter::addTOI(TOI& toi, bool trg) {
+  CHK_INITED
+  TOIProducer* prod = TOIManager::findTOIProducer(toi);
+  if (!prod) throw ArchExc("Cannot produce " + toi.fullName());
+  prod->addTOI(toi, this);
+  request.push_back(TOIInfo(toi,prod,trg?1:0));
+}
+
+#ifdef __MWERKS__
+#pragma mark -
+#endif
+
+
+void TOIIter::registerReqHandler(RequestHandler* h) {
+  CHK_INITED
+  handlers.push_back(h);
+}
+
+
+void TOIIter::readReq(istream& str) {
+  CHK_INITED
+   if (!incDone) defaultInclude();
+   string line;
+   while (str) {
+     getline(str,line);
+     if (!str) break;
+     if (line.substr(0,4)=="#END" && (line.length()==4 || line[5] == ' ')) break;
+     if (line[0] != '@' && line[0] != '#') continue;
+     if (!processRequest(line)) {
+       throw ArchExc("Unrecognized directive " + line);
+     }
+   }
+}
+
+
+bool TOIIter::processRequest(string line) {
+  if (line[0] == '#') {
+    int x = line.find(' ');
+    string keyw = line.substr(0, x);
+    string args = (x>0) ? line.substr(x) : string("");
+    bool handled = processOption(keyw,args);
+    for (list<RequestHandler*>::iterator i = handlers.begin(); 
+	 i != handlers.end(); i++) {
+      handled |= (*i)->processOption(keyw,args);
+    }
+    return handled;
+  }
+
+  if (line[0] == '@') {
+    TOI toi(line.substr(1));
+    // if (kind  == sampleNum || kind == mjd || kind == mutc) notrig = true;
+    bool handled = processTOIReq(toi,line);
+    for (list<RequestHandler*>::iterator i = handlers.begin(); 
+         i != handlers.end(); i++) {
+      handled |= (*i)->processTOIReq(toi,line);
+    }
+    return handled;
+  }
+  return false;
+}
+
+
+bool TOIIter::processTOIReq(TOI& toi,string)
+{
+  TOI toi2 = toi;
+  bool trg=true;
+  if (toi.options.find("notrig") != toi.options.end()) {
+    toi2.options.erase("notrig");
+    trg=false;
+  } 
+  addTOI(toi2, trg);
+  toi.unit = toi2.unit;
+  return true;
+} 
+
+
+bool TOIIter::processOption(string key, string arg)
+{
+  if (arg.length()>0 && arg[0] == ' ') {
+    arg = arg.substr(arg.find_first_not_of(' '));
+  }
+  if (key == "#MJDRANGE") {
+    double tmin, tmax;
+    sscanf(arg.c_str(), "%lg %lg", &tmin, &tmax);
+    setMJDInterval(tmin, tmax);
+  } else if (key == "#UTCRANGE") {
+    double tmin, tmax;
+    sscanf(arg.c_str(), "%lg %lg", &tmin, &tmax);
+    setUTCInterval(tmin, tmax);
+  } else if (key == "#SNRANGE") {
+    long tmin, tmax;
+    sscanf(arg.c_str(), "%ld %ld", &tmin, &tmax);
+    setSNInterval(tmin, tmax);
+  } else if (key == "#PATH") {
+    addDirectory(arg);
+  } else if (key == "#FILE") {
+    addFile(arg);
+  } else if (key == "#UNDERSAMPLE") {
+    setUnderSample(atoi(arg.c_str()));
+  } else if (key == "#MJD0") {
+    double t0;
+    sscanf(arg.c_str(), "%lg", &t0);
+    archParam.acq.tBlock0 = t0;
+  } else if (key == "#UTCORIGIN") {
+    double t0;
+    sscanf(arg.c_str(), "%lg", &t0);
+    archParam.acq.utcOrigin = t0;
+  } else if (key == "#PERECH") {
+    double t0;
+    sscanf(arg.c_str(), "%lg", &t0);
+    archParam.acq.perEch = t0;
+  } else if (key == "#ASIGPS") {
+    ASIGPS* gps = new ASIGPS(arg);
+    TOIManager::registerProducer(new TOIAuxGPSProducer(gps));
+    //    gps->FitsDump("GPSDump.fits");
+  } else if (key == "#INCLUDE") {
+    ifstream f(arg.c_str());
+    readReq(f);
+  } else {
+    return false;
+  }
+  return true;
+}
+
+
+void TOIIter::defaultInclude() {
+  incDone = true;
+  processRequest("#REQVERSION V_270999");
+  processRequest("#MJD0 1376.8358818");
+  processRequest("#PERECH 0.005836818076");
+  processRequest("#UTCORIGIN 1376.5");
+  processRequest("#ASIGPS ASI_GPS_archeops1999.ascii");
+  processRequest("#COMMENT Archtoi V2 -- october 1999 -- Eric Aubourg CEA/DAPNIA");
+  processRequest("#COMMENT ***WARNING***");
+  processRequest("#COMMENT ***SOME TOI'S ARE PRELIMINARY***");
+  processRequest("#COMMENT gyroSpeed is not calibrated");
+  processRequest("#COMMENT azimut/alpha/delta use galaxy crossings and ASI GPS data");
+  processRequest("#COMMENT   and assume no pendulation");
+  processRequest("#COMMENT Focal plane center elevation found at 41.5 deg");
+  processRequest("#COMMENT   with Jupiter");
+  processRequest("#COMMENT boloMuV2 is not protected against glitches");
+}
+
+#ifdef __MWERKS__
+#pragma mark -
+#endif
+
+void TOIIter::init() {
+  if (initDone) return;
+  initDone = true;
  
- file = NULL;
- directory = "";
+  if (utcStart > 0) {
+    double t = (utcStart/24.) + archParam.acq.utcOrigin;
+    if (t > mjdStart) mjdStart=t;
+  }
+  if (utcEnd > 0) {
+    double t = (utcEnd/24.) + archParam.acq.utcOrigin;
+    if (t < mjdEnd) mjdEnd=t;
+  }
+
+  fset.setMJDRange(mjdStart-0.01, mjdEnd+0.01);
+  fset.setSNumRange(sStart-1000, sEnd+1000);
+
+  fset.init();
+  //curSample = fset.getSampleIndex();
+}
+
+bool TOIIter::isTrig(int column) {
+  return (request[column].third & triggering) != 0;
+}
  
- files.clear();
-
- isOnBoardRecorder = false;
-   
- imes=0;
-
- tStart = -9.e99;
- tEnd   = 9.e99;
- utcStart = -9.e99;
- utcEnd   = 9.e99;
- 
- sStart = -999999999;
- sEnd   =  999999999;
- 
- //tBlock0 = -1;
- // perEch = -1;
- // Values for Trapani 99 = default values
- //tBlock0 = 1376.8358818;
- //perEch = 0.005836818076;
- 
- trigMask = 0;
- rawIter = NULL;
- interp  = NULL;
- lastSample = -1;
- maxLookAhead = 10000;
- 
- auxGPS = NULL;
- 
- initDone = false;
- 
- underSample = 1;
-}
-
-TOIIter::TOIIter(TOIIter const& x) {
-  directory = x.directory;
-  files = x.files;
-  if (x.initDone && x.curFile != x.files.end()) curFile = files.find(*(x.curFile));
-  isOnBoardRecorder = x.isOnBoardRecorder;
-  imes   = x.imes;
+TOI TOIIter::getKind(int column) {
+  return request[column].first;
+}
+
+long TOIIter::getSampleNum() {
+  return curSample;
+}
+
+bool TOIIter::next() {
+  if (!initDone) init();
+  for (int ii=0; ii<underSample; ii++)
+    if (!next1()) return false;
   
-  tStart   = x.tStart;
-  tEnd     = x.tEnd;
-  utcStart = x.utcStart;
-  utcEnd   = x.utcEnd;
-  sStart   = x.sStart;
-  sEnd     = x.sEnd;
+  return true;
+}
+
+bool TOIIter::next1() {
+// On tente de produire curSample+1 pour toutes les toi
+// Eventuellement en avancant sur le fichier...
+// Puis on regarde si une TOI triggering a eu une nouvelle
+// valeur.
+// Si on a epuise les fichiers de donnees, on s'arrete des qu'aucune
+// TOI n'a de valeurs apres curSample...
+  if (curSample <= 0) curSample = sStart-1;
+  if (curSample <= 0) curSample = fset.getSampleIndex()-1;
   
-  trigMask = x.trigMask;
-  infos = x.infos;   
-
-  if (x.file)
-    file = new ArcheopsFile(*x.file);
-  else 
-    file = NULL;
-    
-  if (x.rawIter) {
-    rawIter = new TOIIter(*x.rawIter);
-    interp = new TOIInterpolator[infos.size()];
-    for (int i=0; i<infos.size(); i++)
-      interp[i] = x.interp[i];
-  } else {
-    rawIter = NULL;
-    interp  = NULL;
-  }
+  if (curSample >= sEnd || archParam.acq.SN2MJD(curSample) >= mjdEnd) return false;
   
-  lastSample = x.lastSample;
-  maxLookAhead = x.maxLookAhead;
-  
-  auxGPS = x.auxGPS; 
-  if (auxGPS) auxGPS = auxGPS->clone();
-  
-  initDone = x.initDone;
-  underSample = x.underSample;
-}
-
-TOIIter::~TOIIter() {
-  delete file;
-  delete rawIter;
-  delete[] interp;
-  delete auxGPS;
-}
-
-#ifdef __MWERKS__
-#define filesep ':'
-#else
-#define filesep '/'
-#endif
-
-void TOIIter::Init() {
- if (initDone) return;
- initDone = true;
- if (utcStart > 0) {
-   double t = (utcStart/24.) + archParam.acq.utcOrigin;
-   if (t > tStart) tStart=t;
- }
- if (utcEnd > 0) {
-   double t = (utcEnd/24.) + archParam.acq.utcOrigin;
-   if (t < tEnd) tEnd=t;
- }
- // On a soit un repertoire, soit une liste de fichiers....
-  if (directory == "") {
-    if (files.empty()) {   // Ni repertoire, ni fichiers
-      cerr << "toiiter : pas de repertoire, pas de fichiers" << endl;
-      exit(-1);
-    } else {
-      // On a deja une liste de fichiers
+  for (int i=0; i<request.size(); i++)
+    request[i].second->wontNeedEarlier(request[i].first, this, curSample);
+
+  bool endFound = false;
+  while(1) {
+    curSample++;
+    for (vector<TOIInfo>::iterator i = request.begin(); i != request.end(); i++) {
+      while ((*i).second->canGetValueLater(curSample, (*i).first)) {
+        if (! fset.next()) {endFound = true; break;} //return false;
+      }     
     }
-  } else { // On a un repertoire a explorer
-    // On cherche soit les fichiers dans le repertoire donne, soit des fichiers
-    // dans un sous-repertoire "arch-YY_MM_DD". Les fichiers ont un nom en
-    // "hYY_MM_DD-hh_mm_ss".
-    // Pour l'enregistreur de vol, les fichiers ont un nom en ARKxxxxxx.DAT
-    if (directory[directory.length()-1] != filesep) 
-      directory += filesep;
-    DIR* dir = opendir(directory.c_str());
-    struct dirent* ent;
-    while ((ent = readdir(dir)) != NULL) {
-      // si c'est un repertoire, avec un nom de jour, il faut l'explorer...
-      if (!strncmp(ent->d_name, "arch-", 5)) {
-        double mjd = ArcheopsFile::decodeMJD(ent->d_name+5) - 2./24.; // ENTIER + .5 en temps local!
-        if (mjd >= tStart - 1. && mjd <= tEnd) {
-          string direc2 = directory + ent->d_name + filesep;
-          DIR* dir2 = opendir(direc2.c_str());
-          struct dirent* ent2;
-          while ((ent2 = readdir(dir2)) != NULL) {
-            if (*ent2->d_name == 'h') {
-              double mjd2 = ArcheopsFile::decodeMJD(ent->d_name+1) - 2./24.;
-              if (mjd2 >= tStart - 1./24. && mjd2 <= tEnd) {
-                files.insert(direc2 + ent2->d_name);
-              }
-            }
-          }
-        }
-      } else {
-        if (!isOnBoardRecorder && *ent->d_name == 'h') {
-          double mjd = ArcheopsFile::decodeMJD(ent->d_name+1) - 2./24.; // $CHECK$ UTCOffset
-          if (mjd >= tStart - 1./24. && mjd <= tEnd) {
-            files.insert(directory + ent->d_name);
-          }
-        } else if (isOnBoardRecorder) {
-          if (strncmp(ent->d_name, "ARK", 3) && strncmp(ent->d_name, "ark", 3)) continue;
-          char * sfx = ent->d_name + strlen(ent->d_name) - 4;
-          if (strcmp(sfx, ".DAT") && strcmp(sfx, ".dat")) continue;
-          files.insert(directory + ent->d_name);
-        }
-      }
+    bool found=false;
+    bool valuesAhead = false;
+    for (vector<TOIInfo>::iterator i = request.begin(); i != request.end(); i++) {
+      if (((*i).third & triggering) == 0) continue;
+      if ((*i).second->canGetValue(curSample, (*i).first)) {found=true;break;}
+      if ((*i).second->lastSampleNum((*i).first)>curSample) valuesAhead=true;
     }
-    closedir(dir);
-  }
-    
-  ScanFiles();
-  
-  curFile = files.begin();
-  file = new ArcheopsFile((*curFile).c_str());
-  cout << "opening file " << (*curFile).c_str() << endl;
-
-  // On avance jusqu'a avoir au moins un bloc param et un bloc reglage,
-  // car on ne peut rien faire sans...
-  // Si on a des donnees de l'enregistreur de vol, pas de bloc param, et
-  // on en simule un
-  double oldTStart = tStart;
-  tStart = -9.e99; // pour init, on accepte des blocs avant tstart....
-  
-  if (!file->lastParam()) {
-    if (isOnBoardRecorder) {
-      extern param_bolo  parametr;
-      block_type_param block;
-      block.param = parametr;
-      valide_block((block_type_modele*)&block, block_param, 0);
-      file->forceBlock((block_type_modele*)&block);
-    } else {
-      file->nextBlock(block_param_mask);
-    }
-  }
-  if (!file->lastReglage()) file->nextBlock(block_reglage_mask);
-  
-  // On cherche un bloc GPS pour avoir la correspondance timestamp/UTC.
-  // Pour le moment, on se fonde sur le premier bloc GPS. On pourra faire
-  // mieux en prenant le min de tous les delta_T, a condition d'avoir un 
-  // peu plus de details sur la facon dont le GPS est lu.
-  
-  if (archParam.acq.tBlock0 < 0) {
-    archParam.acq.tBlock0 = file->getStartMJD();
-
-    file->pushMark();
-    if (file->lastGPS() || file->nextBlock(block_gps_mask)) {
-      // le temps du bloc courant, en secondes
-      double dt = file->blockNum() * file->perBlock();
-      archParam.acq.tBlock0 = file->getGPSMJD() - dt/86400.;
-    } else { // pas de bloc GPS...
-      archParam.acq.tBlock0 = file->getStartMJD();
-    }
-    file->popMark();
-  }
-  tStart = oldTStart;  // on restaure
-  
-  if (archParam.acq.perEch < 0)
-    archParam.acq.perEch = file->perEchant();
-
-  bool hasInterp = false;
-  
-  trigMask = 0;
-  for (vector<info>::iterator i = infos.begin(); i != infos.end(); i++) {
-    if ((*i).interpolated) hasInterp = true;
-    if ((*i).triggering) {
-      switch ((*i).kind) {
-      case boloMuV:
-      case boloMuV2:
-      case boloRawMuV:
-      case boloRawMuVCN:
-        trigMask |= block_bolo_mask;
-        break;
-      case boloMuV2T:
-      case boloRes:
-      case boloTemp:
-         trigMask |= block_bolo_mask | block_reglage_mask;
-        break;
-      case dilDAC:
-      case dilSwitch:
-        trigMask |= block_dilution_mask;
-      case boloGainAmpli:
-      case boloDACV:
-      case boloDACI:
-        trigMask |= block_reglage_mask;
-        break;
-      case gpsTime:
-      case longitude:
-      case latitude:
-      case altitude:
-        trigMask |= block_gps_mask;
-        break;
-      case azimuthBolo:
-        trigMask |= block_bolo_mask;
-        //file->needSSTProcessMask(SSTHandler::findPeriod);
-        //trigMask |= block_sst_mask;
-        break;
-      case sstStarCnt:
-      case sstStarZ:
-      case sstStarF:
-      case sstStarT:
-        file->needSSTProcessMask(SSTHandler::findStars);
-        trigMask |= block_sst_mask;
-        break;
-      case sstDiode:
-      case sstDiodeCN:
-        file->needSSTProcessMask(SSTHandler::permDiode);
-        trigMask |= block_sst_mask;
-        break;
-      case sstChannel:
-      case sstChannelCN:
-        trigMask |= block_sst_mask;
-        break;
-      case gyroRaw:
-      case gyroV:
-        trigMask |= block_gyro_mask;
-        break;
-      case gyroSpeed:
-        trigMask |= block_gyro_mask; // $CHECK$ + info to calibrate gyros
-        break;
-      case alphaRotAxis:
-      case deltaRotAxis:
-      case alphaSst:
-      case deltaSst:
-      case alphaFPAxis:
-      case deltaFPAxis:
-      case alphaBolo:
-      case deltaBolo:
-        trigMask |= block_bolo_mask;
-        //file->needSSTProcessMask(SSTHandler::findAxis);
-        //trigMask |= block_sst_mask;
-        break;
-      case alphaZenith:
-      case deltaZenith:
-        trigMask |= block_gps_mask;
-        break;
-      case voyantEVO:
-      case voyantEVF:
-      case commandeEV0:
-      case commandeEVF:
-      case commandeEVB:
-      case commandeEVV:
-      case pressEnt3He:
-      case debit3He:
-      case pressSor3He:
-      case pressEnt4He:
-      case debit4He:
-      case pressSor4He:
-      case pressAirVanne:
-      case pressPompChar:
-      case pressMembrane:
-      case pressExterne:
-      case tensPile10T:
-      case tensPileP18D:
-      case tensPileM18D:
-      case tensPile10B:
-      case tensPileP18B:
-      case tensPileM18B:
-      case tensPileCh:
-      case swPile5:
-      case swPile15:
-      case tempCaissH1:
-      case tempCaissH2:
-      case tempCaissB1:
-      case tempCaissB2:
-      case tempCaissTHe:
-      case tempCaissPiles:
-      case tempCaissDrv:
-      case pressHeBain:
-      case pressPirani:
-        trigMask |= block_dilution_mask;
-        break;
-      }
-    }
-  }
-  
-  if (trigMask & (block_bolo_mask | block_sst_mask)) {
-    imes = 9999;
-  } else {
-    imes = 0;
-  }
-  
-  if (hasInterp) {
-    rawIter = new TOIIter(*this);
-    interp = new TOIInterpolator[infos.size()];
-    for (int i=0; i<infos.size(); i++) {
-      rawIter->infos[i].interpolated = false;
-    }
-    delete file; file = NULL; // on ne travaille plus sur le fichier directement...
-  }
-}
-
-void TOIIter::ScanFiles() {
-  file1stSamp.clear();
-  cout << "Scanning all files" << endl;
-  // Petite astuce pour les STL non conformes comme celles de digital
-  // qui ne supportent pas files.erase(i) suivi de i++....
-  set<string> copy = files;
-  for (set<string>::iterator i = copy.begin(); i != copy.end(); i++) {
-    ArcheopsFile fich((*i).c_str());
-    if (fich.nextBlock()) {
-      file1stSamp[*i] = fich.blockNum()*72; // premier numsample
-      cout << "File " << *i << " 1st sample = " << fich.blockNum()*72 << endl;
-    } else {
-      cout << "File " << *i << " unrecoverable, skipping" << endl;
-      files.erase(*i);
-    }
-  }
-  cout << "Scan done" << endl;
-  
-  // Et maintenant, on ne garde que ceux qui tombent dans l'intervalle...
-  copy = files;
-  string prev="";
-  for (set<string>::iterator i = copy.begin(); i != copy.end(); i++) {
-    double smp = file1stSamp[*i];
-    double t   = archParam.acq.tBlock0 + smp * archParam.acq.perEch/86400.;
-    if (t>tEnd || smp>sEnd) {  // premier echantillon apres tEnd
-     files.erase(*i);
-     prev = "";
-     continue;
-    }
-    if (t<tStart || smp<sStart) { // premier echantillon avant tStart -> on vire le precedent si existe
-      if (prev != "") {
-        files.erase(prev);
-      }
-    }
-    prev = *i;
-  }
-}
-
-bool TOIIter::NextFile() {
-  if (rawIter)
-    return rawIter->NextFile();
-    
-  if (files.empty()) {
-    return false;
-  } else {
-    if (curFile == files.end()) return false;
-    curFile++;
-    if (curFile == files.end()) return false;
-    cout << "opening file " << (*curFile).c_str() << endl;
-    ArcheopsFile* newfile = new ArcheopsFile((*curFile).c_str());
-    newfile->grabLastBlocs(*file);
-    delete file;
-    file = newfile;
-    return true;
-  }
-}
-
-bool TOIIter::Next() {
-  for (int ii=0; ii<underSample; ii++)
-    if (!Next1()) return false;
+    if (found) break;
+    if (endFound && !valuesAhead) return false;
+  }
   return true;
 }
 
-bool TOIIter::Next1() {
-  if (!initDone) Init();
-  while (1) {
-    if (!NextSample()) return false; // end of files
-    double t = getMJD();
-    if (t < tStart) continue;
-    if (t > tEnd) return false;
-    return true;
-  }
-}
-
-bool TOIIter::NextSample() {
-  if (rawIter) {  // Delegation pour interpolation
-    // Trouve prochain sample disponible
-    for (int k=0; k<2; k++) {
-      long smp = 2147483647L;
-      for (int i=0; i<infos.size(); i++) {
-        long ss = interp[i].nextSample(lastSample+1);
-        if (ss > 0 && ss < smp) smp=ss;
-      }
-      if (smp != 2147483647L) {
-        lastSample = smp;
-        break;
-      }
-      if (!fetchAhead())  // tout le monde etait en bout de course,
-        return false;     // on lit un echantillon, ca suffit, d'ou le k<2
-    }
-    // Verifie que tous les interpolateurs ont assez de donnees pour
-    // trouver la valeur correspondante
-    for (int i=0; i<infos.size(); i++) {
-      //rif (infos[i].interpolated) 
-        while (interp[i].needMoreDataFor(lastSample) && 
-               rawIter->getSampleIndex() - lastSample < maxLookAhead)
-          if (!fetchAhead()) return false;
-    }
-    
-    // On est pret...
-    return true;
-  }
-
-  // trigger sur info indexee dans bloc bolo, bloc gyro ou bloc sst ?
-  if (trigMask & (block_bolo_mask | block_sst_mask | block_gyro_mask )) {
-    imes++;
-    if (imes < file->nEchBlock()) return true;
-    imes = 0;
-  }
-  
-  // soit pas d'info indexee, soit fin bloc courant...
-  while (1) {
-    if (file->nextBlock(trigMask)) {
-      while (file->sameBlockNumAhead()) {  // tant que meme numero de bloc, on lit
-        if (!file->nextBlock()) {          // fin de fichier ?
-          if (NextFile()) file->nextBlock(); // fichier suivant
-          else return false;    // tout fini
-        }
-      }
-      return true;
-    }
-    if (!NextFile()) return false;
-  }
-}
-
-/* double TOIIter::getTime() {                // MJD 
-   // le temps du bloc courant, en secondes
-   double dt = file->blockNum() * file->perBlock();
-   return tBlock0 + dt/86400. + imes*file->perEchant()/86400.;
- }
- */
- 
+int TOIIter::getColTOI(TOI const& toi) {
+  for (int i=0; i<request.size(); i++)
+    if (request[i].first == toi) return i;
+  throw ArchExc("getColTOI : no such TOI " + toi.name);
+}
+
 bool TOIIter::canGetValue(int column) {
-  if (!initDone) Init();
-   if (column < 0 || column >= infos.size()) return false;
-   TOIKind kind = infos[column].kind;
-   if (auxGPS && 
-       (kind == longitude || kind == latitude || kind == altitude || kind == tsid ||
-        kind == alphaZenith || kind == deltaZenith)) {
-         double dummy;
-         return auxGPS->getLocation(getMJD(), dummy, dummy, dummy) == 0;
-   }
-   if (rawIter) {
-       return interp[column].canGet(lastSample);
-   }
-   int index = infos[column].index;
-   switch (kind) {
-   case sampleNum:
-   case internalTime:
-   case mjd:
-   case mutc:
-     return true;
-   case boloMuV:
-   case boloMuV2:
-   case boloMuV2T:
-   case boloRes:
-   case boloRawMuVCN:
-   case boloTemp:
-     if (imes==0 && file->llastBolo()==NULL) return false;
-     return file->lastBolo() != NULL;
-   case boloRawMuV:
-     return file->lastBolo() != NULL;
-   case boloGainAmpli:
-   case boloDACV:
-   case boloDACI:
-     return file->lastReglage() != NULL;
-   case dilDAC:
-   case dilSwitch:
-     return file->lastDilution() != NULL;
-   case sstDiode:
-   case sstChannel:
-   case sstDiodeCN:
-   case sstChannelCN:
-     return file->lastSST() != NULL;
-   case sstStarCnt:
-   case sstStarZ:
-   case sstStarF:
-   case sstStarT:{
-     if (file->lastSST() == NULL) return false;
-     int n = file->getNumbStar(imes);
-     return (n > 0 && index < n);
-   }
-   case gyroRaw:
-   case gyroV:
-   case gyroSpeed:
-     return (file->lastGyro() != NULL);
-   case gpsTime:
-     return file->hasGPSTime();
-   case longitude:
-   case latitude:
-   case alphaZenith:
-   case deltaZenith:
-     return file->hasGPSPos();
-   case altitude:
-     return file->hasGPSAlt();
-   case tsid:
-     return file->hasGPSPos();
-   case azimuthBolo:
-   case alphaRotAxis:
-   case deltaRotAxis:
-   case alphaFPAxis:
-   case deltaFPAxis:
-   case alphaBolo:
-   case deltaBolo:
-     return true;
-     //return (file->lastGPS() != NULL && file->lastSST() != NULL);
-   case alphaSst:
-   case deltaSst:
-     return false;
-   case voyantEVO:
-   case voyantEVF:
-   case commandeEV0:
-   case commandeEVF:
-   case commandeEVB:
-   case commandeEVV:
-   case pressEnt3He:
-   case debit3He:
-   case pressSor3He:
-   case pressEnt4He:
-   case debit4He:
-   case pressSor4He:
-   case pressAirVanne:
-   case pressPompChar:
-   case pressMembrane:
-   case pressExterne:
-   case tensPile10T:
-   case tensPileP18D:
-   case tensPileM18D:
-   case tensPile10B:
-   case tensPileP18B:
-   case tensPileM18B:
-   case tensPileCh:
-   case swPile5:
-   case swPile15:
-   case tempCaissH1:
-   case tempCaissH2:
-   case tempCaissB1:
-   case tempCaissB2:
-   case tempCaissTHe:
-   case tempCaissPiles:
-   case tempCaissDrv:
-   case pressHeBain:
-   case pressPirani:
-     return file->lastDilution() != NULL;
-   }
-   return false;
-}
-
+   TOIInfo& info = request[column];
+   return(info.second->canGetValue(curSample, info.first));
+}
 
 double TOIIter::getValue(int column) {
-  if (!initDone) Init();
-   if (column < 0 || column >= infos.size()) return -1;
-   TOIKind kind = infos[column].kind;
-   if (auxGPS && 
-       (kind == longitude || kind == latitude || kind == altitude || kind == tsid)) {
-         double lat,lon,alt;
-         if (auxGPS->getLocation(getMJD(), lat, lon, alt)) return -99999;
-         if (kind == longitude) return lon;
-         if (kind == latitude)  return lat;
-         if (kind == altitude)  return alt;
-         if (kind == tsid) {
-           tSid.setLongitude(lon);
-           return tSid.getLST(getMJD());
-         }
-         
-   }
-   if (rawIter) {
-     if (infos[column].interpolated)
-       return interp[column].getIValue(lastSample);
-     else
-       return interp[column].getEValue(lastSample);
-   }
-   int index = infos[column].index;
-   switch (kind) {
-   case sampleNum:
-     return getSampleIndex();
-   case internalTime:
-     return getSampleIndex() * archParam.acq.perEch;
-   case mjd:
-     return getMJD();
-   case mutc:
-     return (getMJD()-archParam.acq.utcOrigin)*24.;
-   case boloMuV:
-     return file->getBoloMuV(index, imes);
-   case boloMuV2:
-     return file->getBoloMuV2(index, imes);
-   case boloRawMuV:
-     return file->getBoloRawMuV(index, imes);
-   case boloRawMuVCN:
-     return file->getBoloRawMuVCN(index, imes);
-   case boloGainAmpli:
-     return file->getGainAmpli(index);
-   case boloDACV:
-     return file->getDACV(index);
-   case boloDACI:
-     return file->getDACI(index);
-   case boloMuV2T:
-     return file->getBoloMuV2T(index, imes);
-   case boloRes:
-     return file->getBoloRes(index, imes);
-   case boloTemp:
-     return file->getBoloTemp(index, imes);
-   case dilDAC:
-     return file->getADCDil(index);
-   case dilSwitch:
-     return file->getSwitchDil();
-   case sstDiode:
-     return file->getSSTSignal(index, imes);
-   case sstChannel:
-     return file->getSSTRawSignal(index, imes);
-   case sstDiodeCN:
-     return file->getSSTSignalCN(index, imes);
-   case sstChannelCN:
-     return file->getSSTRawSignalCN(index, imes);
-   case sstStarCnt:
-     return file->getNumbStar(imes);
-   case sstStarZ:
-     return file->getSSTStarZ(index, imes);
-   case sstStarF:
-     return file->getSSTStarF(index, imes);
-   case sstStarT:
-     return file->getSSTStarT(index, imes);
-   case gyroRaw:
-     return file->getGyroRaw(index, imes);
-   case gyroV:
-     return file->getGyroTens(index, imes);
-   case gyroSpeed:
-     return file->getGyroSpeed(index, imes);
-   case gpsTime:
-     return file->getGPSUTC();
-   case longitude:
-     return file->getGPSLong();
-   case latitude:
-     return file->getGPSLat();
-   case altitude:
-     return file->getGPSAlt();
-   case tsid:
-     tSid.setLongitude(file->getGPSLong());
-     return tSid.getLST(getMJD());
-   case azimuthBolo:
-   case alphaRotAxis:
-   case deltaRotAxis: 
-   case alphaFPAxis:
-   case deltaFPAxis: 
-   case alphaZenith:
-   case deltaZenith: 
-   case alphaBolo:
-   case deltaBolo: {
-        double lat, lon;
-        if (auxGPS) {
-          double alti;
-          auxGPS->getLocation(getMJD(), lat, lon, alti);
-        } else {
-          lon = file->getGPSLong();
-          lat = file->getGPSLat();
-        }
-        tSid.setLongitude(lon);
-        double ts = tSid.getLST(getMJD());
-        tempLocator.setEarthPos(lon, lat);
-        tempLocator.setTSid(ts);
-        if ((kind) == alphaRotAxis) return tempLocator.getAlphaZenith();
-        if ((kind) == deltaRotAxis) return tempLocator.getDeltaZenith();
-        if ((kind) == alphaZenith) return tempLocator.getAlphaZenith();
-        if ((kind) == deltaZenith) return tempLocator.getDeltaZenith();
-        if ((kind) == azimuthBolo) return tempLocator.getAzimutBolo(getSampleIndex(),index);
-        if ((kind) == alphaBolo) return tempLocator.getAlphaBolo(getSampleIndex(),index);
-        if ((kind) == deltaBolo) return tempLocator.getDeltaBolo(getSampleIndex(),index);
-        if ((kind) == alphaFPAxis) return tempLocator.getAlphaCenter(getSampleIndex());
-        if ((kind) == deltaFPAxis) return tempLocator.getDeltaCenter(getSampleIndex());
-        return 0;
-     }
-   case voyantEVO:
-        return voyant_EVO(file->lastDilution());
-   case voyantEVF:
-        return voyant_EVF(file->lastDilution());
-   case commandeEV0:
-        return commande_EVO(file->lastDilution());
-   case commandeEVF:
-        return commande_EVF(file->lastDilution());
-   case commandeEVB:
-        return commande_EVB(file->lastDilution());
-   case commandeEVV:
-        return commande_EVV(file->lastDilution());
-   case pressEnt3He:
-        return pression_entree_3He(file->lastDilution());
-   case debit3He:
-        return debit_3He(file->lastDilution());
-   case pressSor3He:
-        return pression_sortie_3He(file->lastDilution());
-   case pressEnt4He:
-        return pression_entree_4He(file->lastDilution());
-   case debit4He:
-        return debit_4He(file->lastDilution());
-   case pressSor4He:
-        return pression_sortie_4He(file->lastDilution());
-   case pressAirVanne:
-        return pression_air_vanne(file->lastDilution());
-   case pressPompChar:
-        return pression_pompe_charbon(file->lastDilution());
-   case pressMembrane:
-        return pression_membranne(file->lastDilution());
-   case pressExterne:
-        return pression_externe(file->lastDilution());
-   case tensPile10T:
-        return tension_pile_10T(file->lastDilution());
-   case tensPileP18D:
-        return tension_pile_p18D(file->lastDilution());
-   case tensPileM18D:
-        return tension_pile_m18D(file->lastDilution());
-   case tensPile10B:
-        return tension_pile_10B(file->lastDilution());
-   case tensPileP18B:
-        return tension_pile_p18B(file->lastDilution());
-   case tensPileM18B:
-        return tension_pile_m18B(file->lastDilution());
-   case tensPileCh:
-        return tension_pile_Ch(file->lastDilution());
-   case swPile5:
-        return switch_pile_5(file->lastDilution());
-   case swPile15:
-        return switch_pile_15(file->lastDilution());
-   case tempCaissH1:
-        return temperature_caisson_haut1(file->lastDilution());
-   case tempCaissH2:
-        return temperature_caisson_haut2(file->lastDilution());
-   case tempCaissB1:
-        return temperature_caisson_bas1(file->lastDilution());
-   case tempCaissB2:
-        return temperature_caisson_bas2(file->lastDilution());
-   case tempCaissTHe:
-        return temperature_caisson_tube_helium(file->lastDilution());
-   case tempCaissPiles:
-        return temperature_caisson_piles(file->lastDilution());
-   case tempCaissDrv:
-        return temperature_caisson_driver_moteur(file->lastDilution());
-   case pressHeBain:
-        return pression_helium_bain(file->lastDilution());
-   case pressPirani:
-        return pression_pirani(file->lastDilution());
-   }
-   return -1;
-}
- 
-bool   TOIIter::newValue(int column) {
-  if (!initDone) Init();
-   if (column < 0 || column >= infos.size()) return false;
-   TOIKind kind = infos[column].kind;
-   if (auxGPS && 
-       (kind == longitude || kind == latitude || kind == altitude)) {
-      return true;
-   }
-   if (rawIter) {
-       return interp[column].isNewValue(lastSample);
-   }
-   switch (kind) {
-     case sampleNum:
-     case internalTime:
-     case mjd:
-     case mutc:
-     case tsid:
-       return true;
-     case boloMuV:
-     case boloMuV2:
-     case boloMuV2T:
-     case boloRes:
-     case boloTemp:
-       return file->blockNum() == file->getBoloBlockNum();
-     case boloRawMuV:
-     case boloRawMuVCN:
-       return file->blockNum() == file->getBoloBlockNum();
-     case boloGainAmpli:
-       return file->blockNum() == file->getReglageBlockNum() && imes==0;
-     case boloDACI:
-     case boloDACV:
-       return file->blockNum() == file->getReglageBlockNum() && imes==0;
-     case dilDAC:
-     case dilSwitch:
-       return file->blockNum() == file->getDilutionBlockNum() && imes==0;
-     case sstChannel:
-     case sstDiode:
-     case sstStarCnt:
-     case sstStarZ:
-     case sstStarF:
-     case sstStarT:
-       return file->blockNum() == file->getSSTBlockNum();
-     case sstChannelCN:
-     case sstDiodeCN:
-       return file->blockNum() == file->getSSTCompBlockNum();
-     case gyroRaw:
-     case gyroV:
-     case gyroSpeed:
-       return file->blockNum() == file->getGyroBlockNum();
-     case gpsTime:
-       return file->blockNum() == file->getGPSBlockNum() && imes==0;
-     case longitude:
-       return file->blockNum() == file->getGPSBlockNum() && imes==0;
-     case latitude:
-       return file->blockNum() == file->getGPSBlockNum() && imes==0;
-     case altitude:
-       return file->blockNum() == file->getGPSBlockNum() && imes==0;
-     case azimuthBolo:
-     case alphaBolo:
-     case deltaBolo:
-     case alphaZenith:
-     case deltaZenith:
-     case alphaFPAxis:
-     case deltaFPAxis:
-       return true; // $CHECK$ with SSTHandler
-     case alphaRotAxis:
-       return true; // $CHECK$ with SSTHandler
-     case deltaRotAxis:
-       return true; // $CHECK$ with SSTHandler
-     case voyantEVO:
-     case voyantEVF:
-     case commandeEV0:
-     case commandeEVF:
-     case commandeEVB:
-     case commandeEVV:
-     case pressEnt3He:
-     case debit3He:
-     case pressSor3He:
-     case pressEnt4He:
-     case debit4He:
-     case pressSor4He:
-     case pressAirVanne:
-     case pressPompChar:
-     case pressMembrane:
-     case pressExterne:
-     case tensPile10T:
-     case tensPileP18D:
-     case tensPileM18D:
-     case tensPile10B:
-     case tensPileP18B:
-     case tensPileM18B:
-     case tensPileCh:
-     case swPile5:
-     case swPile15:
-     case tempCaissH1:
-     case tempCaissH2:
-     case tempCaissB1:
-     case tempCaissB2:
-     case tempCaissTHe:
-     case tempCaissPiles:
-     case tempCaissDrv:
-     case pressHeBain:
-     case pressPirani:
-       return file->blockNum() == file->getDilutionBlockNum() && imes==0;
-   }
-   return false;
-}
- 
-bool   TOIIter::extendValue(int column) {
-   return (!infos[column].interpolated && !newValue(column));
-}
- 
-bool   TOIIter::interpValue(int column) {
-   return (infos[column].interpolated && !newValue(column));
-}
-
-bool TOIIter::isTrig(int column) {
-   if (column < 0 || column >= infos.size()) return false;
-   return infos[column].triggering;
-}
-
- 
-TOIKind TOIIter::getKind(int column) {
-   if (column < 0 || column >= infos.size()) return (TOIKind)-1;
-   return infos[column].kind;
-}
- 
-int TOIIter::getIndex(int column) {
-   if (column < 0 || column >= infos.size()) return (TOIKind)-1;
-   return infos[column].index;
-}
-
-int TOIIter::getColTOI(TOIKind kind, int index) {
-   for (int i=0; i<infos.size(); i++)
-     if (infos[i].kind == kind && infos[i].index == index)
-       return i;
-   return -1;
-}
-
-bool TOIIter::canGetTOI(TOIKind kind, int index) {
-   int col = getColTOI(kind, index);
-   if (col<0) return false;
-   return canGetValue(col);
-}
-
-double TOIIter::getTOI(TOIKind kind, int index) {
-   int col = getColTOI(kind, index);
-   if (col<0) return -9.e99;
-   return getValue(col);
-}
-
-   
-int TOIIter::getBlockSampleIndex() {
-   return imes;
-}
- 
-int TOIIter::getUnderSampling() {
-  return underSample;
-}
-
-int TOIIter::getSampleIndex() {
-  if (!initDone) Init();
-   if (file) {
-     return file->blockNum() * file->nEchBlock() + imes;
-   } else {
-     return lastSample;
-   }
-}
-
-double TOIIter::getMJD() {
-  if (!initDone) Init();
-  int sample = getSampleIndex();
-  return archParam.acq.tBlock0 + sample*archParam.acq.perEch/86400.;
-}
- 
-bool TOIIter::fetchAhead() { // Seulement si delegation
-  if (!rawIter) return false;
-  if (!rawIter->Next()) return false;
-  long sample = rawIter->getSampleIndex();
-  for (int i=0; i<infos.size(); i++) {
-    if (rawIter->canGetValue(i) && rawIter->newValue(i)) {
-      interp[i].enterValue(rawIter->getValue(i), sample);
-    }
-  }
-  return true;
-}
-
-block_type_param* TOIIter::lastParam() {
-  if (!initDone) Init();
-  if (file) return file->lastParam(); 
-  else return rawIter->lastParam();
-}
-
-
+   TOIInfo& info = request[column];
+   return(info.second->getValue(curSample, info.first));
+}
+
+bool TOIIter::canGetValue(TOI const& toi) {
+  return canGetValue(getColTOI(toi));
+}
+
+double TOIIter::getValue(TOI const& toi) {
+  return getValue(getColTOI(toi));
+}
+
Index: trunk/Poubelle/archTOI.old/toiiter.h
===================================================================
--- trunk/Poubelle/archTOI.old/toiiter.h	(revision 533)
+++ trunk/Poubelle/archTOI.old/toiiter.h	(revision 534)
@@ -1,197 +1,93 @@
 // toiiter.h
-// Eric Aubourg         CEA/DAPNIA/SPP   juillet 1999
+// Eric Aubourg         CEA/DAPNIA/SPP   septembre 1999
 
 #ifndef TOIITER_H
 #define TOIITER_H
 
-
 #include <vector>
+#include <list>
 #include <set>
 #include <map>
 #include <string>
-#include "archeopsfile.h"
-#include "auxgps.h"
-#include "tsid.h"
 
-enum TOIKind {
-  sampleNum,     // Numero d''echantillon (timer interne transputer)
-  internalTime,  // temps transputer depuis debut manip, en secondes.
-  mjd,           // UTC (en jours, MJD = JD - 2450000).
-  mutc,          // UTC en heure, avec soustraction d'origine
-  boloMuV,       // tension en microVolts, filtree avec filtre carre indexe par bolometre
-  boloMuV2,      // tension en microVolts, avec soustraction offset filtre
-  boloRawMuV,    // tension brute en microVolts, non filtree indexe par bolometre, sans chgt signe
-  boloTemp,      // Kelvins, need R(T) -> N/A
-  boloDACV,      // tension de reference du DAC (microVolts)
-  boloDACI,      // courant (microAmps)
-  boloRawMuVCN,  // compression noise on bolo (microVolts), no filter
-  boloMuV2T,     // total, microVolts, avec consigne DAC
-  boloRes,       // Resistance, ohms
-  boloGainAmpli, //
-  dilDAC,        // dilution DAC, index = 0-47
-  dilSwitch,     // dilution, mot de 32 bits
-  serviceTemp,   // service temperature, K
-  sstDiode,      // signal brut SST, indice = diode, 0-45
-  sstChannel,    // signal brut SST, indice = canal, 0-47
-  sstDiodeCN,    // compression noise
-  sstChannelCN,  // compression noise
-  sstStarCnt,    // nombre d''etoiles detectees durant ce sample
-  sstStarZ,      // numero de diode d''une eventuelle etoile,   i=etoile 0..n
-  sstStarF,      // flux d''une eventuelle etoile,             <0 si moins de i+1 etoiles
-  sstStarT,      // temps d''une eventuelle etoile,            <0 si moins de i+1 etoiles
-  gyroRaw,       // valeur brute du gyro, index = 0,1,2
-  gyroV,         // tension gyro, V, index = 0,1,2
-  gyroSpeed,     // vitesse gyro, deg/s, index = 0,1,2, calibree...
-  gpsTime,       // temps fourni par GPS
-  longitude,     // position ballon, degrees  +=EST
-  latitude,      // position ballon, degrees  +=NORD
-  altitude,      // position ballon, m
-  tsid,          // temps sideral en secondes
-  azimuthBolo,   // azimut 
-  alphaRotAxis,  // 
-  deltaRotAxis,  //
-  alphaZenith,   // 
-  deltaZenith,   //
-  alphaSst,      // 
-  deltaSst,      //
-  alphaFPAxis,   //
-  deltaFPAxis,   //
-  alphaBolo,     // sur le ciel, indexe par bolometre
-  deltaBolo,     // sur le ciel, indexe par bolometre
-  voyantEVO,
-  voyantEVF,
-  commandeEV0,
-  commandeEVF,
-  commandeEVB,
-  commandeEVV,
-  pressEnt3He,
-  debit3He,
-  pressSor3He,
-  pressEnt4He,
-  debit4He,
-  pressSor4He,
-  pressAirVanne,
-  pressPompChar,
-  pressMembrane,
-  pressExterne,
-  tensPile10T,
-  tensPileP18D,
-  tensPileM18D,
-  tensPile10B,
-  tensPileP18B,
-  tensPileM18B,
-  tensPileCh,
-  swPile5,
-  swPile15,
-  tempCaissH1,
-  tempCaissH2,
-  tempCaissB1,
-  tempCaissB2,
-  tempCaissTHe,
-  tempCaissPiles,
-  tempCaissDrv,
-  pressHeBain,
-  pressPirani
-}; 
+#include "toiabsorber.h"
+#include "requesthandler.h"
+#include "archfileset.h"
 
-class TOIInterpolator;
+class AuxGPS;
 
-class TOIIter {
+template <class T1, class T2, class T3>
+struct triple {
+    T1 first;
+    T2 second;
+    T3 third;
+	triple() : first(T1()), second(T2()), third(T3()) {}
+    triple (const T1& a, const T2& b, const T3& c) :
+           first (a), second (b), third (c) {}
+};
+
+class TOIIter : public TOIAbsorber /*, public RequestHandler*/ {
 public:
-   TOIIter(TOIIter const&);   // $CHECK$ prevoir operator = ?
-   ~TOIIter();
-   bool Next();
+  TOIIter();
+  // ~TOIIter();
+  
+  void readReq(istream& s);
+  void defaultInclude();
+
+  bool processRequest(string line);
+  void registerReqHandler(RequestHandler*);
+
+  virtual bool processTOIReq(TOI& toi, string);
+  virtual bool processOption(string keyw, string args);
+
+  void addDirectory(string);
+  void addFile(string);
+  //void useAuxGPS(AuxGPS* gps);
    
-   bool    canGetValue(int column);  // data is available for that...
-   double  getValue(int column);
-   bool    newValue(int column);     // a juste change ?
-   bool    extendValue(int column);  // une valeur plus ancienne, etendue ?
-   bool    interpValue(int column);  // une valeur interpolee avec valeur future ?
-   bool    isTrig(int column);  
-   TOIKind getKind(int column);
-   int     getIndex(int column);     // si plusieurs, exemple, tension bolo 2
+  void setMJDInterval(double tStart, double tEnd);
+  void setUTCInterval(double tStart, double tEnd);
+  void setSNInterval(long sStart, long sEnd);
+  void setUnderSample(int n);
+  int  getUnderSample();
+
+  void addTOI(TOI& toi, bool triggering=true);
+
+  void init();
+  
+  bool next();
    
-   bool    canGetTOI(TOIKind kind, int index=0);
-   double  getTOI(TOIKind kind, int index=0);
+  long    getSampleNum();
+  bool    canGetValue(int column);  // data is available for that...
+  double  getValue(int column);
+  bool    canGetValue(TOI const& toi);  // data is available for that...
+  double  getValue(TOI const& toi);
+  bool    newValue(int column);     // a juste change ?
+  bool    extendValue(int column);  // une valeur plus ancienne, etendue ?
+  bool    interpValue(int column);  // une valeur interpolee avec valeur future ?
+  bool    isTrig(int column);  
+  TOI     getKind(int column);
+  
+  ArchFileSet& getFSet() {return fset;}
+      
+protected:   
+  ArchFileSet fset;
+  list<RequestHandler*> handlers;
+  enum {triggering = 1};
+  typedef ::triple<TOI,TOIProducer*,long> TOIInfo;
+  vector<TOIInfo> request; 
    
+  double mjdStart, mjdEnd;  // MJD
+  double utcStart, utcEnd;  // UTC, will be converted towards tStart tEnd at init
+  long   sStart, sEnd;      // samplenum
+        
+  int underSample;
+  long curSample;
    
-   int    getBlockSampleIndex();        // numero d''echantillon dans dernier bloc bolo
-   int    getSampleIndex();             // numero d''echantillon 
-   int    getUnderSampling();           
-   double getMJD();            
+  int getColTOI(TOI const& toi);
+  bool next1();
 
-   block_type_param*         lastParam();  
-   block_type_journal*       lastJournal();
-   block_type_reglage*       lastReglage();
-   block_type_dilution*      lastDilution();
-   block_type_gps*           lastGPS();
-   block_type_une_periode*   lastUnePeriode();
-   block_type_synchro_sol*   lastSynchroSol();
-   block_type_pointage_sol*  lastPointageSol();
-   block_type_bolo*          lastBolo();   
-   block_type_gyro*          lastGyro();
-   block_type_sst*           lastSST();
-   block_type_bolo_comprime* lastBoloComp();   
-   block_type_gyro_comprime* lastGyroComp();
-   block_type_sst_comprime*  lastSSTComp();
-   
-   ArcheopsFile* currentFile() {if (!initDone) Init(); return file;}
-
-protected:
-   TOIIter();
-   void Init(); // After setting the options, opens the first file.
-   void ScanFiles(); // Parcourt tous les fichiers, cherche le premier echantillon...
-   
-   bool Next1();
-   bool NextSample(); // no test of trange
-   bool NextFile();
-   
-   ArcheopsFile* file;
-   string directory;   // If directory scanning
-   set<string> files;  // list of files to be read...
-   map<string, long> file1stSamp; // premier echantillon de chaque fichier
-   set<string>::iterator curFile;
-   bool  isOnBoardRecorder;
-   
-   int imes;
-   
-   double tStart, tEnd;      // MJD
-   double utcStart, utcEnd;  // UTC, will be converted towards tStart tEnd at init
-   long   sStart, sEnd;      // samplenum
-   
-   //double tBlock0;  // MJD du bloc numero zero...
-   //double perEch;   // periode d''echantillonage en secondes
-   
-   struct info {
-     TOIKind kind;
-     int index;
-     bool triggering;
-     bool interpolated;
-   };
-   
-   int getColTOI(TOIKind kind, int index=0);
-   
-   long trigMask;
-   
-   vector<info>   infos;
-   
-   friend class TOISvr;
-   
-   // Gestion de l''interpolation, par delegation a un autre iterateur
-   TOIIter* rawIter; // iterateur sans interpolation, qui avance avec retard
-                     // en bufferisant les valeurs. S''il existe, on lui delegue
-                     // toutes les operations agissant sur le fichier.
-   TOIInterpolator* interp; // interpolateurs pour stocker les valeurs
-   long lastSample;  // last interpolated sample
-   long maxLookAhead;
-   bool fetchAhead(); // avance d''une TOI en nourrissant les interpolateurs
-   
-   AuxGPS* auxGPS;
-   TSid tSid;
-   
-   int underSample;
-   
-   private:
-   bool initDone;
+private:
+  bool initDone;
+  bool incDone;
 };
 
Index: trunk/Poubelle/archTOI.old/toillboloproducer.cc
===================================================================
--- trunk/Poubelle/archTOI.old/toillboloproducer.cc	(revision 534)
+++ trunk/Poubelle/archTOI.old/toillboloproducer.cc	(revision 534)
@@ -0,0 +1,70 @@
+// toillboloproducer.cc
+// Eric Aubourg         CEA/DAPNIA/SPP   septembre 1999
+
+#include "toillboloproducer.h"
+#include "archfileset.h"
+#include "toimanager.h"
+#include "requesthandler.h"
+
+#define raw "rawBoloData"
+#define muv "boloRawMuV"
+#define muvCN "boloRawMuVCN"
+
+#define  val_DS(j,i)  (blk->data_bolo[j][i]&0x1fffff)
+
+TOILLBoloProducer::TOILLBoloProducer()
+{
+  possibleTOIs.insert(TOI(raw, TOI::all, "", "ADU"));  
+  possibleTOIs.insert(TOI(muv, TOI::all, "", "microVolts"));
+  possibleTOIs.insert(TOI(muvCN, TOI::all, "", "microVolts"));
+}
+
+string TOILLBoloProducer::getName() {
+  return("TOILLBoloProducer 1.0");
+}
+
+
+void TOILLBoloProducer::handleBlock(ArchFileSet* fs)
+{
+  block_type_bolo* blk = fs->lastBolo();
+  long sample0 = numero_block(blk)*72;
+  for (set<TOI>::iterator i = producedTOIs.begin(); i != producedTOIs.end(); i++) {
+    int ibolo = (*i).index;
+    if ((*i).name == raw) {
+      for (int j=0; j<nb_per_block*2; j++) {
+        computedValue((*i),sample0+j, val_DS(ibolo,j));
+      }
+    } else if ((*i).name == muv) {
+      block_type_reglage* reglage = fs->lastReglage();
+      block_type_param*   param   = fs->lastParam();
+      for (int j=0; j<nb_per_block*2; j++) {
+        int s = j % 2 ? 1 : -1;
+        computedValue((*i),sample0+j, 
+          s*bolo_muV(&param->param, &reglage->reglage, val_DS(ibolo,j), ibolo));
+      }
+    } else if ((*i).name == muvCN) {
+	  // Si pas bloc comprime -> 1 bit
+	  int lastbit = 1;
+	  block_type_reglage* reglage = fs->lastReglage();
+	  block_type_param*   param = fs->lastParam();
+	  bool isComp = (!(fs->lastBoloComp() == NULL) &&
+	      (numero_block(fs->lastBoloComp()) != numero_block(fs->lastBolo())));
+	  unsigned int4* data = isComp ? fs->lastBoloComp()->data_bolo[ibolo] : NULL;
+      for (int imesure=0; imesure<nb_per_block*2; imesure++) {
+	    // Les deux premieres valeurs sont codees directement...
+	    if (isComp && (imesure>=2)) {
+	      int iExp = (imesure-2)/4 + 1;
+	      int expo = data[iExp] & 0xf;
+	      lastbit = 1 << expo;
+	    } else {
+	      lastbit = 1;
+	    }
+	    double noise = (
+	      bolo_muV(&param->param, &reglage->reglage, lastbit, ibolo) -
+	      bolo_muV(&param->param, &reglage->reglage, 0, ibolo)) /2.;
+        computedValue((*i),sample0+imesure,noise);
+	  }
+    }
+  }
+}
+
Index: trunk/Poubelle/archTOI.old/toillboloproducer.h
===================================================================
--- trunk/Poubelle/archTOI.old/toillboloproducer.h	(revision 534)
+++ trunk/Poubelle/archTOI.old/toillboloproducer.h	(revision 534)
@@ -0,0 +1,23 @@
+// toillboloproducer.h
+// Eric Aubourg         CEA/DAPNIA/SPP   septembre 1999
+
+#ifndef TOILLBOLOPRODUCER_H
+#define TOILLBOLOPRODUCER_H
+
+#include "toiproducer.h"
+#include "ark.h"
+
+
+class TOILLBoloProducer : public TOILowLevProducer {
+public:
+  TOILLBoloProducer();
+  void handleBlock(ArchFileSet*); // push !
+  virtual string getName();
+
+};
+
+
+
+
+
+#endif
Index: trunk/Poubelle/archTOI.old/toilldiluproducer.cc
===================================================================
--- trunk/Poubelle/archTOI.old/toilldiluproducer.cc	(revision 534)
+++ trunk/Poubelle/archTOI.old/toilldiluproducer.cc	(revision 534)
@@ -0,0 +1,154 @@
+// toilldiluproducer.cc
+// Eric Aubourg         CEA/DAPNIA/SPP   octobre 1999
+
+#include "toilldiluproducer.h"
+#include "archfileset.h"
+#include "toimanager.h"
+#include "requesthandler.h"
+
+#define   dilDAC           "dilDAC"
+#define   dilSwitch        "dilSwitch"
+#define   voyantEVO        "voyantEVO"
+#define   voyantEVF        "voyantEVF"
+#define   commandeEV0      "commandeEV0"
+#define   commandeEVF      "commandeEVF"
+#define   commandeEVB      "commandeEVB"
+#define   commandeEVV      "commandeEVV"
+#define   pressEnt3He      "pressEnt3He"
+#define   debit3He         "debit3He"
+#define   pressSor3He      "pressSor3He"
+#define   pressEnt4He      "pressEnt4He"
+#define   debit4He         "debit4He"
+#define   pressSor4He      "pressSor4He"
+#define   pressAirVanne    "pressAirVanne"
+#define   pressPompChar    "pressPompChar"
+#define   pressMembrane    "pressMembrane"
+#define   pressExterne     "pressExterne"
+#define   tensPile10T      "tensPile10T"
+#define   tensPileP18D     "tensPileP18D"
+#define   tensPileM18D     "tensPileM18D"
+#define   tensPile10B      "tensPile10B"
+#define   tensPileP18B     "tensPileP18B"
+#define   tensPileM18B     "tensPileM18B"
+#define   tensPileCh       "tensPileCh"
+#define   swPile5          "swPile5"
+#define   swPile15         "swPile15"
+#define   tempCaissH1      "tempCaissH1"
+#define   tempCaissH2      "tempCaissH2"
+#define   tempCaissB1      "tempCaissB1"
+#define   tempCaissB2      "tempCaissB2"
+#define   tempCaissTHe     "tempCaissTHe"
+#define   tempCaissPiles   "tempCaissPiles"
+#define   tempCaissDrv     "tempCaissDrv"
+#define   pressHeBain      "pressHeBain"
+#define   pressPirani      "pressPirani"
+
+
+TOILLDiluProducer::TOILLDiluProducer()
+{
+  possibleTOIs.insert(TOI(dilDAC,        TOI::all,    "", "ADU"));  
+  possibleTOIs.insert(TOI(dilSwitch,     TOI::unspec, "", "LONGWORD"));  
+  
+  possibleTOIs.insert(TOI(voyantEVO,     TOI::unspec, "", "BOOLEAN"));  
+  possibleTOIs.insert(TOI(voyantEVF,     TOI::unspec, "", "BOOLEAN"));  
+  possibleTOIs.insert(TOI(commandeEV0,   TOI::unspec, "", "BOOLEAN"));  
+  possibleTOIs.insert(TOI(commandeEVF,   TOI::unspec, "", "BOOLEAN"));  
+  possibleTOIs.insert(TOI(commandeEVB,   TOI::unspec, "", "BOOLEAN"));  
+  possibleTOIs.insert(TOI(commandeEVV,   TOI::unspec, "", "BOOLEAN"));  
+  
+  possibleTOIs.insert(TOI(pressEnt3He,   TOI::unspec, "", "bars"));  
+  possibleTOIs.insert(TOI(debit3He,      TOI::unspec, "", "microMoles"));  
+  possibleTOIs.insert(TOI(pressSor3He,   TOI::unspec, "", "bars"));  
+
+  possibleTOIs.insert(TOI(pressEnt4He,   TOI::unspec, "", "bars"));  
+  possibleTOIs.insert(TOI(debit4He,      TOI::unspec, "", "microMoles"));  
+  possibleTOIs.insert(TOI(pressSor4He,   TOI::unspec, "", "bars"));  
+
+  possibleTOIs.insert(TOI(pressAirVanne, TOI::unspec, "", "bars"));  
+  possibleTOIs.insert(TOI(pressPompChar, TOI::unspec, "", "bars"));  
+  possibleTOIs.insert(TOI(pressMembrane, TOI::unspec, "", "bars"));  
+  possibleTOIs.insert(TOI(pressExterne,  TOI::unspec, "", "bars"));  
+  
+  possibleTOIs.insert(TOI(tensPile10T,   TOI::unspec, "", "Volts"));  
+  possibleTOIs.insert(TOI(tensPileP18D,  TOI::unspec, "", "Volts"));  
+  possibleTOIs.insert(TOI(tensPileM18D,  TOI::unspec, "", "Volts"));  
+  possibleTOIs.insert(TOI(tensPile10B,   TOI::unspec, "", "Volts"));  
+  possibleTOIs.insert(TOI(tensPileP18B,  TOI::unspec, "", "Volts"));  
+  possibleTOIs.insert(TOI(tensPileM18B,  TOI::unspec, "", "Volts"));  
+  possibleTOIs.insert(TOI(tensPileCh,    TOI::unspec, "", "Volts"));  
+
+  possibleTOIs.insert(TOI(swPile5,       TOI::unspec, "", "BOOLEAN"));  
+  possibleTOIs.insert(TOI(swPile15,      TOI::unspec, "", "BOOLEAN"));  
+
+  possibleTOIs.insert(TOI(tempCaissH1,   TOI::unspec, "", "Kelvin"));  
+  possibleTOIs.insert(TOI(tempCaissH2,   TOI::unspec, "", "Kelvin"));  
+  possibleTOIs.insert(TOI(tempCaissB1,   TOI::unspec, "", "Kelvin"));  
+  possibleTOIs.insert(TOI(tempCaissB2,   TOI::unspec, "", "Kelvin"));  
+  possibleTOIs.insert(TOI(tempCaissTHe,  TOI::unspec, "", "Kelvin"));  
+  possibleTOIs.insert(TOI(tempCaissPiles,TOI::unspec, "", "Kelvin"));  
+  possibleTOIs.insert(TOI(tempCaissDrv,  TOI::unspec, "", "Kelvin"));  
+
+  possibleTOIs.insert(TOI(pressHeBain,   TOI::unspec, "", "bars"));  
+  possibleTOIs.insert(TOI(pressPirani,   TOI::unspec, "", "bars"));  
+}
+
+string TOILLDiluProducer::getName() {
+  return("TOILLDiluProducer 1.0");
+}
+
+#define COMPTOI(_toi_, _func_)                               \
+    if ((*i).name == _toi_) {                                 \
+      computedValue((*i),sample0, _func_(blk));      \
+    }
+
+void TOILLDiluProducer::handleBlock(ArchFileSet* fs)
+{
+  block_type_dilution* blk = fs->lastDilution();
+  long sample0 = numero_block(blk)*72;
+  for (set<TOI>::iterator i = producedTOIs.begin(); i != producedTOIs.end(); i++) {
+    COMPTOI(voyantEVO,      voyant_EVO) else
+    COMPTOI(voyantEVF,      voyant_EVF) else
+    COMPTOI(commandeEV0,    commande_EVO) else
+    COMPTOI(commandeEVF,    commande_EVF) else
+    COMPTOI(commandeEVB,    commande_EVB) else
+    COMPTOI(commandeEVV,    commande_EVV) else
+    COMPTOI(pressEnt3He,    pression_entree_3He) else
+    COMPTOI(debit3He,       debit_3He) else
+    COMPTOI(pressSor3He,    pression_sortie_3He) else
+    COMPTOI(pressEnt4He,    pression_entree_4He) else
+    COMPTOI(debit4He,       debit_4He) else
+    COMPTOI(pressSor4He,    pression_sortie_4He) else
+    COMPTOI(pressAirVanne,  pression_air_vanne) else
+    COMPTOI(pressPompChar,  pression_pompe_charbon) else
+    COMPTOI(pressMembrane,  pression_membranne) else
+    COMPTOI(pressExterne,   pression_externe) else
+    COMPTOI(tensPile10T,    tension_pile_10T) else
+    COMPTOI(tensPileP18D,   tension_pile_p18D) else
+    COMPTOI(tensPileM18D,   tension_pile_m18D) else
+    COMPTOI(tensPile10B,    tension_pile_10B) else
+    COMPTOI(tensPileP18B,   tension_pile_p18B) else
+    COMPTOI(tensPileM18B,   tension_pile_m18B) else
+    COMPTOI(tensPileCh,     tension_pile_Ch) else
+    COMPTOI(swPile5,        switch_pile_5) else
+    COMPTOI(swPile15,       switch_pile_15) else
+    COMPTOI(tempCaissH1,    temperature_caisson_haut1) else
+    COMPTOI(tempCaissH2,    temperature_caisson_haut2) else
+    COMPTOI(tempCaissB1,    temperature_caisson_bas1) else
+    COMPTOI(tempCaissB2,    temperature_caisson_bas2) else
+    COMPTOI(tempCaissTHe,   temperature_caisson_tube_helium) else
+    COMPTOI(tempCaissPiles, temperature_caisson_piles) else
+    COMPTOI(tempCaissDrv,   temperature_caisson_driver_moteur) else
+    COMPTOI(pressHeBain,    pression_helium_bain) else
+    COMPTOI(pressPirani,    pression_pirani)
+    if ((*i).name == dilDAC) {
+      int k = (*i).index;
+      computedValue((*i), sample0, blk->ADC_dil[k]);
+    } else
+    if ((*i).name == dilSwitch) {
+      computedValue((*i), sample0, blk->switch_dil);
+    }
+  }
+}
+
+
+
Index: trunk/Poubelle/archTOI.old/toilldiluproducer.h
===================================================================
--- trunk/Poubelle/archTOI.old/toilldiluproducer.h	(revision 534)
+++ trunk/Poubelle/archTOI.old/toilldiluproducer.h	(revision 534)
@@ -0,0 +1,23 @@
+// toilldiluproducer.h
+// Eric Aubourg         CEA/DAPNIA/SPP   octobre 1999
+
+#ifndef TOILLDILUPRODUCER_H
+#define TOILLDILUPRODUCER_H
+
+#include "toiproducer.h"
+#include "ark.h"
+
+
+class TOILLDiluProducer : public TOILowLevProducer {
+public:
+  TOILLDiluProducer();
+  void handleBlock(ArchFileSet*); // push !
+  virtual string getName();
+
+};
+
+
+
+
+
+#endif
Index: trunk/Poubelle/archTOI.old/toillgpsproducer.cc
===================================================================
--- trunk/Poubelle/archTOI.old/toillgpsproducer.cc	(revision 534)
+++ trunk/Poubelle/archTOI.old/toillgpsproducer.cc	(revision 534)
@@ -0,0 +1,156 @@
+// toillgpsproducer.cc
+// Eric Aubourg         CEA/DAPNIA/SPP   octobre 1999
+
+#include "toillgpsproducer.h"
+#include "archfileset.h"
+#include "toimanager.h"
+#include "requesthandler.h"
+
+#define   gpsTime          "gpsTime"
+#define   latitude         "latitude"
+#define   longitude        "longitude"
+#define   altitude         "altitude"
+#define   gpsQuality       "gpsQuality"
+#define   gpsNSat          "gpsNSat"
+#define   gpsHDOP          "gpsHDOP"
+#define   gpsGeoidSep      "gpsGeoidSep"
+
+
+TOILLGPSProducer::TOILLGPSProducer()
+{
+  possibleTOIs.insert(TOI(gpsTime,      TOI::unspec,   "", "seconds", "onboardGPS"));  
+  possibleTOIs.insert(TOI(latitude,     TOI::unspec,   "", "degrees", "onboardGPS"));  // + = NORTH
+  possibleTOIs.insert(TOI(longitude,    TOI::unspec,   "", "degrees", "onboardGPS"));  // + = EAST
+  possibleTOIs.insert(TOI(altitude,     TOI::unspec,   "", "meters",  "onboardGPS"));  
+  possibleTOIs.insert(TOI(gpsQuality,   TOI::unspec,   "", "flag",    "onboardGPS"));  
+  possibleTOIs.insert(TOI(gpsNSat,      TOI::unspec,   "", "integer", "onboardGPS"));  
+  possibleTOIs.insert(TOI(gpsHDOP,      TOI::unspec,   "", "real",    "onboardGPS"));  
+  possibleTOIs.insert(TOI(gpsGeoidSep,  TOI::unspec,   "", "meters",  "onboardGPS"));
+}
+
+string TOILLGPSProducer::getName() {
+  return("TOILLGPSProducer 1.0");
+}
+
+
+// GPGGA string : 
+// $hhmmss.ss,ddmm.mmmm,n,dddmm.mmmm,e,q,ss,y.y,a.a,z,,
+// $104020,3740.712,N,00400.781,W,0,00,01.0,0003,M,-050,M,,
+
+
+void TOILLGPSProducer::handleBlock(ArchFileSet* fs)
+{
+  block_type_gps* blk = fs->lastGPS();
+  long sample0 = numero_block(blk)*72;
+    
+  double gpsutc;        //  secondes depuis minuit
+  double gpslat;        //  degres, + = NORD
+  double gpslong;       //  degres, + = EST
+  double alt;           //  altitude en metres
+  int    quality;       //  0 = NO FIX, 1 = GPS FIX, 2 = DGPS FIX
+  int    nsat;          //  nombre de satellites utilises
+  double hdop;          //  horizontal dilution of precision
+  double gsep;          //  separation geoide en metres
+  
+  char* p = blk->gps;
+  char* fence = p+80;
+  if (*p!='$') return;
+  p++;
+  
+  // UTC
+  if (*p < '0' || *p > '9') return;
+  double t;
+  sscanf(p, "%lg", &t);
+  int h = int(t/10000); t -= h*10000;
+  int m = int(t/100);   t -= m*100;
+  gpsutc = h*3600. + m*60. + t;
+  p += 6;
+  if (*p != ',') return;
+  p++;
+  if (p>=fence) return;
+  
+  // LATITUDE
+  if (*p < '0' || *p > '9') return;
+  sscanf(p, "%lg", &t);
+  int d = int(t/100); t -= d*100;
+  t = d + t/60;
+  p += 8;
+  if (*p != ',') return; 
+  p++;
+  if (*p == 'S') t = -t;
+  gpslat = t;
+  p++;
+  if (*p != ',') return; 
+  p++;
+  if (p>=fence) return;
+
+  // LONGITUDE
+  if (*p < '0' || *p > '9') return;
+  sscanf(p, "%lg", &t);
+  d = int(t/100); t -= d*100;
+  t = d + t/60;
+  p += 9;
+  if (*p != ',') return; 
+  p++;
+  if (*p == 'W') t = -t;
+  gpslong = t;
+  p++;
+  if (*p != ',') return; 
+  p++;
+  if (p>=fence) return;
+
+  // QUALITY
+  quality = *p - '0';
+  if (quality < 0 || quality > 9) return;
+  p++;
+  if (*p != ',') return; 
+  p++;
+  if (p>=fence) return;
+  
+  // NSAT
+  if (*p < '0' || *p > '9') return;
+  sscanf(p, "%d", &nsat);
+  p += 2;
+  if (*p != ',') return; 
+  p++;
+  
+  // HDOP
+  if (*p < '0' || *p > '9') return;
+  sscanf(p, "%lg", &hdop);
+  while (*p != ',' && p<fence) p++;
+  if (*p != ',') return; 
+  p++;
+  
+  // Altitude
+  if (*p < '0' || *p > '9') return;
+  sscanf(p, "%lg", &alt);
+  while (*p != ',' && p<fence) p++;
+  if (*p != ',') return; 
+  p++;
+  if (*p != 'M') return; 
+  p++;
+  if (*p != ',') return; 
+  p++;
+
+  // Geoid separation
+  if ((*p < '0' || *p > '9') && *p != '-') return;
+  sscanf(p, "%lg", &gsep);
+  while (*p != ',' && p<fence) p++;
+  if (*p != ',') return; 
+  p++;
+  if (*p != 'M') return; 
+
+  for (set<TOI>::iterator i = producedTOIs.begin(); i != producedTOIs.end(); i++) {
+    if ((*i).name == gpsTime)        computedValue((*i), sample0, gpsutc);
+    if ((*i).name == latitude)       computedValue((*i), sample0, gpslat);
+    if ((*i).name == longitude)      computedValue((*i), sample0, gpslong);
+    if ((*i).name == altitude)       computedValue((*i), sample0, alt);
+    if ((*i).name == gpsQuality)     computedValue((*i), sample0, quality);
+    if ((*i).name == gpsNSat)        computedValue((*i), sample0, nsat);
+    if ((*i).name == gpsHDOP)        computedValue((*i), sample0, hdop);
+    if ((*i).name == gpsGeoidSep)    computedValue((*i), sample0, gsep);
+  }
+}
+
+
+
Index: trunk/Poubelle/archTOI.old/toillgpsproducer.h
===================================================================
--- trunk/Poubelle/archTOI.old/toillgpsproducer.h	(revision 534)
+++ trunk/Poubelle/archTOI.old/toillgpsproducer.h	(revision 534)
@@ -0,0 +1,24 @@
+// toillgpsproducer.h
+// Eric Aubourg         CEA/DAPNIA/SPP   octobre 1999
+
+#ifndef TOILLGPSPRODUCER_H
+#define TOILLGPSPRODUCER_H
+
+#include "toiproducer.h"
+#include "ark.h"
+
+
+class TOILLGPSProducer : public TOILowLevProducer {
+public:
+  TOILLGPSProducer();
+
+  virtual void handleBlock(ArchFileSet*);
+  virtual string getName();
+  
+};
+
+
+
+
+
+#endif
Index: trunk/Poubelle/archTOI.old/toillgyroproducer.cc
===================================================================
--- trunk/Poubelle/archTOI.old/toillgyroproducer.cc	(revision 534)
+++ trunk/Poubelle/archTOI.old/toillgyroproducer.cc	(revision 534)
@@ -0,0 +1,64 @@
+// toillgyroproducer.cc
+// Eric Aubourg         CEA/DAPNIA/SPP   octobre 1999
+
+#include "toillgyroproducer.h"
+#include "archfileset.h"
+#include "toimanager.h"
+#include "requesthandler.h"
+
+#define gyroRaw    "gyroRaw"
+#define gyroV      "gyroV"
+#define gyroCal    "gyroCal"
+#define gyroSpeed  "gyroSpeed"
+
+TOILLGyroProducer::TOILLGyroProducer()
+{
+  possibleTOIs.insert(TOI(gyroRaw,   TOI::all, "", "ADU"));  
+  possibleTOIs.insert(TOI(gyroV,     TOI::all, "", "Volts"));
+  possibleTOIs.insert(TOI(gyroCal,   TOI::unspec, "", "deg/s/V", "theoric"));
+  possibleTOIs.insert(TOI(gyroSpeed, TOI::all, "", "deg/s", "theoric"));
+}
+
+string TOILLGyroProducer::getName() {
+  return("TOILLGyroProducer 1.0");
+}
+
+
+static inline long gyrRaw(block_type_gyro* blk, int igyro, int imesure) {
+  return blk->gyro[igyro][imesure]-32768;
+}
+
+static inline double gyrV(block_type_gyro* blk, int igyro, int imesure) {
+  return gyrRaw(blk, igyro, imesure) * 2. / 32768.; // +- 2V dynamique sur 16 bits;
+}
+
+static inline double gyrSpeed(block_type_gyro* blk, int igyro, int imesure) {
+  return gyrV(blk, igyro, imesure) * 10;
+}
+
+void TOILLGyroProducer::handleBlock(ArchFileSet* fs)
+{
+  block_type_gyro* blk = fs->lastGyro();
+  long sample0 = numero_block(blk)*72;
+  for (set<TOI>::iterator i = producedTOIs.begin(); i != producedTOIs.end(); i++) {
+    int igyro = (*i).index;
+    if ((*i).name == gyroRaw) {
+      for (int j=0; j<nb_per_block*2; j++) {
+        computedValue((*i),sample0+j, gyrRaw(blk,igyro,j));
+      }
+    } else if ((*i).name == gyroV) {
+      for (int j=0; j<nb_per_block*2; j++) {
+        computedValue((*i),sample0+j, gyrV(blk,igyro,j));
+      }
+    } else if ((*i).name == gyroCal) {
+      for (int j=0; j<nb_per_block*2; j++) {
+        computedValue((*i),sample0+j, 10);
+      }
+    } else if ((*i).name == gyroSpeed) {
+      for (int j=0; j<nb_per_block*2; j++) {
+        computedValue((*i),sample0+j, gyrSpeed(blk,igyro,j));
+      }
+    }
+  }
+}
+
Index: trunk/Poubelle/archTOI.old/toillgyroproducer.h
===================================================================
--- trunk/Poubelle/archTOI.old/toillgyroproducer.h	(revision 534)
+++ trunk/Poubelle/archTOI.old/toillgyroproducer.h	(revision 534)
@@ -0,0 +1,23 @@
+// toillgyroproducer.h
+// Eric Aubourg         CEA/DAPNIA/SPP   octobre 1999
+
+#ifndef TOILLGYROPRODUCER_H
+#define TOILLGYROPRODUCER_H
+
+#include "toiproducer.h"
+#include "ark.h"
+
+
+class TOILLGyroProducer : public TOILowLevProducer {
+public:
+  TOILLGyroProducer();
+  void handleBlock(ArchFileSet*); // push !
+  virtual string getName();
+
+};
+
+
+
+
+
+#endif
Index: trunk/Poubelle/archTOI.old/toillreglageproducer.cc
===================================================================
--- trunk/Poubelle/archTOI.old/toillreglageproducer.cc	(revision 534)
+++ trunk/Poubelle/archTOI.old/toillreglageproducer.cc	(revision 534)
@@ -0,0 +1,128 @@
+// toillreglageproducer.cc
+// Eric Aubourg         CEA/DAPNIA/SPP   septembre 1999
+
+#include "toillreglageproducer.h"
+#include "archfileset.h"
+#include "toimanager.h"
+#include "requesthandler.h"
+
+// horloge
+#define horlPeriode    "horlPeriode"
+#define horlNbMesures  "horlNbMesures"
+#define horlTempMort   "horlTempMort"
+#define horlFlag       "horlFlag"
+
+// regul_bolo
+#define regMode        "regMode"         // index regul 
+#define regNumBolo     "regNumBolo"
+#define regVoieChauf   "regVoieChauf"
+#define regProp        "regProp"
+#define regInteg       "regInteg"
+#define regDeriv       "regDeriv"
+#define regChauffage   "regChauffage"
+
+// auto_bolo
+#define autoBolMode    "autoBolMode"     // index voie
+#define autoBolGain    "autoBolGain"
+#define autoBolCourant "autoBolCourant"
+#define autoBolDelai   "autoBolDelai"
+
+// auto_dilu
+#define autoDilVanne   "autoDilVanne"
+#define autoDilHelium  "autoDilHelium"
+#define autoDilChauff  "autoDilChauff"
+#define autoDilPiles   "autoDilPiles"
+#define autoDilTrans   "autoDilTrans"
+#define autoDilTMxVan  "autoDilTMxVan"
+#define autoDilxx7     "autoDilxx7"
+#define autoDilxx8     "autoDilxx8"
+
+// reglage_un_bolo
+#define boloDACV       "boloDACV"       // index bolo
+#define boloDACI       "boloDACI"
+
+
+TOILLReglageProducer::TOILLReglageProducer()
+{
+  possibleTOIs.insert(TOI(horlPeriode,   TOI::unspec, "", "CHAR-CODED"));  
+  possibleTOIs.insert(TOI(horlNbMesures, TOI::unspec, "", "CHAR-CODED"));  
+  possibleTOIs.insert(TOI(horlTempMort,  TOI::unspec, "", "CHAR-CODED"));  
+  possibleTOIs.insert(TOI(horlFlag,      TOI::unspec, "", "CHAR-CODED"));  
+  
+  possibleTOIs.insert(TOI(regMode,       TOI::all,    "", "CHAR-CODED"));  
+  possibleTOIs.insert(TOI(regNumBolo,    TOI::all,    "", "CHAR-CODED"));  
+  possibleTOIs.insert(TOI(regVoieChauf,  TOI::all,    "", "CHAR-CODED"));  
+  possibleTOIs.insert(TOI(regProp,       TOI::all,    "", "CHAR-CODED"));  
+  possibleTOIs.insert(TOI(regInteg,      TOI::all,    "", "CHAR-CODED"));  
+  possibleTOIs.insert(TOI(regDeriv,      TOI::all,    "", "CHAR-CODED"));  
+  possibleTOIs.insert(TOI(regChauffage,  TOI::all,    "", "CHAR-CODED"));  
+
+  possibleTOIs.insert(TOI(autoBolMode,   TOI::all,    "", "CHAR-CODED"));  
+  possibleTOIs.insert(TOI(autoBolGain,   TOI::all,    "", "CHAR-CODED"));  
+  possibleTOIs.insert(TOI(autoBolCourant,TOI::all,    "", "CHAR-CODED"));  
+  possibleTOIs.insert(TOI(autoBolDelai,  TOI::all,    "", "CHAR-CODED"));  
+
+  possibleTOIs.insert(TOI(autoDilVanne,  TOI::unspec, "", "CHAR-CODED"));  
+  possibleTOIs.insert(TOI(autoDilHelium, TOI::unspec, "", "CHAR-CODED"));  
+  possibleTOIs.insert(TOI(autoDilChauff, TOI::unspec, "", "CHAR-CODED"));  
+  possibleTOIs.insert(TOI(autoDilPiles,  TOI::unspec, "", "CHAR-CODED"));  
+  possibleTOIs.insert(TOI(autoDilTrans,  TOI::unspec, "", "CHAR-CODED"));  
+  possibleTOIs.insert(TOI(autoDilTMxVan, TOI::unspec, "", "CHAR-CODED"));  
+  possibleTOIs.insert(TOI(autoDilxx7,    TOI::unspec, "", "CHAR-CODED"));  
+  possibleTOIs.insert(TOI(autoDilxx8,    TOI::unspec, "", "CHAR-CODED"));  
+  
+  possibleTOIs.insert(TOI(boloDACV,      TOI::all,    "", "microVolts"));  
+  possibleTOIs.insert(TOI(boloDACI,      TOI::all,    "", "microAmps"));  
+}
+
+string TOILLReglageProducer::getName() {
+  return("TOILLReglageProducer 1.0");
+}
+
+
+
+#define COMPTOI(_toi_, _field_)                               \
+    if ((*i).name == _toi_) {                                 \
+      computedValue((*i),sample0, blk->reglage._field_);      \
+    }
+
+void TOILLReglageProducer::handleBlock(ArchFileSet* fs)
+{
+  block_type_reglage* blk = fs->lastReglage();
+  long sample0 = numero_block(blk)*72;
+  for (set<TOI>::iterator i = producedTOIs.begin(); i != producedTOIs.end(); i++) {
+    int k = (*i).index;
+    COMPTOI(horlPeriode,    horloge.periode) else
+    COMPTOI(horlNbMesures,  horloge.nb_mesures) else
+    COMPTOI(horlTempMort,   horloge.temp_mort) else
+    COMPTOI(horlFlag,       horloge.flag) else
+    COMPTOI(regMode,        regul[k].mode) else
+    COMPTOI(regNumBolo,     regul[k].num_bolo) else
+    COMPTOI(regVoieChauf,   regul[k].voie_chauf) else
+    COMPTOI(regProp,        regul[k].prop) else
+    COMPTOI(regInteg,       regul[k].integ) else
+    COMPTOI(regDeriv,       regul[k].deriv) else
+    COMPTOI(regChauffage,   regul[k].chauffage) else
+    COMPTOI(autoBolMode,    autom[k].mode) else
+    COMPTOI(autoBolGain,    autom[k].gain) else
+    COMPTOI(autoBolCourant, autom[k].courant) else
+    COMPTOI(autoBolDelai,   autom[k].delai) else
+    COMPTOI(autoDilVanne,   dilu.vanne) else
+    COMPTOI(autoDilHelium,  dilu.helium) else
+    COMPTOI(autoDilChauff,  dilu.chauffage) else
+    COMPTOI(autoDilPiles,   dilu.piles) else
+    COMPTOI(autoDilTrans,   dilu.transmission) else
+    COMPTOI(autoDilTMxVan,  dilu.temps_max_vanne) else
+    COMPTOI(autoDilxx7,     dilu.xx7) else
+    COMPTOI(autoDilxx8,     dilu.xx8) else
+    if ((*i).name == boloDACV) {
+      computedValue((*i), sample0, DAC_muV(&fs->lastParam()->param, &blk->reglage, k));
+    } else
+    if ((*i).name == boloDACI) {
+      computedValue((*i), sample0, DAC_muA(&fs->lastParam()->param, &blk->reglage, k));
+    }
+  }
+}
+
+
+
Index: trunk/Poubelle/archTOI.old/toillreglageproducer.h
===================================================================
--- trunk/Poubelle/archTOI.old/toillreglageproducer.h	(revision 534)
+++ trunk/Poubelle/archTOI.old/toillreglageproducer.h	(revision 534)
@@ -0,0 +1,23 @@
+// toillreglageproducer.h
+// Eric Aubourg         CEA/DAPNIA/SPP   septembre 1999
+
+#ifndef TOILLREGLAGEPRODUCER_H
+#define TOILLREGLAGEPRODUCER_H
+
+#include "toiproducer.h"
+#include "ark.h"
+
+
+class TOILLReglageProducer : public TOILowLevProducer {
+public:
+  TOILLReglageProducer();
+  void handleBlock(ArchFileSet*); // push !
+  virtual string getName();
+
+};
+
+
+
+
+
+#endif
Index: trunk/Poubelle/archTOI.old/toillsstproducer.cc
===================================================================
--- trunk/Poubelle/archTOI.old/toillsstproducer.cc	(revision 534)
+++ trunk/Poubelle/archTOI.old/toillsstproducer.cc	(revision 534)
@@ -0,0 +1,110 @@
+// toillsstproducer.cc
+// Eric Aubourg         CEA/DAPNIA/SPP   octobre 1999
+
+#include "toillsstproducer.h"
+#include "archfileset.h"
+#include "toimanager.h"
+#include "requesthandler.h"
+
+#define sstChannel    "sstChannel"
+#define sstChannelCN  "sstChannelCN"
+#define sstDiode      "sstDiode"
+#define sstDiodeCN    "sstDiodeCN"
+
+// diodpermut[i] = channel de la diode i
+int TOILLSSTProducer::diodpermut[46]=
+ { 8,24,40, 9,25,41,10,26,42,11,
+  27,43,16,32, 1,17,33, 2,18,34,
+   3,19,35,12,28,44,13,29,45,14,
+  30,46,15,31,47,20,36, 5,21,37,
+   6,22,38, 7,23,39};
+ // voies 0 et 4 non connectees, voie 1 en panne.
+
+
+TOILLSSTProducer::TOILLSSTProducer()
+{
+  possibleTOIs.insert(TOI(sstChannel,       TOI::all, "", "ADU"));  
+  possibleTOIs.insert(TOI(sstChannelCN,     TOI::all, "", "ADU"));
+  possibleTOIs.insert(TOI(sstDiode,         TOI::all, "", "ADU"));  
+  possibleTOIs.insert(TOI(sstDiodeCN,       TOI::all, "", "ADU"));
+}
+
+string TOILLSSTProducer::getName() {
+  return("TOILLSSTProducer 1.0");
+}
+
+
+void TOILLSSTProducer::registerProcessor(SSTDataProcessor* p) {
+  processors.push_back(p);
+}
+
+void TOILLSSTProducer::DecodeTMBlock(block_type_sst* blk, int i, int* diod)
+{
+  int j; // 0-5 : numero du bloc de 8 diodes
+  int k; // 0-2 : indice du bloc de 4 bits (une diode = 12 bits = 3 blocs de 4 bits)
+  int l; // 0-7 : indice de la diode dans son bloc (8 diodes * 4 bits = 1 mot de 32 bits)
+  
+  // numero de la diode (0-47) = j*8+l;
+  // indice dans le bloc sst du mot de 32 bits (0-17) = j*3+k;
+  // indice dans mot de 32 bits du premier bit utile = 4*l;
+    
+  for (j=0; j<48; j++) diod[j] = 0;
+  
+  for (j=0; j<6; j++)
+    for (k=0; k<3; k++)
+      for (l=0; l<8; l++) {
+        int4 word = blk->sst[i][j*3+k];
+        word = (word >> (4*l)) & 0xF;
+        diod[j*8+l] = (diod[j*8+l] << 4) + word;
+      }
+
+  for (j=0; j<48; j++)  diod[j] -= 2048;
+}
+
+double TOILLSSTProducer::getSSTRawSignalCN(ArchFileSet* fs, int ichannel, int imesure) {
+  // Si pas bloc comprime -> 0.5
+  if (fs->lastSSTComp() == NULL) return .5;
+  if (numero_block(fs->lastSSTComp()) != numero_block(fs->lastSST())) return 0.5;
+  
+  // Attention, on ne transmet pas les canaux 0 et 4....
+  if (ichannel == 0 || ichannel == 4) return 0;
+  int i = ichannel - 1;
+  if (i >= 4) i--;
+  unsigned int4* data = fs->lastSSTComp()->sst[i];
+  // Les deux premieres valeurs sont codees directement...
+  if (imesure<2) return 0.5;
+  int iExp = (imesure-2)/7 + 1;
+  int expo = data[iExp] & 0xf;
+  int noise = 1 << expo;
+  return noise/2.;
+}
+
+void TOILLSSTProducer::handleBlock(ArchFileSet* fs)
+{
+  block_type_sst* blk = fs->lastSST();
+  long sample0 = numero_block(blk)*72;
+  int channels[48];
+  int diodes[46];
+  for (int j=0; j<nb_per_block*2; j++) {
+    DecodeTMBlock(blk, j, channels);
+    for (int i=0; i<46; i++)
+      diodes[i] = channels[diodpermut[i]];
+    for (vector<SSTDataProcessor*>::iterator i = processors.begin(); 
+         i != processors.end(); i++) {
+      (*i)->dataFeed(sample0 + j, diodes);    
+    }
+    for (set<TOI>::iterator i = producedTOIs.begin(); i != producedTOIs.end(); i++) {
+      int ich = (*i).index;
+      if ((*i).name == sstChannel) {
+        computedValue((*i), sample0+j, channels[ich]);
+      } else if ((*i).name == sstDiode) {
+        computedValue((*i), sample0+j, diodes[ich]);
+      } else if ((*i).name == sstChannelCN) {
+        computedValue((*i), sample0+j, getSSTRawSignalCN(fs, ich, j));
+      } else if ((*i).name == sstDiodeCN) {
+        computedValue((*i), sample0+j, getSSTRawSignalCN(fs, diodpermut[ich], j));
+      }
+    }
+  }
+}
+
Index: trunk/Poubelle/archTOI.old/toillsstproducer.h
===================================================================
--- trunk/Poubelle/archTOI.old/toillsstproducer.h	(revision 534)
+++ trunk/Poubelle/archTOI.old/toillsstproducer.h	(revision 534)
@@ -0,0 +1,35 @@
+// toillsstproducer.h
+// Eric Aubourg         CEA/DAPNIA/SPP   octobre 1999
+
+#ifndef TOILLSSTPRODUCER_H
+#define TOILLSSTPRODUCER_H
+
+#include "toiproducer.h"
+#include "ark.h"
+
+class SSTDataProcessor {
+public:
+   virtual void dataFeed(long sampleNum, int* diodeSignal)=0; // signal for 46 diodes...
+};
+
+class TOILLSSTProducer : public TOILowLevProducer {
+public:
+  TOILLSSTProducer();
+  void handleBlock(ArchFileSet*); // push !
+  
+  void registerProcessor(SSTDataProcessor*);
+  virtual string getName();
+
+protected:
+  static int  diodpermut[46]; // diodpermut[i] = channel de la diode i
+  vector<SSTDataProcessor*> processors;
+  
+  void DecodeTMBlock(block_type_sst* blk, int i, int* diod);
+  double getSSTRawSignalCN(ArchFileSet* fs, int ichannel, int imesure);
+};
+
+
+
+
+
+#endif
Index: trunk/Poubelle/archTOI.old/toimanager.cc
===================================================================
--- trunk/Poubelle/archTOI.old/toimanager.cc	(revision 534)
+++ trunk/Poubelle/archTOI.old/toimanager.cc	(revision 534)
@@ -0,0 +1,102 @@
+// toimanager.cc
+// Eric Aubourg         CEA/DAPNIA/SPP   septembre 1999
+
+#include "toimanager.h"
+#include "archexc.h"
+#include "toiproducer.h"
+//#include "toiabsorber.h"
+
+
+void TOIManager::registerProducer(TOIProducer* p) {
+  producers.insert(p);
+}
+
+TOIProducer* TOIManager::findTOIProducer(TOI const& toi) {
+  TOIProducer* p = NULL;
+  for (set<TOIProducer*>::iterator i=producers.begin();
+       i != producers.end(); i++) {
+    if ((*i)->canProduce(toi)) {
+      if (p) throw ArchExc("Duplicate producers for toi" + toi.name);
+      p = *i;
+    }    
+  }
+  if (!p) return NULL; // no producer for this TOI
+//  p->addTOI(toi, client);
+  return p;
+}
+
+set<TOIProducer*> TOIManager::producers;
+map<TOILowLevProducer*, long> TOIManager::llProducers;
+map<TOILowLevProducer*, long> TOIManager::activeLLProducers;
+int TOIManager::trigMask = 0;
+
+void TOIManager::registerLLProducer(TOILowLevProducer* p, int blk_mask) {
+  registerProducer(p);
+  //trigMask |= blk_mask;
+  llProducers[p] = blk_mask;
+}
+
+void TOIManager::activateLLProducer(TOILowLevProducer* p) {
+  //registerProducer(p);
+  int blk_mask = llProducers[p];
+  trigMask |= blk_mask;
+  activeLLProducers[p] = blk_mask;
+}
+
+
+void TOIManager::dumpAvailTOIs(ostream& s) {
+ s << "*** Available TOIs\n";
+ for (set<TOIProducer*>::iterator i = producers.begin(); i != producers.end(); i++) {
+   TOIProducer* prod = *i;
+   set<TOI> x = prod->getPossibleTOIs();
+   for (set<TOI>::iterator j = x.begin(); j != x.end(); j++) {
+     TOI toi = *j;
+     cout << toi.name;
+     if (toi.index == TOI::all) cout << " * ";
+     for (set<string>::iterator k = toi.options.begin(); k != toi.options.end(); k++) {
+       cout << " ";
+       if (toi.reqOptions.find(*k) != toi.reqOptions.end()) cout << "+";
+       cout << *k;
+     }
+     cout << "\n";
+   }
+ }
+
+}
+
+
+
+#include "archeopsfile.h"
+
+#include "toillboloproducer.h"
+#include "toillreglageproducer.h"
+#include "toilldiluproducer.h"
+#include "toillgpsproducer.h"
+#include "toillgyroproducer.h"
+#include "toillsstproducer.h"
+
+#include "timetoiproducer.h"
+#include "toiboloproducer.h"
+#include "sststarfinder.h"
+#include "tsidproducer.h"
+#include "galcrosslocator.h"
+#include "starmatcher.h"
+
+void TOIManager::registerDefaultProducers() {
+  REGLLPROD(TOILLBoloProducer,    block_bolo_mask);
+  REGLLPROD(TOILLReglageProducer, block_reglage_mask);
+  REGLLPROD(TOILLDiluProducer,    block_dilution_mask);
+  REGLLPROD(TOILLGPSProducer,     block_gps_mask);
+  REGLLPROD(TOILLGyroProducer,    block_gyro_mask);
+  REGLLPROD(TOILLSSTProducer,     block_sst_mask);
+  
+  REGPROD(TimeTOIProducer);
+  REGPROD(TOIBoloProducer);
+  REGPROD(SSTStarFinder);
+  REGPROD(TSidProducer);
+  REGPROD(GalCrossLocator);
+  REGPROD(StarMatcher);
+}
+
+
+
Index: trunk/Poubelle/archTOI.old/toimanager.h
===================================================================
--- trunk/Poubelle/archTOI.old/toimanager.h	(revision 534)
+++ trunk/Poubelle/archTOI.old/toimanager.h	(revision 534)
@@ -0,0 +1,39 @@
+// toimanager.h
+// Eric Aubourg         CEA/DAPNIA/SPP   septembre 1999
+
+#ifndef TOIMANAGER_H
+#define TOIMANAGER_H
+
+#include <set>
+#include <map>
+#include <iostream.h>
+using namespace std;
+
+#include "toi.h"
+
+class TOIProducer;
+class TOILowLevProducer;
+class TOIAbsorber;
+
+class TOIManager {
+public:
+  static void registerDefaultProducers();
+  static void registerProducer(TOIProducer* p);
+  static TOIProducer* findTOIProducer(TOI const& toi); // NULL if cannot build
+  
+  static set<TOIProducer*> producers;
+  
+  static void registerLLProducer(TOILowLevProducer* p, int blk_kind);
+  static void activateLLProducer(TOILowLevProducer* p);
+  static map<TOILowLevProducer*, long> llProducers; // long : masque de bloc
+  static map<TOILowLevProducer*, long> activeLLProducers; // long : masque de bloc
+  static int trigMask;
+  
+  static void dumpAvailTOIs(ostream& s);
+};
+
+#define REGPROD(_x_) TOIManager::registerProducer(new _x_);
+#define REGLLPROD(_x_,_blk_)  TOIManager::registerLLProducer(new _x_, _blk_);
+
+
+#endif
Index: trunk/Poubelle/archTOI.old/toiproducer.cc
===================================================================
--- trunk/Poubelle/archTOI.old/toiproducer.cc	(revision 534)
+++ trunk/Poubelle/archTOI.old/toiproducer.cc	(revision 534)
@@ -0,0 +1,235 @@
+// toiproducer.cc
+// Eric Aubourg         CEA/DAPNIA/SPP   septembre 1999
+
+#include <iostream.h>
+
+#include "toiproducer.h"
+#include "toiabsorber.h"
+#include "toimanager.h"
+#include "archexc.h"
+#include "requesthandler.h"
+
+void TOIProducer::outManifest(RequestHandler* h) {
+  outVersion(h);
+  h->processOption("#COMMENT", " Producing:");
+  for (set<TOI>::iterator i = producedTOIs.begin(); i != producedTOIs.end(); i++) {
+    h->processOption("#COMMENT", "  " + (*i).fullName());
+  }
+}
+
+void TOIProducer::outVersion(RequestHandler* h) {
+  h->processOption("#COMMENT", getName());
+}
+
+string TOIProducer::getName() {
+  return("Anonymous");
+}
+
+
+bool TOIProducer::canProduce(TOI const& toi) {
+  // It should be in our list of possibleTOI's
+  TOI myTOI;
+  for (set<TOI>::const_iterator i = possibleTOIs.begin(); i != possibleTOIs.end(); i++) {
+    if ((toi.name == (*i).name) &&
+        (toi.index == (*i).index || (*i).index == TOI::all)) {
+      myTOI = (*i); 
+      break;
+    }
+  }
+  if (myTOI.name == "") return false; // not in list
+  
+  // Handle options
+  
+  set<string> extraopts = toi.options;
+
+  // should contain mandatory options
+  for (set<string>::iterator i = myTOI.reqOptions.begin(); 
+       i != myTOI.reqOptions.end(); i++) {
+    if (extraopts.find(*i) == extraopts.end()) return false;
+  }
+  
+  // remove local options
+  for (set<string>::iterator i = myTOI.options.begin();
+       i != myTOI.options.end(); i++) {
+    extraopts.erase(*i);   
+  }
+  
+  // should be nothing left
+  if (!extraopts.empty()) return false;
+  
+  return true;
+}
+
+void TOIProducer::addTOI(TOI& toi, TOIAbsorber* client) {
+  if (!canProduce(toi)) throw ArchExc("Cannot produce " + toi.name);
+  // Add unit...
+  for (set<TOI>::const_iterator i = possibleTOIs.begin(); i != possibleTOIs.end(); i++) {
+    if (toi.name == (*i).name) {
+      toi.unit = (*i).unit; 
+      break;
+    }
+  }
+  
+  clients[client].insert(toi);
+  lastNeededSample[toi.ref][client] = 0;
+  producedTOIs.insert(toi);
+}
+
+bool TOIProducer::isProducing(TOI const& toi) {
+  return (producedTOIs.find(toi) != producedTOIs.end());
+}
+
+
+long TOIProducer::wontNeedEarlier(TOI const& toi, TOIAbsorber* client, long t) {
+  CHKPROD
+  long oldT = lastNeededSample[toi.ref][client];
+  if (t<oldT) return -1;
+  lastNeededSample[toi.ref][client] = t;
+  map<TOIAbsorber*, long> m = lastNeededSample[toi.ref];
+  long min=999999999L;
+  for (map<TOIAbsorber*, long>::iterator i = m.begin(); i != m.end(); i++) {
+    if ((*i).second < min) min = (*i).second;
+  }
+  deque<pair<long, double> >& h = history[toi.ref];
+  while(!h.empty() && h.front().first < min) h.pop_front();
+  return min;
+}
+
+set<string> TOIProducer::getProperAvailOptions(TOI const& toi) {
+//  toi.options.clear();
+//  toi.index = -2;
+//  set<TOI>::const_iterator i = possibleTOIs.upper_bound(toi);
+//  if ((*i).name != toi.name) throw ArchExc("no such toi " + toi.name);
+  for (set<TOI>::const_iterator i = possibleTOIs.begin(); i != possibleTOIs.end(); i++)
+    if ((*i).name  == toi.name)
+      return (*i).options;
+  throw ArchExc("no such toi " + toi.name);
+}
+
+set<string> TOIProducer::getAvailOptions(TOI const& toi) {
+  return getProperAvailOptions(toi);
+}
+
+
+  
+long TOIProducer::firstSampleNum(TOI const& toi) {
+  CHKPROD
+//  deque<pair<long, double> > h = (*history.find(toi)).second;
+  deque<pair<long, double> >& h = history[toi.ref];
+  if (h.empty()) return 99999999;
+  return h.front().first;
+}
+
+long TOIProducer::lastSampleNum(TOI const& toi) {
+  CHKPROD
+  deque<pair<long, double> >& h = history[toi.ref];
+  if (h.empty()) return -99999999;
+  return h.back().first;
+}
+
+class comp2nd { public:bool operator()(pair<long, double> const& a, long b) {return a.first<b;}};
+
+deque<pair<long, double> >::const_iterator TOIProducer::findHist(TOI const& toi,long sampleNum) {
+  CHKPROD
+  deque<pair<long, double> >& h = history[toi.ref];
+  return lower_bound(h.begin(), h.end(), sampleNum, comp2nd());
+}
+
+deque<pair<long, double> >::const_iterator TOIProducer::findHist(deque<pair<long, double> >& h,long sampleNum) {
+  return lower_bound(h.begin(), h.end(), sampleNum, comp2nd());
+}
+
+bool TOIProducer::canGetValue(long sampleNum, TOI const& toi) {
+  CHKPROD
+  deque<pair<long, double> >& h = history[toi.ref];
+  if (h.empty()) return false;
+  if (sampleNum < h.front().first || sampleNum > h.back().first) return false;
+  deque<pair<long, double> >::const_iterator i = findHist(h, sampleNum);
+  if (i == h.end()) return false;
+  return ((*i).first == sampleNum);
+}
+
+bool TOIProducer::canGetValueLater(long sampleNum, TOI const& toi) {
+  CHKPROD
+  deque<pair<long, double> >& h = history[toi.ref];
+  if (h.empty()) return true;
+  int x = h.back().first;
+  return sampleNum > x;
+  return (sampleNum > h.back().first);
+}
+
+bool TOIProducer::canGetPrevValue(long sampleNum, TOI const& toi) {
+  CHKPROD
+  deque<pair<long, double> >& h = history[toi.ref];
+  if (h.empty()) return false;
+  return (sampleNum > h.back().first && sampleNum <= h.front().first);
+   // Must be inside, otherwise we don't know if it is prev or simply past
+}
+ 
+bool TOIProducer::canGetNextValue(long sampleNum, TOI const& toi) {
+  CHKPROD
+  deque<pair<long, double> >& h = history[toi.ref];
+  if (h.empty()) return false;
+  return (sampleNum >= h.back().first && sampleNum < h.front().first);
+}
+
+double TOIProducer::getValue(long sampleNum, TOI const& toi) {
+  deque<pair<long, double> >& h = history[toi.ref];
+//  cout << "request " << sampleNum << " history " 
+//       << h.front().first 
+//       << " " << h.back().first << endl;
+  deque<pair<long, double> >::const_iterator i = findHist(h, sampleNum);
+  if (i == h.end()) return -999999;
+//  cout << "found " << (*i).first << endl;
+  return ((*i).first == sampleNum) ? (*i).second : -999999;
+}
+
+// $CHECK$ check this carefully !!!!
+
+double TOIProducer::getPrevValue(long& sampleNum, TOI const& toi) {
+  deque<pair<long, double> >& h = history[toi.ref];
+  deque<pair<long, double> >::const_iterator i = findHist(h, sampleNum);
+  if (i == h.end()) return -999999;
+  if ((*i).first == sampleNum) {
+    if (i == history[toi.ref].begin()) {sampleNum = -99999 ;return -9999;}
+    i--;
+  }
+  sampleNum = (*i).first;
+  return (*i).second;
+}
+
+double TOIProducer::getNextValue(long& sampleNum, TOI const& toi) {
+  deque<pair<long, double> >& h = history[toi.ref];
+  deque<pair<long, double> >::const_iterator i = findHist(h, sampleNum);
+  if (i == h.end()) return -999999;
+  if ((*i).first == sampleNum) {
+    if (i == history[toi.ref].end()) {sampleNum = -99999 ;return -9999;}
+    i++;
+  }
+  sampleNum = (*i).first;
+  return (*i).second;
+}
+
+void TOIProducer::computedValue(TOI const& toi, long sampleNum, double value) {
+  map<int, deque<pair<long, double> > >::iterator i = history.find(toi.ref);
+  if (i == history.end()) throw ArchExc("computedValue : bad TOI " + toi.name);
+  deque<pair<long, double> >& h = (*i).second;
+  if (!h.empty() && sampleNum <= h.back().first)
+    throw ArchExc("computedValue : sampleNum not in sequence for " + toi.name);
+  h.push_back(pair<long,double>(sampleNum,value));
+  
+  for (map<TOIAbsorber*, set<TOI> >::iterator j = clients.begin(); j != clients.end(); j++) {
+    set<TOI>& tois = (*j).second;
+    if (tois.find(toi) != tois.end()) 
+      (*j).first->dataFeed(this, toi, sampleNum, value);
+  } 
+}
+
+
+
+
+
+void TOILowLevProducer::addTOI(TOI& toi, TOIAbsorber* client) {
+  TOIProducer::addTOI(toi, client);
+  TOIManager::activateLLProducer(this);
+}
Index: trunk/Poubelle/archTOI.old/toiproducer.h
===================================================================
--- trunk/Poubelle/archTOI.old/toiproducer.h	(revision 534)
+++ trunk/Poubelle/archTOI.old/toiproducer.h	(revision 534)
@@ -0,0 +1,77 @@
+// toiproducer.h
+// Eric Aubourg         CEA/DAPNIA/SPP   septembre 1999
+
+#ifndef TOIPRODUCER_H
+#define TOIPRODUCER_H
+
+#include <set>
+#include <map>
+#include <deque>
+
+using namespace std;
+
+#include "toi.h"
+#include "ark.h"
+
+class TOIAbsorber;
+class RequestHandler;
+
+class TOIProducer {
+public:
+  TOIProducer() {}
+  virtual ~TOIProducer() {}
+  
+  virtual bool   canProduce(TOI const&);
+  virtual bool   isProducing(TOI const&);
+  virtual void   addTOI(TOI &, TOIAbsorber* client);     // exception si pas productible
+  virtual bool   canGetValue(long sampleNum, TOI const& toi); // for this samplenum
+  virtual bool   canGetPrevValue(long sampleNum, TOI const& toi); 
+  virtual bool   canGetNextValue(long sampleNum, TOI const& toi); 
+  virtual bool   canGetValueLater(long sampleNum, TOI const& toi);  // Might, later but not now
+  
+  virtual double getPrevValue(long& sampleNum, TOI const& toi);
+  virtual double getNextValue(long& sampleNum, TOI const& toi);
+  virtual double getValue(long sampleNum, TOI const& toi);
+  
+  virtual long   firstSampleNum(TOI const&);
+  virtual long   lastSampleNum(TOI const&);
+  
+  virtual long   wontNeedEarlier(TOI const&, TOIAbsorber* client, long);
+  
+  virtual set<string> getAvailOptions(TOI const&);
+  virtual set<string> getProperAvailOptions(TOI const&);
+  
+  virtual void outManifest(RequestHandler*);
+  virtual void outVersion(RequestHandler*);
+  virtual string getName();
+  
+  set<TOI> getPossibleTOIs() {return possibleTOIs;}
+  
+  
+protected:
+  virtual void   computedValue(TOI const& toi, long sampleNum, double value);
+
+  set<TOI>                               possibleTOIs;
+  set<TOI>                               producedTOIs;
+  map<TOIAbsorber*, set<TOI> >           clients;
+  //map<TOI, map<TOIAbsorber*, long> >     lastNeededSample; 
+  //map<TOI, deque<pair<long, double> > >  history;
+  map<int, map<TOIAbsorber*, long> >     lastNeededSample; 
+  map<int, deque<pair<long, double> > >  history;
+  
+  deque<pair<long, double> >::const_iterator findHist(TOI const& toi, long sampleNum);
+  deque<pair<long, double> >::const_iterator findHist(deque<pair<long, double> >& h, long sampleNum);
+};
+
+class ArchFileSet;
+class TOILowLevProducer : public TOIProducer {
+public:
+  virtual void handleBlock(ArchFileSet*)=0; // push !
+  virtual void   addTOI(TOI &, TOIAbsorber* client);     // exception si pas productible
+};
+
+//#define CHKPROD if (!isProducing(toi)) throw ArchExc("Not producing " + toi.name);
+#define CHKPROD toi;
+
+
+#endif
Index: trunk/Poubelle/archTOI.old/toipullproducer.cc
===================================================================
--- trunk/Poubelle/archTOI.old/toipullproducer.cc	(revision 534)
+++ trunk/Poubelle/archTOI.old/toipullproducer.cc	(revision 534)
@@ -0,0 +1,72 @@
+// toipullproducer.cc
+// Eric Aubourg         CEA/DAPNIA/SPP   octobre 1999
+
+
+#include "toipullproducer.h"
+
+TOIPullProducer::TOIPullProducer() {
+  needBefore = needAfter = 0;
+}
+
+bool TOIPullProducer::canGetValue(long sampleNum, TOI const& toi) {
+  map<TOI, TOIProducer*> m = neededTOIs[toi];
+  for (map<TOI, TOIProducer*>::iterator i = m.begin(); i != m.end(); i++) {
+    if (!(*i).second->canGetValue(sampleNum-needBefore, (*i).first) ||
+        !(*i).second->canGetValue(sampleNum+needAfter, (*i).first)) return false;
+  }
+  return true;
+}
+
+bool TOIPullProducer::canGetPrevValue(long sampleNum, TOI const& toi) {
+  return canGetValue(sampleNum-1, toi);
+}
+ 
+bool TOIPullProducer::canGetNextValue(long sampleNum, TOI const& toi) {
+  return canGetValue(sampleNum+1, toi);
+}
+
+bool TOIPullProducer::canGetValueLater(long sampleNum, TOI const& toi) {
+  map<TOI, TOIProducer*> m = neededTOIs[toi];
+  for (map<TOI, TOIProducer*>::iterator i = m.begin(); i != m.end(); i++) {
+    if (!(*i).second->canGetValueLater(sampleNum+needAfter, (*i).first)) return false;
+  }
+  return true;
+}
+
+
+double TOIPullProducer::getPrevValue(long& sampleNum, TOI const& toi) {
+  return getValue(--sampleNum, toi);
+}
+
+double TOIPullProducer::getNextValue(long& sampleNum, TOI const& toi) {
+  return getValue(++sampleNum, toi);
+}
+
+
+long TOIPullProducer::firstSampleNum(TOI const& toi) {
+  long xx = -999999999L;
+  map<TOI, TOIProducer*> m = neededTOIs[toi];
+  for (map<TOI, TOIProducer*>::iterator i = m.begin(); i != m.end(); i++) {
+    long x = (*i).second->firstSampleNum((*i).first) + needBefore;
+    if (x > xx) xx=x;
+  }
+  return xx;
+}
+
+long TOIPullProducer::lastSampleNum(TOI const& toi) {
+  long xx = 999999999L;
+  map<TOI, TOIProducer*> m = neededTOIs[toi];
+  for (map<TOI, TOIProducer*>::iterator i = m.begin(); i != m.end(); i++) {
+    long x = (*i).second->lastSampleNum((*i).first) - needAfter;
+    if (x < xx) xx=x;
+  }
+  return xx;
+}
+
+void TOIPullProducer::propagateLowBound(TOI const& toi, long sampleNum) {
+  CHKPROD
+  map<TOI, TOIProducer*> need = neededTOIs[toi];
+  for (map<TOI, TOIProducer*>::iterator i = need.begin(); i != need.end(); i++) {
+    (*i).second->wontNeedEarlier((*i).first, this, sampleNum-needBefore);
+  }
+}
Index: trunk/Poubelle/archTOI.old/toipullproducer.h
===================================================================
--- trunk/Poubelle/archTOI.old/toipullproducer.h	(revision 534)
+++ trunk/Poubelle/archTOI.old/toipullproducer.h	(revision 534)
@@ -0,0 +1,33 @@
+// toipullproducer.h
+// Eric Aubourg         CEA/DAPNIA/SPP   octobre 1999
+
+#ifndef TOIPULLPRODUCER_H
+#define TOIPULLPRODUCER_H
+
+#include "toiderivproducer.h"
+
+class TOIPullProducer : public TOIDerivProducer {
+public:
+  TOIPullProducer();
+  virtual bool   canGetValue(long sampleNum, TOI const& toi); // for this samplenum
+  virtual bool   canGetPrevValue(long sampleNum, TOI const& toi); 
+  virtual bool   canGetNextValue(long sampleNum, TOI const& toi); 
+  virtual bool   canGetValueLater(long sampleNum, TOI const& toi);  // Might, later but not now
+
+  virtual double getPrevValue(long& sampleNum, TOI const& toi);
+  virtual double getNextValue(long& sampleNum, TOI const& toi);
+  virtual double getValue(long sampleNum, TOI const& toi) = 0;
+
+  virtual long   firstSampleNum(TOI const&);
+  virtual long   lastSampleNum(TOI const&);
+
+protected:
+  long needBefore;
+  long needAfter;
+
+  virtual void         propagateLowBound(TOI const&, long sampleNum);
+};
+
+
+
+#endif
Index: trunk/Poubelle/archTOI.old/toisvr.cc
===================================================================
--- trunk/Poubelle/archTOI.old/toisvr.cc	(revision 533)
+++ trunk/Poubelle/archTOI.old/toisvr.cc	(revision 534)
@@ -162,38 +162,4 @@
     else tsttoi(alphaBolo)
     else tsttoi(deltaBolo)
-    else tsttoi(voyantEVO)
-    else tsttoi(voyantEVF)
-    else tsttoi(commandeEV0)
-    else tsttoi(commandeEVF)
-    else tsttoi(commandeEVB)
-    else tsttoi(commandeEVV)
-    else tsttoi(pressEnt3He)
-    else tsttoi(debit3He)
-    else tsttoi(pressSor3He)
-    else tsttoi(pressEnt4He)
-    else tsttoi(debit4He)
-    else tsttoi(pressSor4He)
-    else tsttoi(pressAirVanne)
-    else tsttoi(pressPompChar)
-    else tsttoi(pressMembrane)
-    else tsttoi(pressExterne)
-    else tsttoi(tensPile10T)
-    else tsttoi(tensPileP18D)
-    else tsttoi(tensPileM18D)
-    else tsttoi(tensPile10B)
-    else tsttoi(tensPileP18B)
-    else tsttoi(tensPileM18B)
-    else tsttoi(tensPileCh)
-    else tsttoi(swPile5)
-    else tsttoi(swPile15)
-    else tsttoi(tempCaissH1)
-    else tsttoi(tempCaissH2)
-    else tsttoi(tempCaissB1)
-    else tsttoi(tempCaissB2)
-    else tsttoi(tempCaissTHe)
-    else tsttoi(tempCaissPiles)
-    else tsttoi(tempCaissDrv)
-    else tsttoi(pressHeBain)
-    else tsttoi(pressPirani)
     else {
       // cerr << "*Warning, unrecognized TOI " << line << endl;
Index: trunk/Poubelle/archTOI.old/tokenizer.cc
===================================================================
--- trunk/Poubelle/archTOI.old/tokenizer.cc	(revision 534)
+++ trunk/Poubelle/archTOI.old/tokenizer.cc	(revision 534)
@@ -0,0 +1,35 @@
+// tokenizer.cc
+// Eric Aubourg         CEA/DAPNIA/SPP   septembre 1999
+
+#include "tokenizer.h"
+
+
+Tokenizer::Tokenizer(string str) 
+: s(str)
+{
+  while (str != "") {
+    size_t x = str.find_first_not_of(' ');
+    if (x != string::npos) 
+      str = str.substr(x);
+    if (str == "") break;
+    x = str.find(' ');
+    if (x != string::npos) {
+      string token = str.substr(0, x);
+      str = str.substr(x+1);
+      tokens.push_back(token);
+    } else {
+      tokens.push_back(str);
+      break;
+    }
+  }
+}
+
+set<string> Tokenizer::getTokenSet() {
+  return set<string>(tokens.begin(), tokens.end());
+}
+
+vector<string> Tokenizer::getTokenVector() {
+  return tokens;
+}
+
+
Index: trunk/Poubelle/archTOI.old/tokenizer.h
===================================================================
--- trunk/Poubelle/archTOI.old/tokenizer.h	(revision 534)
+++ trunk/Poubelle/archTOI.old/tokenizer.h	(revision 534)
@@ -0,0 +1,26 @@
+// tokenizer.h
+// Eric Aubourg         CEA/DAPNIA/SPP   septembre 1999
+
+#ifndef TOKENIZER_H
+#define TOKENIZER_H
+
+#include <string>
+#include <set>
+#include <vector>
+
+using namespace std;
+
+class Tokenizer {
+public:
+  Tokenizer(string str);
+  
+  set<string> getTokenSet();
+  vector<string> getTokenVector();
+
+protected:
+  string s;
+  vector<string> tokens;
+};
+
+#endif
+
Index: trunk/Poubelle/archTOI.old/transfelec.cc
===================================================================
--- trunk/Poubelle/archTOI.old/transfelec.cc	(revision 533)
+++ trunk/Poubelle/archTOI.old/transfelec.cc	(revision 534)
@@ -1,4 +1,5 @@
 #include "transfelec.h"
 
+// D. Yvon, CE Saclay, DAPNIA/SPP, 08/99
 
 // Parametres du circuit electrique de lecture SST
Index: trunk/Poubelle/archTOI.old/transfelec.h
===================================================================
--- trunk/Poubelle/archTOI.old/transfelec.h	(revision 533)
+++ trunk/Poubelle/archTOI.old/transfelec.h	(revision 534)
@@ -3,4 +3,7 @@
 
 //#include <math.h>
+
+// D. Yvon, CE Saclay, DAPNIA/SPP, 08/99
+
 
 #ifdef __MWERKS__
Index: trunk/Poubelle/archTOI.old/tsidproducer.cc
===================================================================
--- trunk/Poubelle/archTOI.old/tsidproducer.cc	(revision 534)
+++ trunk/Poubelle/archTOI.old/tsidproducer.cc	(revision 534)
@@ -0,0 +1,47 @@
+// tsidproducer.cc
+// Eric Aubourg         CEA/DAPNIA/SPP   octobre 1999
+
+#include "tsidproducer.h"
+#include "archexc.h"
+#include "requesthandler.h"
+#include "tsid.h"
+#include "archparam.h"
+
+#define tsid "tsid"
+
+static TSid myTS;
+
+TSidProducer::TSidProducer() {
+  possibleTOIs.insert(TOI(tsid, TOI::unspec, "", "seconds"));  
+}
+
+string TSidProducer::getName() {
+  return("TSidProducer 1.0");
+}
+
+
+double TSidProducer::getValue(long sampleNum, TOI const& toi) {
+  map<TOI, TOIProducer*> m = neededTOIs[toi];
+  // Seulement longitude... 
+  TOI longTOI = (*m.begin()).first;
+  TOIProducer* longProd =  (*m.begin()).second;
+  myTS.setLongitude(longProd->getValue(sampleNum, longTOI));
+  return myTS.getLST(archParam.acq.SN2MJD(sampleNum));
+  
+}
+
+
+set<TOI> TSidProducer::reqTOIFor(TOI const& toi) {
+  set<TOI> t; 
+  if (toi.name == tsid) {
+    t.insert(TOI("longitude", TOI::unspec, "interp"));
+  } else {
+    throw ArchExc("Cannot produce "+toi.name);
+  }
+  return t;
+}
+
+
+
+
+
Index: trunk/Poubelle/archTOI.old/tsidproducer.h
===================================================================
--- trunk/Poubelle/archTOI.old/tsidproducer.h	(revision 534)
+++ trunk/Poubelle/archTOI.old/tsidproducer.h	(revision 534)
@@ -0,0 +1,20 @@
+// tsidproducer.h
+// Eric Aubourg         CEA/DAPNIA/SPP   octobre 1999
+
+#ifndef TSIDPRODUCER_H
+#define TSIDPRODUCER_H
+
+#include "toipullproducer.h"
+
+class TSidProducer : public TOIPullProducer {
+public:
+  TSidProducer();
+  virtual string getName();
+  virtual double getValue(long sampleNum, TOI const& toi);
+
+protected:
+  virtual set<TOI>     reqTOIFor(TOI const&);
+};
+
+
+#endif
