Index: /trunk/ArchTOIPipe/ProcWSophya/Makefile.in
===================================================================
--- /trunk/ArchTOIPipe/ProcWSophya/Makefile.in	(revision 1738)
+++ /trunk/ArchTOIPipe/ProcWSophya/Makefile.in	(revision 1739)
@@ -42,5 +42,5 @@
 
 
-SRCFILES=map2toi.cc toi2map.cc rztoi.cc simtoipr.cc ktoibad.cc
+SRCFILES=map2toi.cc toi2map.cc rztoi.cc simtoipr.cc ktoibad.cc smoothtoi.cc
 
 FILES=$(patsubst %.c,%.o,$(SRCFILES:.cc=.o))
Index: /trunk/ArchTOIPipe/ProcWSophya/ktoibad.cc
===================================================================
--- /trunk/ArchTOIPipe/ProcWSophya/ktoibad.cc	(revision 1738)
+++ /trunk/ArchTOIPipe/ProcWSophya/ktoibad.cc	(revision 1739)
@@ -172,5 +172,10 @@
 int_4 lmmin = lm/2; if(lmmin<2) lmmin=2;
 
-
+// Initialisation
+if(LSide>0) for(int_4 sn=snb;sn<snb+LSide && sn<=sne;sn++) {
+  r_8 bolog; uint_8 fgbolog=0;
+  getData(0,sn,bolog,fgbolog);
+  if(!(fgbolog & flgNotLookAt)) Slpb[1]->Push((r_8)sn,bolog);
+}
 
 for(int_4 sn=snb;sn<=sne;sn++) {
Index: /trunk/ArchTOIPipe/ProcWSophya/smoothtoi.cc
===================================================================
--- /trunk/ArchTOIPipe/ProcWSophya/smoothtoi.cc	(revision 1739)
+++ /trunk/ArchTOIPipe/ProcWSophya/smoothtoi.cc	(revision 1739)
@@ -0,0 +1,136 @@
+#include "machdefs.h"
+#include "toimanager.h"
+#include "pexceptions.h"
+#include "smoothtoi.h"
+
+
+////////////////////////////////////////////////////////////////////////
+// Calcul d'une valeur lissee
+// |--lsm--|<sample>|--lsm--|
+////////////////////////////////////////////////////////////////////////
+
+DataSmooth::DataSmooth(uint_4 lsm,uint_4 deg)
+  : LSmooth(lsm), DegSmooth(deg)
+{
+ if(DegSmooth>2) DegSmooth=2;
+ if(LSmooth<DegSmooth+1) LSmooth = DegSmooth+1;
+ DoNotLookAt();
+ SetFlagFailed();
+ SetBuffUpd();
+ MinSmoothLength();
+}
+
+DataSmooth::~DataSmooth()
+{
+}
+
+void DataSmooth::Print(ostream & os)
+{
+ os<<"DataSmooth::Print LSmooth="<<LSmooth
+   <<" LSmoothMin="<<LSmoothMin
+   <<" DegSmooth="<<DegSmooth<<endl
+   <<" .... BuffUpdate="<<BuffUpdate
+   <<" flgNotLookAt="<<flgNotLookAt
+   <<" flgNotSmoothed="<<flgNotSmoothed<<endl;
+}
+
+void DataSmooth::init()
+{
+ cout << "DataSmooth::init" << endl;
+ declareInput("DataIn");       // input index 0
+ declareOutput("DataSmooth");     // output index 0
+
+ int_4 lbuff = 2*LSmooth +10;
+ if(neededHistory<lbuff) setNeededHistory(lbuff);
+}
+
+void DataSmooth::run()
+{
+long snb = getMinIn();
+long sne = getMaxIn();
+
+if(snb>sne) {
+  cout<<"DataSmooth::run() - Bad sample interval"<<snb<<" , "<<sne<<endl;
+  throw ParmError("DataSmooth::run() - Bad sample interval");
+}
+if(!checkInputTOIIndex(0)) {
+  cout<<"DataSmooth::run() - Input TOI (DataIn) not connected! "<<endl;
+  throw ParmError("DataSmooth::run() Input TOI (DataIn) not connected!");
+}
+if(!checkOutputTOIIndex(0)) {
+  cout<<"DataSmooth::run() - Output TOI (DataOut) not connected! "<<endl;
+  throw ParmError("DataSmooth::run() Output TOI (DataOut) not connected!");
+}
+
+//---------------------------------------------------------
+try {
+
+ SLinParBuff slb0(LSmooth,BuffUpdate,0.,0.,true);
+ SLinParBuff slb1(LSmooth,BuffUpdate,0.,0.,true);
+ SLinParBuffMerger slbm;
+
+cout<<"DataSmooth::run(): SampleNum de "<<snb<<" a "<<sne<<endl;
+uint_4 notsmoothed=0;
+
+// Initialisation
+for(int_4 sn=snb;sn<snb+LSmooth && sn<=sne;sn++) {
+  r_8 bolo; uint_8 fgbolo=0;
+  getData(0,sn,bolo,fgbolo);
+  if(!(fgbolo & flgNotLookAt)) slb1.Push((r_8)sn,bolo);
+}
+
+for(int_4 sn=snb;sn<=sne;sn++) {
+
+  r_8 bolo; uint_8 fgbolo=0;
+  getData(0,sn,bolo,fgbolo);
+
+  //    <---lms---><i><---lms--->
+  //              |             |
+  //             ideb          ifin
+  int_4 ideb=sn-1, ifin=sn+LSmooth;
+
+  if(ideb>=snb) {
+    r_8 bol; uint_8 fgb=0;
+    getData(0,ideb,bol,fgb);
+    if(fgb&flgNotLookAt) slb0.Pop();
+      else slb0.Push((r_8)ideb,bol);
+  }
+
+  if(ifin<=sne) {
+    r_8 bol; uint_8 fgb=0;
+    getData(0,ifin,bol,fgb);
+    if(fgb&flgNotLookAt) slb1.Pop();
+      else slb1.Push((r_8)ifin,bol);
+  } else slb1.Pop();
+
+  slbm.Reset(); slbm.Add(slb0); slbm.Add(slb1);
+
+  if(slbm.NPoints()>=LSmoothMin) {
+    r_8 s=-1.,a0,a1=0.,a2=0.;
+    if(DegSmooth==0)      s = slbm.Compute(a0);
+    else if(DegSmooth==1) s = slbm.Compute(a0,a1);
+    else if(DegSmooth==2) s = slbm.Compute(a0,a1,a2);
+    if(s>=0.) {
+      bolo -= a0 + (a1 + a2*sn)*sn;
+    } else {
+      fgbolo |= flgNotSmoothed;
+      notsmoothed++;
+    }
+  } else {
+    fgbolo |= flgNotSmoothed;
+    notsmoothed++;
+  }
+
+  putData(0,sn,bolo,fgbolo);
+}
+cout<<"DataSmooth::run(): Fin de boucle: notsmoothed="<<notsmoothed
+    <<" / tot="<<sne-snb+1<<endl;
+
+//---------------------------------------------------------
+} catch (PException & exc) {
+  cout<<"DataSmooth: Catched Exception "<<(string)typeid(exc).name()
+      <<"\n .... Msg= "<<exc.Msg()<<endl;
+}
+
+return;                                                                            
+}
Index: /trunk/ArchTOIPipe/ProcWSophya/smoothtoi.h
===================================================================
--- /trunk/ArchTOIPipe/ProcWSophya/smoothtoi.h	(revision 1739)
+++ /trunk/ArchTOIPipe/ProcWSophya/smoothtoi.h	(revision 1739)
@@ -0,0 +1,45 @@
+// This may look like C code, but it is really -*- C++ -*-
+#ifndef SMOOTHTOI_H
+#define SMOOTHTOI_H
+
+#include "toiprocessor.h"
+#include "flagtoidef.h"
+#include "slinparbuff.h"
+
+//////////////////////////////////////////////////////
+//-- Pour flagguer les samples hors dynamique
+//   toi BoloIn ---> |FlagOutOfRange| ---> toi BoloOut
+//////////////////////////////////////////////////////
+class DataSmooth : public TOIProcessor {
+public:
+  DataSmooth(uint_4 lsm,uint_4 deg);
+  virtual ~DataSmooth();
+
+  virtual void	init(void);
+  virtual void	run(void);
+
+  //! Ne pas traiter les samples flaggues par la valeur flag
+  inline void DoNotLookAt(uint_8 flag=FlgToiAll) {flgNotLookAt = flag;}
+  //! Flagguer les valeurs ou le smooth a echoue avec la valeur flag
+  inline void SetFlagFailed(uint_8 flag=FlgToiInterp) {flgNotSmoothed = flag;}
+  //! Frequency to update SLinParBuff buffer
+  inline void SetBuffUpd(uint_4 bupd=100) {BuffUpdate = bupd;}
+  //! Nombre minimum de valeurs requises pour smoother un sample
+  inline void MinSmoothLength(uint_4 lsmin=0)
+              {
+              if(lsmin==0) lsmin=LSmooth;
+              LSmoothMin = (lsmin<DegSmooth+1)? DegSmooth+1: lsmin;
+              }
+
+  //! Print
+  void Print(ostream & os);
+  inline void Print(void) {Print(cout);}
+
+protected:
+  uint_8 flgNotLookAt,flgNotSmoothed;
+  uint_4 LSmooth,LSmoothMin;
+  uint_4 DegSmooth;
+  uint_4 BuffUpdate;
+};
+
+#endif
Index: /trunk/ArchTOIPipe/ProcWSophya/toi2map.h
===================================================================
--- /trunk/ArchTOIPipe/ProcWSophya/toi2map.h	(revision 1738)
+++ /trunk/ArchTOIPipe/ProcWSophya/toi2map.h	(revision 1739)
@@ -5,5 +5,5 @@
 //                               Christophe Magneville
 //                               Reza Ansari
-// $Id: toi2map.h,v 1.7 2001-11-08 15:47:46 aubourg Exp $
+// $Id: toi2map.h,v 1.8 2001-11-08 17:47:23 cmv Exp $
 
 #ifndef TOI2MAP_H
@@ -50,5 +50,5 @@
               {mTypCoorOut = mfg;}
   // Test on flag value ? if yes, BAD sample have flag matching mBadFlag
-  inline void SetTestFlag(bool tflg=false, uint_8 badflg=0)
+  inline void SetTestFlag(bool tflg=false, uint_8 badflg=FlgToiAll)
               {mTFlag = tflg; mBadFlag = badflg;}
   // Test on min value ? if yes, GOOD sample have value >= mValMin
Index: /trunk/ArchTOIPipe/TestPipes/tstktoibad.cc
===================================================================
--- /trunk/ArchTOIPipe/TestPipes/tstktoibad.cc	(revision 1738)
+++ /trunk/ArchTOIPipe/TestPipes/tstktoibad.cc	(revision 1739)
@@ -9,4 +9,5 @@
 #include "sophyainit.h"
 #include "ktoibad.h"
+#include "smoothtoi.h"
 
 void usage(void);
@@ -18,4 +19,5 @@
  <<" -g lg,lm,nsg,bupd"
  <<" -a lmaround"
+ <<" -S lsmooth,sdeg"
  <<" -p lp,sn1,sn2"
  <<endl;
@@ -27,9 +29,10 @@
  int_4 lp=1,sn1=-1,sn2=-1;
  uint_4 lg=3,lm=15,bupd=1000,lmaround=10;
+ uint_4 lsmooth=1024,sdeg=2;
  r_8 nsg=5.;
  r_8 vmin=1.,vmax=-1.;
  char *label_bolomuv = "boloMuV";
   int c;
- while((c = getopt(narg,arg,"hs:g:d:b:a:p:")) != -1) {
+ while((c = getopt(narg,arg,"hs:g:d:b:a:S:p:")) != -1) {
   switch (c) {
   case 's' :
@@ -44,4 +47,7 @@
   case 'a' :
    sscanf(optarg,"%d",&lmaround);
+   break;
+  case 'S' :
+   sscanf(optarg,"%d,%d",&lsmooth,&sdeg);
    break;
   case 'b' :
@@ -90,4 +96,7 @@
  flgaround.Print();
 
+ DataSmooth dsmooth(lsmooth,sdeg);
+ dsmooth.Print();
+
  ////// Creation des tuyaux et des connections associees
  int taille = 8192;
@@ -108,8 +117,14 @@
  flgaround.addInput("DataIn",toi2);
 
- // tuyau bolo pour entree fits writer
+ // tuyau bolo pour smooth DataSmooth et fits writer
  TOISegmented * toi3 = new TOISegmented("tuyau_bolo_3",taille);
  flgaround.addOutput("DataOut",toi3);
+ dsmooth.addInput("DataIn",toi3);
  wfits.addInput(label_bolomuv,toi3,true);
+
+ // tuyau bolo pour entree fits writer
+ TOISegmented * toi31 = new TOISegmented("tuyau_bolo_31",taille);
+ dsmooth.addOutput("DataSmooth",toi31);
+ wfits.addInput("smbolo",toi31,true);
 
  // Print de status avant lancement des taches:
@@ -123,4 +138,5 @@
  toi2->PrintStatus(cout);  
  toi3->PrintStatus(cout);  
+ toi31->PrintStatus(cout);  
  cout<<"-----FlagOutOfRange ::PrintStatus() : -----"<<endl;
  flgout.PrintStatus(cout);  
@@ -129,4 +145,6 @@
  cout<<"-----FlagAround ::PrintStatus() : -----"<<endl;
  flgaround.PrintStatus(cout);  
+ cout<<"-----DataSmooth ::PrintStatus() : -----"<<endl;
+ dsmooth.PrintStatus(cout);  
 
  // Lancement des taches
@@ -137,4 +155,5 @@
  deglitch.start();
  flgaround.start();  
+ dsmooth.start();  
 
  // Gestion de la re-connection des threads
Index: /trunk/ArchTOIPipe/TestPipes/tsttoi2map.cc
===================================================================
--- /trunk/ArchTOIPipe/TestPipes/tsttoi2map.cc	(revision 1738)
+++ /trunk/ArchTOIPipe/TestPipes/tsttoi2map.cc	(revision 1739)
@@ -85,5 +85,5 @@
     cout<<"Requested Samples from "<<sdeb<<" , "<<sfin<<endl;
     if(sfin>=sdeb) mgr->setRequestedSample(sdeb,sfin);
-    else {cout<<"Bad sample interval "<<endl; exit(2);}
+    //else {cout<<"Bad sample interval "<<endl; exit(2);}
     break;
   case 'w' :
Index: /trunk/ArchTOIPipe/files_sophya
===================================================================
--- /trunk/ArchTOIPipe/files_sophya	(revision 1738)
+++ /trunk/ArchTOIPipe/files_sophya	(revision 1739)
@@ -10,2 +10,4 @@
 ktoibad.h
 ktoibad.cc
+smoothtoi.h
+smoothtoi.cc
