Index: trunk/ArchTOIPipe/ProcWSophya/rztoi.cc
===================================================================
--- trunk/ArchTOIPipe/ProcWSophya/rztoi.cc	(revision 1439)
+++ trunk/ArchTOIPipe/ProcWSophya/rztoi.cc	(revision 1442)
@@ -3,5 +3,5 @@
 #include "pexceptions.h"
 #include "fftpserver.h"
-#include "timing.h"
+#include "ctimer.h"
 
 RzTOIProc::RzTOIProc(int w1, int w2, int nmax)
@@ -15,6 +15,6 @@
 void RzTOIProc::init() {
   cout << "RzTOIProc::init" << endl;
-  declareInput("signal");
-  declareOutput("sfout");
+  declareInput("in");
+  declareOutput("out");
   name = "rzproc";
   upExtra = 1;
@@ -33,4 +33,5 @@
 
   try {
+    Timer tm("RzTOIProc::run()");
 
     FFTPackServer ffts;
@@ -116,5 +117,6 @@
 	nkv++;
       }
-      PrtTim("End of bloc");
+
+      tm.Split("End of bloc");
     }
 
@@ -150,22 +152,24 @@
   }
   catch (PException & e) {
-    cout << "RzTOIProc exception Msg= " << e.Msg() << endl;
-  }
-}
-
-
-
-RzSimpleTOIProc::RzSimpleTOIProc(double fact, int npr)
+    cout << "RzTOIProc: Catched exception " << (string)typeid(e).name()
+	 << "\n Msg= " << e.Msg() << endl;
+  }
+}
+
+
+
+RzSimpleTOIProc::RzSimpleTOIProc(int wsz, double fact)
 {
+  if (wsz < 4) wsz = 4;
   cout << "RzSimpleTOIProc::RzSimpleTOIProc() factor= " << fact 
-       << " npr=" << npr << endl; 
+       << " WSize=" << wsz << endl; 
   _fact = fact;
-  _nprt = npr;
+  _wsz = wsz;
 }
 
 void RzSimpleTOIProc::init() {
   cout << "RzSimpleTOIProc::init" << endl;
-  declareInput("signal");
-  declareOutput("sfout");
+  declareInput("in");
+  declareOutput("out");
   name = "rzsimpleproc";
   upExtra = 1;
@@ -177,19 +181,45 @@
   int sne = getMaxIn();
 
-  cout << " RzSimpleTOIProc::run(): snb=" << snb << " sne=" << sne << endl;
+  int nstot = sne-snb;
+  int nbloc = nstot/_wsz;
+  cout << " RzSimpleTOIProc::run(): snb=" << snb << " sne=" 
+       << sne << " NBloc=" << nbloc << endl;
 
   double val;
+  int snlast = snb;
+  int istart,ii,kb;
   try {
-    for (int k=snb; k<sne; k++) {
-      if ((k-snb)%_nprt == 0) 
-	cout << " RzSimpleTOIProc::run() - Processing sample k= " << k
-	     << endl;
-
-      val = getData(0, k);
-      putData(0, k, val*_fact);
-    }
+    Timer tm("RzSimpleTOIProc::run()");
+    Vector vin(_wsz);
+    for (kb=0; kb<nbloc; kb++) {
+      istart = kb*_wsz+snb;
+      if (kb%2 == 0) {  // On parcourt a l'envers
+	cout << " ... Processing bloc[" << kb << "] (Reverse) SampleNum=" 
+	     << istart+_wsz << " ->" << istart << endl;
+	for(ii=_wsz-1; ii>=0; ii--)
+	  vin(ii) = getData(0, ii+istart);
+      }
+      else {  // On parcourt vers l'avant 
+	cout << " ... Processing bloc[" << kb << "] SampleNum=" 
+	     << istart << " ->" << istart+_wsz << endl;
+	for(ii=0; ii<_wsz; ii++)
+	  vin(ii) = getData(0, ii+istart);	
+      }
+      for(ii=0; ii<_wsz; ii++)
+	putData(0, ii+istart, vin(ii)*_fact);
+      snlast = istart+_wsz;
+    }
+    cout << " ... Processing remaining Samples - SN=" 
+	 << snlast << " ->" << sne << endl;
+    for(ii=snlast; ii<sne; ii++) {
+      val = getData(0, ii);
+      putData(0, ii, val*_fact);
+    }
+    
+    
   }
   catch (PException & e) {
-    cout << "RzSimpleTOIProc exception Msg= " << e.Msg() << endl;
-  }
-}
+    cout << "RzSimpleTOIProc exception " << (string)typeid(e).name()
+	 << "\n  Msg= " << e.Msg() << endl;
+  }
+}
Index: trunk/ArchTOIPipe/ProcWSophya/rztoi.h
===================================================================
--- trunk/ArchTOIPipe/ProcWSophya/rztoi.h	(revision 1439)
+++ trunk/ArchTOIPipe/ProcWSophya/rztoi.h	(revision 1442)
@@ -23,5 +23,5 @@
 class RzSimpleTOIProc : public TOIProcessor {
 public:
-  RzSimpleTOIProc(double fact=1.0, int npr=1000);
+  RzSimpleTOIProc(int wsz=1024, double fact=1.0);
   virtual void init();  
   virtual void run();
@@ -29,5 +29,5 @@
 protected:
   double _fact;
-  int _nprt;
+  int _wsz;
 };
 
