Index: /trunk/ArchTOIPipe/ProcWSophya/ktoibad.cc
===================================================================
--- /trunk/ArchTOIPipe/ProcWSophya/ktoibad.cc	(revision 1735)
+++ /trunk/ArchTOIPipe/ProcWSophya/ktoibad.cc	(revision 1736)
@@ -4,4 +4,80 @@
 #include "ntuple.h"
 #include "ktoibad.h"
+
+
+////////////////////////////////////////////////////////////////////////
+// Flag des sample hors dynamique
+////////////////////////////////////////////////////////////////////////
+
+FlagOutOfRange::FlagOutOfRange(r_8 vmin,r_8 vmax,uint_8 flag)
+  : VMin(vmin), VMax(vmax), flgBad(flag)
+{
+ if(VMax<VMin) {
+   cout<<"FlagOutOfRange::run() - Bad range interval "<<VMin<<" , "<<VMax<<endl;
+   throw ParmError("FlagOutOfRange::FlagOutOfRange() - Bad range interval");
+ }
+}
+
+FlagOutOfRange::~FlagOutOfRange()
+{
+}
+
+void FlagOutOfRange::Print(ostream & os)
+{
+ os<<"FlagOutOfRange::Print Range: ["<<VMin<<","<<VMax<<"] flgBad="<<flgBad<<endl;
+}
+
+void FlagOutOfRange::init()
+{
+  cout << "FlagOutOfRange::init" << endl;
+  declareInput("DataIn");       // input index 0
+  declareOutput("DataOut");     // output index 0
+}
+
+void FlagOutOfRange::run()
+{
+long snb = getMinIn();
+long sne = getMaxIn();
+
+if(snb>sne) {
+  cout<<"FlagOutOfRange::run() - Bad sample interval"<<snb<<" , "<<sne<<endl;
+  throw ParmError("FlagOutOfRange::run() - Bad sample interval");
+}
+if(!checkInputTOIIndex(0)) {
+  cout<<"FlagOutOfRange::run() - Input TOI (DataIn) not connected! "<<endl;
+  throw ParmError("FlagOutOfRange::run() Input TOI (DataIn) not connected!");
+}
+if(!checkOutputTOIIndex(0)) {
+  cout<<"FlagOutOfRange::run() - Output TOI (DataOut) not connected! "<<endl;
+  throw ParmError("FlagOutOfRange::run() Output TOI (DataOut) not connected!");
+}
+
+//---------------------------------------------------------
+try {
+
+cout<<"FlagOutOfRange::run(): SampleNum de "<<snb<<" a "<<sne<<endl;
+uint_4 nbad=0;
+
+for(int_4 sn=snb;sn<=sne;sn++) {
+  r_8 bolo; uint_8 fgbolo=0;
+  getData(0,sn,bolo,fgbolo);
+  if(bolo<VMin || bolo>VMax) { // Pixel out of range
+    nbad++;
+    fgbolo |= flgBad;
+  }
+  putData(0,sn,bolo,fgbolo);
+}
+cout<<"FlagOutOfRange::run(): Fin de boucle: nbad="<<nbad
+    <<" / tot="<<sne-snb+1<<endl;
+
+//---------------------------------------------------------
+} catch (PException & exc) {
+  cout<<"FlagOutOfRange: Catched Exception "<<(string)typeid(exc).name()
+      <<"\n .... Msg= "<<exc.Msg()<<endl;
+}
+
+return;                                                                            
+}
+
 
 ////////////////////////////////////////////////////////////////////////
@@ -19,5 +95,4 @@
 ////////////////////////////////////////////////////////////////////////
 
-////////////////////////////////////////////////////////////////////////
 FlagGlitch::FlagGlitch(uint_4 lg,uint_4 lm,r_8 nsg)
   : mLP(0), mLPsnb(-1), mLPsne(-1)
@@ -42,5 +117,4 @@
 }
 
