Index: trunk/ArchTOIPipe/Kernel/cgt.cc
===================================================================
--- trunk/ArchTOIPipe/Kernel/cgt.cc	(revision 1994)
+++ trunk/ArchTOIPipe/Kernel/cgt.cc	(revision 1994)
@@ -0,0 +1,158 @@
+// ArchTOIPipe           (C)     CEA/DAPNIA/SPP IN2P3/LAL
+//                               Eric Aubourg
+//                               Christophe Magneville
+//                               Reza Ansari
+
+// -------------------------------------------------------------------------
+// classe CGT : Compagnie Generale des Tuyaux 
+// Gestionnaire de tuyaux (toi) et d'unites de traitements (TOIProcessor)
+//                                         R. Ansari / Mai 2002
+// -------------------------------------------------------------------------
+
+#include "cgt.h"
+#include "toiseqbuff.h"
+#include "toisegment.h"
+
+#ifdef WITH_SOPHYA
+#include "pexceptions.h"
+#else
+#include "apexceptions.h"
+#endif
+
+#include <pthread.h>
+
+CGT::CGT(bool fgsegmented, int bufsz, int maxseg)
+{
+  if (fgsegmented) {
+    SelectTOISeqBuffered(bufsz);
+    SelectTOISegmented(bufsz, maxseg);
+  }
+  else {
+    SelectTOISegmented(bufsz, maxseg);
+    SelectTOISeqBuffered(bufsz);
+  }
+}
+
+CGT::~CGT()
+{
+  vector< tuyau >::iterator it;
+  if (dbgLevel > 0) 
+    cout << " CGT::~CGT() - deleting TOI's " << endl;
+  for(it = lesTuyaux.begin(); it != lesTuyaux.end(); it++) { 
+    if (dbgLevel > 1) 
+      cout << " ... deleting TOI " << (*it).toi->getName() << endl;
+    delete (*it).toi;
+  }
+}
+
+
+void CGT::SelectTOISegmented(int bufsz, int maxseg)
+{
+  fgSegmented = true;
+  fgSeqbuff = false;
+  segBuffsz = bufsz;
+  segMaxseg = maxseg;
+}
+
+void CGT::SelectTOISeqBuffered(int wsz)
+{
+  fgSeqbuff = true;
+  fgSegmented = false;
+  seqWsz = wsz;
+} 
+
+TOI& CGT::Connect(TOIProcessor& prout, string& out, 
+		  TOIProcessor& prin, string& in, string nom, int wbsz)
+{
+  int id1 = findProcId(&prout);
+  int id2 = findProcId(&prin);
+  struct tuyau tuy;
+  tuy.pr1id = id1;
+  tuy.pr2id = id2;
+  TOI* toi;
+  if (nom.length() < 1) {
+    char buff[128];
+    sprintf(buff, "TOI%d_C[%d-%d]", (int)lesTuyaux.size(), id1, id2);
+    nom = buff;
+  }
+  if (wbsz < 16)   wbsz = (fgSegmented) ? segBuffsz : seqWsz;
+  if (fgSegmented) toi = new TOISegmented(nom, wbsz, segMaxseg);
+  else toi = new TOISeqBuffered(nom, wbsz);
+  tuy.toi = toi;
+  lesTuyaux.push_back(tuy);
+  prout.addOutput(out, toi);
+  prin.addInput(in, toi);
+  if (dbgLevel > 1)
+    cout << " CGT::Connect() TOI " << toi->getName() << " created " << endl;
+  return(*toi);
+}
+
+TOI& CGT::Connect(TOIProcessor& prout, const char* out, 
+		  TOIProcessor& prin, const char* in, string nom, int wbsz)
+{
+  string outs = out;  
+  string ins = in;
+  return Connect(prout, outs, prin, ins, nom, wbsz);
+}
+
+void CGT::ListProcs(::ostream& os, bool prstat) // const plus tard
+{
+  os << " --- CGT::ListProcs() , NbProcs=" << lesProcs.size() << " ----- " << endl;
+  //  vector< TOIProcessor*  >::const_iterator it;
+  //  for(it = lesProcs.begin(); it != lesProcs.end(); it++) { 
+  for(int i=0; i< lesProcs.size(); i++) {
+    os << " >> Proc Id= " << i << " @ " << hex << lesProcs[i] << dec << endl;
+    if (prstat) lesProcs[i]->PrintStatus(os);
+  }
+}
+
+void CGT::ListTOIs(::ostream& os, bool prstat)
+{
+  os << " --- CGT::ListTOIs() , NbProcs=" << lesTuyaux.size();
+  if ( fgSegmented ) os << " Default TOI: TOISegmented " << endl;
+  else os << " Default TOI: TOISeqBuffered " << endl;
+  for(int i=0; i< lesTuyaux.size(); i++) {
+    os << " >> TOI " << lesTuyaux[i].toi->getName() << " Connecting ProcId" 
+       << lesTuyaux[i].pr1id << " <---> " << lesTuyaux[i].pr2id << endl;
+    if (prstat) lesTuyaux[i].toi->PrintStatus(os);    
+  }  
+}
+
+void CGT::PrintStatus(::ostream & os, bool prstat)
+{
+  ListProcs(os, prstat);
+  ListTOIs(os, prstat);
+}
+
+void CGT::DeleteProcs()
+{
+  vector< TOIProcessor*  >::iterator it;
+  cout << " CGT::DeleteProcs() - deleting TOIProcessors - NProc=" 
+       << lesProcs.size() << endl;
+  for(it = lesProcs.begin(); it != lesProcs.end(); it++) {
+    if (dbgLevel > 1) 
+      cout << " ... deleting TOIProcessors @ " << hex << *it << dec << endl;
+    delete *it;
+  }
+}
+
+void CGT::Start()
+{
+  vector< TOIProcessor*  >::iterator it;
+  cout << " CGT::Start() starting TOIProcessors ... NProc=" 
+       << lesProcs.size() << endl;
+  for(int i=0; i< lesProcs.size(); i++) {
+    if (dbgLevel > 1) 
+      cout << " Staring Proc Id= " << i << " @ " << hex << lesProcs[i] << dec << endl;
+    lesProcs[i]->start();
+  }
+}
+
+int CGT::findProcId(TOIProcessor* pr)
+{
+  for(int i=0; i< lesProcs.size(); i++) 
+    if (lesProcs[i] == pr) return(i);
+
+  lesProcs.push_back(pr);
+  return(lesProcs.size()-1);
+}
Index: trunk/ArchTOIPipe/Kernel/cgt.h
===================================================================
--- trunk/ArchTOIPipe/Kernel/cgt.h	(revision 1994)
+++ trunk/ArchTOIPipe/Kernel/cgt.h	(revision 1994)
@@ -0,0 +1,60 @@
+// This may look like C code, but it is really -*- C++ -*-
+
+// ArchTOIPipe           (C)     CEA/DAPNIA/SPP IN2P3/LAL
+//                               Eric Aubourg
+//                               Christophe Magneville
+//                               Reza Ansari
+
+#ifndef CGT_H
+#define CGT_H
+
+#include "toi.h"
+#include "toiprocessor.h"
+#include <vector>
+
+// -------------------------------------------------------------------------
+// classe CGT : Compagnie Generale des Tuyaux 
+// Gestionnaire de tuyaux (toi) et d'unites de traitements (TOIProcessor)
+//                                         R. Ansari / Mai 2002
+// -------------------------------------------------------------------------
+
+class CGT {
+public:
+  CGT(bool fgsegmented = true, int bufsz=1024, int maxseg=20);
+  virtual ~CGT();
+
+  void    SelectTOISegmented(int bufsz=1024, int maxseg=20);
+  void    SelectTOISeqBuffered(int wsz=8192);
+
+  inline void  SetDebugLevel(int lev=0) {dbgLevel = lev; }
+  
+  virtual TOI& Connect(TOIProcessor& prout, string& out, 
+		       TOIProcessor& prin, string& in, string nom="", int wbsz=0);
+  virtual TOI& Connect(TOIProcessor& prout, const char* out, 
+		       TOIProcessor& prin, const char* in, string nom="", int wbsz=0);
+
+  virtual void ListProcs(::ostream& os, bool prstat=false); // const plus tard
+  virtual void ListTOIs(::ostream& os, bool prstat=false);  // const plus tard 
+  virtual void PrintStatus(::ostream & os, bool prstat=false); // const plus tard
+
+  virtual void DeleteProcs();
+  virtual void Start();
+
+protected:
+  int findProcId(TOIProcessor* pr);
+
+  struct tuyau { int pr1id; int pr2id; TOI* toi; };
+  vector< tuyau > lesTuyaux;
+  vector< TOIProcessor* > lesProcs;
+  bool fgSegmented;
+  int segBuffsz, segMaxseg;
+  bool fgSeqbuff;
+  int seqWsz;
+
+  int dbgLevel;
+};
+
+inline ostream& operator << (ostream& os, CGT& cgt) 
+{ cgt.PrintStatus(os); return os; }
+
+#endif
Index: trunk/ArchTOIPipe/Kernel/fitstoirdr.cc
===================================================================
--- trunk/ArchTOIPipe/Kernel/fitstoirdr.cc	(revision 1993)
+++ trunk/ArchTOIPipe/Kernel/fitstoirdr.cc	(revision 1994)
@@ -3,5 +3,5 @@
 //                               Christophe Magneville
 //                               Reza Ansari
