Index: trunk/ArchTOIPipe/Kernel/fitstoirdr.cc
===================================================================
--- trunk/ArchTOIPipe/Kernel/fitstoirdr.cc	(revision 1410)
+++ trunk/ArchTOIPipe/Kernel/fitstoirdr.cc	(revision 1437)
@@ -103,4 +103,5 @@
     //    if (sn < mgr->getRequestedBegin()+10) cout << "rdr out " << sn << endl;
     for (int j=1; j<=ncols; j++) {
+      if ( !checkOutputTOIIndex(j-1) )  continue;  // Reza - Si TOI non connecte
       fits_lock();
       fits_read_col_dbl(fptr,j+1,i+1,1,1,0,&y,&anyNul,&fstatus);
Index: trunk/ArchTOIPipe/Kernel/fitstoiwtr.cc
===================================================================
--- trunk/ArchTOIPipe/Kernel/fitstoiwtr.cc	(revision 1410)
+++ trunk/ArchTOIPipe/Kernel/fitstoiwtr.cc	(revision 1437)
@@ -92,9 +92,11 @@
       fits_unlock();
       for (int i=0; i<ndata; i++) {
-	double x = getData(i, sn);
+	double x = -9.e19;  // $CHECK$ - Reza valeur par defaut !
+	if (checkInputTOIIndex(i)) x = getData(i, sn);
 	fits_lock();
 	if (outFlags) {
 	  fits_write_col_dbl(fptr, 2*i+2, fitsLine, 1, 1, &x, &fstatus);
-	  x = getFlag(i, sn);
+	  if (checkInputTOIIndex(i))   x = getFlag(i, sn);
+	  else x = -9.e19;  // $CHECK$ - Reza valeur par defaut !
 	  fits_write_col_dbl(fptr, 2*i+3, fitsLine, 1, 1, &x, &fstatus);
 	} else {
Index: trunk/ArchTOIPipe/Kernel/toi.cc
===================================================================
--- trunk/ArchTOIPipe/Kernel/toi.cc	(revision 1410)
+++ trunk/ArchTOIPipe/Kernel/toi.cc	(revision 1437)
@@ -25,4 +25,10 @@
 void TOI::TOIInit() {
   pthread_mutex_init(&mutex, NULL);
+  //   ----- Rajouts Reza 12/3/2001
+  pthread_cond_init(&condv, NULL);
+  fgwaitput = fgwaitget = false;
+  fgsigput = fgsigget = false;
+  countwaitput = countwaitget = 0;
+  //  Fin rajouts Reza 12/3/2001 ------
 //  pthread_mutex_setname_np(&mutex, (name + "_toi_mutex").c_str(), 0);
   defaultValue = 0;
@@ -35,4 +41,18 @@
 }
 
+void TOI::PrintStatus(ostream & os) const
+{
+  os << "TOI::PrintStatus() - Name=" << getName() << endl;
+  os << " WaitStatus: Put/" ;
+  if (isPutWaiting()) os << "Waiting " ;
+  else os << "Running ";
+  os << " PutCountWait= " << getCountWaitPut() << endl;
+  os << " WaitStatus: Get/" ;
+  if (isGetWaiting()) os << "Waiting " ;
+  else os << "Running ";
+  os << " GetCountWait= " << getCountWaitGet() << endl;
+}
+
+
 void TOI::setProducer(TOIProcessor* p) {
   if (producer) 
@@ -76,4 +96,5 @@
   Array a = doGetData(iStart, iEnd);
   unlock();
+  if (fgsigput) { fgsigput = false; broadcast(); }
   return a;
 }
@@ -84,4 +105,5 @@
   double dat = doGetData(i);
   unlock();
+  if (fgsigput) { fgsigput = false; broadcast(); }
   return dat;
 }
@@ -93,4 +115,5 @@
   TArray<int_4> a = doGetFlag(iStart, iEnd);
   unlock();
+  if (fgsigput) { fgsigput = false; broadcast(); }
   return a;
 }
@@ -101,4 +124,5 @@
   int_4 f = doGetFlag(i);
   unlock();
+  if (fgsigput) { fgsigput = false; broadcast(); }
   return f;
 }
@@ -110,4 +134,5 @@
   doPutData(i, value, flag);
   unlock();
+  if (fgsigget) { fgsigget = false; broadcast(); }
 }
 
Index: trunk/ArchTOIPipe/Kernel/toi.h
===================================================================
--- trunk/ArchTOIPipe/Kernel/toi.h	(revision 1410)
+++ trunk/ArchTOIPipe/Kernel/toi.h	(revision 1437)
@@ -26,4 +26,8 @@
   TOI(string name);
   virtual ~TOI();
+
+  //   ----- Rajouts Reza 12/3/2001
+  virtual void PrintStatus(ostream & os) const;
+  //  Fin rajouts Reza 12/3/2001 ------
 
 #ifdef WITH_SOPHYA
@@ -55,9 +59,19 @@
 
   void setName(string n) {name =n;}
-  string getName() {return name;}
+  string getName() const {return name;}
 
 protected:
   TOI*                  errorTOI;
   pthread_mutex_t       mutex;
+  //   ----- Rajouts Reza 12/3/2001
+  pthread_cond_t        condv;
+  bool                  fgwaitput;
+  bool                  fgwaitget;
+  bool                  fgsigput;
+  bool                  fgsigget;
+  int                   countwaitput;
+  int                   countwaitget;
+  //  Fin rajouts Reza 12/3/2001 ------
+
   TOIProcessor*         producer;
   vector<TOIProcessor*> consumers;
@@ -86,8 +100,33 @@
   void  TOIInit();
 
+  // Il faut faire attention avec mutex et condv, si TOI cree sur le stack !
+  // Il faut donc faire new TOI  -    Reza 11/3/2001
   void lock() {pthread_mutex_lock(&mutex);}
   void unlock() {pthread_mutex_unlock(&mutex);}
 
