Index: /trunk/ArchTOIPipe/Kernel/Makefile.in
===================================================================
--- /trunk/ArchTOIPipe/Kernel/Makefile.in	(revision 2384)
+++ /trunk/ArchTOIPipe/Kernel/Makefile.in	(revision 2385)
@@ -65,5 +65,5 @@
            fitstoirdr.cc fitstoiwtr.cc asciitoiwtr.cc \
 	   toisegment.cc toiseqbuff.cc cgt.cc \
-           ring.cc \
+           ring.cc ringpipe.cc ringprocessor.cc \
 	   fitsringwtr.cc fitsringrdr.cc $(PIOFILES)
 
Index: /trunk/ArchTOIPipe/Kernel/ring.cc
===================================================================
--- /trunk/ArchTOIPipe/Kernel/ring.cc	(revision 2385)
+++ /trunk/ArchTOIPipe/Kernel/ring.cc	(revision 2385)
@@ -0,0 +1,39 @@
+// ArchTOIPipe           (C)     CEA/DAPNIA/SPP IN2P3/LAL
+//                               Eric Aubourg
+//                               Christophe Magneville
+//                               Reza Ansari
+// $Id: ring.cc,v 1.1 2003-05-19 23:31:29 aubourg Exp $
+
+#include "ring.h"
+#include "ringphase.h"
+
+Ring::Ring(int ns, double th, double p, double ap, RingPhase* rp) 
+  : n(ns), theta(th), phi(p), aperture(ap), ringPhase(rp), ownRingPhase(false), data(new double[ns])
+{
+  if (ringPhase == NULL) {
+    ringPhase = new SimpleRingPhase(n);
+    ownRingPhase = true;
+  }
+}
+
+Ring::~Ring() {
+  if (ownRingPhase) delete ringPhase;
+  delete[] data;
+}
+
+void Ring::setData(double* d) {
+  memcpy(data, d, n*sizeof(double));
+}
+
+void Ring::setData(int i, double d) {
+  data[i] = d;
+}
+
+const double* Ring::getData() const {
+  return data;
+}
+
+double Ring::getData(int i) const {
+  return data[i];
+}
+
Index: /trunk/ArchTOIPipe/Kernel/ring.h
===================================================================
--- /trunk/ArchTOIPipe/Kernel/ring.h	(revision 2385)
+++ /trunk/ArchTOIPipe/Kernel/ring.h	(revision 2385)
@@ -0,0 +1,55 @@
+// This may look like C code, but it is really -*- C++ -*-
+
+// ArchTOIPipe           (C)     CEA/DAPNIA/SPP IN2P3/LAL
+//                               Eric Aubourg
+//                               Christophe Magneville
+//                               Reza Ansari
+// $Id: ring.h,v 1.1 2003-05-19 23:31:29 aubourg Exp $
+
+#ifndef RING_H
+#define RING_H
+
+#include "config.h"
+using namespace std;
+
+#ifdef WITH_SOPHYA
+#include "array.h"
+#include "pexceptions.h"
+using namespace SOPHYA;
+#else
+#include "apexceptions.h"
+#endif
+
+class RingProcessor;
+class RingPhase;
+
+class Ring {
+public:
+  Ring(int nsamples, double theta, double phi, double aperture, RingPhase* phinfo = NULL);
+  virtual ~Ring();
+
+  void setData(double* data);
+  void setData(int i, double data);
+  
+  const double* getData() const; 
+  double getData(int i) const;
+
+  int getNSamples() const {return n;}
+  double getTheta() const {return theta;}
+  double getPhi() const {return phi;}
+  double getAperture() const {return aperture;}
+
+  
+protected:
+  int n;
+  double theta;
+  double phi;
+  double aperture;
+  RingPhase* ringPhase;
+  bool ownRingPhase;
+  double* data;
+};
+  
+  
+#endif
+
Index: /trunk/ArchTOIPipe/Kernel/ringphase.h
===================================================================
--- /trunk/ArchTOIPipe/Kernel/ringphase.h	(revision 2385)
+++ /trunk/ArchTOIPipe/Kernel/ringphase.h	(revision 2385)
@@ -0,0 +1,43 @@
+// This may look like C code, but it is really -*- C++ -*-
+
+// ArchTOIPipe           (C)     CEA/DAPNIA/SPP IN2P3/LAL
+//                               Eric Aubourg
+//                               Christophe Magneville
+//                               Reza Ansari
+// $Id: ringphase.h,v 1.1 2003-05-19 23:31:29 aubourg Exp $
+
+#ifndef RINGPHASE_H
+#define RINGPHASE_H
+
+#include "config.h"
+using namespace std;
+
+#ifdef WITH_SOPHYA
+#include "array.h"
+#include "pexceptions.h"
+using namespace SOPHYA;
+#else
+#include "apexceptions.h"
+#endif
+
+class RingPhase {
+public:
+  virtual ~RingPhase() {};
+
+  virtual int getNSamples() const = 0;
+  virtual double getPhase(int i) const = 0;
+
+};
+
+class SimpleRingPhase : public RingPhase {
+public:
+  SimpleRingPhase(int nsamples) : n(nsamples) {}
+  
+  int getNSamples() const {return n;}
+  double getPhase(int i) const {return (double)i / n;}
+  
+protected:
+  int n;
+};
+
+#endif
Index: /trunk/ArchTOIPipe/Kernel/ringpipe.cc
===================================================================
--- /trunk/ArchTOIPipe/Kernel/ringpipe.cc	(revision 2385)
+++ /trunk/ArchTOIPipe/Kernel/ringpipe.cc	(revision 2385)
@@ -0,0 +1,106 @@
+// ArchTOIPipe           (C)     CEA/DAPNIA/SPP IN2P3/LAL
+//                               Eric Aubourg
+//                               Christophe Magneville
+//                               Reza Ansari
+// $Id: ringpipe.cc,v 1.1 2003-05-19 23:31:29 aubourg Exp $
+
+#include "ringpipe.h"
+#include "ringprocessor.h"
+
+
+#ifdef WITH_SOPHYA
+#include "pexceptions.h"
+#else
+#include "apexceptions.h"
+#endif
+
+RingPipe::RingPipe() {
+  i0 = -1;
+  producer = NULL;
+  pthread_cond_init(&ringReady, NULL);
+  pthread_mutexattr_init(&mutattr);
+  pthread_mutex_init(&mutex, &mutattr);
+}
+
+RingPipe::~RingPipe() {
+  pthread_mutex_destroy(&mutex);
+  pthread_cond_destroy(&ringReady);
+}
+
+Ring const* RingPipe::getRing(int i) {
+  lock();
+  waitForRing(i);
+  Ring const* ring =  data[i-i0];
+  unlock();
+  return ring;
+}
+
+void RingPipe::putRing(int i, Ring const* ring) {
+  lock();
+  if (i0 == -1) {
+    data.insert(data.begin(), 1, (Ring const*) NULL);
+    i0 = i;
+  } else if (i<i0) {
+    data.insert(data.begin(), i0-i, (Ring const*) NULL); 
+    i0 = i;
+  } else if (i>=i0+(int)data.size()) {
+    data.insert(data.end(), (long)  (i-(i0+data.size())+1),  (Ring const*)NULL);
+  }
+  data[i-i0] = ring;
+  notify();
+  unlock();
+}
+
+void RingPipe::waitForRing(int i) {
+  if (producer == NULL) throw NotFoundExc("RingPipe has no producer !");
+  
+  DataStatus s = isRingAvail(i);
+  if (s == DATA_OK) {
+    return;
+  }
+  if (s == DATA_DELETED) {
+    throw NotFoundExc("Data has been deleted !");
+  }
+
+  while (isRingAvail(i) == DATA_NOT_YET) {
+    wait();
+  }
+  return;
+}
+
+void RingPipe::getRingRange(int& min, int& max) {
+  producer->getRingRange(min, max);
+}
+
+RingPipe::DataStatus RingPipe::isRingAvail(int i) {
+  if (i >= i0 + (long)data.size()) return DATA_NOT_YET;
+  if (i < i0) return DATA_DELETED;
+  return DATA_OK;
+}
+
+void RingPipe::wontNeedRingBefore(int i) {
+  int j=i;
+  for (vector<RingProcessor*>::iterator k = consumers.begin();
+       k != consumers.end(); k++) {
+    if ((*k)->getWontNeedBefore() < j) j = (*k)->getWontNeedBefore();
+  }
+  lock();
+  if (i >= i0 + (long)data.size())
+    i = i0 + (long)data.size() -1;
+  if (i > i0) {
+    data.erase(data.begin(), data.begin()+(i-i0));
+    i0=i;
+  }
+  unlock();
+}
+
+void RingPipe::addConsumer(RingProcessor* cons) {
+  consumers.push_back(cons);
+}
+
+void RingPipe::setProducer(RingProcessor* proc) {
+  if (producer) 
+    throw DuplicateIdExc("RingPipe::setProducer : producer already defined");
+  producer = proc;
+}
+
Index: /trunk/ArchTOIPipe/Kernel/ringpipe.h
===================================================================
--- /trunk/ArchTOIPipe/Kernel/ringpipe.h	(revision 2385)
+++ /trunk/ArchTOIPipe/Kernel/ringpipe.h	(revision 2385)
@@ -0,0 +1,62 @@
+// This may look like C code, but it is really -*- C++ -*-
+
+// ArchTOIPipe           (C)     CEA/DAPNIA/SPP IN2P3/LAL
+//                               Eric Aubourg
+//                               Christophe Magneville
+//                               Reza Ansari
+// $Id: ringpipe.h,v 1.1 2003-05-19 23:31:29 aubourg Exp $
+
+#ifndef RINGPIPE_H
+#define RINGPIPE_H
+
+#include "config.h"
+
+#include <vector>
+
+#include <pthread.h>
+
+class RingProcessor;
+class Ring;
+
+class RingPipe {
+public:
+  RingPipe();
+  virtual ~RingPipe();
+
+  virtual Ring const* getRing(int i);
+  virtual void putRing(int i, Ring const* ring);
+
+  virtual void wontNeedRingBefore(int i);
+
+protected:
+  pthread_mutex_t       mutex;
+  pthread_mutexattr_t   mutattr;
+  pthread_cond_t        ringReady;
+  
+  RingProcessor* producer;
+  vector<RingProcessor*> consumers;
+
+  virtual void          setProducer(RingProcessor* prod);
+  virtual void          addConsumer(RingProcessor* prod);
+
+  friend class RingProcessor;
+
+  void lock() {pthread_mutex_lock(&mutex);}
+  void unlock() {pthread_mutex_unlock(&mutex);}
+  void wait() {pthread_cond_wait(&ringReady, &mutex);}
+  void notify() {pthread_cond_broadcast(&ringReady);}
+
+  vector<Ring const*> data;
+  int i0;
+
+  enum DataStatus {DATA_OK=0, DATA_DELETED, DATA_NOT_YET};
+
+  virtual void waitForRing(int i); // should be locked before
+  virtual DataStatus isRingAvail(int i);  // should be locked before
+
+  virtual void getRingRange(int& min, int& max);
+};
+
+
+#endif
+
Index: /trunk/ArchTOIPipe/Kernel/ringprocessor.cc
===================================================================
--- /trunk/ArchTOIPipe/Kernel/ringprocessor.cc	(revision 2385)
+++ /trunk/ArchTOIPipe/Kernel/ringprocessor.cc	(revision 2385)
@@ -0,0 +1,182 @@
+// ArchTOIPipe           (C)     CEA/DAPNIA/SPP IN2P3/LAL
+//                               Eric Aubourg
+//                               Christophe Magneville
+//                               Reza Ansari
+// $Id: ringprocessor.cc,v 1.1 2003-05-19 23:31:29 aubourg Exp $
+
+#include "ringprocessor.h"
+#include "ringpipe.h"
+
+#include <iostream>
+#include <typeinfo>        // ajout pour linux
+#ifdef HAVE_VALUES_H
+#include <values.h>
+#endif
+#ifndef MAXINT
+#define MAXINT 2147483647
+#endif
+
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#endif
+
+
+#ifdef WITH_SOPHYA
+#include "pexceptions.h"
+#else
+#include "apexceptions.h"
+#endif
+
+RingProcessor::RingProcessor() {
+  outRings = NULL;
+  inRings = NULL;
+  inited = false;
+
+  ringBegin = 0;
+  ringEnd = MAXINT;
+
+  wontNeedRing = -1;
+}
+
+RingProcessor::~RingProcessor() {
+  delete[] inRings;
+  delete[] outRings;
+}
+
+
+void RingProcessor::init()
+{}
+
+void RingProcessor::afterinit() {
+  inRings = new (RingPipe*[inRingIx.size()]);
+  for (int i=0; i<inRingIx.size(); i++)
+    inRings[i] = NULL;
+  outRings = new (RingPipe*[outRingIx.size()]);
+  for (int i=0; i<outRingIx.size(); i++)
+    outRings[i] = NULL;
+}
+
+
+
+int RingProcessor::declareRingInput(string ring) {
+  if (inRingIx.find(ring) != inRingIx.end())
+    throw DuplicateIdExc("RingProcessor::declareRingInput : "+ring+
+			 " already declared");
+  int i = inRingIx.size();
+  inRingIx[ring] = i;
+  return i;
+}
+
+
+int RingProcessor::declareRingOutput(string ring) {
+  if (outRingIx.find(ring) != outRingIx.end())
+    throw DuplicateIdExc("RingProcessor::declareRingOutput : "+ring+
+			 " already declared");
+  int i = outRingIx.size();
+  outRingIx[ring] = i;
+  return i;
+}
+
+void RingProcessor::addRingInput(string name, RingPipe* ring) {
+  chkinit();
+  map<string, int>::iterator i = inRingIx.find(name);
+  if (i == inRingIx.end()) throw NotFoundExc("RingProcessor::addInput "+
+					 name+" not declared");
+  inRings[(*i).second] = ring;
+  ring->addConsumer(this);  
+}
+
+void RingProcessor::addRingOutput(string name, RingPipe* ring) {
+  chkinit();
+  map<string, int>::iterator i = outRingIx.find(name);
+  if (i == outRingIx.end()) throw NotFoundExc("RingProcessor::addOutput "+
+					  name+" not declared");
+  ring->setProducer(this);
+  outRings[(*i).second] = ring;
+}
+
+void RingProcessor::run()
+{}
+
+void* RingProcessor::ThreadStart(void* arg) {
+  RingProcessor* r = (RingProcessor*) arg;
+  try {
+    r->run();
+  }
+  catch (PThrowable & exc) {
+    cerr << "\n RingProcessor::ThreadStart() Catched Exception RingProcessor@" 
+	 << hex << r << dec << "\n"  
+	 << (string)typeid(exc).name() 
+	 << " - Msg= " << exc.Msg() << endl;
+  }
+  catch (const std::exception & sex) {
+    cerr << "\n RingProcessor::ThreadStart() Catched std::exception RingProcessor@" 
+	 << hex << r << dec << "\n"  
+	 << (string)typeid(sex).name() << endl; 
+  }
+  catch (...) {
+    cerr << "\n RingProcessor::ThreadStart() Catched ... exception RingProcessor@" 
+	 << hex << r << dec << endl;
+  }
+  //  r->warnPutDone();
+  pthread_exit(NULL);
+  return NULL;
+}
+
+
+void RingProcessor::start() {
+  pthread_create(&thread, NULL, ThreadStart, this);
+}
+
+RingPipe* RingProcessor::getInputRing(int index) {
+  if (index >= inRingIx.size())
+    throw RangeCheckError("RingProcessor::getInputRing() out of bound");
+  RingPipe* ring = inRings[index];
+  if (ring == NULL)
+    throw NullPtrError("RingProcessor::getInputRing() - Not assigned Ring !");
+  return(ring);
+}
+
+RingPipe* RingProcessor::getOutputRing(int index) {
+  if (index >= outRingIx.size())
+    throw RangeCheckError("RingProcessor::getOutputRing() out of bound");
+  RingPipe* ring = outRings[index];
+  if (ring == NULL)
+    throw NullPtrError("RingProcessor::getOutputRing() - Not assigned Ring !");
+  return(ring);
+}
+
+
+Ring const* RingProcessor::getRing(int index, int i) {
+  RingPipe* pipe = getInputRing(index);
+  pipe->waitForRing(i);
+  return pipe->getRing(i);
+}
+
+
+void RingProcessor::putRing(int index, int i, Ring const* ring) {
+  RingPipe* pipe = getOutputRing(index);
+  if (pipe == NULL) return;
+  pipe->putRing(i, ring);
+}
+
+void RingProcessor::wontNeedRingBefore(int i) {
+  if (i<wontNeedRing) return;
+  wontNeedRing = i;
+  for (int j=0; j< (int) inRingIx.size();  j++) {
+    if (inRings[j])  inRings[j]->wontNeedRingBefore(i);
+  }
+}
+
+
+void RingProcessor::getRingRange(int& min, int&max) {
+  if (min < ringBegin) min = ringBegin;
+  if (max > ringEnd)   max = ringEnd;
+
+  for (int i=0; i<inRingIx.size(); i++)
+    inRings[i]->getRingRange(min, max);
+
+  ringBegin = min;
+  ringEnd   = max;
+}
+
Index: /trunk/ArchTOIPipe/Kernel/ringprocessor.h
===================================================================
--- /trunk/ArchTOIPipe/Kernel/ringprocessor.h	(revision 2385)
+++ /trunk/ArchTOIPipe/Kernel/ringprocessor.h	(revision 2385)
@@ -0,0 +1,83 @@
+// This may look like C code, but it is really -*- C++ -*-
+
+// ArchTOIPipe           (C)     CEA/DAPNIA/SPP IN2P3/LAL
+//                               Eric Aubourg
+//                               Christophe Magneville
+//                               Reza Ansari
+// $Id: ringprocessor.h,v 1.1 2003-05-19 23:31:29 aubourg Exp $
+
+
+
+#ifndef RINGPROCESSOR_H
+#define RINGPROCESSOR_H
+
+
+#include "config.h"
+
+#include <pthread.h>
+#include <string>
+#include <map>
+
+class Ring;
+class RingPipe;
+
+class RingProcessor {
+public:
+  RingProcessor();
+  virtual ~RingProcessor();
+  virtual void init();
+protected:
+  int declareRingInput(string ring);
+  int declareRingOutput(string ring);
+
+  void chkinit() {
+    if (!inited) {init(); afterinit(); inited=true;}
+  }
+  bool inited;
+  virtual void afterinit();
+
+public:
+  virtual void run();
+
+  virtual int getMinRingIndex();
+  virtual int getMaxRingIndex();
+  virtual void setRingRange(int min, int max) {ringBegin=min; ringEnd=max;}
+
+  virtual void addRingInput(string name, RingPipe* ring);
+  virtual void addRingOutput(string name, RingPipe* ring);
+
+  virtual void start();
+  virtual void setName(string n) {name=n;}
+
+  virtual int getWontNeedBefore() {return wontNeedRing;}
+
+  
+protected:
+  virtual Ring const* getRing(int index, int i); // le ring sera desalloue par le systeme
+  virtual void        putRing(int index, int i, Ring const*); // le ring a ete alloue par new, il sera gere
+                                                              // par le systeme.
+
+  RingPipe*        getInputRing(int index);
+  RingPipe*        getOutputRing(int index);
+  virtual void wontNeedRingBefore(int i);  
+  friend class RingPipe;
+  virtual void getRingRange(int& min, int& max);
+
+
+  int ringBegin;
+  int ringEnd;
+  int wontNeedRing;
+
+  map<string, int> inRingIx;
+  map<string, int> outRingIx;
+
+  RingPipe** inRings;
+  RingPipe** outRings;
+
+  string name;
+
+  pthread_t        thread;
+
+  static void* ThreadStart(void *);
+};
+#endif
Index: /trunk/ArchTOIPipe/Kernel/toimanager.cc
===================================================================
--- /trunk/ArchTOIPipe/Kernel/toimanager.cc	(revision 2384)
+++ /trunk/ArchTOIPipe/Kernel/toimanager.cc	(revision 2385)
@@ -3,5 +3,5 @@
 //                               Christophe Magneville
 //                               Reza Ansari
-// $Id: toimanager.cc,v 1.20 2003-02-24 14:14:51 cecile Exp $
+// $Id: toimanager.cc,v 1.21 2003-05-19 23:31:29 aubourg Exp $
 
 #include "toimanager.h"
@@ -111,4 +111,7 @@
 
 void TOIManager::setRequestedSample(int begin, int end) {
+  cout << "TOIManager::setRequestedSample should not be called anymore" << endl;
+  cout << " call same method one any toiprocessor" << endl;
+  exit(-1);
   reqBegin = begin;
   reqEnd   = end;
