Index: /trunk/ArchTOIPipe/ProcWSophya/genwproc.cc
===================================================================
--- /trunk/ArchTOIPipe/ProcWSophya/genwproc.cc	(revision 1495)
+++ /trunk/ArchTOIPipe/ProcWSophya/genwproc.cc	(revision 1496)
@@ -6,4 +6,7 @@
 #include "ctimer.h"
 
+
+// #define DEBUGGENW 1 
+
 // -------------------------------------------------------------
 //   Class GenWindowTOIProcessor : generic processor with window
@@ -19,5 +22,5 @@
   if(wsz%2==0) wsz++;
   if(wstep<1) wstep=1;
-  if(wsztot<wsz) wsztot = 2*wsz;
+  if(wsztot<wsz) wsztot = 2*wsz;  // CMV prise de decision wsztot / wstep
 
   NbInput = nbinput;
@@ -27,9 +30,11 @@
   WSizeTot = wsztot;
 
-  SNdeb = SNend = StartSample = CurSnInd = -1;
+  SNdeb = SNend = StartSample = CurWtIndex = -1;
   TotNsCount = 0;
 
-  TVector<r_8> vr8;
-  TVector<int_8> vi8;
+  SetDefaultValue();
+
+  TVector<r_8> vr8(1);     // CMV+RZ supprimer taille(1) apres correction de 
+  TVector<int_8> vi8(1);   // constructeur copie de TArray (taille nulle)
   
   int k;
@@ -44,4 +49,5 @@
     WOutFlg.push_back(false);
     WPutOutFlg.push_back(false);
+    WPutOutOwnVector.push_back(false);
     OutSample.push_back(0);
   }
@@ -71,6 +77,6 @@
     throw RangeCheckError("GenWindowTOIProcessor::GetWData : toi out of range !");
   if(!WInFlg[numtoi])
-    throw RangeCheckError("GenWindowTOIProcessor::GetWData : toi not connected!");
-  return WDataIn[numtoi];
+    throw ParmError("GenWindowTOIProcessor::GetWData : toi not connected!");
+  return (WDataIn[numtoi])(Range(StartWtIndex(),0,WSize));
 }
 
@@ -80,6 +86,39 @@
     throw RangeCheckError("GenWindowTOIProcessor::GetWFlag : toi out of range !");
   if(!WInFlg[numtoi])
-    throw RangeCheckError("GenWindowTOIProcessor::GetWFlag : toi not connected!");
-  return WFlagIn[numtoi];
+    throw ParmError("GenWindowTOIProcessor::GetWFlag : toi not connected!");
+  return (WFlagIn[numtoi])(Range(StartWtIndex(),0,WSize));
+}
+
+r_8 * GenWindowTOIProcessor::GetWDataPointer(int numtoi)
+{
+  if(numtoi<0 || numtoi>=NbInput)
+    throw RangeCheckError("GenWindowTOIProcessor::GetWDataPointer : toi out of range !");
+  if(!WInFlg[numtoi])
+    throw ParmError("GenWindowTOIProcessor::GetWDataPointer : toi not connected!");
+  return (WDataIn[numtoi].Data()+StartWtIndex());
+
+}
+ 
+int_8 * GenWindowTOIProcessor::GetWFlagPointer(int numtoi)
+{
+  if(numtoi<0 || numtoi>=NbInput)
+    throw RangeCheckError("GenWindowTOIProcessor::GetWFlagPointer : toi out of range !");
+  if(!WInFlg[numtoi])
+    throw ParmError("GenWindowTOIProcessor::GetWFlagPointer : toi not connected!");
+  return (WFlagIn[numtoi].Data()+StartWtIndex());
+}
+
+void GenWindowTOIProcessor::GetData(int numtoi, int_8 numsample, r_8 & data, int_8 & flag)
+{
+  if(numtoi<0 || numtoi>=NbInput)
+    throw RangeCheckError("GenWindowTOIProcessor::GetData : toi out of range !");
+  if(!WInFlg[numtoi])
+    throw ParmError("GenWindowTOIProcessor::GetData : toi not connected!");
+  int_8 k = numsample-GetStartSample();
+  if ((k<0) || (k >= GetWSize()))
+    throw RangeCheckError("GenWindowTOIProcessor::GetData : numsample out of window!");
+  k += StartWtIndex();
+  data = (WDataIn[numtoi])(k);
+  flag = (WFlagIn[numtoi])(k);
 }
 