+  //   ----- Rajouts Reza 12/3/2001
+  void wait() {pthread_cond_wait(&condv, &mutex);}
+  void signal() {pthread_cond_signal(&condv);}
+  void broadcast() {pthread_cond_broadcast(&condv);}
+  inline void waitPut() 
+    {fgwaitput=true; countwaitput++; pthread_cond_wait(&condv, &mutex);}
+  inline void waitGet() 
+    {fgwaitget=true; countwaitget++; pthread_cond_wait(&condv, &mutex);}
+  inline bool isPutWaiting() const { return fgwaitput; }
+  inline bool isGetWaiting() const { return fgwaitget; }
+  inline void signalPut() {fgsigput=true;}
+  inline void signalGet() {fgsigget=true;}
+  inline void cleanWaitPut() { fgsigput = fgwaitput = false; }
+  inline void cleanWaitGet() { fgsigget = fgwaitget = false; }
+
+public:
+  inline int  getCountWaitPut() const { return countwaitput; }
+  inline int  getCountWaitGet() const { return countwaitget; }
+  //  Fin rajouts Reza 12/3/2001 ------
+
 };
+
+inline ostream & operator << (ostream & os, TOI const & toi)
+{ toi.PrintStatus(os); return os; }
 
 class TOIRegular : public TOI {
@@ -101,5 +140,5 @@
   TOIRegularWindow();
   TOIRegularWindow(string nm);
-  ~TOIRegularWindow();
+  virtual ~TOIRegularWindow();
 
   virtual DataStatus isDataAvailNL(int iStart, int iEnd);
@@ -112,5 +151,5 @@
   long          i0;
   double defaultValue;
-  
+ 
 #ifdef WITH_SOPHYA
   virtual Array         doGetData(int iStart, int iEnd);
Index: trunk/ArchTOIPipe/Kernel/toiprocessor.cc
===================================================================
--- trunk/ArchTOIPipe/Kernel/toiprocessor.cc	(revision 1410)
+++ trunk/ArchTOIPipe/Kernel/toiprocessor.cc	(revision 1437)
@@ -44,6 +44,11 @@
 
 void TOIProcessor::afterinit() {
+  int i;
   inTOIs = new (TOI*[inIx.size()]);
+  for(i=0; i<inIx.size(); i++) 
+    inTOIs[i] = NULL;
   outTOIs = new (TOI*[outIx.size()]);
+  for(i=0; i<outIx.size(); i++) 
+    outTOIs[i] = NULL;
 }
 
@@ -123,4 +128,62 @@
 }
 
+//  Methodes rajoutees par Reza 11/3/2001
+TOI* TOIProcessor::getInputTOI(int toiIndex) {
+  //  chkinit();
+  if (toiIndex >= inIx.size()) 
+    throw RangeCheckError("TOIProcessor::getInputTOI() out of bound toiIndex");
+  TOI* toi = inTOIs[toiIndex];
+  if (toi == NULL) 
+    throw NullPtrError("TOIProcessor::getInputTOI() - Not assigned TOI !");
+  return(toi);
+}
+
+TOI* TOIProcessor::getOutputTOI(int toiIndex) {
+  //  chkinit();
+  if (toiIndex >= outIx.size()) 
+    throw RangeCheckError("TOIProcessor::getOutputTOI() out of bound toiIndex");
+  TOI* toi = outTOIs[toiIndex];
+  if (toi == NULL) 
+    throw NullPtrError("TOIProcessor::getOutputTOI() - Not assigned TOI !");
+  return(toi);
+}
+
+bool TOIProcessor::checkInputTOIIndex(int toiIndex) {
+  if (toiIndex >= inIx.size()) return false;
+  if (inTOIs[toiIndex] == NULL) return false;
+  return true;
+}
+
+bool TOIProcessor::checkOutputTOIIndex(int toiIndex) {
+  if (toiIndex >= outIx.size()) return false;
+  if (outTOIs[toiIndex] == NULL) return false;
+  return true;
+}
+
+void TOIProcessor::PrintStatus(ostream & os) 
+{
+  os << " TOIProcessor::PrintStatus() - Name= " << name 
+     << " MinIn=" << getMinIn() << " MaxIn=" << getMaxIn() << endl;
+  os << " --- Inputs N= " << inIx.size() << endl;
+  int k;
+  for(k=0; k<inIx.size(); k++) {
+    os << "Input[" << k << "] : " <<  getInName(k) ;
+    if (inTOIs[k] != NULL) 
+      os << " Connected TOI " << inTOIs[k]->getName() << endl;
+    else os << " NO TOI " << endl;
+  }
+  os << " --- Outputs N= " << outIx.size() << endl;
+  for(k=0; k<outIx.size(); k++) {
+    os << "Output[" << k << "] : " <<  getOutName(k) ;
+    if (outTOIs[k] != NULL) 
+      os << " Connected TOI " << outTOIs[k]->getName() << endl;
+    else os << " NO TOI " << endl;
+  }
+  os << endl;
+  return;
+}
+
+//  Fin rajout Reza 11/3/2001 
+
 void TOIProcessor::addInput(string name, TOI* toi) {
   chkinit();
@@ -143,7 +206,9 @@
   if (i > outIx.size()) throw RangeCheckError("TOIProcessor::getOutName "
 					     " out of bound");
-  map<string, int>::iterator j = outIx.begin();
-  while (i) {i--; j++;};
-  return (*j).first;
+  map<string, int>::iterator j;
+  for(j=outIx.begin(); j!= outIx.end(); j++) 
+    if ((*j).second == i)  return (*j).first;
+
+  throw RangeCheckError("TOIProcessor::getOutName  Not found index !");
 }
 
@@ -151,7 +216,9 @@
   if (i > inIx.size()) throw RangeCheckError("TOIProcessor::getInName "
 					     " out of bound");
-  map<string, int>::iterator j = inIx.begin();
-  while (i) {i--; j++;};
-  return (*j).first;
+  map<string, int>::iterator j;
+  for(j=inIx.begin(); j!= inIx.end(); j++) 
+    if ((*j).second == i)  return (*j).first;
+
+  throw RangeCheckError("TOIProcessor::getOutName  Not found index !");
 }
 