Index: trunk/ArchTOIPipe/ProcWSophya/simtoipr.cc
===================================================================
--- trunk/ArchTOIPipe/ProcWSophya/simtoipr.cc	(revision 1442)
+++ trunk/ArchTOIPipe/ProcWSophya/simtoipr.cc	(revision 1442)
@@ -0,0 +1,235 @@
+#include "simtoipr.h"
+#include "toimanager.h"
+#include "pexceptions.h"
+#include "ctimer.h"
+
+SimpleDeglitcher::SimpleDeglitcher(int wsz, double ns, int maxnpt)
+{
+  if (wsz < 5) wsz = 5;
+  if (wsz%2 == 0) wsz++;
+  if (maxnpt > wsz) maxnpt = wsz;
+
+  cout << "SimpleDeglitcher::SimpleDeglitcher() WSize= " << wsz 
+       << " nSig=" << ns << " maxNPt=" << maxnpt << endl;
+  
+  wsize = wsz;
+  nsig = ns;
+  maxpoints = maxnpt;
+  totnscount = glnscount = glcount = 0;
+}
+
+SimpleDeglitcher::~SimpleDeglitcher()
+{
+}
+
+void SimpleDeglitcher::init() {
+  cout << "SimpleDeglitcher::init" << endl;
+  declareInput("in");
+  declareOutput("out");
+  declareOutput("mean");
+  declareOutput("sigma");
+  name = "SimpleDeglitcher";
+  //  upExtra = 1;   A quoi ca sert ?
+}
+
+void SimpleDeglitcher::run() {
+
+  //  TOIManager* mgr = TOIManager::getManager();
+  int snb = getMinIn();
+  int sne = getMaxIn();
+
+  bool fgout = checkOutputTOIIndex(0);
+  bool fgmean = checkOutputTOIIndex(1);
+  bool fgsigma = checkOutputTOIIndex(2);
+  
+  if (!checkInputTOIIndex(0)) {
+    cerr << " SimpleDeglitcher::run() - Input TOI (in) not connected! "
+	 << endl;
+    throw ParmError("SimpleDeglitcher::run() Input TOI (in) not connected!");
+  }
+  if (!fgout && !fgmean && !fgsigma) {
+    cerr << " SimpleDeglitcher::run() - No Output TOI connected! "
+	 << endl;
+    throw ParmError("SimpleDeglitcher::run() No output TOI connected!");
+  }
+  
+  if (!fgout) {
+    cout << "Warning:  SimpleDeglitcher::run() - No TOI connected to out \n"
+	 << " No deglitching would be performed !" << endl;
+  }
+
+  cout << " SimpleDeglitcher::run() SN=" << snb << " - " << sne << endl; 
+  try {
+    // Le debut 
+    int wsz2 = wsize/2;
+    Vector vin(wsize);
+    int k;
+    for(k=0; k<wsize; k++) 
+      vin(k) = getData(0, k+snb);
+    double s = vin.Sum()/wsize;
+    double mean = s/wsize;
+    double s2 = vin.SumX2();
+    double sigma = sqrt(s2/wsize-mean*mean);
+    int kgl = -1;
+    int ii,lastput;
+    bool fgglitch = false;
+    double valcur,valsub,valadd;
+    for(k=0;k<sne-snb;k++) {
+      totnscount++;
+      if (k%10000 == 0) cout << " DBG: K=" << k << endl;
+      // Calcul mean-sigma
+      if ((k>wsz2) && (k<sne-snb-wsz2)) {
+	valsub = vin((k+wsz2)%wsize);
+	vin((k+wsz2)%wsize) = valadd = getData(0, k+snb);
+	s += (valadd-valsub);
+	s2 += (valadd*valadd-valsub-valsub);
+	mean = s/wsize;
+	sigma = sqrt(s2/wsize-mean*mean);
+      }
+
+      //  On gere les sorties Mean et Sigma
+      if (fgmean) 
+	putData(1, k+snb, mean, 0);
+      if (fgsigma) 
+	putData(2, k+snb, sigma, 0);
+
+      if (!fgout)   continue;  // Pas de sortie out (deglitche)
+
+      valcur = vin(k%wsize);
+
+      if (valcur < mean+nsig*sigma) {  // inferieur au seuil
+	if (fgglitch) {  
+	  if (k-kgl < maxpoints) {   // On vient de detecter un glitch
+	    glcount++;
+	    for(ii=kgl; ii<k; ii++) {
+	      putData(0, ii+snb, mean, 7);
+	      glnscount++; 
+	    }
+	    lastput = snb+k-1;
+	  }
+	  else {
+	    for(ii=kgl; ii<k; ii++) {
+	      putData(0, ii+snb, vin(ii%wsize), 0);
+	    }
+	    lastput = snb+k-1;  
+	  } 
+	}
+	putData(0, k+snb, valcur, 0);
+	lastput = snb+k;
+	kgl = -1;  fgglitch = false;
+      }
+      else {  // Superieur au seuil
+	if (fgglitch) {
+	  if (k-kgl+1 >= maxpoints) {  // serie de points > seuil
+	    for(ii=kgl; ii<=k; ii++)   // -> Donc pas glitch
+	      putData(0, ii+snb, vin(ii%wsize), 0);
+	    lastput = snb+k;
+	    fgglitch = false;  
+	  }
+	}
+	else {
+	  if (kgl < 0) {  // debut possible de glitch
+	    fgglitch = true;  kgl = k;
+	  }
+	  else { // On est toujours dans une serie > seuil
+	    putData(0, k+snb, valcur, 0);
+	    lastput = snb+k;
+	  }
+	}
+      }
+
+      if (k%5000 == 0) cout << " ---DBG2: K=" << k << " glcount=" 
+			    << glcount << " LastPut= " << lastput << endl;
+    }  // Boucle sur les num-sample
+    cout << " La fin lastput=" << lastput << " SNE=" << sne; 
+    for(k=lastput-snb; k<sne-snb; k++) 
+      putData(0, k+snb, vin(k%wsize), 0);
+    cout << " DBG3- OUT of try bloc ! " << endl;
+      
+  }  // Bloc try 
+  catch (PException & exc) {
+    cerr << "SimpleDeglitcher: Catched Exception " << (string)typeid(exc).name()
+         << "\n .... Msg= " << exc.Msg() << endl;
+  }                                                                             
+}
+
+
+
+SimpleFilter::SimpleFilter(int wsz, FilterKind fk, double a, double s)
+{
+  if (wsz < 3) wsz = 3;
+  if (wsz%2 == 0) wsz++;
+  cout << "SimpleFilter::SimpleFilter() wsz= " << wsz 
+       << " fk=" << fk << endl; 
+  wsize = wsz;
+  totnscount = 0;
+  coef = new double[wsz];
+  for(int kk=0; kk<wsz; kk++) 
+    coef[kk] = 1./wsize;
+}
+
+SimpleFilter::~SimpleFilter()
+{
+  delete[] coef;
+}
+
+void SimpleFilter::init() {
+  cout << "SimpleFilter::init" << endl;
+  declareInput("in");
+  declareOutput("out");
+  name = "SimpleFilter";
+  //  upExtra = 1;
+}
+
+void SimpleFilter::run() {
+  //  TOIManager* mgr = TOIManager::getManager();
+  int snb = getMinIn();
+  int sne = getMaxIn();
+
+  cout << " SimpleFilter::run(): snb=" << snb << " sne=" << sne << endl;
+
+  bool fgout = checkOutputTOIIndex(0);
+
+  if (!checkInputTOIIndex(0)) {
+    cerr << " SimpleFilter::run() - Input TOI (in) not connected! "
+	 << endl;
+    throw ParmError("SimpleFilter::run() Input TOI (in) not connected!");
+  }
+  if (!fgout) {
+    cerr << " SimpleFilter::run() - No Output TOI connected! "
+	 << endl;
+    throw ParmError("SimpleFilter::run() No output TOI connected!");
+  }
+  
+
+  try {
+    // Le debut
+    int wsz2 = wsize/2;
+    Vector vin(wsize);
+    int k;
+    for(k=0; k<wsize; k++) 
+      vin(k) = getData(0, k+snb);
+    double mean = vin.Sum()/wsize;
+    for(k=0; k<wsize/2; k++) vin(k) = mean; 
+    for(k=0;k<sne-snb;k++) {
+      totnscount++;
+      // Calcul mean-sigma
+      if ((k>wsz2) && (k<sne-snb-wsz2)) 
+	vin((k+wsz2)%wsize) = getData(0, k+snb);
+      //      if (k == sne-snb-wsz2) {
+      //      }
+      double sortie = 0;
+      for(int ii=0; ii<wsize; ii++) {
+	sortie += vin((ii+k)%wsize)*coef[ii];
+      }
+      putData(0,k+snb,sortie,0);
+    }  // Boucle sur les num-sample
+  }  // Bloc try 
+
+  catch (PException & exc) {
+    cerr << "SimpleFilter: Catched Exception " << (string)typeid(exc).name()
+         << "\n .... Msg= " << exc.Msg() << endl;
+  }                                                                             
+
+
+}
Index: trunk/ArchTOIPipe/ProcWSophya/simtoipr.h
===================================================================
--- trunk/ArchTOIPipe/ProcWSophya/simtoipr.h	(revision 1442)
+++ trunk/ArchTOIPipe/ProcWSophya/simtoipr.h	(revision 1442)
@@ -0,0 +1,75 @@
+// This may look like C code, but it is really -*- C++ -*-
+
+#ifndef SIMTOIPR_H
+#define SIMTOIPR_H
+
+#include "toiprocessor.h"
+
+// ---------  Un deglitcheur simple
+// Dans chaque fenetre de largeur de wsz
+// if (val > Mean(Window)+ns*Sigma(Window)) val = Mean(Window)
+// Si Pas plus de maxnpt points remplissants cette condition
+
+class SimpleDeglitcher : public TOIProcessor {
+public:
+		SimpleDeglitcher(int wsz=64, double ns=3, int maxnpt=5);
+  virtual	~SimpleDeglitcher();
+
+  virtual void	init();  
+  virtual void	run();
+
+  inline int	WSize() const { return wsize; }
+  inline double NbSigmas() const { return nsig; }
+  inline int	MaxPoints() const { return maxpoints; }
+  
+  inline int	TotalSampleCount() const { return totnscount; }
+  inline int	GlitchCount() const { return glcount; }
+  inline int    GlitchSampleCount() const { return glnscount; }
+  
+protected:
+  int totnscount;   // Nombre total d'echantillon processe
+  int glnscount;    // Nombre total de glitch
+  int glcount;      // Nombre de glitch detecte
+
+  int wsize;        // Taille de fenetre de travail
+  double nsig;      // Seuil en nb de sigmas 
+  int maxpoints;    // Nb maxi de points > ns sigmas
+};
+
+
+//  Un filtre simple, dans le domaine temporel
+//  remplace val -> Somme(val(i)*coeff(i)) ds Fenetre
+
+class SimpleFilter : public TOIProcessor {
+public:
+  enum FilterKind {
+    UserFilter=0,	// User defined filter function
+    MeanFilter=1,       // Replace sample by the window mean value (lowpass)
+    SumFilter=2,        // Replace sample by the window sum (lowpass)
+    GaussFilter=3,      // Apply a gaussian to the window samples
+    DiffFilter=4,	// value -= MeanValue
+  };
+
+		SimpleFilter(int wsz=128, 
+			      FilterKind fk=SimpleFilter::MeanFilter,
+		              double a=1., double s=1.);
+  //		SimpleFilter(int wsz, Arr_DoubleFunctionOfX f=NULL);
+		~SimpleFilter();
+
+  inline FilterKind Type() { return fkind; }
+
+  inline int	WSize() const { return wsize; }
+  inline int	TotalSampleCount() const { return totnscount; }
+
+  virtual void	init();  
+  virtual void	run();
+
+protected:
+  FilterKind fkind;
+  int totnscount;   // Nombre total d'echantillon processe
+  int wsize;        // Taille de fenetre de travail
+  double* coef;     // Coefficients du filtre 
+  
+};
+
+#endif