@@ -91,11 +130,14 @@
     throw RangeCheckError("GenWindowTOIProcessor::PutWFlag : toi out of range !");
   if(!WOutFlg[numtoi])
-    throw RangeCheckError("GenWindowTOIProcessor::PutWFlag : toi not connected!");
+    throw ParmError("GenWindowTOIProcessor::PutWFlag : toi not connected!");
   if(data.Size()!=flag.Size())
     throw ParmError("GenWindowTOIProcessor::PutWFlag : data.Size()!=flag.Size()!");
+  if(data.Size() == 0)
+    throw ParmError("GenWindowTOIProcessor::PutWFlag : data.Size()==0 !");
   WDataOut[numtoi].Share(data);
   WFlagOut[numtoi].Share(flag);
   OutSample[numtoi] = numsample;
   WPutOutFlg[numtoi] = true;
+  WPutOutOwnVector[numtoi] = false;
 }
 
@@ -106,9 +148,12 @@
     throw RangeCheckError("GenWindowTOIProcessor::PutWFlag : toi out of range !");
   if(!WOutFlg[numtoi])
-    throw RangeCheckError("GenWindowTOIProcessor::PutWFlag : toi not connected!");
-  WDataOut[numtoi].Realloc(1,BaseArray::SameVectorType,true);
-    (WDataOut[numtoi])(0) = data;
-  WFlagOut[numtoi].Realloc(1,BaseArray::SameVectorType,true);
-    (WFlagOut[numtoi])(0) = flag;
+    throw ParmError("GenWindowTOIProcessor::PutWFlag : toi not connected!");
+  if (!WPutOutOwnVector[numtoi]) {
+    WDataOut[numtoi].Realloc(1,BaseArray::SameVectorType,true);
+    WFlagOut[numtoi].Realloc(1,BaseArray::SameVectorType,true);
+    WPutOutOwnVector[numtoi] = true;
+  }
+  (WDataOut[numtoi])(0) = data;
+  (WFlagOut[numtoi])(0) = flag;
   OutSample[numtoi] = numsample;
   WPutOutFlg[numtoi] = true;
@@ -116,15 +161,15 @@
 
 ////////////////////////////////////////////////////////////////
-void GenWindowTOIProcessor::UserInit()
+void GenWindowTOIProcessor::UserInit(int_8 kstart)
 {
   cout<<"GenWindowTOIProcessor::UserInit() Default implementation does nothing"<<endl;
 }
 
-void GenWindowTOIProcessor::UserProc()
+void GenWindowTOIProcessor::UserProc(int_8 ks)
 {
   cout<<"GenWindowTOIProcessor:UserProc() Default implementation does nothing"<<endl;
 }
 
