Index: trunk/ArchTOIPipe/ProcWSophya/simtoipr.cc
===================================================================
--- trunk/ArchTOIPipe/ProcWSophya/simtoipr.cc	(revision 1442)
+++ trunk/ArchTOIPipe/ProcWSophya/simtoipr.cc	(revision 1443)
@@ -17,8 +17,24 @@
   maxpoints = maxnpt;
   totnscount = glnscount = glcount = 0;
+  deglitchdone = false;
 }
 
 SimpleDeglitcher::~SimpleDeglitcher()
 {
+}
+
+void SimpleDeglitcher::PrintStatus(ostream & os)
+{
+  os << "\n ------------------------------------------------------ \n" 
+     << " SimpleDeglitcher::PrintStatus() - WindowSize=" << WSize() 
+     << "  NbSigmas=" << NbSigmas() << " MaxPoints=" << MaxPoints() << endl;
+  TOIProcessor::PrintStatus(os);
+  if (deglitchdone) os << " Deglitching performed " << endl;
+  else os << " NO deglitching done " << endl;
+  double nst = (TotalSampleCount() > 0) ? TotalSampleCount() : 1.;
+  os << " TotalSampleCount=" << TotalSampleCount() << " GlitchCount= " 
+     << GlitchCount() << " GlitchSampleCount=" << GlitchSampleCount() 
+     << "( " << (double)GlitchSampleCount()*100./nst << " % )" << endl;
+  os << " ------------------------------------------------------ " << endl;
 }
 
@@ -29,4 +45,5 @@
   declareOutput("mean");
   declareOutput("sigma");
+  declareOutput("incopie");
   name = "SimpleDeglitcher";
   //  upExtra = 1;   A quoi ca sert ?
@@ -42,4 +59,5 @@
   bool fgmean = checkOutputTOIIndex(1);
   bool fgsigma = checkOutputTOIIndex(2);
+  bool fgincopie = checkOutputTOIIndex(3);
   
   if (!checkInputTOIIndex(0)) {
@@ -48,5 +66,5 @@
     throw ParmError("SimpleDeglitcher::run() Input TOI (in) not connected!");
   }
-  if (!fgout && !fgmean && !fgsigma) {
+  if (!fgout && !fgmean && !fgsigma &&!fgincopie) {
     cerr << " SimpleDeglitcher::run() - No Output TOI connected! "
 	 << endl;
@@ -59,6 +77,7 @@
   }
 
-  cout << " SimpleDeglitcher::run() SN=" << snb << " - " << sne << endl; 
+  cout << " SimpleDeglitcher::run() SNRange=" << snb << " - " << sne << endl; 
   try {
+    Timer tm("SimpleDeglitcher::run()");
     // Le debut 
     int wsz2 = wsize/2;
@@ -67,5 +86,5 @@
     for(k=0; k<wsize; k++) 
       vin(k) = getData(0, k+snb);
-    double s = vin.Sum()/wsize;
+    double s = vin.Sum();
     double mean = s/wsize;
     double s2 = vin.SumX2();
@@ -75,13 +94,13 @@
     bool fgglitch = false;
     double valcur,valsub,valadd;
-    for(k=0;k<sne-snb;k++) {
+    for(k=0;k<=sne-snb;k++) {
       totnscount++;
-      if (k%10000 == 0) cout << " DBG: K=" << k << endl;
+//       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);
+	vin((k+wsz2)%wsize) = valadd = getData(0, k+wsz2+snb);
 	s += (valadd-valsub);
-	s2 += (valadd*valadd-valsub-valsub);
+	s2 += (valadd*valadd-valsub*valsub);
 	mean = s/wsize;
 	sigma = sqrt(s2/wsize-mean*mean);
@@ -94,7 +113,18 @@
 	putData(2, k+snb, sigma, 0);
 
+      valcur = vin(k%wsize);
+      if (fgincopie) 
+	putData(3, k+snb, valcur, 0);
+	
       if (!fgout)   continue;  // Pas de sortie out (deglitche)
 
-      valcur = vin(k%wsize);
+      
+//             if (k<100) { 
+//       	cout << "DBG-A-Deglitch[" << k << "] mean=" 
+//       	     << mean << " sigma=" << sigma << " valcur=" 
+//       	     << valcur << " Kgl=" << kgl ;
+//       	if (fgglitch) cout << " In Glitch" ;
+//       	cout << endl;
+//            }
 
       if (valcur < mean+nsig*sigma) {  // inferieur au seuil
@@ -139,12 +169,16 @@
       }
 
-      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;
-      
+//           if (k%5000 == 0) cout << " ---DBG2: K=" << k << " glcount=" 
+// 				<< glcount << " LastPut= " << lastput << endl;
+    }  // Fin de Boucle sur les num-sample
+
+    //DBG    cout << " La fin lastput=" << lastput << " SNE=" << sne; 
+    //DBG    for(k=lastput-snb+1; k<sne-snb; k++) 
+    //DBG      putData(0, k+snb, vin(k%wsize), 0);
+    //    cout << " DBG3- OUT of try bloc ! " << endl;
+    cout << " SimpleDeglitcher::run() - End of processing " 
+    << " TotalSampleCount=" << TotalSampleCount() 
+    <<  " GlitchCount= " << GlitchCount() << endl;
+    if (fgout) deglitchdone = true;
   }  // Bloc try 
   catch (PException & exc) {
@@ -174,8 +208,22 @@
 }
 
+void SimpleFilter::PrintStatus(ostream & os)
+{
+  os << "\n ------------------------------------------------------ \n" 
+     << " SimpleFilter::PrintStatus() - WindowSize=" << WSize() 
+     << " FilterKind= " << Type() << endl;
+  TOIProcessor::PrintStatus(os);
+  os << " Coeff= " ; 
+  for(int k=0; k<wsize; k++) os << coef[k] << " " ;
+  os << endl;
+  os << " TotalSampleCount=" << TotalSampleCount() << endl;
+  os << " ------------------------------------------------------ " << endl;
+}
+
 void SimpleFilter::init() {
   cout << "SimpleFilter::init" << endl;
   declareInput("in");
   declareOutput("out");
+  declareOutput("incopie");
   name = "SimpleFilter";
   //  upExtra = 1;
@@ -187,7 +235,6 @@
   int sne = getMaxIn();
 
-  cout << " SimpleFilter::run(): snb=" << snb << " sne=" << sne << endl;
-
   bool fgout = checkOutputTOIIndex(0);
+  bool fgincopie = checkOutputTOIIndex(1);
 
   if (!checkInputTOIIndex(0)) {
@@ -201,7 +248,10 @@
     throw ParmError("SimpleFilter::run() No output TOI connected!");
   }
+
+  cout << " SimpleFilter::run() SNRange=" << snb << " - " << sne << endl; 
   
 
   try {
+    Timer tm("SimpleFilter::run()");
     // Le debut
     int wsz2 = wsize/2;
@@ -212,5 +262,5 @@
     double mean = vin.Sum()/wsize;
     for(k=0; k<wsize/2; k++) vin(k) = mean; 
-    for(k=0;k<sne-snb;k++) {
+    for(k=0;k<=sne-snb;k++) {
       totnscount++;
       // Calcul mean-sigma
@@ -224,5 +274,7 @@
       }
       putData(0,k+snb,sortie,0);
+      if (fgincopie) putData(1,k+snb,vin(k%wsize),0);
     }  // Boucle sur les num-sample
+    cout << " SimpleFilter::run() - End of processing " << endl;
   }  // Bloc try 
 