-// $Id: fitstoirdr.cc,v 1.26 2001-12-21 17:00:40 aubourg Exp $
+// $Id: fitstoirdr.cc,v 1.27 2002-05-13 13:11:32 ansari Exp $
 
 #include "fitstoirdr.h"
@@ -27,7 +27,13 @@
 }
 
-void FITSTOIReader::setImplicitSN(int snStart) {
+void FITSTOIReader::setImplicitSN(long snStart) {
   implicitSN = true;
   implicitSNStart = snStart;
+}
+
+void FITSTOIReader::setBufferSize(int buffsz)
+{
+  Buff_Sz = (buffsz>0) ? buffsz: 1024;
+  return;
 }
 
@@ -144,10 +150,14 @@
   for (vector<string>::iterator i=allfn.begin(); i!=allfn.end(); i++) {
     openFile(*i);
-    //run1();
-    run2();
+    if (Buff_Sz > 1) run2();  // Lecture bufferise
+    else run1();              // Lecture un echantillon a la fois
   }
 }
 
 // run 1 : deprecated. NON MAINTENU. Incompatible avec implicit SN.
+//                     ^^^^^^^^^^^^  Reza , 13/5/2002 , Je viens de rajouter 
+//                                   implicitSNStart et switvh run1/run2 
+//                                   suivant buffersize
+  
 void FITSTOIReader::run1() {
   // Il faudrait optimiser en fonction de ce qui a ete demande comme samplenum,
@@ -165,7 +175,11 @@
     double y;
     fits_lock();
-    fits_read_col_dbl(fptr,1,i+1,1,1,0,&y,&anyNul,&fstatus);
+    long sn;
+    if (implicitSN) {
+      fits_read_col_dbl(fptr,1,i+1,1,1,0,&y,&anyNul,&fstatus);
+      sn = (long) (y+.1); 
+    }
+    else sn = implicitSNStart+i;
     //fits_unlock();
-    long sn = (long) (y+.1); 
     TOIManager* mgr = TOIManager::getManager();
     if (sn > mgr->getRequestedEnd()) {fits_unlock(); break;}
@@ -228,5 +242,5 @@
  long ideb=-1,ifin=-1;
  for(long i=0; i<nrows; i+=Buff_Sz) {
-
+   fits_lock();   // lock en debut de boucle de lecture - Reza 13/05/2002
    // faut-il lire dans le fichier fits ?
    if(i<ideb || i>ifin) { // Toujours vrai avec le += Buff_Sz
@@ -244,16 +258,16 @@
 	 samplenum[j] = j+ideb+implicitSNStart;
        }
-       fits_lock();
+       //---- Pas la peine, fait en debut de boucle - Reza 13/05/2002  fits_lock();
      } else {
-       fits_lock();
+       //---- Pas la peine, fait en debut de boucle - Reza 13/05/2002 fits_lock();
        fits_read_col_dbl(fptr,1,ideb+1,1,n,0,samplenum,&anyNul,&fstatus);
        if (samplenum[0] > mgr->getRequestedEnd() 
 	   || (forcedMaxIn > 0 && samplenum[0] > forcedMaxIn)) {
-	 fits_unlock();
+	 fits_unlock();  // unlock avant de casser la boucle - Reza 13/05/2002
 	 break;
        }
        if (samplenum[n-1] < mgr->getRequestedBegin()
 	   || (forcedMinIn > 0 && samplenum[n-1] < forcedMinIn)) {
-	 fits_unlock();
+	 //---- Pas la peine, fait en fin de boucle - Reza 13/05/2002 fits_unlock();
 	 continue;
        }
@@ -268,8 +282,9 @@
      if(fstatus!=0) {
        fits_report_error(stderr,fstatus);
+       fits_unlock(); // On supprime le lock avant le throw - Reza 13/05/2002
        throw RangeCheckError("FITSTOIReader::run2: Error Reading Fits file\n");
      }
-     fits_unlock();
    }
+   fits_unlock();   // unlock en debut de boucle de lecture - Reza 13/05/2002
 
    long ip = i-ideb; // pointeurs dans les buffers
@@ -288,5 +303,5 @@
      }
    }