-void GenWindowTOIProcessor::UserEnd()
+void GenWindowTOIProcessor::UserEnd(int_8 kend)
 {
   cout<<"GenWindowTOIProcessor::UserEnd() Default implementation does nothing"<<endl;
@@ -152,8 +197,8 @@
 {
   //  TOIManager* mgr = TOIManager::getManager();
-  int_8 SNdeb = getMinIn();
-  int_8 SNend = getMaxIn();
+  SNdeb = getMinIn();
+  SNend = getMaxIn();
   if(SNend-SNdeb<WSize)
-    throw RangeCheckError("GenWindowTOIProcessor::run : sne-snb<WSize !");
+    throw ParmError("GenWindowTOIProcessor::run : sne-snb<WSize !");
 
   // Allocation des tailles pour les vecteurs
@@ -169,6 +214,5 @@
     throw ParmError("GenWindowTOIProcessor::run() No input TOI connected!");
   }
-  for(kc=0;kc<NbOutput;kc++)
-      WOutFlg[kc] = checkOutputTOIIndex(kc);
+  for(kc=0;kc<NbOutput;kc++) WOutFlg[kc] = checkOutputTOIIndex(kc);
 
   // Lecture des samples et remplissage des vecteurs
@@ -176,14 +220,23 @@
   try {
     Timer tm("GenWindowTOIProcessor::run()");
-    int_8 ki = -1;
-
-    for(int_8 ks=SNdeb;ks<=SNend;ks++) {
+    for(int_8 ks=SNdeb;ks<=SNend;ks++) {  // CMV gerer le += step
       Remplissage(ks);
+      if (ks == SNdeb) {
+	UserInit(ks);
+	Ecriture();
+      }
+      if ((ks-SNdeb)%WStep == 0) {
+	UserProc(ks);
+	// Il faut traiter les ecritures en sortie 
+	Ecriture();
+      }
       TotNsCount++;
     }
+    UserEnd(SNend);
+    Ecriture();
     cout << " GenWindowTOIProcessor::run() - End of processing " << endl;
 
   } catch(PException & exc) {
-    cerr<<"GenWindowTOIProcessor: Catched Exception "<<(string)typeid(exc).name()
+    cerr<<"GenWindowTOIProcessor::run Catched Exception "<<(string)typeid(exc).name()
         <<"\n .... Msg= "<<exc.Msg()<<endl;
   }
@@ -196,15 +249,14 @@
 //      samples :   sn-ws/2        sn          sn+ws/2
 //      fenetre :   0              ws/2+1      ws-1
-//   ki : index des vecteurs a remplir.
-//        C'est l'index ou on veut remplir la donnee
-//        dans un vecteur (fictif) de taille WSize.
-//        La routine gere le decalage dans le grand buffer WSizeTot.
-//  Si ki depasse la taille maximale permise on decale, sinon on ne fait rien
-// RETURN:
-//   numero du PROCHAIN index a remplir (ki+1 si pas decale !)
-{
-if(ks<SNdeb || ks>SNend)
+{
+#ifdef DEBUGGENW
+ cout << "GenWindowTOIProcessor::Remplissage(" << ks << ") CurWtIndex=" << CurWtIndex << endl;
+#endif 
+
+if(ks<SNdeb || ks>SNend) {
+  cerr << "GenWindowTOIProcessor::remplissage/Erreur : ks(=" << ks << ") <" 
+       << SNdeb << " || ks>" << SNend << endl; 
   throw RangeCheckError("GenWindowTOIProcessor::remplissage : ks<SNdeb || ks>SNend !");
-
+ }
 int_8 wsz2=WSize/2;
 
@@ -212,23 +264,30 @@
 
 // Premier remplissage ???? Gestion de la borne inferieure
-if(CurSnInd<0) {
-  CurSnInd = 0;
+if(CurWtIndex<0) {
+#ifdef DEBUGGENW
+  cout << "GenWindowTOIProcessor::Remplissage 1ere fois" << endl; 
+#endif 
+  CurWtIndex = 0;
   for(int_8 k=ks-wsz2; k<=ks+wsz2; k++) { // Lecture TOI
     for(int kc=0; kc<NbInput; kc++) {
       if(!WInFlg[kc]) continue;
       if(k>=SNdeb && k<=SNend) {
-        getData(kc,k,(WDataIn[kc])(CurSnInd), (WFlagIn[kc])(CurSnInd));
+        getData(kc,k,(WDataIn[kc])(CurWtIndex), (WFlagIn[kc])(CurWtIndex));
       } else {
-        (WDataIn[kc])(CurSnInd) = (r_8) 0.;
-        (WFlagIn[kc])(CurSnInd) = (int_8) 0;
+        (WDataIn[kc])(CurWtIndex) = R8DefVal;
+        (WFlagIn[kc])(CurWtIndex) = I8DefVal;
       }
     }
-    CurSnInd++;
+    CurWtIndex++;
   }
   return;
 }
 
+// CMV gere decalage seulement si step < wsize sinon copie.
 // Faut-il decaler ????
-if(CurSnInd == WSizeTot) { // On decale
+if(CurWtIndex == WSizeTot) { // On decale
+#ifdef DEBUGGENW
+  cout << "GenWindowTOIProcessor::Remplissage Decalage " << endl; 
+#endif 
   for(int kc=0; kc<NbInput; kc++) {
     if(!WInFlg[kc]) continue;
@@ -238,20 +297,42 @@
       }
   }
-  CurSnInd = WSize-1;
+  CurWtIndex = WSize-1;
 }
 
 // Remplissage de ks+wsz2 (dernier element de la fenetre pour ks central)
 int_8 kse = ks+wsz2;
+#ifdef DEBUGGENW
+  cout << "GenWindowTOIProcessor::Normal fill " << endl; 
+#endif 
 for(int kc=0; kc<NbInput; kc++) {
   if(!WInFlg[kc]) continue;
   if(kse>=SNdeb && kse<=SNend) {
-    getData(kc,kse,(WDataIn[kc])(CurSnInd),(WFlagIn[kc])(CurSnInd));
+    getData(kc,kse,(WDataIn[kc])(CurWtIndex),(WFlagIn[kc])(CurWtIndex));
   } else {
-    (WDataIn[kc])(CurSnInd) = (r_8) 0.;
-    (WFlagIn[kc])(CurSnInd) = (int_8) 0;
-  }
-}
-CurSnInd++;
+    (WDataIn[kc])(CurWtIndex) = R8DefVal;
+    (WFlagIn[kc])(CurWtIndex) = I8DefVal;
+  }
+}
+CurWtIndex++;
 
 return;
 }
+
+void GenWindowTOIProcessor::Ecriture()
+{
+  int_8 maxlenout = 0;
+  int kc;
+  for(kc=0; kc<NbOutput; kc++)
+    if(WOutFlg[kc] && WPutOutFlg[kc] && (WDataOut[kc].Size() > maxlenout) )
+      maxlenout = WDataOut[kc].Size();
+
+  for(int_8 k=0; k<maxlenout; k++) {
+    for(int kc=0; kc<NbOutput; kc++) {
+      if(!WOutFlg[kc]) continue;
+      if(!WPutOutFlg[kc]) continue;
+      if(k>=WDataOut[kc].Size()) continue;
+      putData(kc, k+OutSample[kc], (WDataOut[kc])(k), (WFlagOut[kc])(k));      
+    }
+  }
+  for(kc=0; kc<NbOutput; kc++)  WPutOutFlg[kc] = false;
+}
Index: /trunk/ArchTOIPipe/ProcWSophya/genwproc.h
===================================================================
--- /trunk/ArchTOIPipe/ProcWSophya/genwproc.h	(revision 1495)
+++ /trunk/ArchTOIPipe/ProcWSophya/genwproc.h	(revision 1496)
@@ -13,5 +13,5 @@
 public:
   GenWindowTOIProcessor(int nbinput,int nboutput,int wsz, int wstep=1, int wsztot=-1);
-  ~GenWindowTOIProcessor();
+  virtual ~GenWindowTOIProcessor();
 
   inline int_8 GetWSize() const { return WSize; }
@@ -21,6 +21,18 @@
   inline int_8 GetStartSample()  {return StartSample;}
   inline int_8 GetCenterSample() {return StartSample + WSize/2;}
+  inline int_8 StartSampleNum() { return SNdeb; }
+  inline int_8 EndSampleNum() { return SNend; }
+
+  inline void SetDefaultValue(r_8 r8dval=0., int_8 i8dval=0)
+                      {R8DefVal = r8dval; I8DefVal = i8dval;}
+
   TVector<r_8> GetWData(int numtoi=0);
   TVector<int_8> GetWFlag(int numtoi=0);
+  r_8 * GetWDataPointer(int numtoi=0);
+  int_8 * GetWFlagPointer(int numtoi=0);
+  void GetData(int numtoi, int_8 numsample, r_8 & data, int_8 & flag);
+  inline void GetData(int_8 numsample, r_8 & data, int_8 & flag)
+                      { GetData(0, numsample, data, flag); }
+
   void PutWData(int numtoi,int_8 numsample,TVector<r_8>& data,TVector<int_8>& flag);
   void PutWData(int numtoi,int_8 numsample,r_8 data,int_8 flag);
@@ -32,7 +44,7 @@
   virtual void PrintStatus(ostream & os);
 
-  virtual void UserInit();
-  virtual void UserProc();
-  virtual void UserEnd();
+  virtual void UserInit(int_8 kstart);
+  virtual void UserProc(int_8 ks);
+  virtual void UserEnd(int_8 kend);
 
   virtual void	init();  
@@ -41,14 +53,17 @@
 protected:
   void Remplissage(int_8 ks);
-  inline int_8 StartSnIndex()
-         {if(CurSnInd<0) return -1; else return CurSnInd-WSize;}
-  inline int_8 CenterSnIndex()
-         {if(CurSnInd<0) return -1; else return CurSnInd-(WSize+1)/2;}
+  void Ecriture();
+  inline int_8 StartWtIndex()
+         {if(CurWtIndex<0) return -1; else return CurWtIndex-WSize;}
+  inline int_8 CenterWtIndex()
+         {if(CurWtIndex<0) return -1; else return CurWtIndex-(WSize+1)/2;}
 
   int NbInput,NbOutput;
   int_8 WSizeTot,WSize,WStep;
   int_8 SNdeb,SNend;
-  int_8 StartSample,CurSnInd;
+  int_8 StartSample,CurWtIndex;
   int_8 TotNsCount;
+  r_8 R8DefVal;
+  int_8 I8DefVal;
   vector< TVector<r_8>   > WDataIn;
   vector< TVector<int_8> > WFlagIn;
@@ -58,4 +73,5 @@
   vector< bool > WOutFlg;
   vector< bool > WPutOutFlg;
+  vector< bool > WPutOutOwnVector;
   vector< int_8 > OutSample;
 };
Index: /trunk/ArchTOIPipe/SMakefile
===================================================================
--- /trunk/ArchTOIPipe/SMakefile	(revision 1495)
+++ /trunk/ArchTOIPipe/SMakefile	(revision 1496)
@@ -16,7 +16,7 @@
 EXEOLIST := $(AOBJ)fits2asc.o $(AOBJ)tsttoi.o $(AOBJ)tsttoi2.o $(AOBJ)simtst.o \
             $(AOBJ)tstrztoi.o $(AOBJ)rztoi.o \
-            $(AOBJ)fits2ascii.o $(AOBJ)tstmap2toi.o $(AOBJ)tsttoi2map.o 
+            $(AOBJ)fits2ascii.o $(AOBJ)tgenw.o $(AOBJ)tstmap2toi.o $(AOBJ)tsttoi2map.o 
 EXELIST := $(AOBJ)sfftc $(AOBJ)simtst $(AOBJ)mesovh $(AOBJ)tstrztoi $(AOBJ)fits2asc $(AOBJ)tsttoi \
-           $(AOBJ)tsttoi2 $(AOBJ)fits2ascii $(AOBJ)tstmap2toi $(AOBJ)tsttoi2map
+           $(AOBJ)tsttoi2 $(AOBJ)fits2ascii $(AOBJ)tgenw $(AOBJ)tstmap2toi $(AOBJ)tsttoi2map
 
 INCLIST := asciitoiwtr.h fitstoirdr.h fitstoiwtr.h toi.h config.h conf.h \
@@ -55,4 +55,6 @@
 $(AOBJ)fits2ascii: $(AOBJ)fits2ascii.o $(LIBOLIST)
 	$(LINK.cc)  -o $@ $^ $(LIBS)
+$(AOBJ)tgenw: $(AOBJ)tgenw.o  $(LIBOLIST)
+	$(LINK.cc)  -o $@ $^ $(LIBS)
 $(AOBJ)tstmap2toi: $(AOBJ)tstmap2toi.o $(LIBOLIST)
 	$(LINK.cc)  -o $@ $^ $(LIBS)
@@ -69,4 +71,5 @@
 $(AOBJ)tsttoi2.o: tsttoi2.cc $(INCLIST)
 $(AOBJ)fits2ascii.o: fits2ascii.cc $(INCLIST)
+$(AOBJ)tgenw.o: tgenw.cc $(INCLIST)
 $(AOBJ)tstmap2toi.o: tstmap2toi.cc $(INCLIST)
 $(AOBJ)tsttoi2map.o: tsttoi2map.cc $(INCLIST)
