Index: /trunk/ArchTOIPipe/Kernel/apexceptions.h
===================================================================
--- /trunk/ArchTOIPipe/Kernel/apexceptions.h	(revision 1365)
+++ /trunk/ArchTOIPipe/Kernel/apexceptions.h	(revision 1365)
@@ -0,0 +1,205 @@
+// This may look like C code, but it is really -*- C++ -*-
+#ifndef PEXCEPTIONS_SEEN
+#define PEXCEPTIONS_SEEN
+
+#include "config.h"
+#include <string>
+
+using namespace std;
+
+// Petit utilitaire pour accoler numero de ligne et nom de fichier aux messages
+// d'exception
+#define PExcLongMessage(a) BuildLongExceptionMessage(a,__FILE__,__LINE__)
+
+
+//! Utility function for appending a file name and line number to a message
+  string BuildLongExceptionMessage(const char * s, const char *file, int line);
+
+/*! \ingroup SysTools
+    \brief Base exception class in Sophya
+
+    Ancestor for PError and PException
+    It has a message, and an id to give more
+    information on the exception.
+*/
+  class PThrowable {
+  public:
+    //! Constructor with the message and error-id (optional) specification
+    explicit PThrowable(const string& m, int ident=0) 
+      : msg(m), id(ident) {}
+    virtual ~PThrowable() { }
+    //! Returns the associated message string
+    virtual string const& Msg() const  {return msg;}
+    //! Returns the associated error-id
+    virtual int Id() const {return id; }
+  private:
+    string msg;
+    int    id;
+  };
+
+//  PThrowable
+//      PError
+//      PException
+  
+/*! \ingroup SysTools 
+    \brief A PError is a serious logic error. Usually not caught... */
+  class PError : public PThrowable {
+  public:
+    explicit PError(const string& m, int id=0) : PThrowable(m,id) {}
+  };
+  
+/*! \ingroup SysTools 
+    \brief A PException is not as serious... Can be caught. */
+  class PException : public PThrowable {
+  public:
+    explicit PException(const string& m, int id=0) : PThrowable(m,id) {}
+  };
+  
+//  ----   Errors ----
+//  PError
+//     AllocationError
+//     NullPtrError
+//     ForbiddenError
+//     AssertionFailedError
+
+/*! \ingroup SysTools 
+    \brief Memory allocation failure */
+  class AllocationError : public PError {
+  public:
+    explicit AllocationError(const string& m, int id=0) : PError(m,id) {}
+  };
+  
+/*! \ingroup SysTools 
+    \brief Null pointer error */
+  class NullPtrError : public PError {
+  public:
+    explicit NullPtrError(const string& m, int id=0) : PError(m,id) {}
+  };
+  
+  
+/*! \ingroup SysTools 
+    \brief Calling a forbidden method, trying a forbidden operation */
+  class ForbiddenError : public PError {
+  public:
+    explicit ForbiddenError(const string& m, int id=0) : PError(m,id) {}
+  };
+
+  
+/*! \ingroup SysTools 
+    \brief ASSERT macro failure. The message is the assertion... */
+  class AssertionFailedError : public PError {
+  public:
+    explicit AssertionFailedError(const string& m, int id=0) : PError(m,id) {}
+  };
+  
+  // Standard exceptions
+  //
+  // PException
+  //   IOExc
+  //     FileFormatExc
+  //   SzMismatchError
+  //   RangeCheckError
+  //   ParmError
+  //   TypeMismatchExc
+  //   MathExc
+  //     SingMatxExc
+  //   DuplicateIdExc
+  //   NotFoundExc
+  //   CaughtSignalExc
+  
+/*! \ingroup SysTools 
+    \brief Generic IO Exception */
+  class IOExc : public PException {
+  public:
+    explicit IOExc(const string& m, int id=0) : PException(m,id) {}
+  };
+
+/*! \ingroup SysTools 
+    \brief Bad file format */
+  class FileFormatExc : public IOExc {
+  public:
+    explicit FileFormatExc(const string& m, int id=0) : IOExc(m,id) {}
+  };
+
+/*! \ingroup SysTools 
+    \brief Size mismatch between objects */
+  class SzMismatchError : public PException {
+  public:
+    explicit SzMismatchError(const string& m, int id=0) : PException(m,id) {}
+  };
+  
+/*! \ingroup SysTools 
+    \brief Out of bounds for array, matrix, etc */
+  class RangeCheckError : public PException {
+  public:
+    explicit RangeCheckError(const string& m, int id=0) : PException(m,id) {}
+  };
+  
+/*! \ingroup SysTools 
+    \brief Invalid parameter to method/constructor... */
+  class ParmError : public PException {
+  public:
+    explicit ParmError(const string& m, int id=0) : PException(m,id) {}
+  };
+
+/*! \ingroup SysTools 
+    \brief Calling a non available / not implemented method */
+  class NotAvailableOperation : public PException {
+  public:
+    explicit NotAvailableOperation(const string& m, int id=0) : PException(m,id) {}
+  };
+
+/*! \ingroup SysTools 
+    \brief Bad data type -> keep ? */
+  class TypeMismatchExc : public PException {
+  public:
+    explicit TypeMismatchExc(const string& m, int id=0) : PException(m,id) {}
+  };
+
+/*! \ingroup SysTools 
+    \brief Math operation exception */
+  class MathExc : public PException {
+  public:
+    explicit MathExc(const string& m, int id=0) : PException(m,id) {}
+  };
+  
+/*! \ingroup SysTools 
+    \brief Singular matrix  */
+  class SingMatrixExc : public MathExc {
+  public:
+    explicit SingMatrixExc(const string& m, int id=0) : MathExc(m,id) {}
+  };
+
+/*! \ingroup SysTools 
+    \brief Duplicate identifier during registration */
+  class DuplicateIdExc : public PException {
+  public:
+    explicit DuplicateIdExc(const string& m, int id=0) : PException(m,id) {}
+  };
+  
+/*! \ingroup SysTools 
+    \brief Not found identifier  */
+  class NotFoundExc : public PException {
+  public:
+    explicit NotFoundExc(const string& m, int id=0) : PException(m,id) {}
+  };
+  
+/*! \ingroup SysTools 
+    \brief Generated exception when processing a signal */
+  class CaughtSignalExc : public PException {
+  public:
+    explicit CaughtSignalExc(const string& m, int id=0) : PException(m,id) {}
+  };
+    
+
+
+#define ASSERT(_a_) if (!(_a_)) { \
+     cerr << "Assertion failed " #_a_ " file " __FILE__ " line " << __LINE__ \
+          << endl; \
+		     throw(AssertionFailedError(#_a_)); }
+   
+#define FAILNIL(_x_) \
+       {if (!(_x_)) throw(NullPtrError(#_x_))}
+
+
+#endif
Index: /trunk/ArchTOIPipe/Kernel/fitstoirdr.cc
===================================================================
--- /trunk/ArchTOIPipe/Kernel/fitstoirdr.cc	(revision 1365)
+++ /trunk/ArchTOIPipe/Kernel/fitstoirdr.cc	(revision 1365)
@@ -0,0 +1,107 @@
+#include "fitstoirdr.h"
+#include "toimanager.h"
+
+
+
+FITSTOIReader::FITSTOIReader(string fn) {
+  fname = fn;
+  cout << "FITSTOIReader::FITSTOIReader" << endl;
+  cout << "FITSTOIReader::inited " << inited << endl;
+  name = "rdr";
+}
+
+FITSTOIReader::~FITSTOIReader() {
+}
+
+pthread_mutex_t fits_mutex = PTHREAD_MUTEX_INITIALIZER;
+void fits_lock();
+void fits_unlock();
+
+void fits_lock() {
+  pthread_mutex_lock(&fits_mutex);
+}
+void fits_unlock() {
+  pthread_mutex_unlock(&fits_mutex);
+}
+
+void FITSTOIReader::init() {
+  fits_lock();
+  cout << "FITSTOIReader::init" << endl;
+  fstatus = 0;
+  // Open file
+  fits_open_file(&fptr,fname.c_str(),READONLY,&fstatus);
+  if (fstatus != 0) {
+    fits_report_error(stderr, fstatus);
+    fits_unlock();
+    exit (-1);
+  }
+  
+  // Go to first extension, which should be a BINTABLE
+  
+  int simple, bitpix, naxis;
+  long naxes;
+  long pcount, gcount;
+  int extend;
+  fits_read_imghdr(fptr, 1, &simple, &bitpix, 
+		   &naxis, &naxes, &pcount, &gcount, &extend, &fstatus);
+  
+  fits_movabs_hdu(fptr, 2, NULL, &fstatus);
+  
+  int ncols;
+  fits_get_num_cols(fptr,&ncols,&fstatus);
+  fits_get_num_rows(fptr,&nrows,&fstatus);
+
+  cout << "FITSTOIReader cols = " << ncols << endl;
+
+  // Dans cette version, on s'attend a ce que la premiere colonne soit le samplenum
+  for (int i=1; i<ncols; i++) {
+    char templt[10];
+    sprintf(templt, "%d", i+1);
+    char colname[200];
+    int colnum;
+    fits_get_colname(fptr, CASESEN, templt, colname, &colnum, &fstatus);
+    cout << "FITSTOIReader col " << colname << endl;
+    declareOutput(colname);
+  }
+  int anyNul;
+  double y;
+  fits_read_col_dbl(fptr,1,1,1,1,0,&y,&anyNul,&fstatus);
+  firstSn = (int) (y+.1);
+  fits_unlock();
+}
+
+int FITSTOIReader::calcMinOut() {
+  return firstSn;
+}
+
+int FITSTOIReader::calcMaxOut() {
+  return firstSn + nrows - 1;
+}
+
+
+void FITSTOIReader::run() {
+  // Il faudrait optimiser en fonction de ce qui a ete demande comme samplenum,
+  // mais cela implique de gerer aussi bien echant uniforme que non.
+  // On pourrait aussi lire plusieurs elements d'un coup.
+  int ncols = outIx.size();
+  cout << "reader reading..." << endl;
+  for (int i=0; i<nrows; i++) {
+    int anyNul;
+    double y;
+    fits_lock();
+    fits_read_col_dbl(fptr,1,i+1,1,1,0,&y,&anyNul,&fstatus);
+    fits_unlock();
+    int sn = (int) (y+.1);
+    TOIManager* mgr = TOIManager::getManager();
+    if (sn > mgr->getRequestedEnd()) break;
+    if (sn < mgr->getRequestedBegin()) continue;
+    //    if (sn < mgr->getRequestedBegin()+10) cout << "rdr out " << sn << endl;
+    for (int j=1; j<=ncols; j++) {
+      fits_lock();
+      fits_read_col_dbl(fptr,j+1,i+1,1,1,0,&y,&anyNul,&fstatus);
+      fits_unlock();
+      putData(j-1, sn, y);
+    }
+  }
+  cout << "reader done reading... " << pthread_self() << endl;
+}
Index: /trunk/ArchTOIPipe/Kernel/fitstoirdr.h
===================================================================
--- /trunk/ArchTOIPipe/Kernel/fitstoirdr.h	(revision 1365)
+++ /trunk/ArchTOIPipe/Kernel/fitstoirdr.h	(revision 1365)
@@ -0,0 +1,31 @@
+// This may look like C code, but it is really -*- C++ -*-
+
+#ifndef FITSTOIRDR_H
+#define FITSTOIRDR_H
+
+#include "toiprocessor.h"
+#include <string>
+#include "fitsio.h"
+
+
+class FITSTOIReader : public TOIProcessor {
+public:
+  FITSTOIReader(string fn);
+  ~FITSTOIReader();
+  virtual void init();  
+  virtual void run();  
+
+protected:
+  virtual int   calcMinOut();
+  virtual int   calcMaxOut();
+
+private:
+  string fname;
+  fitsfile *fptr;
+  int fstatus;
+  long nrows;
+  int firstSn;
+};
+
+
+#endif
Index: /trunk/ArchTOIPipe/Kernel/fitstoiwtr.cc
===================================================================
--- /trunk/ArchTOIPipe/Kernel/fitstoiwtr.cc	(revision 1365)
+++ /trunk/ArchTOIPipe/Kernel/fitstoiwtr.cc	(revision 1365)
@@ -0,0 +1,109 @@
+#include "fitstoiwtr.h"
+#include "toimanager.h"
+
+
+
+extern void fits_lock();
+extern void fits_unlock();
+
+FITSTOIWriter::FITSTOIWriter(string fn) {
+  fname = fn;
+  fstatus = 0;
+
+  // Open file
+  remove(fname.c_str()); 
+  fits_lock();
+  fits_create_file(&fptr,fname.c_str(),&fstatus);
+  fits_unlock();
+  name = "wtr";
+}
+
+FITSTOIWriter::~FITSTOIWriter() {
+}
+
+void FITSTOIWriter::addInput(string name, TOI* toi) {
+  declareInput(name);
+  fwinputs.push_back(toi);
+}
+
+
+void FITSTOIWriter::run() {
+  cout << "fitstoiwriter running" << endl;
+  // init done here
+  delete[] inTOIs;
+  inTOIs = new (TOI*[fwinputs.size()]);
+
+  for (int i=0; i<fwinputs.size(); i++) {
+    inTOIs[i] = fwinputs[i];
+  }
+
+  int ncols = inIx.size();
+
+  char** colnames = new (char*[ncols]);
+  char** coltypes = new (char*[ncols]);
+  char** colunits = new (char*[ncols]);
+
+  for (map<string, int>::iterator i = inIx.begin(); i != inIx.end(); i++) {
+    int j = (*i).second;
+    string n = (*i).first;
+    colnames[j] = const_cast<char*>(n.c_str());
+    coltypes[j] = "1D";
+    colunits[j] = "?";
+  }
+
+  fits_lock();
+  fits_create_tbl(fptr, BINARY_TBL, 0, ncols, colnames, coltypes, colunits, NULL, &fstatus);
+  fits_write_date(fptr, &fstatus);
+  fits_unlock();
+
+  delete[] colunits;
+  delete[] coltypes;
+  delete[] colnames;
+
+  // Add headers ?
+
+  // loop
+
+  int fitsLine = 1;
+  TOIManager* mgr = TOIManager::getManager();
+  // int snb = mgr->getRequestedBegin();
+  //int sne = mgr->getRequestedEnd();
+  int snb = getMinIn();
+  int sne = getMaxIn();
+
+  for (int sn = snb; sn <= sne; sn++) {
+    try {
+      for (int i=0; i<ncols; i++) {
+	//	cout << "wtr req " << sn << endl;
+	double x = getData(i, sn);
+	//	cout << "wtr got " << sn << endl;
+	fits_lock();
+	fits_write_col_dbl(fptr, i+1, fitsLine, 1, 1, &x, &fstatus);
+	if (fstatus != 0) {
+	  cerr << "fitstoiwtr error sn = " << sn << " i = "<< i << endl;
+	  fits_report_error(stderr, fstatus);
+	  abort();
+	}
+	fits_unlock();
+      }
+    } catch (PException e) {
+      cout << "fitstoiwtr exception " << e.Msg() << endl;
+      continue;
+    }
+    fitsLine++;
+  }
+
+  fits_lock();
+  fits_close_file(fptr, &fstatus);
+  fits_report_error(stderr, fstatus);
+  fits_unlock();
+  cout << "fitstoiwriter done" << endl;
+}
+
+
+
+
+
+
+
+
Index: /trunk/ArchTOIPipe/Kernel/fitstoiwtr.h
===================================================================
--- /trunk/ArchTOIPipe/Kernel/fitstoiwtr.h	(revision 1365)
+++ /trunk/ArchTOIPipe/Kernel/fitstoiwtr.h	(revision 1365)
@@ -0,0 +1,31 @@
+// This may look like C code, but it is really -*- C++ -*-
+
+#ifndef FITSTOIWTR_H
+#define FITSTOIWTR_H
+
+#include "toi.h"
+#include "toiprocessor.h"
+#include <string>
+#include <map>
+#include "fitsio.h"
+
+
+class FITSTOIWriter : public TOIProcessor {
+public:
+  FITSTOIWriter(string fn);
+  ~FITSTOIWriter();
+  
+  virtual void  addInput(string name, TOI* toi);
+
+  //virtual void  init();  
+  virtual void  run();  
+  
+private:
+  string fname;
+  fitsfile *fptr;
+  int fstatus;
+  vector<TOI*> fwinputs;
+
+};
+
+#endif
Index: /trunk/ArchTOIPipe/Kernel/toi.cc
===================================================================
--- /trunk/ArchTOIPipe/Kernel/toi.cc	(revision 1365)
+++ /trunk/ArchTOIPipe/Kernel/toi.cc	(revision 1365)
@@ -0,0 +1,283 @@
+#include "toiprocessor.h"
+#include "toi.h"
+#include <pthread.h>
+
+#ifdef WITH_SOPHYA
+#include "pexceptions.h"
+#else
+#include "apexceptions.h"
+#endif
+
+#define CHKSYNC(ctx)  
+//  if (((TOIRegularWindow*)this)->data.size() != ((TOIRegularWindow*)this)->flags.size())        \
+//    cout << ctx << ((TOIRegularWindow*)this)->data.size() << "  " <<  \
+//      ((TOIRegularWindow*)this)->flags.size() << endl;  \
+
+TOI::TOI() {
+  TOIInit();
+}
+
+TOI::TOI(string n) {
+  name = n;
+  TOIInit();
+}
+
+void TOI::TOIInit() {
+  pthread_mutex_init(&mutex, NULL);
+//  pthread_mutex_setname_np(&mutex, (name + "_toi_mutex").c_str(), 0);
+  defaultValue = 0;
+  producer = NULL;
+  dbg = false;
+}
+
+TOI::~TOI() {
+  pthread_mutex_destroy(&mutex);
+}
+
+void TOI::setProducer(TOIProcessor* p) {
+  if (producer) 
+    throw DuplicateIdExc("TOI::setProducer : producer already defined");
+  producer = p;
+}
+
+void TOI::addConsumer(TOIProcessor* p) {
+  consumers.push_back(p);
+}
+
+int TOI::getMinSn(){
+  return producer->getMinOut();
+}
+
+int TOI::getMaxSn(){
+  return producer->getMaxOut();
+}
+
+#ifndef NO_SOPHYA
+Array TOI::getError(int iStart, int iEnd) {
+  if (errorTOI == NULL) throw NotFoundExc("TOI::getDataError : no Error TOI");
+  return errorTOI->getData(iStart, iEnd);
+}
+#endif
+
+double TOI::getError(int i) {
+  if (errorTOI == NULL) throw NotFoundExc("TOI::getDataError : no Error TOI");
+  return errorTOI->getData(i);
+}
+
+void TOI::putDataError(int i, double value, double error, int_4 flag) {
+  if (errorTOI == NULL) throw NotFoundExc("TOI::getDataError : no Error TOI");
+  putData(i, value, flag);
+  errorTOI->putData(i, value, flag);
+}
+
+#ifndef NO_SOPHYA
+Array TOI::getData(int iStart, int iEnd) {
+  lock();
+  Array a = doGetData(iStart, iEnd);
+  unlock();
+  return a;
+}
+#endif
+
+double TOI::getData(int i) {
+  lock();
+  double dat = doGetData(i);
+  unlock();
+  return dat;
+}
+
+
+#ifndef NO_SOPHYA
+TArray<int_4> TOI::getFlag(int iStart, int iEnd) {
+  lock();
+  TArray<int_4> a = doGetFlag(iStart, iEnd);
+  unlock();
+  return a;
+}
+#endif
+
+int_4 TOI::getFlag(int i) {
+  lock();
+  int_4 f = doGetFlag(i);
+  unlock();
+  return f;
+}
+  
+  
+
+void TOI::putData(int i, double value, int_4 flag) {
+  lock();
+  doPutData(i, value, flag);
+  unlock();
+}
+
+void TOI::waitForData(int iStart, int iEnd) {
+  if (producer == NULL) throw NotFoundExc("TOI has no producer !");
+    
+  DataStatus s = isDataAvail(iStart, iEnd);
+  if (s == DATA_OK) {
+      return;
+  }
+  if (s == DATA_DELETED) {
+      throw NotFoundExc("Data has been purged !");
+  }
+
+  producer->lock();
+  while (isDataAvailNL(iStart, iEnd) == DATA_NOT_YET) {
+    producer->wait();
+  }
+  producer->unlock();
+  return;
+}
+
+void TOI::waitForData(int i) {
+  waitForData(i,i);
+}
+
+void TOI::waitForAnyData() {
+  if (! hasSomeData()) {
+    producer->lock();
+    producer->wait();
+    producer->unlock();
+  }
+}
+
+TOI::DataStatus TOI::isDataAvail(int i) {
+  lock();
+  DataStatus stat = isDataAvailNL(i);
+  unlock();
+  return stat;
+}
+
+TOI::DataStatus TOI::isDataAvail(int i, int j) {
+  lock();
+  DataStatus stat = isDataAvailNL(i,j);
+  unlock();
+  return stat;
+}
+
+TOI::DataStatus TOI::isDataAvailNL(int i) {
+  return isDataAvailNL(i,i);
+}
+
+void TOI::wontNeedBefore(int i) {
+  int j=i;
+  for (vector<TOIProcessor*>::iterator k = consumers.begin();
+       k != consumers.end(); k++) {
+    if ((*k)->wontNeedValue < j) j = (*k)->wontNeedValue;
+  }
+  lock();
+  doWontNeedBefore(j);
+  unlock();
+}
+
+void TOI::doWontNeedBefore(int i) {
+}
+
+
+TOIRegularWindow::TOIRegularWindow() {
+  i0 = -1;
+}
+
+TOIRegularWindow::TOIRegularWindow(string nm) {
+  i0 = -1;
+  setName(nm);
+}
+
+TOIRegularWindow::~TOIRegularWindow() {
+}
+
+TOI::DataStatus TOIRegularWindow::isDataAvailNL(int iStart, int iEnd) {
+  if (iEnd >= i0 + (long)data.size()) return DATA_NOT_YET;
+  if (iStart < i0) return DATA_DELETED;
+  return DATA_OK;
+}
+
+TOI::DataStatus TOIRegularWindow::isDataAvailNL(int i) {
+  return TOI::isDataAvailNL(i);
+}
+
+void TOIRegularWindow::doWontNeedBefore(int i) {
+  if (i>= i0 + (long)data.size())
+    i = i0 + (long)data.size() - 1;
+  if (i>i0) {  // don't empty list
+    int osz = data.size();
+    data.erase(data.begin(), data.begin()+(i-i0));
+    flags.erase(flags.begin(), flags.begin()+(i-i0));
+    i0 = i;
+  }
+}
+
+
+#ifndef NO_SOPHYA
+Array TOIRegularWindow::doGetData(int iStart, int iEnd) {
+  if (!isDataAvailNL(iStart, iEnd)) throw RangeCheckError("TOI::getData : data not available");
+  Array dat(iEnd - iStart + 1);
+  long j0 = iStart - i0;
+  for (int i=0; i<iEnd-iStart+1; i++) {
+    dat[i] = data[i+j0];
+  }
+  return dat;
+}
+#endif
+
+double TOIRegularWindow::doGetData(int i) {
+  if (isDataAvailNL(i) != DATA_OK) throw RangeCheckError("TOI::getData : data not available");
+  double dat = data[i - i0];
+  return dat;
+}
+
+
+#ifndef NO_SOPHYA
+TArray<int_4> TOIRegularWindow::doGetFlag(int iStart, int iEnd) {
+  if (isDataAvailNL(iStart, iEnd) != DATA_OK) throw RangeCheckError("TOI::getData : data not available");
+  TArray<int_4> dat(iEnd - iStart + 1);
+  long j0 = iStart - i0;
+  for (int i=0; i<iEnd-iStart+1; i++) {
+    dat[i] = flags[i+j0];
+  }
+  return dat;
+}
+#endif
+
+int_4 TOIRegularWindow::doGetFlag(int i) {
+  if (!isDataAvailNL(i)) throw RangeCheckError("TOI::getData : data not available");
+  return flags[i - i0]; 
+}
+
+
+void TOIRegularWindow::doPutData(int i, double value, int_4 flag) {
+  if (i0 == -1) {
+    data.insert(data.begin(), 1,  defaultValue);
+    flags.insert(flags.begin(), 1,  0);
+    i0 = i;
+  } else if (i<i0) {
+    data.insert(data.begin(), i0-i, defaultValue); 
+    flags.insert(flags.begin(), i0-i, 0);
+    i0 = i;
+  } else if (i>=i0+(int)data.size()) {
+    data.insert(data.end(), (long)  (i-(i0+data.size())+1), defaultValue);
+    flags.insert(flags.end(), (long) (i-(i0+flags.size())+1), 0);
+  }
+  data[i-i0] = value;
+  flags[i-i0] = flag;  
+}
+
+bool TOIRegularWindow::hasSomeData() {
+  lock();
+  bool x = !data.empty();
+  unlock();
+  return x;
+}
+
+int TOIRegularWindow::nextDataAvail(int iAfter) {
+  lock();
+  if (iAfter >= i0 + (long)data.size()) {unlock(); return -1;}
+  if (iAfter < i0) {unlock(); return i0;}
+  unlock();
+  return iAfter+1;
+}
+
+/*  A faire, le nettoyage (heuristique selon demandes ?, guide ? ) */
+		 
+
Index: /trunk/ArchTOIPipe/Kernel/toi.h
===================================================================
--- /trunk/ArchTOIPipe/Kernel/toi.h	(revision 1365)
+++ /trunk/ArchTOIPipe/Kernel/toi.h	(revision 1365)
@@ -0,0 +1,129 @@
+// This may look like C code, but it is really -*- C++ -*-
+#ifndef TOI_H
+#define TOI_H
+
+#include "config.h"
+
+#include <pthread.h>
+#include <vector>
+using namespace std;
+
+#ifdef WITH_SOPHYA
+#include "array.h"
+#include "pexceptions.h"
+using namespace SOPHYA;
+#else
+#include "apexceptions.h"
+#endif
+
+
+
+class TOIProcessor;
+
+class TOI {
+public:
+  TOI();
+  TOI(string name);
+  virtual ~TOI();
+
+#ifdef WITH_SOPHYA
+  virtual Array         getData(int iStart, int iEnd);
+  virtual Array         getError(int iStart, int iEnd);
+  virtual TArray<int_4> getFlag(int iStart, int iEnd);
+#endif
+    
+  virtual double        getData(int i);
+  virtual double        getError(int i);
+  virtual int_4         getFlag(int i);
+
+  enum DataStatus       {DATA_OK=0, DATA_DELETED, DATA_NOT_YET};
+  virtual DataStatus    isDataAvail(int iStart, int iEnd);
+  virtual DataStatus    isDataAvail(int i);
+  virtual void          waitForData(int iStart, int iEnd);
+  virtual void          waitForData(int i);
+  virtual void          waitForAnyData();
+  virtual int           nextDataAvail(int iAfter)=0;
+  virtual bool          hasSomeData()=0;
+  
+  virtual void          putData(int i, double value, int_4 flag=0);
+  virtual void          putDataError(int i, double value, 
+		                     double error, int_4 flag=0);
+
+  virtual void          wontNeedBefore(int i);
+  
+  bool  dbg;
+
+  void setName(string n) {name =n;}
+  string getName() {return name;}
+
+protected:
+  TOI*                  errorTOI;
+  pthread_mutex_t       mutex;
+  TOIProcessor*         producer;
+  vector<TOIProcessor*> consumers;
+  double                defaultValue;
+  
+#ifdef WITH_SOPHYA
+  virtual Array         doGetData(int iStart, int iEnd)=0;
+  virtual TArray<int_4> doGetFlag(int iStart, int iEnd)=0;
+#endif
+  virtual double        doGetData(int i)=0;
+  virtual int_4         doGetFlag(int i)=0;
+  virtual void          doPutData(int i, double value, int_4 flag=0)=0;
+  virtual void          doWontNeedBefore(int i);
+
+  virtual DataStatus    isDataAvailNL(int iStart, int iEnd)=0;
+  virtual DataStatus    isDataAvailNL(int i);
+
+  virtual void          setProducer(TOIProcessor* prod);
+  virtual void          addConsumer(TOIProcessor* prod);
+  friend class          TOIProcessor;
+      
+  string name;
+
+  virtual int           getMinSn();
+  virtual int           getMaxSn();
+  void  TOIInit();
+
+  void lock() {pthread_mutex_lock(&mutex);}
+  void unlock() {pthread_mutex_unlock(&mutex);}
+
+};
+
+class TOIRegular : public TOI {
+};
+
+// Classe de TOI avec une fenetre glissante, et echantillonnage regulier.
+// Pour le moment au moins,
+// il faut que les providers fassent arriver les donnees par samplenum croissant.
+class TOIRegularWindow : public TOIRegular {
+public:
+  TOIRegularWindow();
+  TOIRegularWindow(string nm);
+  ~TOIRegularWindow();
+
+  virtual DataStatus isDataAvailNL(int iStart, int iEnd);
+  virtual DataStatus isDataAvailNL(int i); // override required
+
+
+//protected:
+  vector<double> data;
+  vector<int_4>  flags;
+  long          i0;
+  double defaultValue;
+  
+#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();
+};
+
+#endif
Index: /trunk/ArchTOIPipe/Kernel/toimanager.cc
===================================================================
--- /trunk/ArchTOIPipe/Kernel/toimanager.cc	(revision 1365)
+++ /trunk/ArchTOIPipe/Kernel/toimanager.cc	(revision 1365)
@@ -0,0 +1,44 @@
+#include "toimanager.h"
+#include <limits.h>
+#include <pthread.h>
+#include <iostream>
+
+TOIManager::TOIManager() {
+  reqBegin = 0;
+  reqEnd = LONG_MAX;
+}
+
+TOIManager* TOIManager::instance = NULL;
+
+TOIManager* TOIManager::getManager() {
+  if (instance == NULL) instance =  new TOIManager();
+  return instance;
+}
+
+void TOIManager::setRequestedSample(long begin, long end) {
+  reqBegin = begin;
+  reqEnd   = end;
+}
+
+long TOIManager::getRequestedBegin() {
+  return reqBegin;
+}
+
+long TOIManager::getRequestedEnd() {
+  return reqEnd;
+}
+
+void TOIManager::addThread(pthread_t* t) {
+  //  cout << "adding thread  "  <<  t << endl;
+  threads.push_back(t); 
+}
+
+void TOIManager::joinAll() {
+  for (vector<pthread_t*>::iterator i = threads.begin();
+       i != threads.end(); i++) {
+    pthread_t* pth = *i;
+    cout << "joining thread  " << pth <<  endl;
+    pthread_join(*pth, NULL);
+    cout << "thread joined " << pth << endl;
+  }
+}
Index: /trunk/ArchTOIPipe/Kernel/toimanager.h
===================================================================
--- /trunk/ArchTOIPipe/Kernel/toimanager.h	(revision 1365)
+++ /trunk/ArchTOIPipe/Kernel/toimanager.h	(revision 1365)
@@ -0,0 +1,26 @@
+// This may look like C code, but it is really -*- C++ -*-
+
+#ifndef TOIMANAGER_H
+#define TOIMANAGER_H
+
+#include <vector>
+
+class TOIManager {
+public:
+  static TOIManager* getManager();
+  void setRequestedSample(long begin, long end);
+  long getRequestedBegin();
+  long getRequestedEnd();
+  void addThread(pthread_t*);
+  void joinAll();
+  
+protected:
+  TOIManager();
+  static TOIManager* instance;
+  long reqBegin;
+  long reqEnd;
+
+  vector<pthread_t*> threads;
+};
+
+#endif
Index: /trunk/ArchTOIPipe/Kernel/toiprocessor.cc
===================================================================
--- /trunk/ArchTOIPipe/Kernel/toiprocessor.cc	(revision 1365)
+++ /trunk/ArchTOIPipe/Kernel/toiprocessor.cc	(revision 1365)
@@ -0,0 +1,256 @@
+#include "toiprocessor.h"
+#include "toimanager.h"
+#include <pthread.h>
+#include <values.h>
+
+#ifdef WITH_SOPHYA
+#include "pexceptions.h"
+#else
+#include "apexceptions.h"
+#endif
+
+#define pthread_mutexattr_setkind_np pthread_mutexattr_settype
+
+TOIProcessor::TOIProcessor() {
+  //cout << "TOIProcessor::TOIProcessor" << endl;
+  outTOIs = NULL;
+  inTOIs = NULL;
+  inited=false;
+
+  upExtra  = 0;
+  lowExtra = 0;
+  minOut = -1;
+  maxOut = -1;
+  neededHistory = 1000;
+  lastAWN = 0;
+  wontNeedValue = -1;
+
+}
+
+TOIProcessor::~TOIProcessor() {
+  delete[] outTOIs;
+  delete[] inTOIs;
+  //if (mutex) 
+  pthread_mutex_destroy(&mutex);
+  //if (dataReady) 
+  pthread_cond_destroy(&dataReady);
+  pthread_detach(thread);
+}
+
+
+void TOIProcessor::init() {
+  //cout << "TOIProcessor::init" << endl;
+}
+
+void TOIProcessor::afterinit() {
+  inTOIs = new (TOI*[inIx.size()]);
+  outTOIs = new (TOI*[outIx.size()]);
+}
+
+int TOIProcessor::getMinOut() {
+  //cout << name << "minout" << endl;
+  if (minOut < 0) minOut = calcMinOut();
+  //cout << name << "minout=" << minOut << endl;
+  return minOut;
+}
+
+int TOIProcessor::getMaxOut() {
+  //cout << name << "maxout" << endl;
+  if (maxOut < 0) maxOut = calcMaxOut();
+  //cout << name << "maxout=" << maxOut << endl;
+  return maxOut;
+}
+
+int TOIProcessor::calcMinOut() {
+  return getMinIn() + lowExtra;
+}
+
+int TOIProcessor::calcMaxOut() {
+  return getMaxIn() - upExtra;
+}
+
+int TOIProcessor::getMinIn() {
+  int nIn = inIx.size();
+  int minIn = 0;
+  for (int i=0; i<nIn; i++) {
+    TOI* toi = inTOIs[i];
+    int x = toi->getMinSn();
+    if (x > minIn) minIn = x;
+  }
+  return minIn;
+}
+
+int TOIProcessor::getMaxIn() {
+  int nIn = inIx.size();
+  int maxIn = MAXINT;
+  for (int i=0; i<nIn; i++) {
+    TOI* toi = inTOIs[i];
+    int x = toi->getMaxSn();
+    if (x < maxIn) maxIn = x;
+  }
+  return maxIn;
+}
+
+
+int TOIProcessor::declareInput(string toi) {
+  if (inIx.find(toi) != inIx.end())
+    throw DuplicateIdExc("TOIProcessor::declareInput : "+toi+" already declared");
+  int i = inIx.size();
+  inIx[toi] = i;
+  return i;
+}
+
+int  TOIProcessor::declareOutput(string toi) {
+  if (outIx.find(toi) != outIx.end())
+    throw DuplicateIdExc("TOIProcessor::declareInput : "+toi+" already declared");
+  int i = outIx.size();
+  outIx[toi] = i;
+  return i;
+}
+
+int TOIProcessor::getInputTOIIndex(string toi) {
+  map<string, int>::iterator i = inIx.find(toi);
+  if (i == inIx.end()) return -1;
+  return (*i).second;
+}
+
+int TOIProcessor::getOutputTOIIndex(string toi) {
+  map<string, int>::iterator i = outIx.find(toi);
+  if (i == outIx.end()) return -1;
+  return (*i).second;
+}
+
+void TOIProcessor::addInput(string name, TOI* toi) {
+  chkinit();
+  map<string, int>::iterator i = inIx.find(name);
+  if (i == inIx.end()) throw NotFoundExc("TOIProcessor::addInput "+
+					 name+" not declared");
+  inTOIs[(*i).second] = toi; 
+}
+
+void TOIProcessor::addOutput(string name, TOI* toi) {
+  chkinit();
+  map<string, int>::iterator i = outIx.find(name);
+  if (i == outIx.end()) throw NotFoundExc("TOIProcessor::addOutput "+
+					  name+" not declared");
+  toi->setProducer(this);
+  outTOIs[(*i).second] = toi; 
+}
+
+void TOIProcessor::run() {
+  
+}
+
+void* TOIProcessor::ThreadStart(void* arg) {
+  TOIProcessor* p = (TOIProcessor*) arg;
+  //  cout << p->name << " new thread running " << pthread_self() << endl;
+  p->run();
+  //  cout << p->name << " thread done " << pthread_self() << endl;
+  return NULL;
+}
+
+#ifdef Linux
+#define pthread_mutexattr_settype  pthread_mutexattr_setkind_np
+#define  PTHREAD_MUTEX_ERRORCHECK PTHREAD_MUTEX_ERRORCHECK_NP
+#define pthread_mutex_setname_np(a,b,c)
+#define pthread_cond_setname_np(a,b,c)
+#endif
+
+void TOIProcessor::start() {
+  pthread_cond_init(&dataReady, NULL);
+  pthread_mutexattr_init(&mutattr);
+  //  pthread_mutexattr_settype(&mutattr, PTHREAD_MUTEX_ERRORCHECK);
+  pthread_mutex_init(&mutex, &mutattr);
+  //pthread_mutex_setname_np(&mutex, (name + "_proc_mutex").c_str(), 0);
+  //pthread_cond_setname_np(&dataReady, (name + "_proc_cond").c_str(), 0);
+  //cout << name << " starting thread " << &thread << endl;
+  pthread_create(&thread, NULL, ThreadStart, this);
+  TOIManager::getManager()->addThread(&thread);
+}
+
+#ifndef NO_SOPHYA
+Array TOIProcessor::getData(int toiIndex, int iStart, int iEnd) {
+  TOI* toi = inTOIs[toiIndex];
+  toi->waitForData(iStart, iEnd);
+  return toi->getData(iStart, iEnd);
+}
+
+Array TOIProcessor::getError(int toiIndex, int iStart, int iEnd) {
+  TOI* toi = inTOIs[toiIndex];
+  toi->waitForData(iStart, iEnd);
+  return toi->getError(iStart, iEnd);
+}
+
+TArray<int_4> TOIProcessor::getFlag(int toiIndex, int iStart, int iEnd) {
+  TOI* toi = inTOIs[toiIndex];
+  toi->waitForData(iStart, iEnd);
+  return toi->getFlag(iStart, iEnd);
+}
+#endif
+
+double TOIProcessor::getData(int toiIndex, int i) {
+  TOI* toi = inTOIs[toiIndex];
+  toi->waitForData(i);
+  return toi->getData(i);
+}
+
+double TOIProcessor::getError(int toiIndex, int i) {
+  TOI* toi = inTOIs[toiIndex];
+  toi->waitForData(i);
+  return toi->getError(i);
+}
+
+int_4 TOIProcessor::getFlag(int toiIndex, int i) {
+  TOI* toi = inTOIs[toiIndex];
+  toi->waitForData(i);
+  return toi->getFlag(i);
+}
+
+void TOIProcessor::setNeededHistory(int nsamples) {
+  neededHistory =  nsamples;
+}
+
+void TOIProcessor::wontNeedBefore(int i) {
+  if (i<wontNeedValue) return;
+  wontNeedValue = i;
+  for (int j=0; j< (int) inIx.size();  j++) {
+    inTOIs[j]->wontNeedBefore(i);
+  }
+}
+
+void TOIProcessor::autoWontNeed(int iCur) {
+  if (neededHistory <=0) return;
+  if (iCur < lastAWN + neededHistory) return;
+  lastAWN = iCur;
+  //cout << name << " wontNeedBefore "  << iCur-neededHistory << endl;
+  wontNeedBefore(iCur-neededHistory);
+}
+
+void TOIProcessor::notify() {
+  lock();
+/*  if (mutex.__m_lock.__status == 0) {
+    cout << "wait without lock" << endl; abort();
+  }*/
+  
+  pthread_cond_broadcast(&dataReady);
+  unlock();
+}
+
+
+void TOIProcessor::putData(int toiIndex, int i, double value, int_4 flg) {
+  TOI* toi = outTOIs[toiIndex];
+  toi->putData(i, value, flg);
+  autoWontNeed(i);
+  notify();
+}
+
+
+void TOIProcessor::putDataError(int toiIndex, int i, double value, 
+				double error, int_4 flg) { 
+  TOI* toi = outTOIs[toiIndex];
+  toi->putDataError(i, value, error, flg);
+  autoWontNeed(i);
+  notify();
+}
+
+
Index: /trunk/ArchTOIPipe/Kernel/toiprocessor.h
===================================================================
--- /trunk/ArchTOIPipe/Kernel/toiprocessor.h	(revision 1365)
+++ /trunk/ArchTOIPipe/Kernel/toiprocessor.h	(revision 1365)
@@ -0,0 +1,132 @@
+// This may look like C code, but it is really -*- C++ -*-
+
+
+#ifndef TOIPROCESSOR_H
+#define TOIPROCESSOR_H
+
+#include "config.h"
+
+#include <pthread.h>
+
+#include <string>
+#include <map>
+#include <iostream>
+
+#ifndef NO_SOPHYA
+#include "tarray.h"
+using namespace SOPHYA;
+#endif
+
+#include "toi.h"
+
+
+class TOIProcessor {
+public:
+  virtual void init();  
+  // Les methodes qui suivent peuvent etre appelees par init
+protected:
+  int declareInput(string toi);
+  int declareOutput(string toi);  
+  
+  // void declareMultInput(string toi);
+  // Question : multiple output ? 
+
+  void chkinit() {
+   if (!inited) {init(); afterinit(); inited=true;}
+  }
+  bool inited;
+  virtual void afterinit();
+
+public:
+  virtual void run();
+  // Les methodes qui suivent peut etre appelees par run
+protected:
+#ifndef NO_SOPHYA
+  Array         getData(int toiIndex, int iStart, int iEnd);
+  Array         getError(int toiIndex, int iStart, int iEnd);
+  TArray<int_4> getFlag(int toiIndex, int iStart, int iEnd);
+#endif
+  // si multiple input (indexed input), tableau 2D.
+
+  // Les methodes qui suivent ne peuvent etre 
+  // utilisees que sur des entrees simples
+  double        getData(int toiIndex, int i);
+  double        getError(int toiIndex, int i);
+  int_4         getFlag(int toiIndex, int i);
+
+  void          wontNeedBefore(int i);
+  int           wontNeedValue;
+  void          setNeededHistory(int nsamples); // -1 : disable
+
+  void          putData(int toiIndex, int i, double value, int_4 flag=0);
+  void          putDataError(int toiIndex, int i, double value, 
+		             double error, int_4 flag=0);
+
+  // Gestion des bornes pour les transformations de TOIs...
+  virtual int   calcMinOut();
+  virtual int   calcMaxOut();
+
+  virtual int   getMinOut();
+  virtual int   getMaxOut();
+  int           minOut;
+  int           maxOut;
+
+  virtual int   getMinIn();
+  virtual int   getMaxIn();
+  // Implementation par defaut
+  int           upExtra;
+  int           lowExtra;
+
+  int           neededHistory;
+
+protected:
+  int           getInputTOIIndex(string toi);
+  int           getOutputTOIIndex(string toi);
+  void          autoWontNeed(int iCur);
+  int           lastAWN;
+
+public:
+  // Appele par les assembleurs de pipeline
+  virtual void  addInput(string name, TOI* toi);
+  virtual void  addOutput(string name, TOI* toi);
+
+  virtual void  start();
+  
+  TOIProcessor();
+  virtual ~TOIProcessor();
+
+protected:
+
+  map<string, int> inIx;
+  map<string, int> outIx;
+  TOI**  inTOIs;
+  TOI**  outTOIs;
+
+  string name;
+  // Thread handling
+  pthread_t        thread;
+  pthread_cond_t   dataReady;
+  pthread_mutex_t  mutex;
+  pthread_mutexattr_t mutattr;
+
+  void lock() {
+    pthread_mutex_lock(&mutex);
+  }
+
+  void unlock() {
+    pthread_mutex_unlock(&mutex);
+  }
+  
+  void wait()   {
+    pthread_cond_wait(&dataReady, &mutex); 
+  }
+
+  void notify();
+  
+
+  friend class TOI;
+  
+  static void* ThreadStart(void *);
+};
+
+#endif
Index: /trunk/ArchTOIPipe/Makefile.in
===================================================================
--- /trunk/ArchTOIPipe/Makefile.in	(revision 1365)
+++ /trunk/ArchTOIPipe/Makefile.in	(revision 1365)
@@ -0,0 +1,88 @@
+srcdir = @srcdir@
+#VPATH = @srcdir@
+INSTALL = @INSTALL@
+prefix = @prefix@
+exec_prefix = @exec_prefix@
+bindir = @bindir@
+CXX=@CXX@
+CXXFLAGS=-O -g
+CFLAGS=-O -g
+
+USE_SOPHYA=@use_sophya@
+
+MACHEROS := $(shell echo `uname`)
+MACHDIR := $(MACHEROS)-$(CXX)
+
+
+ifeq ($(USE_SOPHYA),1) 
+ include $(DPCDEVREP)/Include/Makefile.h
+
+ ifdef NOSHLIB
+  LIBF =  $(LIB)libSysTools.a $(LIB)libNTools.a $(LIB)libBlitz.a $(LIB)libFitsIOServer.a $(LIB)libPI.a $(LIB)libPIext.a 
+  LIBS = -L$(LIB) -lPIext -lPI -lSysTools -lNTools -lBlitz  -lm
+  ifeq ($(CXX),cxx)
+   # librairie des instances de templates cxx
+   LIBS := $(LIBS) -lrt
+  endif
+ else
+  LIBF =  $(SLB)libsophya.so 
+  LIBS = -L$(SLB) -lPI -lextsophya -lsophya -lm 
+  ifeq ($(MACHEROS),OSF1)
+   LIBS := $(LIBS) -lfor
+  endif
+  ifeq ($(MACHEROS),Linux)
+   LIBS := $(LIBS) -ldl -lf2c
+  endif
+ endif
+ 
+ CPPFLAGS := -DWITH_SOPHYA $(CPPFLAGS)
+else
+ ifeq ($(CXX), cxx)
+  CXXFLAGS := -O -g -D__USE_STD_IOSTREAM
+ endif
+endif
+
+
+CPPFLAGS    :=  $(CPPFLAGS) @cfitsincdir@ -I. -DANSI 
+
+LDLIBS=@cfitslibdir@ -lcfitsio $(LIBS)
+
+ifeq ($(MACHEROS),IRIX64)
+ ifeq ($(CXX), g++)
+   LDLIBS=@cfitslibdir@ -lcfitsio -L /usr/lib32/
+ endif
+ ifeq ($(CXX), CC)
+   CXXFLAGS = -LANG:std -woff 1171,1174,1552 -O -OPT:Olimit=0
+   CFLAGS  =  -O -OPT:Olimit=0
+ endif
+endif
+
+ifeq ($(CXX), g++)
+  CC = gcc
+endif
+
+default:
+	echo "no program specified"
+
+clean:
+	rm -f *.o 
+	rm -rf rii_files ii_files cxxrep cxx_repository
+
+SRCFILES=@srcfiles@
+
+FILES=$(patsubst %.c,%.o,$(SRCFILES:.cc=.o))
+
+%: %.o $(FILES)
+	$(LINK.cc) $^ $(LOADLIBES) $(LDLIBS) -pthread -o $@ -lm
+
+%.o:$(srcdir)/%.cc
+	$(COMPILE.cc) -pthread -o $@ $<
+
+
+
+%.d: $(srcdir)/%.cc
+	$(SHELL) -ec 'gcc -MM $(CPPFLAGS) -I. $< \
+		| sed '\''s/\($*\)\.o[ :]*/\1.o $@ : /g'\'' > $@; \
+		[ -s $@ ] || rm -f $@'
+
+include $(SRCFILES:.cc=.d)
Index: /trunk/ArchTOIPipe/Processors/toisqfilter.cc
===================================================================
--- /trunk/ArchTOIPipe/Processors/toisqfilter.cc	(revision 1365)
+++ /trunk/ArchTOIPipe/Processors/toisqfilter.cc	(revision 1365)
@@ -0,0 +1,28 @@
+#include "toisqfilter.h"
+#include "toimanager.h"
+
+void TOISqFilter::init() {
+  cout << "TOISqFilter::init" << endl;
+  declareInput("signal");
+  declareOutput("out");
+  name = "sqfilt";
+  upExtra = 1;
+}
+
+void TOISqFilter::run() {
+  TOIManager* mgr = TOIManager::getManager();
+  int snb = getMinOut();
+  int sne = getMaxOut();
+
+  for (int sn = snb; sn <= sne; sn++) {
+    try {
+      double x1 = getData(0, sn);
+      double x2 = getData(0, sn+1);
+      double y = (x1+x2)/2;
+      putData(0, sn, y);
+    } catch (PException e) {
+      cout << "TOISqFilter exception " << e.Msg() << endl;
+      continue;
+    }
+  }
+}
Index: /trunk/ArchTOIPipe/Processors/toisqfilter.h
===================================================================
--- /trunk/ArchTOIPipe/Processors/toisqfilter.h	(revision 1365)
+++ /trunk/ArchTOIPipe/Processors/toisqfilter.h	(revision 1365)
@@ -0,0 +1,14 @@
+// This may look like C code, but it is really -*- C++ -*-
+
+#ifndef TOISQFILTER_H
+#define TOISQFILTER_H
+
+#include "toiprocessor.h"
+
+class TOISqFilter : public TOIProcessor {
+public:
+  virtual void init();  
+  virtual void run();
+};
+
+#endif
Index: /trunk/ArchTOIPipe/TestPipes/tsttoi.cc
===================================================================
--- /trunk/ArchTOIPipe/TestPipes/tsttoi.cc	(revision 1365)
+++ /trunk/ArchTOIPipe/TestPipes/tsttoi.cc	(revision 1365)
@@ -0,0 +1,35 @@
+#include "toi.h"
+#include "toiprocessor.h"
+#include "fitstoirdr.h"
+#include "fitstoiwtr.h"
+#include "toisqfilter.h"
+#include "toimanager.h"
+
+int main(int argc, char** argv) {
+  cout << "tsttoi starting" << endl;
+  TOIManager* mgr = TOIManager::getManager();
+  mgr->setRequestedSample(11680920,11710584);
+  TOISqFilter f;
+  FITSTOIReader r(argv[1]); cout << "reader created" << endl;
+  FITSTOIWriter w(argv[2]);
+
+  
+  TOI* toi = new TOIRegularWindow("t1");
+  //  toi->dbg=true;
+  r.addOutput("boloMuV_11", toi);
+  f.addInput("signal", toi);
+
+  toi = new TOIRegularWindow("t2");
+  // toi->dbg = true;
+  f.addOutput("out", toi);
+  w.addInput("bolo_filtered", toi);
+  
+  cout << "starting" << endl;
+
+  r.start();
+  w.start();
+  f.start();
+
+  cout << "joining" << endl;
+  mgr->joinAll();
+}
Index: /trunk/ArchTOIPipe/TestPipes/tsttoi2.cc
===================================================================
--- /trunk/ArchTOIPipe/TestPipes/tsttoi2.cc	(revision 1365)
+++ /trunk/ArchTOIPipe/TestPipes/tsttoi2.cc	(revision 1365)
@@ -0,0 +1,28 @@
+#include "toi.h"
+#include "toiprocessor.h"
+#include "fitstoirdr.h"
+#include "fitstoiwtr.h"
+#include "toisqfilter.h"
+#include "toimanager.h"
+
+void main(int argc, char** argv) {
+  cout << "tsttoi starting" << endl;
+  TOIManager* mgr = TOIManager::getManager();
+  mgr->setRequestedSample(11680920,11710584);
+  FITSTOIReader r(argv[1]); cout << "reader created" << endl;
+  FITSTOIWriter w(argv[2]);
+
+  
+  TOI* toi = new TOIRegularDeque("t1");
+  //  toi->dbg=true;
+  r.addOutput("boloMuV_11", toi);
+  w.addInput("bolo_filtered", toi);
+  
+  cout << "starting" << endl;
+
+  r.start();
+  w.start();
+
+  cout << "joining" << endl;
+  mgr->joinAll();
+}
Index: /trunk/ArchTOIPipe/conf.h.in
===================================================================
--- /trunk/ArchTOIPipe/conf.h.in	(revision 1365)
+++ /trunk/ArchTOIPipe/conf.h.in	(revision 1365)
@@ -0,0 +1,25 @@
+/* conf.h.in.  Generated automatically from configure.in by autoheader.  */
+
+/* Define if you have the ANSI C header files.  */
+#undef STDC_HEADERS
+
+/* The number of bytes in a double.  */
+#undef SIZEOF_DOUBLE
+
+/* The number of bytes in a float.  */
+#undef SIZEOF_FLOAT
+
+/* The number of bytes in a int.  */
+#undef SIZEOF_INT
+
+/* The number of bytes in a long.  */
+#undef SIZEOF_LONG
+
+/* The number of bytes in a long double.  */
+#undef SIZEOF_LONG_DOUBLE
+
+/* The number of bytes in a short.  */
+#undef SIZEOF_SHORT
+
+/* Define if you have the m library (-lm).  */
+#undef HAVE_LIBM
Index: /trunk/ArchTOIPipe/config.h
===================================================================
--- /trunk/ArchTOIPipe/config.h	(revision 1365)
+++ /trunk/ArchTOIPipe/config.h	(revision 1365)
@@ -0,0 +1,20 @@
+#ifndef CONFIG_H
+#define CONFIG_H
+
+#define _GNU_SOURCE
+
+#include "conf.h"
+
+
+#ifndef WITH_SOPHYA
+#define NO_SOPHYA
+#if SIZEOF_SHORT == 4
+  #define int_4  short int
+#elif SIZEOF_INT == 4
+  #define int_4  int
+#else
+  #define int_4  long
+#endif
+#endif
+
+#endif
Index: /trunk/ArchTOIPipe/configure.in
===================================================================
--- /trunk/ArchTOIPipe/configure.in	(revision 1365)
+++ /trunk/ArchTOIPipe/configure.in	(revision 1365)
@@ -0,0 +1,83 @@
+dnl Process this file with autoconf to produce a configure script.
+AC_INIT(toi.cc)
+AC_CONFIG_HEADER(conf.h)
+
+AC_ARG_WITH(sophya, [  --with-sophya           Compile and link with SOPHYA],
+	use_sophya=1, use_sophya=0)
+
+AC_SUBST(use_sophya)
+
+if test `uname` = OSF1 -a -z "$CXX"; then
+  if test -x /usr/bin/cxx; then
+    echo "using cxx on alpha"
+    CXX=cxx
+    export CXX
+  fi
+fi
+
+AC_PROG_CXX
+
+AC_CHECK_SIZEOF(short)
+AC_CHECK_SIZEOF(int)
+AC_CHECK_SIZEOF(long)
+AC_CHECK_SIZEOF(float)
+AC_CHECK_SIZEOF(double)
+AC_CHECK_SIZEOF(long double)
+
+dnl look for cfitsio include and cfitsio library
+dnl if installed in /usr/local, nothing to do
+
+AC_MSG_CHECKING("for cfitsio lib")
+MACHDIR=`uname`-$CXX
+if test -f $ARCHBASEREP/$MACHDIR/Libs/libcfitsio.a; then
+  cfitslibdir='-L$(ARCHBASEREP)/$(MACHDIR)/Libs'
+elif test -f $CFITSIOLIBDIR/$MACHDIR/Libs/libcfitsio.a; then
+  cfitslibdir='-L$(CFITSIOLIBDIR)/$(MACHDIR)/Libs'
+elif test -f $CFITSIOLIBDIR/$MACHDIR/libcfitsio.a; then
+  cfitslibdir='-L$(CFITSIOLIBDIR)/$(MACHDIR)'
+elif test -f $CFITSIOLIBDIR/`uname`/lib/libcfitsio.a; then
+  cfitslibdir='-L$(CFITSIOLIBDIR)/'`uname`/lib
+elif test -f $CFITSIOLIBDIR/`uname`/libcfitsio.a; then
+  cfitslibdir='-L$(CFITSIOLIBDIR)/'`uname`
+elif test -f $CFITSIOLIBDIR/libcfitsio.a; then
+  cfitslibdir='-L$(CFITSIOLIBDIR)'
+elif test -f $CFITSIODIR/libcfitsio.a; then
+  cfitslibdir='-L$(CFITSIODIR)'
+elif test -f /usr/local/lib/libcfitsio.a; then
+  cfitslibdir=""
+else 
+  AC_MSG_ERROR("Cannot find cfitsio library")
+fi
+AC_MSG_RESULT($cfitslibdir)
+AC_SUBST(cfitslibdir)
+
+AC_MSG_CHECKING("for cfitsio includes")
+if test -f $CFITSIODIR/fitsio.h; then
+  cfitsincdir='-I$(CFITSIODIR)'
+elif test -f /usr/local/include/fitsio.h; then
+  cfitsincdir=""
+else
+  AC_MSG_ERROR("Cannot find cfitsio include fitsio.h")
+fi
+AC_MSG_RESULT($cfitsincdir)
+AC_SUBST(cfitsincdir)
+
+dnl Checks for libraries.
+dnl AC_CHECK_LIB(cfitsio, ffread,,AC_MSG_ERROR("Cannot find cfitsio library"))
+AC_CHECK_LIB(m, sin)
+
+AC_MSG_CHECKING("for source files in distribution")
+srcfiles=""
+curd=`pwd`
+cd $srcdir
+for n in *.cc; do
+  grep -q 'main(.*)' $n || srcfiles="$srcfiles $n"
+done
+cd $curd
+AC_SUBST(srcfiles)
+AC_MSG_RESULT("done")
+
+dnl Checks for header files.
+AC_HEADER_STDC
+
+AC_OUTPUT(Makefile)