-   totnscount++;
+   totnscount += (ifin-ideb+1);
  }
 
@@ -300,4 +315,4 @@
  colval.resize(0); colflg.resize(0);
 
- cout << "reader done reading... " << pthread_self() << endl;
-}
+ cout << "reader (buffered) done reading... " << pthread_self() << endl;
+}
Index: trunk/ArchTOIPipe/Kernel/fitstoirdr.h
===================================================================
--- trunk/ArchTOIPipe/Kernel/fitstoirdr.h	(revision 1993)
+++ trunk/ArchTOIPipe/Kernel/fitstoirdr.h	(revision 1994)
@@ -5,5 +5,5 @@
 //                               Christophe Magneville
 //                               Reza Ansari
-// $Id: fitstoirdr.h,v 1.10 2001-11-27 12:13:41 aubourg Exp $
+// $Id: fitstoirdr.h,v 1.11 2002-05-13 13:11:32 ansari Exp $
 
 
@@ -21,8 +21,11 @@
 class FITSTOIReader : public TOIProcessor {
 public:
-  FITSTOIReader(string fn,int buff_sz=1000);
+  FITSTOIReader(string fn,int buff_sz=1024);
   ~FITSTOIReader();
 
-  void         setImplicitSN(int snStart=0);
+  void         setImplicitSN(long snStart=0);
+
+  void         setBufferSize(int buffsz=1024);
+  inline int   getBufferSize() { return Buff_Sz; }
 
   virtual void addFile(string fn);
@@ -54,5 +57,5 @@
 
   bool      implicitSN;
-  int       implicitSNStart;
+  long      implicitSNStart;
   
   vector<string> allfn;
Index: trunk/ArchTOIPipe/Processors/nooppr.cc
===================================================================
--- trunk/ArchTOIPipe/Processors/nooppr.cc	(revision 1993)
+++ trunk/ArchTOIPipe/Processors/nooppr.cc	(revision 1994)
@@ -3,5 +3,5 @@
 //                               Christophe Magneville
 //                               Reza Ansari
-// $Id: nooppr.cc,v 1.9 2001-11-13 16:22:47 aubourg Exp $
+// $Id: nooppr.cc,v 1.10 2002-05-13 13:11:32 ansari Exp $
 
 #include <typeinfo>
@@ -14,4 +14,5 @@
 NoOpProcessor::NoOpProcessor(int wsz)
 {
+  if (wsz < 1) wsz = 1;
   wsize = wsz;
   totnscount = 0;
@@ -48,9 +49,17 @@
 
 
-  if (!checkInputTOIIndex(0)) {
+  if (!checkInputTOIIndex(0) && !checkInputTOIIndex(1) && 
+      !checkOutputTOIIndex(0) && !checkOutputTOIIndex(1) ) {
+    cerr << " NoOpProcessor::run() - No TOI connected! "
+	 << endl;
+    throw ParmError("NoOpProcessor::run() No TOI connected!");
+  }
+
+  if (!acceptnoinput && !checkInputTOIIndex(0)) {
     cerr << " NoOpProcessor::run() - Input TOI (in) not connected! "
 	 << endl;
     throw ParmError("NoOpProcessor::run() Input TOI (in) not connected!");
   }
+  bool fgin = checkInputTOIIndex(0);
   bool fgin2 = checkInputTOIIndex(1);
 
@@ -58,5 +67,5 @@
   bool fgout2 = checkOutputTOIIndex(1);
 
-  if (fgout2 && !fgin2) {
+  if (fgout2 && (!fgin2 && !acceptnoinput) ) {
     cerr << " NoOpProcessor::run() - out2 connected without in2!"
 	 << endl;
@@ -78,7 +87,13 @@
       vin = new double[wsize];
       vfg = new uint_8[wsize];
-      if (fgin2) {
+      for(i=0; i<wsize; i++) { 
+	vin[i] = defval; vfg[i] = defflag;
+      }
+      if (fgin2 || fgout2) {
 	vin2 = new double[wsize];
 	vfg2 = new uint_8[wsize];
+	for(i=0; i<wsize; i++) { 
+	  vin2[i] = defval; vfg2[i] = defflag;
+	}	
       }
     
@@ -86,40 +101,39 @@
       // 1er partie, on traite par paquets de wsize
       for(k=snb;k<=sne-wsize+1;k+=wsize) {
-	for(i=0; i<wsize; i++) { 
-	  getData(0, k+i, vin[i], vfg[i]);
-	  if (fgin2)
-	    getData(1, k+i, vin2[i], vfg2[i]);
-	}
+	if (fgin) 
+	  getData(0, k, wsize, vin, vfg);
+	if (fgin2)
+	  getData(1, k, wsize, vin2, vfg2);
 	totnbblock++;
-	for(i=0; i<wsize; i++) {
-	  if (fgout) 
-	    putData(0,k+i,vin[i],vfg[i]);
-	  if (fgout2)  
-	    putData(1, k+i, vin2[i], vfg2[i]);
-	}
+	if (fgout) 
+	  putData(0, k, wsize, vin, vfg);
+	if (fgout2)  
+	  putData(1, k, wsize, vin2, vfg2);
 	klast+=wsize;
 	totnscount+=wsize;
+	totnbblock++;
       }
     }
 
     // 2eme partie, on traite la fin du bloc d'echantillons si necessaire
-    double inval;
-    uint_8 inflg;
+    double inval = defval;;
+    uint_8 inflg = defflag;
+    double inval2 = defval;;
+    uint_8 inflg2 = defflag;
     if (klast < sne) 
       for(k=klast+1; k<=sne; k++) {
-	getData(0, k, inval, inflg);
+	if (fgin) 
+	  getData(0, k, inval, inflg);
 	if (fgout) putData(0, k, inval, inflg);
-	if (fgin2) { 
-	  getData(1, k, inval, inflg);
-	  if (fgout2) 
-	    putData(1, k, inval, inflg);
-	}
+	if (fgin2)  
+	  getData(1, k, inval2, inflg2);
+	if (fgout2) 
+	    putData(1, k, inval2, inflg2);
 	totnscount++;
       }
-
-    totnbblock++;
+    totnbblock++; 
 
     cout << " NoOpProcessor::run() - End of processing " 
-	 << " TotNbBlocks= " << totnbblock << endl;
+	 << " TotNbBlocks= " << totnbblock << " ProcSamples=" << totnscount << endl;
   }  // Bloc try 
 
Index: trunk/ArchTOIPipe/Processors/nooppr.h
===================================================================
--- trunk/ArchTOIPipe/Processors/nooppr.h	(revision 1993)
+++ trunk/ArchTOIPipe/Processors/nooppr.h	(revision 1994)
@@ -5,5 +5,5 @@
 //                               Christophe Magneville
 //                               Reza Ansari
-// $Id: nooppr.h,v 1.5 2001-11-13 16:22:47 aubourg Exp $
+// $Id: nooppr.h,v 1.6 2002-05-13 13:11:32 ansari Exp $
 
 
@@ -25,4 +25,7 @@
   inline int_8	ProcessedSampleCount() const { return totnscount; }
 
+  inline void   AcceptNoInput(double val=0., long flg=0)
+         { acceptnoinput = true; defval = val; defflag = flg; }
+
   virtual void  PrintStatus(::ostream & os) ; // const plus tard
 
@@ -33,4 +36,8 @@
   int_8 totnscount;   // Nombre total d'echantillon processe
   int wsize;         // Taille de fenetre de travail
+
+  bool acceptnoinput;
+  double defval;
+  long defflag;
 };
 
Index: trunk/ArchTOIPipe/smkmflib
===================================================================
--- trunk/ArchTOIPipe/smkmflib	(revision 1993)
+++ trunk/ArchTOIPipe/smkmflib	(revision 1994)
@@ -24,5 +24,5 @@
 rm -f $liblist
 touch $liblist
-ls *.{c,cc} | comm -3 -1 $TMPDIR/exclude.sort - | sed -e 's/\.cc/.o/' | sed -e 's/\.c/.o/' >> $liblist
+ls -1 *.{c,cc} | comm -3 -1 $TMPDIR/exclude.sort - | sed -e 's/\.cc/.o/' | sed -e 's/\.c/.o/' >> $liblist
 unset liblist
 
@@ -61,5 +61,5 @@
 
 echo $libf ':' \
- `ls *.{c,cc} | comm -3 -1 $TMPDIR/exclude.sort - | sed -e 's/\.cc/.o/' | sed -e 's/\.c/.o/' | sed -e 's/^/$(OBJ)/'` >> GNUmakefile
+ `ls -1 *.{c,cc} | comm -3 -1 $TMPDIR/exclude.sort - | sed -e 's/\.cc/.o/' | sed -e 's/\.c/.o/' | sed -e 's/^/$(OBJ)/'` >> GNUmakefile
 echo '	$(ARCXX) $(ARCXXFLAGS) $@ $($(ARARGS))' >> GNUmakefile
 #  Pour faire compiler les instantiations automatique de cxx (DEC)