-////////////////////////////////////////////////////////////////////////
 void FlagGlitch::Print(ostream & os)
 {
@@ -52,8 +126,9 @@
 
 ////////////////////////////////////////////////////////////////////////
-void FlagGlitch::init() {
+void FlagGlitch::init()
+{
   if(mLP) cout << "FlagGlitch::init" << endl;
-  declareInput("BoloIn");       // input index 0
-  declareOutput("BoloOut");     // output index 0
+  declareInput("DataIn");       // input index 0
+  declareOutput("DataOut");     // output index 0
 
   for(int i=0;i<2;i++)
@@ -64,5 +139,4 @@
 }
 
-////////////////////////////////////////////////////////////////////////
 void FlagGlitch::run()
 {
@@ -75,10 +149,10 @@
 }
 if(!checkInputTOIIndex(0)) {
-  cout<<"FlagGlitch::run() - Input TOI (BoloIn) not connected! "<<endl;
-  throw ParmError("FlagGlitch::run() Input TOI (BoloIn) not connected!");
+  cout<<"FlagGlitch::run() - Input TOI (DataIn) not connected! "<<endl;
+  throw ParmError("FlagGlitch::run() Input TOI (DataIn) not connected!");
 }
 if(!checkOutputTOIIndex(0)) {
-  cout<<"FlagGlitch::run() - Output TOI (BoloOut) not connected! "<<endl;
-  throw ParmError("FlagGlitch::run() Output TOI (BoloOut) not connected!");
+  cout<<"FlagGlitch::run() - Output TOI (DataOut) not connected! "<<endl;
+  throw ParmError("FlagGlitch::run() Output TOI (DataOut) not connected!");
 }
 
@@ -220,9 +294,4 @@
 
 
-
-
-
-
-
 ////////////////////////////////////////////////////////////////////////
 // Flag des sample autour d'un sample deja flaggue :
@@ -232,6 +301,5 @@
 ////////////////////////////////////////////////////////////////////////
 
-////////////////////////////////////////////////////////////////////////
-FlagAround::FlagAround(uint_4 lm,uint_8 flgs)
+FlagAroundFlag::FlagAroundFlag(uint_4 lm,uint_8 flgs)
 {
  // Mise en forme des arguments
@@ -240,24 +308,24 @@
  SetFlag();
  SetFlagAroundFlag(flgs);
-}
-
-FlagAround::~FlagAround()
-{
-}
-
-////////////////////////////////////////////////////////////////////////
-void FlagAround::Print(ostream & os)
-{
- os<<"FlagAround::Print"
+ SetLimits();
+}
+
+FlagAroundFlag::~FlagAroundFlag()
+{
+}
+
+void FlagAroundFlag::Print(ostream & os)
+{
+ os<<"FlagAroundFlag::Print"
    <<" LSide="<<LSide
-   <<" flgSample="<<flgSample<<" flgAround="<<flgAround
-   <<endl;
-}
-
-////////////////////////////////////////////////////////////////////////
-void FlagAround::init() {
-  cout << "FlagAround::init" << endl;
-  declareInput("BoloIn");       // input index 0
-  declareOutput("BoloOut");     // output index 0
+   <<" flgSample="<<flgSample<<" flgAround="<<flgAround<<endl
+   <<" ... Range: ["<<VMin<<","<<VMax<<"]"<<" flgBad="<<flgBad<<endl;
+}
+
+void FlagAroundFlag::init()
+{
+  cout << "FlagAroundFlag::init" << endl;
+  declareInput("DataIn");       // input index 0
+  declareOutput("DataOut");     // output index 0
 
   int_4 lbuff = 2*LSide +10;
@@ -265,6 +333,5 @@
 }
 
-////////////////////////////////////////////////////////////////////////
-void FlagAround::run()
+void FlagAroundFlag::run()
 {
 long snb = getMinIn();
@@ -272,14 +339,14 @@
 
 if(snb>sne) {
-  cout<<"FlagAround::run() - Bad sample interval"<<snb<<" , "<<sne<<endl;
-  throw ParmError("FlagAround::run() - Bad sample interval");
+  cout<<"FlagAroundFlag::run() - Bad sample interval"<<snb<<" , "<<sne<<endl;
+  throw ParmError("FlagAroundFlag::run() - Bad sample interval");
 }
 if(!checkInputTOIIndex(0)) {
-  cout<<"FlagAround::run() - Input TOI (BoloIn) not connected! "<<endl;
-  throw ParmError("FlagAround::run() Input TOI (BoloIn) not connected!");
+  cout<<"FlagAroundFlag::run() - Input TOI (DataIn) not connected! "<<endl;
+  throw ParmError("FlagAroundFlag::run() Input TOI (DataIn) not connected!");
 }
 if(!checkOutputTOIIndex(0)) {
-  cout<<"FlagAround::run() - Output TOI (BoloOut) not connected! "<<endl;
-  throw ParmError("FlagAround::run() Output TOI (BoloOut) not connected!");
+  cout<<"FlagAroundFlag::run() - Output TOI (DataOut) not connected! "<<endl;
+  throw ParmError("FlagAroundFlag::run() Output TOI (DataOut) not connected!");
 }
 
@@ -287,13 +354,16 @@
 try {
 
-cout<<"FlagAround::run(): SampleNum de "<<snb<<" a "<<sne<<endl;
-uint_4 nflag=0, nflagged=0, nflagalready=0;
-
-// Un peu boeuf! On pourrait optimiser!
+cout<<"FlagAroundFlag::run(): SampleNum de "<<snb<<" a "<<sne<<endl;
+uint_4 nflag=0, nflagged=0, nflagalready=0, nbad=0;
+
+// Un peu lourdingue! On pourrait optimiser!
 // Si on ne tue pas (LSide=0), alors juste un transfert de donnees
 for(int_4 sn=snb;sn<=sne;sn++) {
   r_8 bolo; uint_8 fgbolo=0;
   getData(0,sn,bolo,fgbolo);
-  if(fgbolo&flgSample) { // Pixel flaggue flgSample
+  if(VMin<=VMax && (bolo<VMin || bolo>VMax)) { // Pixel out of range
+    nbad++;
+    fgbolo |= flgBad;
+  } else if(fgbolo&flgSample) { // Pixel flaggue flgSample
     nflag++;
   } else if(fgbolo&flgAround) { // Pixel deja flagge around?
@@ -310,11 +380,11 @@
   putData(0,sn,bolo,fgbolo);
 }
-cout<<"FlagAround::run(): Fin de boucle: nflag="<<nflag
-    <<" nflagged="<<nflagged<<" (already="<<nflagalready
-    <<") / tot="<<sne-snb+1<<endl;
+cout<<"FlagAroundFlag::run(): Fin de boucle: nflag="<<nflag
+    <<" nflagged="<<nflagged<<" (already="<<nflagalready<<")"<<endl
+    <<" ......      bad="<<nbad<<" / tot="<<sne-snb+1<<endl;
 
 //---------------------------------------------------------
 } catch (PException & exc) {
-  cout<<"FlagAround: Catched Exception "<<(string)typeid(exc).name()
+  cout<<"FlagAroundFlag: Catched Exception "<<(string)typeid(exc).name()
       <<"\n .... Msg= "<<exc.Msg()<<endl;
 }
Index: /trunk/ArchTOIPipe/ProcWSophya/ktoibad.h
===================================================================
--- /trunk/ArchTOIPipe/ProcWSophya/ktoibad.h	(revision 1735)
+++ /trunk/ArchTOIPipe/ProcWSophya/ktoibad.h	(revision 1736)
@@ -7,6 +7,29 @@
 #include "slinparbuff.h"
 
+//////////////////////////////////////////////////////
+//-- Pour flagguer les samples hors dynamique
+//   toi BoloIn ---> |FlagOutOfRange| ---> toi BoloOut
+//////////////////////////////////////////////////////
+class FlagOutOfRange : public TOIProcessor {
+public:
+  FlagOutOfRange(r_8 vmin,r_8 vmax,uint_8 flag=FlgToiOut);
+  virtual ~FlagOutOfRange();
+
+  virtual void	init(void);
+  virtual void	run(void);
+
+  //! Print
+  void Print(ostream & os);
+  inline void Print(void) {Print(cout);}
+
+protected:
+  uint_8 flgBad;
+  r_8 VMin,VMax;
+};
+
+//////////////////////////////////////////////////////
 //-- Pour rechercher les glitches
-//   toi BoloIn ---> |FlagGlitch | ---> toi BoloOut
+//   toi BoloIn ---> |FlagGlitch| ---> toi BoloOut
+//////////////////////////////////////////////////////
 class FlagGlitch : public TOIProcessor {
 public:
@@ -42,10 +65,13 @@
 };
 
+//////////////////////////////////////////////////////
 //-- Pour flagguer les samples autour de samples deja flaggues
-//   toi BoloIn ---> |FlagAround | ---> toi BoloOut
-class FlagAround : public TOIProcessor {
+//   Permet aussi de flagguer les samples ayant de mauvaises valeurs.
+//   toi BoloIn ---> |FlagAroundFlag| ---> toi BoloOut
+//////////////////////////////////////////////////////
+class FlagAroundFlag : public TOIProcessor {
 public:
-  FlagAround(uint_4 lm,uint_8 flgs=FlgToiAll);
-  virtual ~FlagAround();
+  FlagAroundFlag(uint_4 lm,uint_8 flgs=FlgToiAll);
+  virtual ~FlagAroundFlag();
 
   virtual void	init(void);
@@ -56,4 +82,7 @@
   //! Flagguer autour des samples ayant la valeur flag
   inline void SetFlagAroundFlag(uint_8 flag=FlgToiAll) {flgSample = flag;}
+  //! Flagguer les samples hors limite
+  inline void SetLimits(r_8 vmin=1.,r_8 vmax=-1.,uint_8 flag=FlgToiOut)
+              {VMin=vmin; VMax=vmax; flgBad = flag;}
   //! Print
   void Print(ostream & os);
@@ -61,6 +90,7 @@
 
 protected:
-  uint_8 flgSample,flgAround;
+  uint_8 flgSample,flgAround,flgBad;
   uint_4 LSide;
+  r_8 VMin,VMax;
 };
 
Index: /trunk/ArchTOIPipe/TestPipes/tstktoibad.cc
===================================================================
--- /trunk/ArchTOIPipe/TestPipes/tstktoibad.cc	(revision 1735)
+++ /trunk/ArchTOIPipe/TestPipes/tstktoibad.cc	(revision 1736)
@@ -15,4 +15,5 @@
  <<" -s sdeb,sfin"
  <<" -b label_bolomuv"
+ <<" -d vmin,vmax"
  <<" -g lg,lm,nsg,bupd"
  <<" -a lmaround"
@@ -27,10 +28,14 @@
  uint_4 lg=3,lm=15,bupd=1000,lmaround=10;
  r_8 nsg=5.;
+ r_8 vmin=1.,vmax=-1.;
  char *label_bolomuv = "boloMuV";
   int c;
- while((c = getopt(narg,arg,"hs:g:b:a:p:")) != -1) {
+ while((c = getopt(narg,arg,"hs:g:d:b:a:p:")) != -1) {
   switch (c) {
   case 's' :
    sscanf(optarg,"%d,%d",&sdeb,&sfin);
+   break;
+  case 'd' :
+   sscanf(optarg,"%lf,%lf",&vmin,&vmax);
    break;
   case 'g' :
@@ -63,13 +68,17 @@
  //--------------------------------------------------------------------
 
+ ////// Lecteurs / ecriveurs FITS
  // FITS reader
  FITSTOIReader rfits(fitsin);
  cout<<"Lecteur: created"<<endl;
 
- // FITS writter
+ // FITS writer
  FITSTOIWriter wfits(fitsout);
  cout<<"Ecriveur: created"<<endl;
 
- // TOI processeurs
+ ////// TOI processeurs
+ FlagOutOfRange flgout(vmin,vmax);
+ flgout.Print();
+
  FlagGlitch deglitch(lg,lm,nsg);
  deglitch.SetBuffUpd(bupd);
@@ -77,23 +86,30 @@
  deglitch.Print();
 
- FlagAround flgaround(lm);
+ FlagAroundFlag flgaround(lm);
+ //flgaround.SetLimits(vmin,vmax);
  flgaround.Print();
 
- // Creation des tuyaux et des connections associees
+ ////// Creation des tuyaux et des connections associees
  int taille = 8192;
+
+ // tuyau bolo pour entree processeur FlagOutOfRange
+ TOISegmented * toi0 = new TOISegmented("tuyau_bolo_0",taille);
+ rfits.addOutput(label_bolomuv,toi0);
+ flgout.addInput("DataIn",toi0);
+
  // tuyau bolo pour entree processeur FlagGlitch
- TOISegmented * toi1 = new TOISegmented("tuyau_bolo_in1",taille);
- rfits.addOutput(label_bolomuv,toi1);
- deglitch.addInput("BoloIn",toi1);
+ TOISegmented * toi1 = new TOISegmented("tuyau_bolo_1",taille);
+ flgout.addOutput("DataOut",toi1);
+ deglitch.addInput("DataIn",toi1);
 
  // tuyau bolo pour entree processeur FlagAround
- TOISegmented * toi2 = new TOISegmented("tuyau_bolo_in2",taille);
- deglitch.addOutput("BoloOut",toi2);
- flgaround.addInput("BoloIn",toi2);
+ TOISegmented * toi2 = new TOISegmented("tuyau_bolo_2",taille);
+ deglitch.addOutput("DataOut",toi2);
+ flgaround.addInput("DataIn",toi2);
 
  // tuyau bolo pour entree fits writer
- TOISegmented * toiout = new TOISegmented("tuyau_bolo_out",taille);
- flgaround.addOutput("BoloOut",toiout);
- wfits.addInput(label_bolomuv,toiout,true);
+ TOISegmented * toi3 = new TOISegmented("tuyau_bolo_3",taille);
+ flgaround.addOutput("DataOut",toi3);
+ wfits.addInput(label_bolomuv,toi3,true);
 
  // Print de status avant lancement des taches:
@@ -103,7 +119,10 @@
  wfits.PrintStatus(cout);  
  cout<<"----- TOISegmented::PrintStatus() : -----"<<endl;
+ toi0->PrintStatus(cout);  
  toi1->PrintStatus(cout);  
  toi2->PrintStatus(cout);  
- toiout->PrintStatus(cout);  
+ toi3->PrintStatus(cout);  
+ cout<<"-----FlagOutOfRange ::PrintStatus() : -----"<<endl;
+ flgout.PrintStatus(cout);  
  cout<<"-----FlagGlitch ::PrintStatus() : -----"<<endl;
  deglitch.PrintStatus(cout);  
@@ -115,4 +134,5 @@
  rfits.start();
  wfits.start();
+ flgout.start();  
  deglitch.start();
  flgaround.start();  