@@ -189,5 +256,5 @@
 #ifndef NO_SOPHYA
 Array TOIProcessor::getData(int toiIndex, int iStart, int iEnd) {
-  TOI* toi = inTOIs[toiIndex];
+  TOI* toi = getInputTOI(toiIndex);
   toi->waitForData(iStart, iEnd);
   return toi->getData(iStart, iEnd);
@@ -195,5 +262,5 @@
 
 Array TOIProcessor::getError(int toiIndex, int iStart, int iEnd) {
-  TOI* toi = inTOIs[toiIndex];
+  TOI* toi = getInputTOI(toiIndex);
   toi->waitForData(iStart, iEnd);
   return toi->getError(iStart, iEnd);
@@ -201,5 +268,5 @@
 
 TArray<int_4> TOIProcessor::getFlag(int toiIndex, int iStart, int iEnd) {
-  TOI* toi = inTOIs[toiIndex];
+  TOI* toi = getInputTOI(toiIndex);
   toi->waitForData(iStart, iEnd);
   return toi->getFlag(iStart, iEnd);
@@ -208,5 +275,5 @@
 
 double TOIProcessor::getData(int toiIndex, int i) {
-  TOI* toi = inTOIs[toiIndex];
+  TOI* toi = getInputTOI(toiIndex);
   toi->waitForData(i);
   return toi->getData(i);
@@ -214,5 +281,5 @@
 
 double TOIProcessor::getError(int toiIndex, int i) {
-  TOI* toi = inTOIs[toiIndex];
+  TOI* toi = getInputTOI(toiIndex);
   toi->waitForData(i);
   return toi->getError(i);
@@ -220,5 +287,5 @@
 
 int_4 TOIProcessor::getFlag(int toiIndex, int i) {
-  TOI* toi = inTOIs[toiIndex];
+  TOI* toi = getInputTOI(toiIndex);
   toi->waitForData(i);
   return toi->getFlag(i);
@@ -257,5 +324,5 @@
 
 void TOIProcessor::putData(int toiIndex, int i, double value, int_4 flg) {
-  TOI* toi = outTOIs[toiIndex];
+  TOI* toi = getOutputTOI(toiIndex);
   toi->putData(i, value, flg);
   autoWontNeed(i);
@@ -266,5 +333,7 @@
 void TOIProcessor::putDataError(int toiIndex, int i, double value, 
 				double error, int_4 flg) { 
-  TOI* toi = outTOIs[toiIndex];
+  TOI* toi = getOutputTOI(toiIndex);
+  if (toi == NULL) 
+    throw NullPtrError("TOIProcessor::putDataError() - Not assigned TOI !");
   toi->putDataError(i, value, error, flg);
   autoWontNeed(i);
Index: trunk/ArchTOIPipe/Kernel/toiprocessor.h
===================================================================
--- trunk/ArchTOIPipe/Kernel/toiprocessor.h	(revision 1410)
+++ trunk/ArchTOIPipe/Kernel/toiprocessor.h	(revision 1437)
@@ -83,4 +83,13 @@
   int           getInputTOIIndex(string toi);
   int           getOutputTOIIndex(string toi);
+
+  //  Methodes rajoutees par Reza 11/3/2001
+  TOI*          getInputTOI(int toiIndex);
+  TOI*          getOutputTOI(int toiIndex);
+  bool          checkInputTOIIndex(int toiIndex);
+  bool          checkOutputTOIIndex(int toiIndex);
+
+  //  Fin rajout Reza 11/3/2001 
+
   void          autoWontNeed(int iCur);
   int           lastAWN;
@@ -96,4 +105,8 @@
   string getOutName(int i);
   string getInName(int i);
+
+  //  Methodes rajoutees par Reza 11/3/2001
+  void          PrintStatus(ostream & os) ; // const plus tard
+  //  Fin rajout Reza 11/3/2001 
 
   virtual void  start();
@@ -136,3 +149,8 @@
 };
 
+inline ostream & operator << (ostream & os, TOIProcessor /*const*/ & toip)
+{ toip.PrintStatus(os); return os; }
+
+
 #endif
+
Index: trunk/ArchTOIPipe/Kernel/toiseqbuff.cc
===================================================================
--- trunk/ArchTOIPipe/Kernel/toiseqbuff.cc	(revision 1437)
+++ trunk/ArchTOIPipe/Kernel/toiseqbuff.cc	(revision 1437)
@@ -0,0 +1,209 @@
+#include "toiprocessor.h"
+#include "toiseqbuff.h"
+#include <pthread.h>
+
+#ifdef WITH_SOPHYA
+#include "pexceptions.h"
+#else
+#include "apexceptions.h"
+#endif
+
+
+TOISeqBuffered::TOISeqBuffered(int wsz) {
+  AllocBuffer(wsz);
+}
+
+TOISeqBuffered::TOISeqBuffered(string nm, int wsz) {
+  AllocBuffer(wsz);
+  setName(nm);
+}
+
+TOISeqBuffered::~TOISeqBuffered() {
+  delete[] data;
+  delete[] flags;
+}
+
+void TOISeqBuffered::AllocBuffer(int wsz) 
+{
+  if (wsz < 128) wsz = 128;
+  wsize = wsz;
+  buffsize = 2*wsz;
+  data = new double[buffsize];
+  flags = new int_4[buffsize];
+  for(int k=0; k<buffsize; k++) {
+    data[k] = defaultValue;
+    flags[k] = 0;
+  }
+  next_in = next_out = -1;
+  first_in = first_out = -1;
+  started = false;
+  dbglev = 0;
+}
+
+void TOISeqBuffered::PrintStatus(ostream & os) const
+{
+  os << "---TOISeqBuffered::PrintStatus() - Name=" << getName() << endl;
+  os << "Index: FirstIn= " << getFirstIn() << " LastIn= " << getLastIn()
+     << "  Total= " << getLastIn()-getFirstIn()+1 << endl;
+  os << "Index: FirstOut= " << getFirstOut() << " LastOut= " << getLastOut()
+     << "  Total= " << getLastOut()-getFirstOut()+1 << endl;
+  os << " WaitStatus: Put/" ;
+  if (isPutWaiting()) os << "Waiting " ;
+  else os << "Running ";
+  os << " PutCountWait= " << getCountWaitPut() << endl;
+  os << " WaitStatus: Get/" ;
+  if (isGetWaiting()) os << "Waiting " ;
+  else os << "Running ";
+  os << " GetCountWait= " << getCountWaitGet() << endl;
+}
+
+TOI::DataStatus TOISeqBuffered::isDataAvailNL(int iStart, int iEnd) {
+  if (iEnd < iStart) 
+    throw RangeCheckError("TOISeqBuffered::isDataAvailNL : iEnd<iStart !");
+  if (!started) return DATA_NOT_YET;
+  if (iEnd >= next_in) return DATA_NOT_YET;
+  if (iStart < (next_in-buffsize)) return DATA_DELETED;
+  return DATA_OK;
+}
+
+TOI::DataStatus TOISeqBuffered::isDataAvailNL(int i) {
+  return TOI::isDataAvailNL(i);
+}
+
+void TOISeqBuffered::doWontNeedBefore(int i) {
+  next_out = i;
+}
+
+
+#ifndef NO_SOPHYA
+Array TOISeqBuffered::doGetData(int iStart, int iEnd) {
+  //  if (iEnd < iStart) 
+  //    throw RangeCheckError("TOI::getData : iEnd<iStart !");
+  //  if (iStart <= out_last)
+  if (!started)   waitGet(); 
+  if (!isDataAvailNL(iStart, iEnd)) 
+    throw RangeCheckError("TOISeqBuffered::getData(iS,iE) : data not available");
+  cleanWaitGet();
+  Vector dat(iEnd - iStart + 1);
+  for (int i=0; i<iEnd-iStart+1; i++) {
+    dat(i) = dataRef(i+iStart);
+  }
+  if (first_out < 0)  first_out = iStart;
+  if ((iEnd+1) > next_out)  next_out = iEnd+1;
+  if (isPutWaiting() && (next_in-next_out < wsize/2 )) signalPut();
+  return dat;
+}
+#endif
+
+double TOISeqBuffered::doGetData(int i) {
+  if (!started) { 
+    cout << " TOISeqBuffered::doGetData() - waitGet() Waiting for start ... " << endl;
+    waitGet(); 
+  }
+  cleanWaitGet();
+  if (isDataDeleted(i))
+    throw RangeCheckError("TOISeqBuffered::doGetData(i) : data deleted");
+  while (i >= next_in) { 
+    if (i>next_out) next_out = i; 
+    if (dbglev > 0) 
+      cout << " TOISeqBuffered::doGetData() - waitGet() name=" << getName()  
+	   << " i=" << i << " next_in= " << next_in 
+	   << " next_out=" << next_out << endl;
+    waitGet(); 
+    if (dbglev > 0) 
+      cout << " ... Out of waitGet() i=" << i
+	   << " next_in= " << next_in << " next_out=" << next_out << endl;
+  }
+  cleanWaitGet();
+  double dat = dataRef(i);
+  if (first_out < 0)  first_out = i;
+  if ((i+1) > next_out)  next_out = i+1;
+  if (isPutWaiting() && (next_in-next_out < wsize/2 )) { 
+    if (dbglev > 0) 
+      cout << " TOISeqBuffered::doGetData() - signalPut() name=" << getName()  
+	   << " i=" << i << " next_in= " << next_in 
+	   << " next_out=" << next_out << endl;
+    signalPut();
+  }
+  return dat;
+}
+
+
+#ifndef NO_SOPHYA
+TArray<int_4> TOISeqBuffered::doGetFlag(int iStart, int iEnd) {
+  if (!started) waitGet(); 
+  cleanWaitGet();
+  if (!isDataAvailNL(iStart, iEnd)) 
+    throw RangeCheckError("TOISeqBuffered::getFlag(iS,iE) : data not available");
+  TVector<int_4> dat(iEnd - iStart + 1);
+  for (int i=0; i<iEnd-iStart+1; i++) {
+    dat[i] = flagRef(i+iStart);
+  }
+  return dat;
+}
+#endif
+
+int_4 TOISeqBuffered::doGetFlag(int i) {
+  if (!started) waitGet(); 
+  cleanWaitGet();
+  if (isDataDeleted(i))
+    throw RangeCheckError("TOISeqBuffered::doGetFlag(i) : data deleted");
+  while (i >= next_in) waitGet();
+  int_4 dat = flagRef(i);
+  return dat;
+}
+
+
+void TOISeqBuffered::doPutData(int i, double value, int_4 flag) {
+  if (!started) {
+    first_in = next_in = i;
+    next_out = next_in;
+    started = true;
+  }
+  else {
+    if (i != next_in) {
+      string msg = "TOISeqBuffered::doPutData() : i!=next_in TOIname="  + getName();
+      throw RangeCheckError(msg);
+    }
+    if (next_in-next_out >= wsize) { 
+      if (dbglev > 0) 
+	cout << " TOISeqBuffered::doPutData() - waitPut() " << getName() 
+	     << " i=" << i 
+	     << " next_in= " << next_in << " next_out=" << next_out << endl;
+      waitPut();
+      if (dbglev > 0) 
+	cout << " ... Out of waitPut() i=" << i
+	     << " next_in= " << next_in << " next_out=" << next_out << endl;
+    }
+    cleanWaitPut();
+  }
+  dataRef(i) = value;
+  flagRef(i) = flag;
+  next_in = i+1;
+  if (isGetWaiting() && (next_in-next_out > wsize/8))  { 
+    if (dbglev > 0) 
+      cout << " TOISeqBuffered::doPutData() - signalGet() name=" << getName()
+	   << " i=" << i << " next_in= " << next_in 
+	   << " next_out=" << next_out << endl;
+    signalGet();
+  }
+}
+
+bool TOISeqBuffered::hasSomeData() {
+  lock();
+  bool x =  started;
+  unlock();
+  return x;
+}
+
+int TOISeqBuffered::nextDataAvail(int iAfter) {
+  lock();
+  if (iAfter >= next_in ) {unlock(); return -1;}
+  if (iAfter < (next_in-buffsize)) {unlock(); return (next_in-buffsize);}
+  unlock();
+  return iAfter+1;
+}
+
+/*  A faire, le nettoyage (heuristique selon demandes ?, guide ? ) */
+		 
+
Index: trunk/ArchTOIPipe/Kernel/toiseqbuff.h
===================================================================
--- trunk/ArchTOIPipe/Kernel/toiseqbuff.h	(revision 1437)
+++ trunk/ArchTOIPipe/Kernel/toiseqbuff.h	(revision 1437)
@@ -0,0 +1,65 @@
+// This may look like C code, but it is really -*- C++ -*-
+#ifndef TOISEQBUFF_H
+#define TOISEQBUFF_H
+
+#include "toi.h"
+
+// Classe de TOI avec buffer, et echantillonnage regulier.
+// Pour le moment au moins,
+// il faut que les providers fassent arriver les donnees par samplenum croissant.
+class TOISeqBuffered : public TOIRegular {
+public:
+  TOISeqBuffered(int wsz=8192);
+  TOISeqBuffered(string nm, int wsz=8192);
+  virtual ~TOISeqBuffered();
+
+  virtual void PrintStatus(ostream & os) const; 
+
+  inline void setDebugLevel(int lev=0) { dbglev=lev; }
+  inline int  getDebugLevel() const { return dbglev; }
+
+  inline int getFirstIn() const { return first_in; }
+  inline int getFirstOut() const { return first_out; }
+  inline int getLastIn() const { return (next_in-1); }
+  inline int getLastOut() const { return (next_out-1); }
+
+
+  virtual DataStatus isDataAvailNL(int iStart, int iEnd);
+  virtual DataStatus isDataAvailNL(int i); // override required
+
+protected:
+  double* data;
+  int_4*  flags;
+  int wsize;
+  int buffsize;
+  int next_in;
+  int next_out;
+  int first_in;
+  int first_out;
+  bool started;
+  double defaultValue;
+  int dbglev;
+
+  void    AllocBuffer(int wsz);
+
+#ifdef WITH_SOPHYA
+  virtual Array         doGetData(int iStart, int iEnd);
+  virtual TArray<int_4> doGetFlag(int iStart, int iEnd);
+#endif
+  virtual double        doGetData(int i);
+  virtual int_4         doGetFlag(int i);
+   
+  virtual void          doPutData(int i, double value, int_4 flag=0);
+  virtual void          doWontNeedBefore(int i);
+
+  virtual int           nextDataAvail(int iAfter);
+  virtual bool          hasSomeData();
+
+  inline double &       dataRef(int i) { return data[i%buffsize]; }
+  inline int_4 &        flagRef(int i) { return flags[i%buffsize]; }
+  inline bool           isDataDeleted(int i) 
+    { return((i < next_in-wsize-1) ? true : false); }
+};
+
+
+#endif
Index: trunk/ArchTOIPipe/ProcWSophya/rztoi.cc
===================================================================
--- trunk/ArchTOIPipe/ProcWSophya/rztoi.cc	(revision 1437)
+++ trunk/ArchTOIPipe/ProcWSophya/rztoi.cc	(revision 1437)
@@ -0,0 +1,178 @@
+#include "rztoi.h"
+#include "toimanager.h"
+#include "pexceptions.h"
+#include "fftpserver.h"
+#include "timing.h"
+
+RzTOIProc::RzTOIProc(int w1, int w2, int nmax)
+{
+  cout << "RzTOIProc::RzTOIProc() Width= " << w1 << "," << w2 << " NMax=" << nmax;
+  _width1 = w1;
+  _width2 = w2;
+  _nmax = nmax;
+}
+
+void RzTOIProc::init() {
+  cout << "RzTOIProc::init" << endl;
+  declareInput("signal");
+  declareOutput("sfout");
+  name = "rzproc";
+  upExtra = 1;
+}
+
+void RzTOIProc::run() {
+  //  TOIManager* mgr = TOIManager::getManager();
+  int snb = getMinIn();
+  int sne = getMaxIn();
+
+  int istart, iend;
+  int ilast;
+  ilast = istart = snb; 
+  iend = sne;
+  int ii, jj;
+
+  try {
+
+    FFTPackServer ffts;
+
+    bool fgppf = false;
+    int nkv = 0;
+    int nkvmx = 8;
+    Vector vkin[nkvmx];
+    Vector vkout[nkvmx];
+    TVector< complex<r_8> > vkfft[nkvmx];
+    if (outppf.length() > 0)    fgppf = true;
+    
+    Vector vin, vout;
+    TVector< complex<r_8> > vfft;
+
+    for (int k=0; k<_nmax; k++) {
+      istart = snb + k*_width1;
+      //      if (k>0)  istart -= _width2;
+      iend = istart +_width1;
+      cout << " RzTOIProc::run() - Processing bloc k= " << k 
+	   << " istart= " << istart << " iend= " << iend << endl;
+      if (iend > sne) {
+	cout << " RzTOIProc::run() - iend > getMaxIn() -> break " << endl;
+	break;
+      }
+      //      Vector vin = getData(0, istart, iend);
+      vin.ReSize(_width1);
+      jj = 0;
+      for(ii=istart; ii<iend; ii++)  
+	vin(jj++) = getData(0, ii);
+      
+      cout << " End of getData() for bloc " << k << endl;
+
+      vout.ReSize(vin.Size());
+      double vlast = 0.;
+      for(int i=0; i<vout.Size()-_width2; i++) {
+	vout(i) = vin(Range(i,-1,_width2)).Sum()/(r_8)_width2;
+	putData(0, i+istart, vout(i));
+	vlast = vout(i);
+      }
+
+      for(int i=vout.Size()-_width2; i<vout.Size(); i++) {
+	vout(i) = vlast;
+	putData(0, i+istart, vout(i));
+      }
+
+      cout << " End of putData() for bloc " << k << " Mean vout= " 
+	   << vout.Sum()/vout.Size() << endl;
+
+      vin -= vout;
+
+      TVector< complex<r_8> > vfft;
+      ffts.FFTForward(vin, vfft);
+      ilast = iend;
+      /*
+      if (fgppf) {
+	string nom;
+	nom = "in" + (string)MuTyV(k);
+	ppo->PutObject(vin, nom);
+	nom = "out" + (string)MuTyV(k);
+	ppo->PutObject(vout, nom);
+	nom = "fft" + (string)MuTyV(k);
+	ppo->PutObject(vfft, nom);
+      }
+      */
+      if (fgppf && (nkv < nkvmx) ) {
+	vkin[nkv] = vin;
+	vkout[nkv] = vout;
+	vkfft[nkv] = vfft;
+	nkv++;
+      }
+      PrtTim("End of bloc");
+    }
+
+    if (fgppf) {
+      cout << " Writing to Out PPF ... " << endl;
+      POutPersist ppo(outppf);
+      for(int kkk=0; kkk<nkv; kkk++) {
+	string nom;
+	nom = "in" + (string)MuTyV(kkk);
+	ppo.PutObject(vkin[kkk], nom);
+	nom = "out" + (string)MuTyV(kkk);
+	ppo.PutObject(vkout[kkk], nom);
+	nom = "fft" + (string)MuTyV(kkk);
+	ppo.PutObject(vkfft[kkk], nom);
+      }
+    }
+
+    cout << " Filling -9999 : putData(0, ii, -9999.) ii: "
+	 << iend << " .. " << sne << endl;
+    double xxx;
+    for(ii=iend; ii<sne; ii++) {
+      if ((ii-iend)%1000 == 0) 
+	cout << " RzTOIProc::run() - Processing sample ii= " << ii
+	     << endl;
+      xxx=getData(0,ii);
+      putData(0,ii,xxx-9999.);
+    }
+
+  }
+  catch (PException & e) {
+    cout << "RzTOIProc exception Msg= " << e.Msg() << endl;
+  }
+}
+
+
+
+RzSimpleTOIProc::RzSimpleTOIProc(double fact, int npr)
+{
+  cout << "RzSimpleTOIProc::RzSimpleTOIProc() factor= " << fact 
+       << " npr=" << npr << endl; 
+  _fact = fact;
+  _nprt = npr;
+}
+
+void RzSimpleTOIProc::init() {
+  cout << "RzSimpleTOIProc::init" << endl;
+  declareInput("signal");
+  declareOutput("sfout");
+  name = "rzsimpleproc";
+  upExtra = 1;
+}
+
+void RzSimpleTOIProc::run() {
+  //  TOIManager* mgr = TOIManager::getManager();
+  int snb = getMinIn();
+  int sne = getMaxIn();
+
+  cout << " RzSimpleTOIProc::run(): snb=" << snb << " sne=" << sne << endl;
+
+  double val;
+  try {
+    for (int k=snb; k<sne; k++) {
+      if ((k-snb)%_nprt == 0) 
+	cout << " RzSimpleTOIProc::run() - Processing sample k= " << k
+	     << endl;
+
+      val = getData(0, k);
+      putData(0, k, val*_fact);
+    }
+  }
+  catch (PException & e) {
+    cout << "RzSimpleTOIProc exception Msg= " << e.Msg() << endl;
+  }
+}
Index: trunk/ArchTOIPipe/ProcWSophya/rztoi.h
===================================================================
--- trunk/ArchTOIPipe/ProcWSophya/rztoi.h	(revision 1437)
+++ trunk/ArchTOIPipe/ProcWSophya/rztoi.h	(revision 1437)
@@ -0,0 +1,34 @@
+// This may look like C code, but it is really -*- C++ -*-
+
+#ifndef RZTOIPROC_H
+#define RZTOIPROC_H
+
+#include "toiprocessor.h"
+
+class RzTOIProc : public TOIProcessor {
+public:
+  RzTOIProc(int w1=4096, int w2=128, int nmax=20);
+  inline void setOutPPF(string const & ppfname) 
+              { outppf = ppfname; }
+  virtual void init();  
+  virtual void run();
+
+protected:
+  int _width1;
+  int _width2;
+  int _nmax;
+  string outppf;
+};
+
+class RzSimpleTOIProc : public TOIProcessor {
+public:
+  RzSimpleTOIProc(double fact=1.0, int npr=1000);
+  virtual void init();  
+  virtual void run();
+
+protected:
+  double _fact;
+  int _nprt;
+};
+
+#endif
Index: trunk/ArchTOIPipe/SMakefile
===================================================================
--- trunk/ArchTOIPipe/SMakefile	(revision 1437)
+++ trunk/ArchTOIPipe/SMakefile	(revision 1437)
@@ -0,0 +1,63 @@
+USERFLAGS = -I$(EXTLIBDIR)/Include/FitsIO -DWITH_SOPHYA
+include $(DPCBASEREP)/Include/MakefileUser.h
+ 
+ALIB := ./Objs/
+AOBJ := ./Objs/
+
+$(AOBJ)%.o:%.cc
+	$(COMPILE.cc)   $(USERFLAGS) -o $@ $<
+$(AOBJ)%.o:%.c
+	$(COMPILE.c) -c $(CFLAGS) $(USERFLAGS) -o $@ $<
+
+LIBOLIST := $(AOBJ)asciitoiwtr.o $(AOBJ)fitstoirdr.o $(AOBJ)fitstoiwtr.o $(AOBJ)toi.o $(AOBJ)toimanager.o $(AOBJ)toiprocessor.o $(AOBJ)toisqfilter.o \
+$(AOBJ)toiseqbuff.o 
+EXEOLIST := $(AOBJ)fits2asc.o $(AOBJ)tsttoi.o $(AOBJ)tsttoi2.o
+EXELIST := $(AOBJ)tstrztoi $(AOBJ)fits2asc $(AOBJ)tsttoi $(AOBJ)tsttoi2
+
+INCLIST := asciitoiwtr.h fitstoirdr.h fitstoiwtr.h toi.h config.h conf.h \
+ toiprocessor.h toimanager.h toiseqbuff.h 
+
+
+all : $(EXELIST) 
+
+clean:
+	rm -f  $(LIBOLIST)
+	rm -f  $(EXEOLIST)
+	rm -f  $(EXELIST)
+#	rm -f $(AOBJ)asciitoiwtr.o $(AOBJ)fitstoirdr.o $(AOBJ)fitstoiwtr.o $(AOBJ)toi.o $(AOBJ)toimanager.o $(AOBJ)toiprocessor.o $(AOBJ)toisqfilter.o $(AOBJ)tsttoi.o 
+
+LIBF =  $(SLB)libsophya.so $(SLB)libextsophya.so 
+LIBS = -L$(SLB) -lextsophya -lsophya -lpthread -lm 
+ifeq ($(MACHEROS),OSF1)
+LIBS := $(LIBS) -lfor
+endif
+
+
+$(AOBJ)tstrztoi: $(AOBJ)tstrztoi.o $(AOBJ)rztoi.o $(LIBOLIST)
+	$(LINK.cc)  -o $@ $^ $(LIBS)
+$(AOBJ)fits2asc: $(AOBJ)fits2asc.o $(LIBOLIST)
+	$(LINK.cc)  -o $@ $^ $(LIBS)
+$(AOBJ)tsttoi: $(AOBJ)tsttoi.o $(LIBOLIST)
+	$(LINK.cc)  -o $@ $^ $(LIBS)
+$(AOBJ)tsttoi2: $(AOBJ)tsttoi2.o $(LIBOLIST)
+	$(LINK.cc)  -o $@ $^ $(LIBS)
+
+$(AOBJ)tstrztoi.o: tstrztoi.cc rztoi.h $(INCLIST)
+$(AOBJ)rztoi.o: rztoi.cc rztoi.h $(INCLIST)
+$(AOBJ)fits2asc.o: fits2asc.cc $(INCLIST)
+$(AOBJ)tsttoi.o: tsttoi.cc $(INCLIST)
+$(AOBJ)tsttoi2.o: tsttoi2.cc $(INCLIST)
+
+ 
+$(AOBJ)asciitoiwtr.o: asciitoiwtr.cc asciitoiwtr.h toi.h config.h conf.h \
+ toiprocessor.h toimanager.h 
+$(AOBJ)fitstoirdr.o: fitstoirdr.cc fitstoirdr.h toiprocessor.h config.h conf.h
+$(AOBJ)fitstoiwtr.o: fitstoiwtr.cc fitstoiwtr.h toi.h config.h conf.h
+$(AOBJ)toi.o: toi.cc toiprocessor.h config.h conf.h toi.h 
+$(AOBJ)toimanager.o: toimanager.cc toimanager.h
+$(AOBJ)toiprocessor.o: toiprocessor.cc toiprocessor.h config.h conf.h toi.h \
+ toimanager.h
+$(AOBJ)toisqfilter.o: toisqfilter.cc toisqfilter.h toiprocessor.h config.h \
+ conf.h toi.h toimanager.h
+$(AOBJ)toiseqbuff.o: toiseqbuff.cc toiprocessor.h config.h conf.h toi.h \
+toiseqbuff.h 
Index: trunk/ArchTOIPipe/TestPipes/fits2asc.cc
===================================================================
--- trunk/ArchTOIPipe/TestPipes/fits2asc.cc	(revision 1410)
+++ trunk/ArchTOIPipe/TestPipes/fits2asc.cc	(revision 1437)
@@ -5,5 +5,5 @@
 #include "asciitoiwtr.h"
 
-void main(int argc, char** argv) {
+int main(int argc, char** argv) {
   TOIManager* mgr = TOIManager::getManager();
   //  mgr->setRequestedSample(11680920,11710584);
@@ -26,3 +26,5 @@
 
   mgr->joinAll();
+
+  return(0);
 }
Index: trunk/ArchTOIPipe/TestPipes/tstrztoi.cc
===================================================================
--- trunk/ArchTOIPipe/TestPipes/tstrztoi.cc	(revision 1437)
+++ trunk/ArchTOIPipe/TestPipes/tstrztoi.cc	(revision 1437)
@@ -0,0 +1,195 @@
+#include <unistd.h>
+#include "toi.h"
+#include "toiprocessor.h"
+#include "fitstoirdr.h"
+#include "fitstoiwtr.h"
+#include "toisqfilter.h"
+#include "toimanager.h"
+#include "rztoi.h"
+#include "toiseqbuff.h"
+#include "timing.h"
+#include "sambainit.h"
+
+void Usage(bool fgerr)
+{
+  cout << endl;
+  if (fgerr) {
+    cout << " tstrztoi : Argument Error ! tstrztoi -h for usage " << endl; 
+    exit(1);
+  }
+  else {
+    cout << "\n Usage : tstrztoi [-sproc] [-rwtoi] [-dbg] [-start snb] [-end sne] \n" 
+	 << "         [-w1 sz] [-w2 sz] inFitsName outFitsName ppfFileName \n" 
+	 << "   -sproc : Run RzSimpleTOIProc (default RzTOIProc) \n"
+	 << "   -rwtoi : Use Regular Window TOI (default TOISeqBuffered) \n" 
+	 << "   -dbg : sets TOISeqBuffered debug level to 1 \n"
+	 << "   -start snb : sets the start sample num \n"
+	 << "   -end sne : sets the end sample num \n"
+	 << "   -w1 sz : sets main data window size (def= 8192)\n"
+	 << "   -w2 sz : sets secondary window size (def= 512) \n"
+	 << endl;
+    exit(0);
+  }
+}
+
+int main(int narg, char** arg) {
+
+  if ((narg > 1) && (strcmp(arg[1],"-h") == 0) ) Usage(false);
+
+  cout << "tstrztoi starting - Decoding arguments " << " narg=" << narg << endl;
+
+  bool fgsimple = false;
+  bool fgrwtoi = false;
+  bool fgdbg = false;
+  int w1 = 8192;
+  int w2 = 512;
+  int nmax = 10;
+  int istart = 104121000+w1*5;
+  int iend = 0;
+  string infile;
+  string outfile;
+  string ppffile;
+
+  if (narg < 4) Usage(true);
+  int ko=1;
+  // decoding arguments 
+  for(int ia=1; ia<narg; ia++) {
+    if (strcmp(arg[ia],"-start") == 0) {
+      if (ia == narg-1) Usage(true);  // -start est suivi d'un argument 
+      istart = atoi(arg[ia+1]); ia++;
+    }    
+    else if (strcmp(arg[ia],"-end") == 0) {
+      if (ia == narg-1) Usage(true);  
+      iend = atoi(arg[ia+1]); ia++;
+    }    
+    else if (strcmp(arg[ia],"-w1") == 0) {
+      if (ia == narg-1) Usage(true);  
+      w1 = atoi(arg[ia+1]); ia++;
+    }    
+    else if (strcmp(arg[ia],"-w2") == 0) {
+      if (ia == narg-1) Usage(true);  
+      w2 = atoi(arg[ia+1]); ia++;
+    }    
+    else if (strcmp(arg[ia],"-sproc") == 0)  fgsimple = true;
+    else if (strcmp(arg[ia],"-rwtoi") == 0)  fgrwtoi = true;
+    else if (strcmp(arg[ia],"-dbg") == 0)  fgdbg = true;
+
+    else { ko = ia; break; }  // Debut des noms
+  }
+
+  if (iend < istart) iend = istart+w1*(nmax+5);
+  if ((narg-ko) < 3)  Usage(true); 
+  infile = arg[ko];
+  outfile = arg[ko+1];
+  ppffile = arg[ko+2];
+
+  cout << " Initializing SOPHYA ... " << endl;
+  SophyaInit();
+  InitTim();
+
+  cout << ">>>> tstrztoi: Infile= " << infile << " outFile=" << outfile 
+       << " ppfFile= " << ppffile << endl;
+  cout << ">>>> Window Size W1= " << w1 << " W2= " << w2
+       << "  iStart= " << istart << " iEnd= " << iend << endl;
+  try {
+    TOIManager* mgr = TOIManager::getManager();
+  
+    //  mgr->setRequestedSample(11680920,11710584);
+    //  mgr->setRequestedSample(104121000, 104946120);
+
+    mgr->setRequestedSample(istart, iend);
+  
+    //    FITSTOIReader r("/data/Archeops/bolo11.fits); 
+    FITSTOIReader r(infile); 
+    cout << "reader created" << endl;
+    //    FITSTOIWriter w("/data/Archeops/rz.fits");
+    FITSTOIWriter w(outfile);
+    w.setOutFlags(true);
+    cout << "fits writer created" << endl;
+
+
+    char * colname[5] = {"MJD", "UTC","boloMuV_11","magnFlux","pivot"};
+    TOI* toitab[5];
+    TOI* toi2;
+    int kk;
+    if (fgrwtoi) {
+      cout << " Using TOIRegularWindow TOI's ... " << endl;
+      for(kk=0; kk<5; kk++) {
+	toitab[kk] = new TOIRegularWindow((string)"t_"+colname[kk]);
+      }
+      toi2 = new TOIRegularWindow("t2");
+    }
+    else {
+      cout << " Using TOISeqBuffered TOI's ... " << endl;
+      for(kk=0; kk<5; kk++) {
+	TOISeqBuffered * toisb = new TOISeqBuffered((string)"t_"+colname[kk], w1);
+	toitab[kk] = toisb;
+	if (fgdbg) toisb->setDebugLevel(1);
+      }
+      TOISeqBuffered * toisb = new TOISeqBuffered("t2", w1);
+      if (fgdbg) toisb->setDebugLevel(1);
+      toi2 = toisb;
+    }
+
+    // Connecting TOI to FITSTOIReader Processor
+    //    for(kk=0; kk<5; kk++) {
+    //      r.addOutput(colname[kk], toitab[kk]);
+    //    }
+
+    kk = 2;
+    TOI* toi = toitab[kk];
+    r.addOutput(colname[kk], toi);
+    //  toi->dbg=true;
+    //  r.addOutput("boloMuV_11", toi);
+    cout << " connecting in/out to RzTOIProcessor ... " << endl;
+
+    //    TOIProcessor * filt = NULL;
+
+    cout << " Creating Rz TOIProcessors: RzTOIProc () " << endl;
+    RzSimpleTOIProc rzs(2., 1000);
+    RzTOIProc rzp(w1, w2, nmax);
+    if (fgsimple) {
+      cout << " Using Simple TOIProcessor: RzSimpleTOIProc () " << endl;
+      rzs.addInput("signal", toi);
+      rzs.addOutput("sfout", toi2);
+      }
+    else {
+      cout << " Using Rz TOIProcessor: RzTOIProc () " << endl;
+      //      rzp.setOutPPF("/data/Archeops/toto.ppf");
+      rzp.setOutPPF(ppffile);
+      rzp.addInput("signal", toi);
+      rzp.addOutput("sfout", toi2);
+    }
+
+
+    w.addInput("bolo_filtered", toi2);
+
+    PrtTim("starting threads");
+    r.start();
+    if (fgsimple) rzs.start();
+    else rzp.start();
+    w.start();
+
+    r.PrintStatus(cout);  
+    
+    for(int jj=0; jj<3; jj++) {
+      sleep(2);
+      cout << *toi; 
+    }
+
+    mgr->joinAll();
+    PrtTim("End threads");
+    cout << " ------ toi and toi2 Status information ------- " << endl;
+    cout << *toi; 
+    cout << *toi2;
+  }
+  catch (PThrowable & exc) {
+    cerr << "rztsttoi: Catched Exception \n" << (string)typeid(exc).name() 
+	 << " - Msg= " << exc.Msg() << endl;
+  }
+  catch (...) {
+    cerr << "rztsttoi: some other exception was caught ! " << endl;
+  }
+
+  return(0);
+}
Index: trunk/ArchTOIPipe/TestPipes/tsttoi.cc
===================================================================
--- trunk/ArchTOIPipe/TestPipes/tsttoi.cc	(revision 1410)
+++ trunk/ArchTOIPipe/TestPipes/tsttoi.cc	(revision 1437)
@@ -33,3 +33,4 @@
   cout << "joining" << endl;
   mgr->joinAll();
+  return(0);
 }
Index: trunk/ArchTOIPipe/TestPipes/tsttoi2.cc
===================================================================
--- trunk/ArchTOIPipe/TestPipes/tsttoi2.cc	(revision 1410)
+++ trunk/ArchTOIPipe/TestPipes/tsttoi2.cc	(revision 1437)
@@ -6,5 +6,5 @@
 #include "toimanager.h"
 
-void main(int argc, char** argv) {
+int main(int argc, char** argv) {
   cout << "tsttoi starting" << endl;
   TOIManager* mgr = TOIManager::getManager();
@@ -23,3 +23,5 @@
 
   mgr->joinAll();
+
+  return(0);
 }
