Index: /trunk/AddOn/TAcq/bracqvers.h
===================================================================
--- /trunk/AddOn/TAcq/bracqvers.h	(revision 3682)
+++ /trunk/AddOn/TAcq/bracqvers.h	(revision 3683)
@@ -5,6 +5,6 @@
    Software version     LAL - 2008-2010 
 */
-#define BAOR_ACQ_VER 6.5
-#define BAOR_ACQ_VER_STR "BaoAcq_v6r5_Nov09 "
+#define BAOR_ACQ_VER 6.6
+#define BAOR_ACQ_VER_STR "BaoAcq_v6r6_Nov09 "
 
 #endif
Index: /trunk/AddOn/TAcq/brbaseproc.cc
===================================================================
--- /trunk/AddOn/TAcq/brbaseproc.cc	(revision 3683)
+++ /trunk/AddOn/TAcq/brbaseproc.cc	(revision 3683)
@@ -0,0 +1,97 @@
+//----------------------------------------------------------------
+// Projet BAORadio - (C) LAL/IRFU  2008-2010
+// Classes de base pour les threads de traitememt donnees BAORadio 
+//----------------------------------------------------------------
+
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <fstream>
+#include "brbaseproc.h"
+
+
+using namespace SOPHYA;
+//---------------------------------------------------------------------
+// Classe de traitement - calcul de visibilite pour n fibres 
+//---------------------------------------------------------------------
+
+/* --Methode-- */
+BRBaseProcessor::BRBaseProcessor(RAcqMemZoneMgr& memgr)
+  : memgr_(memgr) 
+{
+  for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++)  {
+    vpaq_.push_back(BRPaquet(NULL,memgr_.PaqSize()));
+    vpchk_.push_back(BRPaqChecker(true,0)); 
+    curfc_.push_back(0);
+  }
+  totprocnpaq_=0;
+}
+
+/* --Methode-- */
+void BRBaseProcessor::run()
+{
+  setRC(1);	
+  int rc=0;
+  try {
+    cout << " BRBaseProcessor::run() - Starting " << " NFibers=" << memgr_.NbFibres() 
+	 << " NChan=" << 2*memgr_.NbFibres() << endl;	
+
+    size_t paqsz=memgr_.PaqSize();
+    vector<Byte*> fbuff;
+    for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++)  fbuff.push_back(NULL);
+    bool fgrun=true;
+    while (fgrun) {
+      if (stop_) break;
+      if (memgr_.GetRunState() == MemZR_Stopped) break;
+      int mid = memgr_.FindMemZoneId(MemZA_ProcA);
+      Byte* buffg = memgr_.GetMemZone(mid);
+      if (buffg == NULL) {
+	cout << "BRBaseProcessor::run()/ERROR memgr.GetMemZone(" << mid << ") -> NULL" << endl;
+	setRC(7);      fgrun=false;		
+	break;	
+      }
+      for(size_t jp=0; jp<memgr_.NbPaquets(); jp++) {   // boucle sur les paquets d'une zone  
+	fgokallfibers_=true;
+	for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++) {
+	  fbuff[fib] = memgr_.GetMemZone(mid,fib);
+	  if (fbuff[fib] == NULL) { // cela ne devrait pas arriver 
+	    cout << "BRBaseProcessor::run()/ERROR memgr.GetMemZone(" << mid << "," << fib << ") -> NULL" << endl;
+	    setRC(9);	  fgrun=false;		
+	    break;
+	  }
+	  vpaq_[fib].Set(fbuff[fib]+jp*paqsz);
+	  vfgok_[fib] = vpchk_[fib].Check(vpaq_[fib],curfc_[fib]);
+	  if (!vfgok_[fib])  fgokallfibers_=false;
+	}
+	//--- Traitement 
+	int rcp = Process();
+	totprocnpaq_++;
+	if (rcp != 0)   { fgrun=false; break; }
+      }  // Fin de boucle sur les paquets 
+      memgr_.FreeMemZone(mid, MemZS_ProcA);
+    } // Fin de boucle sur les zones a traiter 
+    //------------------------------------
+    cout << " --------- END BRBaseProcessor::run() , TotNbProcPaq=" << totprocnpaq_ << endl;
+  }
+  catch (std::exception& exc) {
+    cout << " BRBaseProcessor::run()/catched std::exception " << exc.what() << endl;
+    setRC(98);	
+    return; 
+  }
+  catch(...) {
+    cout << " BRBaseProcessor::run()/catched unknown ... exception " << endl;
+    setRC(99);	
+    return; 
+  }
+
+}
+
+
+/* --Methode-- */
+int BRBaseProcessor::Process()
+{
+  // la methode par defaut ne fait rien 
+  // if (fgokallfibers_) { faire le traitement }
+  return 0;
+}
+
Index: /trunk/AddOn/TAcq/brbaseproc.h
===================================================================
--- /trunk/AddOn/TAcq/brbaseproc.h	(revision 3683)
+++ /trunk/AddOn/TAcq/brbaseproc.h	(revision 3683)
@@ -0,0 +1,45 @@
+#ifndef  BRBASEPROC_H_SEEN
+#define  BRBASEPROC_H_SEEN
+
+//----------------------------------------------------------------
+// Projet BAORadio - (C) LAL/IRFU  2008-2010
+// Classes de threads de traitememt donnees BAORadio 
+//----------------------------------------------------------------
+
+
+#include "racqumem.h"
+#include <string>
+#include <vector>
+#include <iostream>
+
+#include "brpaqu.h"
+
+using namespace std;
+
+//---------------------------------------------------------------------
+// Classe de base pour l'analyse donnees (paquets acquisition) BAORadio 
+// Les classes de traitement des paquets BAORadio peuvent heriter de 
+// cette classe de base BRBaseProcessor en redefinissant la methode Process()
+//---------------------------------------------------------------------
+class BRBaseProcessor : public SOPHYA::ZThread {
+public:	
+  BRBaseProcessor(RAcqMemZoneMgr& memgr);
+  virtual void run();
+  // Methode devant etre redefinie pour effectuer le traitement 
+  virtual int Process();  // renvoie 0 si OK, sinon, arret traitement 
+  inline void Stop();
+  inline void STOP() { stop_ = true; }	
+protected:
+  RAcqMemZoneMgr& memgr_;
+  bool stop_;  
+  vector<BRPaquet> vpaq_;   // Vecteur de BRPaquet pour chaque fibre
+  vector<uint_8> vfgok_;    // Vecteur de flag si paquet OK pour chaque fibre
+  vector<uint_8> curfc_;    // Vecteur de numero de FrameCounter pour chaque fibre
+  bool fgokallfibers_;      // true -> paquets for all fibers OK
+  vector<BRPaqChecker> vpchk_;
+  uint_8 totprocnpaq_; 
+};
+
+
+
+#endif
Index: /trunk/AddOn/TAcq/brfitsrd.cc
===================================================================
--- /trunk/AddOn/TAcq/brfitsrd.cc	(revision 3682)
+++ /trunk/AddOn/TAcq/brfitsrd.cc	(revision 3683)
@@ -1,5 +1,5 @@
 //----------------------------------------------------------------
-// ---- classes de threads pour lecture fichiers minifits
-// LAL -      R. Ansari - Mai 2009 
+// Projet BAORadio - (C) LAL/IRFU  2008-2010
+// Classes de threads pour lecture fichiers fits BAORadio
 //----------------------------------------------------------------
 
@@ -10,5 +10,6 @@
 #include <unistd.h>
 #include <fstream>
-#include <signal.h>
+#include <exception>
+
 #include "pexceptions.h"
 #include "timestamp.h"
@@ -16,23 +17,218 @@
 
 #include "brpaqu.h"
-#include "minifits.h"
 
 #include "resusage.h" // Pour mesure temps elapsed/CPU ...
-#include "datatable.h" // Pour sauver les entetes de paquet 
 #include <sys/time.h>  // pour gettimeofday
 
+using namespace SOPHYA;
+
+//---------------------------------------------------------------------
+// Classe thread de lecture de Multi-fibres de fichiers FITS BAORadio  
+//---------------------------------------------------------------------
+
+/* --Methode-- */
+BRMultiFitsReader::BRMultiFitsReader(RAcqMemZoneMgr& mem, vector<string>& dirs, bool rdsamefc, 
+				     uint_4 imin, uint_4 imax, uint_4 istep)
+  :  memgr_(mem), dirs_(dirs), rdsamefc_(rdsamefc), imin_(imin), imax_(imax), istep_(istep) 
+{
+  SetPrintLevel();
+  totnbytesrd_ = 0;
+  totsamefc_ = 0;
+  if (memgr_.NbFibres() > MAXANAFIB) 
+    throw BAORadioException("BRMultiFitsReader::BRMultiFitsReader/ NbFibres>MAXANAFIB "); 
+  if (dirs_.size() != memgr_.NbFibres()) 
+    throw BAORadioException("BRMultiFitsReader::BRMultiFitsReader/ NbFibres != Nb Data Directories"); 
+
+  packsize_=memgr_.PaqSize();
+  mid_=-2; 
+  mmbuf_=NULL;
+  max_targ_npaq = memgr_.NbPaquets();
+  for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++) mmbufib_[fib]=NULL;
+
+  char flnm[1024];
+  for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++) {
+    sprintf(flnm,"%s/signal%d.fits",dirs_[fib].c_str(),imin_);
+    mff_[fib].Open(flnm, MF_Read);
+    if (mff_[fib].NAxis1() != memgr_.PaqSize())  {
+      cout << " BRMultiFitsReader::BRMultiFitsReader/ fib=" << fib << " File=" << flnm <<
+	" NAxis1()= " << mff_[fib].NAxis1() << " <> PaqSize()=" << memgr_.PaqSize() << endl;
+      throw BAORadioException("BRMultiFitsReader::BRMultiFitsReader/ mff.NAxis1() != memgr_.PaqSize() "); 
+    }
+    vfilenum_.push_back(imin_);
+    vfpos_.push_back(0);
+    vpaq_.push_back(BRPaquet(NULL,memgr_.PaqSize()));
+    vpchk_.push_back(BRPaqChecker(true,0)); 
+    curfc_.push_back(0);
+    totnpqrd_.push_back(0);
+    totnpqok_.push_back(0);    
+  }
+}
+
+
+/* --Methode-- */
+void BRMultiFitsReader::run()
+{
+  setRC(1); 
+  try {
+    TimeStamp ts; 
+    Timer tm("BRMultiFitsReader", false);
+    cout << " BRMultiFitsReader::run() - Starting " << ts << " NbFibres()=" << memgr_.NbFibres()
+	 << "  PaqSize() = " << memgr_.PaqSize() << endl;
+    cout << " ...ReadMode: " << ((rdsamefc_)?"Paquets With SameFrameCounter":"All OK paquets") 
+	 << " signalII.fits IMin=" << imin_ << " IMax=" << imax_ << " IStep=" << istep_ << endl;
+
+    Byte* nextpaq=NULL;
+    bool fgok=true;
+    while (fgok) {
+      if (stop_) break;
+      if ( MoveToNextTarget() ) {
+	cout << "BRMultiFitsReader::run()/Error-A- MoveToNextTarget() returned true ->STOP 9" << endl;
+	setRC(7);  fgok=false;  break;
+      }
+      for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++) {
+	nextpaq=GetPaquetTarget(fib);
+	if (nextpaq == NULL) { // Cela ne devrait pas arriver 
+	  cout << "BRMultiFitsReader::run()/Error-A2- GetPaquetTarget(fib)  returned NULL ->STOP 9" << endl;
+	  setRC(9);  fgok=false;  break;
+	}
+	vpaq_[fib].Set(nextpaq);
+      }
+      if (ReadNextAllFibers()) { fgok=false;  break; }
+    }
+
+    MoveToNextTarget();  // Pour faire traiter le dernier paquet si plein 
+    MZoneManage(true);   // Nettoyage final 
+    usleep(50000);       // Attente de traitement du dernier paquet
+    memgr_.Stop();        // Arret 
+
+    cout << " ------------------  BRMultiFitsReader::run() END ----------------- " << endl;
+    ts.SetNow();
+    tm.SplitQ();
+    cout << "  END reading : " << ts ;
+    if (rdsamefc_) cout << " NSameFC=" << totsamefc_ << endl;
+    else cout << endl;
+    for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++)  {
+      int perc=0;
+      if (totnpqrd_[fib]>0) perc=100*totsamefc_/totnpqrd_[fib];
+      cout << " Fiber" << fib << " TotNPaqRd=" << totnpqrd_[fib] << " TotNPaqOK=" << totnpqok_[fib] 
+	   << " FracSameFC=" << perc << " %" << endl;
+    }
+    cout << "  TotalDiskRead= " << totnbytesrd_/(1024*1024) << " MBytes Disk-Read rate= " 
+         << (double)(totnbytesrd_)/1024./tm.PartialElapsedTimems() << " MB/s" << endl;    
+    cout << " BRMultiFitsReader::run()/Timing: \n"; 
+    tm.Print();
+    cout << " ---------------------------------------------------------- " << endl;
+
+  }  // Fin du bloc try 
+  catch (std::exception& exc) {
+    cout << " BRMultiFitsReader::run()/catched execption msg=  " << exc.what() << endl;
+    setRC(3);	
+    return; 
+  }
+  catch(...) {
+    cout << " BRMultiFitsReader::run()/catched unknown ... exception " << endl;
+    setRC(4);	
+    return; 
+  }
+  setRC(0);
+  return;
+}
+
+/* --Methode-- */
+bool BRMultiFitsReader::ReadNextAllFibers()
+{
+  for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++)  {
+    if (ReadNext(fib)) return true;  // probleme 
+  }
+  if (!rdsamefc_ || (memgr_.NbFibres()<2))  { 
+    totsamefc_++;  return false;  // c'est OK 
+  }
+  uint_8 cfc=curfc_[0];
+  bool fgsamefc=true;
+  for(size_t fib=1; fib<memgr_.NbFibres(); fib++) {
+    if (curfc_[fib]!=cfc) {
+      fgsamefc=false;
+      if (curfc_[fib] > cfc)  cfc=curfc_[fib]; 
+    }
+  }
+  if (fgsamefc) { 
+    totsamefc_++;  return false;  // c'est OK  , same framecounter
+  }
+  else {  // else !fgsame
+    for(uint_4 fib=0; fib<memgr_.NbFibres(); fib++) {
+      while (curfc_[fib]<cfc) {
+	if (ReadNext(fib)) return true;  // probleme 
+      }
+    }
+  }   // fin de  else !fgsame 
+  totsamefc_++; 
+  return false; // c'est OK
+}
+
+/* --Methode-- */
+bool BRMultiFitsReader::ReadNext(int fib)
+{
+  if (!mff_[fib].IsOpen())  return true;
+  bool fggood=false;
+  while(!fggood) { 
+    if (vfpos_[fib] >= mff_[fib].NAxis2()) {
+      mff_[fib].Close();
+      vfilenum_[fib]++;
+      if (vfilenum_[fib]>imax_)  return true;
+      char flnm[1024];
+      sprintf(flnm,"%s/signal%d.fits",dirs_[fib].c_str(),vfilenum_[fib]++);
+      if (prtlev_ > 0)
+	cout << " BRMultiFitsReader::ReadNext() opening" << flnm << endl;
+      mff_[fib].Open(flnm, MF_Read);
+      if (mff_[fib].NAxis1() != packsize_)  {
+	cout << " BRMultiFitsReader::ReadNext(fib=" << fib << " File=" << flnm <<
+	  " NAxis1()= " << mff_[fib].NAxis1() << " <> PaqSize()=" << packsize_ << endl;
+	throw BAORadioException("BRMultiFitsReader::ReadNext()/ mff.NAxis1() != memgr_.PaqSize() "); 
+      }
+      vfpos_[fib]=0;
+    }
+    mff_[fib].ReadB(vpaq_[fib].Begin(), packsize_, vfpos_[fib]*packsize_);
+    vfpos_[fib]++;
+    totnbytesrd_+=packsize_;
+    totnpqrd_[fib]++;
+    fggood = vpchk_[fib].Check(vpaq_[fib],curfc_[fib]);
+  }
+  totnpqok_[fib]++;
+  return false;
+}
+
+/* --Methode-- */
+bool BRMultiFitsReader::MZoneManage(bool fgclean)    // Retourne true si probleme 
+{
+  /* Pour debug 
+  cout << " BRMultiFitsReader::MZoneManage() mid_=" << mid_ << " arg_npaq_= " << targ_npaq_  
+       << " max_targ_npaq=" << max_targ_npaq << endl;
+  */
+  if (mid_ >= 0)  { 
+    if (fgclean) memgr_.FreeMemZone(mid_, MemZS_Free);    
+    memgr_.FreeMemZone(mid_, MemZS_Filled);
+  }
+  mmbuf_ = NULL;  targ_npaq_ = 0;  mid_ = -2;
+  for (int fib=0;fib<(int)memgr_.NbFibres() ;fib++) mmbufib_[fib]=NULL;
+  if (fgclean)  return false;
+  mid_ = memgr_.FindMemZoneId(MemZA_Fill);
+  mmbuf_ = memgr_.GetMemZone(mid_);
+  if (mmbuf_==NULL)   return true;
+  for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++)
+    mmbufib_[fib]=memgr_.GetMemZone(mid_,fib);
+  return false;
+}
+
 //-------------------------------------------------------
-// Classe thread de sauvegarde sur fichiers
+// Classe thread de lecture de fichiers fits BAORadio 
 //-------------------------------------------------------
 
+/* --Methode-- */
 BRFitsReader::BRFitsReader(RAcqMemZoneMgr& mem, vector<string>& infiles, bool fgnotrl)
   :  memgr(mem), infiles_(infiles), fgnotrl_(fgnotrl)
 {
 }
-void BRFitsReader::Stop()
-{
-  // cout<< " BRFitsReader:Stop ........ " << endl;
-  stop_=true;
-}
+
+/* --Methode-- */
 void BRFitsReader::run()
 {
Index: /trunk/AddOn/TAcq/brfitsrd.h
===================================================================
--- /trunk/AddOn/TAcq/brfitsrd.h	(revision 3682)
+++ /trunk/AddOn/TAcq/brfitsrd.h	(revision 3683)
@@ -3,7 +3,6 @@
 
 //----------------------------------------------------------------
-// classes de threads pour lecture de fichier fits produit 
-//    par le programme d'acquisition TAcq/ de BAORadio
-// LAL -      R. Ansari - Mai 2009
+// Projet BAORadio - (C) LAL/IRFU  2008-2010
+// Classes de threads pour lecture fichiers fits BAORadio
 //----------------------------------------------------------------
 
@@ -12,12 +11,71 @@
 #include <vector>
 #include <iostream>
-#include "sopnamsp.h"
-#include "zthread.h"
 
-#include "brtypes.h"
 #include "brpaqu.h"
+#include "minifits.h"
 
 using namespace std;
 
+#ifndef MAXANAFIB 
+#define MAXANAFIB  32
+#endif
+
+//-------------------------------------------------------
+// Classe thread de lecture des fichiers data BAORadio 
+//  BRMultiFitsReader : Lecture multi-fibres 
+//-------------------------------------------------------
+
+class BRMultiFitsReader : public SOPHYA::ZThread {
+public:	
+  BRMultiFitsReader(RAcqMemZoneMgr& mem, vector<string>& dirs, 
+		    bool rdsamefc=true, uint_4 imin=0, uint_4 imax=0, uint_4 istep=1); 
+
+  virtual void run(); 
+  inline void Stop() { stop_ = true; } 
+  inline void STOP() { stop_ = true; }	
+
+  inline int SetPrintLevel(int lev=0) { prtlev_=lev; }
+protected:
+  bool ReadNextAllFibers();      // Renvoie true si probleme 
+  bool ReadNext(int fib);   // Renvoie true si probleme 
+  // Permet d'avancer d'un paquet dans la zone - renvoie true si probleme
+  inline bool MoveToNextTarget()  {
+    if ((mmbuf_ == NULL )||(targ_npaq_ >= max_targ_npaq)) 
+      if (MZoneManage()) return true;
+    targ_npaq_++;
+    return false;
+  }
+  inline Byte* GetPaquetTarget(int numfib)  {
+    if ((mmbufib_[numfib] == NULL )||(targ_npaq_ > max_targ_npaq)||(targ_npaq_ == 0))  return NULL; 
+    Byte* rb=mmbufib_[numfib]+(targ_npaq_-1)*packsize_;
+    return rb;
+  }
+  bool MZoneManage(bool clean=false);  // Renvoie true si probleme
+
+  RAcqMemZoneMgr& memgr_;
+  vector<string> dirs_;  //  repertoires donnees chaque fibre 
+  bool stop_;
+  bool rdsamefc_;  // if true, read paquets with same value of FrameCounter on different fibers
+  uint_4 imin_, imax_, istep_; 
+  size_t totnbytesrd_;
+  uint_8 totsamefc_;   // nombre total de paquets avec meme framecounter  
+  MiniFITSFile mff_[MAXANAFIB];
+  vector<uint_4> vfilenum_;
+  vector<uint_4> vfpos_; 
+  vector<BRPaquet> vpaq_; 
+  vector<BRPaqChecker> vpchk_;
+  vector<uint_8> curfc_;       // Numeros des FrameCounter des paquets courants
+  vector<uint_8> totnpqrd_;    // nombre total de paquets lus / fibre 
+  vector<uint_8> totnpqok_;    // nombre total de paquets OK / fibre  
+
+  uint_4 packsize_;
+  int mid_;  // Identificateur zone memoire
+  uint_4 targ_npaq_;  // Numero de paquet dans une seule zone memoire 
+  uint_4 max_targ_npaq; // =  mmgr.NbPaquets() = Max de targ_npaq_
+  Byte* mmbuf_;  // Pointeur zone memoire rendu par RAcqMemZoneMgr 
+  Byte* mmbufib_[MAXANAFIB];  // Pointeurs zone memoire de chaque fibre rendu par RAcqMemZoneMgr 
+
+  int prtlev_;
+};
 
 //-------------------------------------------------------
@@ -25,10 +83,10 @@
 //-------------------------------------------------------
 
-class BRFitsReader : public ZThread {
+class BRFitsReader : public SOPHYA::ZThread {
 public:	
   BRFitsReader(RAcqMemZoneMgr& mem, vector<string>& infiles, bool fgnotrl=false); 
 
   virtual void run(); 
-  void Stop(); 
+  inline void Stop() { stop_ = true; } 
   inline void STOP() { stop_ = true; }	
 
Index: /trunk/AddOn/TAcq/brpaqu.cc
===================================================================
--- /trunk/AddOn/TAcq/brpaqu.cc	(revision 3682)
+++ /trunk/AddOn/TAcq/brpaqu.cc	(revision 3683)
@@ -204,4 +204,11 @@
   dst_ = NULL;
   sz_ = paqsz;
+}
+
+/* --Methode__ */
+BRPaquet::BRPaquet(BRPaquet const& paq)
+{
+  dst_ = paq.dst_;
+  sz_ = paq.sz_;
 }
 
@@ -605,4 +612,19 @@
   DefineHDRTag();
   DefineTRLTag();
+}
+
+/* --Methode__ */
+BRPaqChecker::BRPaqChecker(BRPaqChecker const& pck)
+{
+  totnframes=pck.totnframes;
+  nframeok=pck.nframeok;
+  lostframes=pck.lostframes;
+  frclst=pck.frclst;
+  lastframenum=pck.lastframenum;
+  cktrl_=pck.cktrl_;
+  cnt_saut=pck.cnt_saut;
+  maxprt_=pck.maxprt_;
+  hdrtag_=pck.hdrtag_;
+  trltag_=pck.trltag_;
 }
 
Index: /trunk/AddOn/TAcq/brpaqu.h
===================================================================
--- /trunk/AddOn/TAcq/brpaqu.h	(revision 3682)
+++ /trunk/AddOn/TAcq/brpaqu.h	(revision 3683)
@@ -117,6 +117,9 @@
   BRPaquet(Byte* srcdst, int paqsz);
   BRPaquet(int paqsz);
+  BRPaquet(BRPaquet const& paq);
 
   //  ~BRPaquet();
+  inline void Set(Byte* dst)   { dst_=dst; return; }
+  inline void Set(Byte* dst, int paqsz)   { dst_=dst;  sz_=paqsz; return; }
 
   // Pour la copie/reduction de taille de paquet 
@@ -210,5 +213,10 @@
   // if cktrl==true, check header AND trailer, ==false check header only 
   BRPaqChecker(bool cktrl=true, int maxprt=0);
+  BRPaqChecker(BRPaqChecker const& pck);
+
   ~BRPaqChecker();
+
+  inline bool SetCheckTrailerFlag(bool cktrl=true) { cktrl_=cktrl; return cktrl_; }
+  inline int SetMaxPrint(int maxprt=0) { maxprt=maxprt_; return maxprt_; }
 
   UInt64 DefineHDRTag(UInt32 hdr1=0x76543210, UInt32 hdr2=0xFEDCBA98);
@@ -237,5 +245,5 @@
 protected:
   UInt64 totnframes;    // Nombre totale de frames/paquets traites 
-  UInt64  nframeok;     // Nombre totale de frames/paquets avec HDR/TRL OK
+  UInt64 nframeok;      // Nombre totale de frames/paquets avec HDR/TRL OK
   UInt64 lostframes;    // Nombre totale de frames/paquets perdus 
   UInt16 frclst;         // derniere valeur du frame-counter 
Index: /trunk/AddOn/TAcq/brproc.cc
===================================================================
--- /trunk/AddOn/TAcq/brproc.cc	(revision 3682)
+++ /trunk/AddOn/TAcq/brproc.cc	(revision 3683)
@@ -26,4 +26,29 @@
 #include "brproc.h"
 
+//---------------------------------------------------------------------
+// Classe de traitement - calcul de visibilite pour n fibres 
+//---------------------------------------------------------------------
+
+/* --Methode-- */
+BRVisibilityCalculator::BRVisibilityCalculator(RAcqMemZoneMgr& memgr, string outpath, uint_4 nmean, 
+		       uint_4 freq1, uint_4 freq2, uint_4 nbfreq)
+  : BRBaseProcessor(memgr), outpath_(outpath), nmean_(nmean), numfreq1_(freq1), numfreq2_(freq2), nbinfreq_(nbfreq)
+{
+  for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++)  {
+    vframecount_.push_back(0);
+    vtimetag_.push_back(0);
+    vnpaqm_.push_back(0);
+  }
+}
+
+/* --Methode-- */
+BRVisibilityCalculator::~BRVisibilityCalculator()
+{
+}
+
+/* --Methode-- */
+int BRVisibilityCalculator::Process()
+{
+}
 
 //---------------------------------------------------------------
@@ -35,10 +60,13 @@
 
 /* --Methode-- */
-BRProcARaw2C::BRProcARaw2C(RAcqMemZoneMgr& mem, string& path, uint_4 nmean, 
+BRProcA2C::BRProcA2C(RAcqMemZoneMgr& mem, string& path, bool fgraw, uint_4 nmean, 
                            uint_4 nmax, bool fghist, uint_4 nfsmap, bool fgnotrl, int card)
   :  memgr(mem) 
 {
+  fgraw_ = fgraw;
   nmax_ = nmax;	
   nmean_ = nmean;
+  if (fgraw_) cout << " BRProcA2C::BRProcA2C() - constructeur RAW data - NMean=" << nmean_ << endl;
+  else cout << " BRProcA2C::BRProcA2C() - constructeur FFT data - NMean=" << nmean_ << endl;
   nfsmap_ = nfsmap;
   stop_ = false;	
@@ -51,8 +79,8 @@
 
 /* --Methode-- */
-void BRProcARaw2C::Stop()
+void BRProcA2C::Stop()
 {
  stop_=true;
- // cout <<" BRProcARaw2C::Stop ... > STOP " << endl;
+ // cout <<" BRProcA2C::Stop ... > STOP " << endl;
 }
 
@@ -67,9 +95,9 @@
 }
 /* --Methode-- */
-void BRProcARaw2C::run()
+void BRProcA2C::run()
 {
   setRC(1);	
   try {
-    Timer tm("BRProcARaw2C", false);
+    Timer tm("BRProcA2C", false);
     TimeStamp ts; 
     BRPaqChecker pcheck(!fgnotrl_);  // Verification/comptage des paquets 
@@ -78,11 +106,11 @@
     size_t totnbytesproc = 0;
 
-    cout << " BRProcARaw2C::run() - Starting " << ts << " NMaxMemZones=" << nmax_ 
+    cout << " BRProcA2C::run() - Starting " << ts << " NMaxMemZones=" << nmax_ 
 	 << " NMean=" << nmean_ << card2name_(card_) << endl;	
-    cout << " BRProcARaw2C::run()... - Output Data Path: " << path_ << endl;
+    cout << " BRProcA2C::run()... - Output Data Path: " << path_ << endl;
     char fname[512];
 //    sprintf(fname,"%s/proc.log",path_.c_str());
 //    ofstream filog(fname);
-//    filog << " BRProcARaw2C::run() - starting log file " << ts << endl;		       
+//    filog << " BRProcA2C::run() - starting log file " << ts << endl;		       
 //    filog << " ... NMaxMemZones=" << nmax_ << " NMean=" << nmean_ << " Step=" << step_ << endl;	
 
@@ -94,7 +122,18 @@
     double ms1,ms2,ms12,ms12re,ms12im,ms12phi;
 ----*/
-// Time sample histograms 
-   Histo h1(-0.5, 255.5, 256);
-   Histo h2(-0.5, 255.5, 256);
+// Time sample (raw data) /FFT coeff histograms
+   Histo* ph1=NULL;
+   Histo* ph2=NULL;
+   if (fghist_) {
+     if (fgraw_) {
+       ph1 = new Histo(-0.5, 255.5, 256);     
+       ph2 = new Histo(-0.5, 255.5, 256);     
+     }
+     else {
+       ph1 = new Histo(-128.5, 128.5, 257);     
+       ph2 = new Histo(-128.5, 128.5, 257);     
+     }
+   }
+
 // Initialisation pour calcul FFT 
     TVector< complex<r_4> > cfour1;  // composant TF
@@ -132,5 +171,5 @@
       timfreqV2.SetSize(nmean_, spectreV2.Size()/nfsmap_);
     }
-    cout << " *DBG*BRProcARaw2C PaqSz=" << paqsz << " ProcPaqSize=" << procpaqsz 
+    cout << " *DBG*BRProcA2C PaqSz=" << paqsz << " ProcPaqSize=" << procpaqsz 
          << " procpaqsz/2=" << procpaqsz/2 << " cfour1.Size()=" << cfour1.Size()
          << " *8="  << cfour1.Size()*8 << endl;
@@ -160,10 +199,10 @@
       Byte* buff = memgr.GetMemZone(mid);
       if (buff == NULL) {
-         cout << " BRProcARaw2C::run()/ERROR memgr.GetMemZone(" << mid << ") -> NULL" << endl;
+         cout << " BRProcA2C::run()/ERROR memgr.GetMemZone(" << mid << ") -> NULL" << endl;
   	     break;		
       }
       Byte* procbuff = memgr.GetProcMemZone(mid);
       if (procbuff == NULL) {
-  	    cout << " BRProcARaw2C::run()/ERROR memgr.GetProcMemZone(" << mid << ") -> NULL" << endl;
+  	    cout << " BRProcA2C::run()/ERROR memgr.GetProcMemZone(" << mid << ") -> NULL" << endl;
         break;	
       }
@@ -178,45 +217,47 @@
         if (fghist_) {
           for(sa_size_t j=0; j<vx.Size(); j++) {
-            r_4 vts=(r_4)(*(paq.Data1()+j));
-            h1.Add((r_8)vts);
+            r_4 vts=(fgraw_)?((r_4)(*(paq.Data1()+j))):((r_4)(*(paq.Data1S()+j)));
+            ph1->Add((r_8)vts);
             moysig[0] += (double)vts;
             sigsig[0] += ((double)vts)*((double)vts);
             nbsig[0]++;
-  	    vx(j) = vts-127.5;
           }
-        }
-        else {
-          for(sa_size_t j=0; j<vx.Size(); j++) 
-  	    vx(j) = (r_4)(*(paq.Data1()+j))-127.5;
-        }
-//        fftwf_complex* coeff1 = (fftwf_complex*)(procbuff+i*procpaqsz);
-  	    fftwf_execute(plan1); 
-//  	  complex<r_4>* zp1 = (complex<r_4>*)(vx.Data());
-//        ffts.FFTForward(vx, cfour1);
-        for(sa_size_t j=0; j<spectreV1.Size(); j++) 
-          spectreV1(j) += Zmod2(cfour1(j));
-        memcpy(procbuff+i*procpaqsz, cfour1.Data(), sizeof(complex<r_4>)*cfour1.Size());
-        if (fgtimfreq) {   // Remplissage tableau temps-frequence
-          for(sa_size_t c=1; c<timfreqV1.NCols(); c++) {
-            for(sa_size_t j=c*nfsmap_; j<(c+1)*nfsmap_; j++) 
-              timfreqV1(nzm, c) += Zmod2(cfour1(j));
-	  }
-	}
-// Traitement voie 2  	    
-        if (fghist_) {
-          for(sa_size_t j=0; j<vx.Size(); j++) {
-            r_4 vts=(r_4)(*(paq.Data2()+j));
-            h2.Add((r_8)vts);
+	  for(sa_size_t j=0; j<vx.Size(); j++) {
+            r_4 vts=(fgraw_)?((r_4)(*(paq.Data2()+j))):((r_4)(*(paq.Data2S()+j)));
+            ph2->Add((r_8)vts);
             moysig[1] += (double)vts;
             sigsig[1] += ((double)vts)*((double)vts);
             nbsig[1]++;
-  	    vx(j) = vts-127.5;
           }
         }
-        else {
-          for(sa_size_t j=0; j<vx.Size(); j++) 
-  	    vx(j) = (r_4)(*(paq.Data2()+j))-127.5;
-        }
-        fftwf_execute(plan2); 
+	if (fgraw_) {
+	  for(sa_size_t j=0; j<vx.Size(); j++) 
+	    vx(j) = (r_4)(*(paq.Data1()+j))-127.5;
+	  //        fftwf_complex* coeff1 = (fftwf_complex*)(procbuff+i*procpaqsz);
+	  fftwf_execute(plan1); 
+	  // Traitement voie 2  	    
+	  for(sa_size_t j=0; j<vx.Size(); j++) 
+	    vx(j) = (r_4)(*(paq.Data2()+j))-127.5;
+	  fftwf_execute(plan2); 
+	}
+	else {
+	  for(sa_size_t j=1; j<cfour1.Size()-1; j++) {
+	    cfour1(j) = complex<r_4>((r_4)paq.Data1C()[j].realB(), (r_4)paq.Data1C()[j].imagB());
+	    cfour2(j) = complex<r_4>((r_4)paq.Data2C()[j].realB(), (r_4)paq.Data2C()[j].imagB());
+	  }
+	  cfour1(0) = complex<r_4>((r_4)paq.Data1C()[0].realB(), (r_4)0.);
+	  cfour1(cfour1.Size()-1) = complex<r_4>((r_4)paq.Data1C()[0].imagB(), (r_4)0.);
+	  cfour2(0) = complex<r_4>((r_4)paq.Data2C()[0].realB(), (r_4)0.);
+	  cfour2(cfour2.Size()-1) = complex<r_4>((r_4)paq.Data2C()[0].imagB(), (r_4)0.);
+	}
+	for(sa_size_t j=0; j<spectreV1.Size(); j++) 
+	  spectreV1(j) += Zmod2(cfour1(j));
+	memcpy(procbuff+i*procpaqsz, cfour1.Data(), sizeof(complex<r_4>)*cfour1.Size());
+	if (fgtimfreq) {   // Remplissage tableau temps-frequence
+	  for(sa_size_t c=1; c<timfreqV1.NCols(); c++) {
+	    for(sa_size_t j=c*nfsmap_; j<(c+1)*nfsmap_; j++) 
+	      timfreqV1(nzm, c) += Zmod2(cfour1(j));
+	  }
+	}
         for(sa_size_t j=0; j<spectreV2.Size(); j++) 
           spectreV2(j) += Zmod2(cfour2(j));  // Zmod2(zp2[j]); 
@@ -314,6 +355,6 @@
         po << PPFNameTag(tag12) << visiV12; 
         if (fghist_) {
-          po << PPFNameTag(tagh1) << h1; 
-          po << PPFNameTag(tagh2) << h2; 
+          po << PPFNameTag(tagh1) << (*ph1); 
+          po << PPFNameTag(tagh2) << (*ph2); 
 
           double sspvmax[3] = {0.,0.,0.};
@@ -354,6 +395,6 @@
         visiV12 = complex<r_4>(0., 0.);
         if (fghist_) {
-          h1.Zero();
-          h2.Zero();
+          ph1->Zero();
+          ph2->Zero();
           moysig[0]=moysig[1]=0.;
           sigsig[0]=sigsig[1]=0.;
@@ -367,10 +408,10 @@
 //        ts.SetNow();
 //        filog << ts << " :  proc file  " << fname << endl;		       
-        cout << " BRProcARaw2C::run() created file  " << fname << card2name_(card_) << endl;
+        cout << " BRProcA2C::run() created file  " << fname << card2name_(card_) << endl;
       }   
       
       memgr.FreeMemZone(mid, MemZS_ProcA);
     }  // Fin de boucle sur les zones a traiter 
-  cout << " ------------  BRProcARaw2C::run() END " << card2name_(card_) 
+  cout << " ------------  BRProcA2C::run() END " << card2name_(card_) 
        << " ------------ " << endl;
 /*---- DELETE
@@ -381,5 +422,5 @@
   POutPersist po(fname);
   po << PPFNameTag("ntv12") << nt; 
-  cout << " BRProcARaw2C::run() created NTuple file " << fname << card2name_(card_) << endl;
+  cout << " BRProcA2C::run() created NTuple file " << fname << card2name_(card_) << endl;
   }
 ---- */ 
@@ -405,7 +446,11 @@
     po << PPFNameTag("rsbV1") << rsbV1; 
     po << PPFNameTag("rsbV2") << rsbV2; 
-    cout << " BRProcARaw2C::run() created moysigspec file " << fname << card2name_(card_) << endl;
-  }
-
+    cout << " BRProcA2C::run() created moysigspec file " << fname << card2name_(card_) << endl;
+  }
+
+  if (fghist_) {
+    delete ph1; 
+    delete ph2;
+  }
   ts.SetNow();
   tm.SplitQ();
@@ -414,5 +459,5 @@
        << " ProcDataOut=" <<  totnbytesout/(1024*1024) << " MB" << endl;    
   cout << pcheck;
-  cout << " BRProcARaw2C::run()/Timing: " << card2name_(card_) << endl; 
+  cout << " BRProcA2C::run()/Timing: " << card2name_(card_) << endl; 
   tm.Print();
   cout << " ---------------------------------------------------------- " << endl;
@@ -420,10 +465,10 @@
   }
   catch (PException& exc) {
-    cout << " BRProcARaw2C::run()/catched PException " << exc.Msg() << endl;
+    cout << " BRProcA2C::run()/catched PException " << exc.Msg() << endl;
     setRC(3);	
     return; 
   }
   catch(...) {
-    cout << " BRProcARaw2C::run()/catched unknown ... exception " << endl;
+    cout << " BRProcA2C::run()/catched unknown ... exception " << endl;
     setRC(4);	
     return; 
@@ -434,14 +479,17 @@
 
 //---------------------------------------------------------------------
-// Classe thread de traitement 2 x 2 voies/frames (Apres BRProcARaw2C)
+// Classe thread de traitement 2 x 2 voies/frames (Apres BRProcA2C)
 //---------------------------------------------------------------------
 
 /* --Methode-- */
-BRProcBRaw4C::BRProcBRaw4C(RAcqMemZoneMgr& mem1, RAcqMemZoneMgr& mem2, 
-                           string& path, uint_4 nmean, uint_4 nmax, bool fgnotrl)
+BRProcB4C::BRProcB4C(RAcqMemZoneMgr& mem1, RAcqMemZoneMgr& mem2, string& path,
+		     bool fgraw, uint_4 nmean, uint_4 nmax, bool fgnotrl)
   :  memgr1(mem1), memgr2(mem2) 
 {
+  fgraw_ = fgraw;
   nmax_ = nmax;	
   nmean_ = nmean;
+  if (fgraw_) cout << " BRProcB4C::BRProcB4C() - constructeur RAW data - NMean= " << nmean_ << endl;
+  else cout << " BRProcB4C::BRProcB4C() - constructeur FFT data - NMean= " << nmean_ << endl;
   stop_ = false;	
   path_ = path;	
@@ -450,17 +498,17 @@
 
 /* --Methode-- */
-void BRProcBRaw4C::Stop()
+void BRProcB4C::Stop()
 {
  stop_=true;
- // cout <<" BRProcBRaw4C::Stop ... > STOP " << endl;
-}
-
-
-/* --Methode-- */
-void BRProcBRaw4C::run()
+ // cout <<" BRProcB4C::Stop ... > STOP " << endl;
+}
+
+
+/* --Methode-- */
+void BRProcB4C::run()
 {
   setRC(1);	
   try {
-    Timer tm("BRProcBRaw4C", false);
+    Timer tm("BRProcB4C", false);
     TimeStamp ts; 
     BRPaqChecker pcheck1(!fgnotrl_);  // Verification/comptage des paquets 
@@ -470,12 +518,12 @@
     size_t totnbytesproc = 0;
 
-    cout << " BRProcBRaw4C::run() - Starting " << ts << " NMaxMemZones=" << nmax_ 
+    cout << " BRProcB4C::run() - Starting " << ts << " NMaxMemZones=" << nmax_ 
 	 << " NMean=" << nmean_ << endl;	
-    cout << " BRProcBRaw4C::run()... - Output Data Path: " << path_ << endl;
+    cout << " BRProcB4C::run()... - Output Data Path: " << path_ << endl;
 
     uint_4 paqsz = memgr1.PaqSize();
     uint_4 procpaqsz = memgr1.ProcPaqSize();
     if ((paqsz != memgr2.PaqSize())||(procpaqsz!= memgr2.ProcPaqSize())) {
-      cout << "BRProcBRaw4C::run()/ERROR : different paquet size -> stop \n ...(PaqSz1="
+      cout << "BRProcB4C::run()/ERROR : different paquet size -> stop \n ...(PaqSz1="
            << paqsz << " Sz2=" << memgr2.PaqSize() << " ProcPaqSz1=" 
            << procpaqsz << " Sz2=" << memgr2.ProcPaqSize() << " )" << endl;
@@ -504,5 +552,5 @@
     TVector< complex<r_4> > visiV24( szfour );
     // cout << " *DBG*AAAAA ---- Vectors OK" << endl; 
-    cout << " *DBG*BRProcBRaw4C PaqSz=" << paqsz << " ProcPaqSize=" << procpaqsz 
+    cout << " *DBG*BRProcB4C PaqSz=" << paqsz << " ProcPaqSize=" << procpaqsz 
          << " procpaqsz/2=" << procpaqsz/2 << " cfour.Size()=" << szfour
          << " *8="  << szfour*8 << endl;
@@ -537,10 +585,10 @@
       Byte* buff1 = memgr1.GetMemZone(mid1);
       if (buff1 == NULL) {
-         cout << " BRProcBRaw4C::run()/ERROR memgr.GetMemZone(" << mid1 << ") -> NULL" << endl;
+         cout << " BRProcB4C::run()/ERROR memgr.GetMemZone(" << mid1 << ") -> NULL" << endl;
   	     break;		
       }
       Byte* procbuff1 = memgr1.GetProcMemZone(mid1);
       if (procbuff1 == NULL) {
-  	    cout << " BRProcBRaw4C::run()/ERROR memgr.GetProcMemZone(" << mid1 << ") -> NULL" << endl;
+  	    cout << " BRProcB4C::run()/ERROR memgr.GetProcMemZone(" << mid1 << ") -> NULL" << endl;
         break;	
       }
@@ -548,10 +596,10 @@
       Byte* buff2 = memgr2.GetMemZone(mid2);
       if (buff1 == NULL) {
-         cout << " BRProcBRaw4C::run()/ERROR memgr.GetMemZone(" << mid2 << ") -> NULL" << endl;
+         cout << " BRProcB4C::run()/ERROR memgr.GetMemZone(" << mid2 << ") -> NULL" << endl;
   	     break;		
       }
       Byte* procbuff2 = memgr2.GetProcMemZone(mid2);
       if (procbuff2 == NULL) {
-  	    cout << " BRProcBRaw4C::run()/ERROR memgr.GetProcMemZone(" << mid2 << ") -> NULL" << endl;
+  	    cout << " BRProcB4C::run()/ERROR memgr.GetProcMemZone(" << mid2 << ") -> NULL" << endl;
         break;	
       }
@@ -584,5 +632,5 @@
         if (fgfirst) { 
           firsttt=paq1.TimeTag();  firsttt2=paq2.TimeTag(); 
-          cout << " BRProcBRaw4C()/Info First FC="<<curfc<<" , "<<curfc2<<" -> TT=" 
+          cout << " BRProcB4C()/Info First FC="<<curfc<<" , "<<curfc2<<" -> TT=" 
                << firsttt<<" , "<<firsttt2 <<endl;
           fgfirst=false; 
@@ -653,13 +701,13 @@
 //        ts.SetNow();
 //        filog << ts << " :  proc file  " << fname << endl;		       
-        cout << " BRProcBRaw4C::run() created file  " << fname << endl;
+        cout << " BRProcB4C::run() created file  " << fname << endl;
       }   
       double okfrac = (nokpaq>1)?((double)noksfc/(double)nokpaq*100.):0.;
-      cout << "BRProcBRaw4C ["<<kmz<<"] NOKPaq=" << nokpaq << " NSameFC=" << noksfc 
+      cout << "BRProcB4C ["<<kmz<<"] NOKPaq=" << nokpaq << " NSameFC=" << noksfc 
            << " (" << okfrac << " %)" << endl;
       totnokpaq += nokpaq;
       totnoksfc += noksfc;
     }  // Fin de boucle sur les zones a traiter 
-    cout << " ------------------  BRProcBRaw4C::run() END ----------------- " << endl;
+    cout << " ------------------  BRProcB4C::run() END ----------------- " << endl;
     {     
     dt.Info()["FirstTT1"]=firsttt;     
@@ -670,5 +718,5 @@
     POutPersist po(fname);
     po << PPFNameTag("ttfc") << dt; 
-    cout << " BRProcBRaw4C::run() created TimeTag/FrameCounter file " << fname  << endl;
+    cout << " BRProcB4C::run() created TimeTag/FrameCounter file " << fname  << endl;
     }     
     ts.SetNow();
@@ -681,15 +729,15 @@
 //  cout << pcheck1;
 //  cout << pcheck2;
-    cout << " BRProcBRaw4C::run()/Timing: \n"; 
+    cout << " BRProcB4C::run()/Timing: \n"; 
     tm.Print();
     cout << " ---------------------------------------------------------- " << endl;
 }
   catch (PException& exc) {
-    cout << " BRProcBRaw4C::run()/catched PException " << exc.Msg() << endl;
+    cout << " BRProcB4C::run()/catched PException " << exc.Msg() << endl;
     setRC(3);	
     return; 
   }
   catch(...) {
-    cout << " BRProcBRaw4C::run()/catched unknown ... exception " << endl;
+    cout << " BRProcB4C::run()/catched unknown ... exception " << endl;
     setRC(4);	
     return; 
Index: /trunk/AddOn/TAcq/brproc.h
===================================================================
--- /trunk/AddOn/TAcq/brproc.h	(revision 3682)
+++ /trunk/AddOn/TAcq/brproc.h	(revision 3683)
@@ -1,19 +1,21 @@
-#ifndef  BRPROCA_H_SEEN
-#define  BRPROCA_H_SEEN
+#ifndef  BRPROC_H_SEEN
+#define  BRPROC_H_SEEN
 
 //----------------------------------------------------------------
-// ---- classe de thread de traitememt  acquisition BAORadio -----
-// LAL -      R. Ansari - Juin/Juillet 2008 
+// Projet BAORadio - (C) LAL/IRFU  2008-2010
+// Classes de threads de traitememt donnees BAORadio 
 //----------------------------------------------------------------
 
 
-#include "racqumem.h"
 #include <string>
 #include <vector>
 #include <iostream>
+
+#include "racqumem.h"
+#include "brbaseproc.h"
 #include "sopnamsp.h"
-#include "zthread.h"
-
-#include "brtypes.h"
+#include "tvector.h"
+#include "ntuple.h"
+#include "datatable.h"
 
 using namespace std;
@@ -21,5 +23,30 @@
 
 //---------------------------------------------------------------------
-// Classe thread de traitement avec 2 voies par frame (donnees brutes)
+// Classe de traitement - calcul de visibilite pour n fibres 
+//---------------------------------------------------------------------
+class BRVisibilityCalculator : public BRBaseProcessor {
+public:	
+  BRVisibilityCalculator(RAcqMemZoneMgr& memgr, string outpath, uint_4 nmean=1000, 
+			 uint_4 freq1=0, uint_4 freq2=0, uint_4 nbfreq=1);
+  virtual ~BRVisibilityCalculator(); // Fait le nettoyage final , sauvegarde des objets ...
+
+  virtual int Process(); 
+protected:
+  uint_4 nmean_;  // Nombre de spectres pour le calcul des moyennes 
+  string outpath_;  // directory pour fichiers de sortie
+  uint_4 numfreq1_,numfreq2_,nbinfreq_;
+  vector<uint_8> vframecount_;
+  vector<uint_8> vtimetag_;
+  vector<uint_8> vnpaqm_;
+
+};
+
+
+//-------------------------------------------------------------------------
+//    **** OBSOLETE : BRProcA2C et BRProcB4C
+//   Anciennes classes de traitement (Avant Nov2009) utilises par mcrd.cc
+//-------------------------------------------------------------------------
+//---------------------------------------------------------------------
+// Classe thread de traitement avec 2 voies par frame (donnees raw/FFT
 //---------------------------------------------------------------------
 
@@ -35,9 +62,9 @@
   o card : numero de carte , juste pour les impressions 
 */
-class BRProcARaw2C : public ZThread {
+class BRProcA2C : public ZThread {
 public:	
-  BRProcARaw2C(RAcqMemZoneMgr& mem, string& path, uint_4 nmean=10, 
-               uint_4 nmax=100, bool fgtshist=false, uint_4 nfsmap=0, 
-               bool fgnotrl=false, int card=1);
+  BRProcA2C(RAcqMemZoneMgr& mem, string& path, bool fgraw, 
+	    uint_4 nmean=10, uint_4 nmax=100, bool fgtshist=false, 
+	    uint_4 nfsmap=0, bool fgnotrl=false, int card=1);
   virtual void run(); 
   void Stop();
@@ -46,4 +73,5 @@
   RAcqMemZoneMgr& memgr;
   bool stop_;  
+  bool fgraw_;   // true -> raw data 
   uint_4 nmax_;  // Nombre maxi de blocs MemZone traites
   uint_4 nmean_;  // Nombre de spectres pour le calcul des moyennes 
@@ -56,5 +84,5 @@
 
 //---------------------------------------------------------------------
-// Classe thread de traitement 2 x 2 voies/frames (Apres BRProcARaw2C)
+// Classe thread de traitement 2 x 2 voies/paquet (Apres BRProcA2C)
 //---------------------------------------------------------------------
 /*-- Arguments du constructeur : 
@@ -67,8 +95,8 @@
 */
 
-class BRProcBRaw4C : public ZThread {
+class BRProcB4C : public ZThread {
 public:	
-  BRProcBRaw4C(RAcqMemZoneMgr& mem1, RAcqMemZoneMgr& mem2, string& path, 
-               uint_4 nmean=10, uint_4 nmax=100, bool fgnotrl=false);
+  BRProcB4C(RAcqMemZoneMgr& mem1, RAcqMemZoneMgr& mem2, string& path, 
+	    bool fgraw, uint_4 nmean=10, uint_4 nmax=100, bool fgnotrl=false);
   virtual void run(); 
   void Stop();
@@ -78,4 +106,5 @@
   RAcqMemZoneMgr& memgr2;
   bool stop_;  
+  bool fgraw_;   // true -> raw data 
   uint_4 nmax_;  // Nombre maxi de blocs MemZone traites
   uint_4 nmean_;  // Nombre de blocs pour le calcul des moyennes 
Index: /trunk/AddOn/TAcq/dspms.pic
===================================================================
--- /trunk/AddOn/TAcq/dspms.pic	(revision 3683)
+++ /trunk/AddOn/TAcq/dspms.pic	(revision 3683)
@@ -0,0 +1,100 @@
+#  Script affichage spectre moyennes fait par Monitoring
+if ( $# < 2 ) then 
+  echo ' dspms.pic/Erreur - Usage dspms Directory NumFile [BaseDir] ' 
+  return 
+endif
+set dir $1
+set numf $2
+
+set bdir /Raid/PittsNov09
+if ( $# > 2 ) then 
+  set bdir $3
+endif
+
+delobjs *
+# openppf /Raid/PittsNov09/$dir/meanspec$numf.ppf
+set flnm $bdir/$dir/meanspec$numf.ppf
+echo '------ Opening file ' $flnm 
+openppf $flnm 
+del myspec
+mv spectre  myspec
+# mv /home/meanspec$numf  myspec
+set nchan ${myspec.nrows}
+for i 0:$nchan
+  del smV$i 
+  objaoper myspec row $i smV$i
+end
+
+setaxesatt 'font=helvetica,bold,16 fixedfontsize minorticks'
+zone 1
+
+set exfreq (n+2212)*250/4096+1250 
+# set exfreq (n*250/4096+1250) 
+plot2d smV0 $exfreq 10*log10(val) val>1.e-6 'black nsta cpts notit'
+setaxelabels  ' Freq (MHz)' 'Spectra - dB' 'font=helvetica,bolditalic,16'
+ 
+set cols ( black darkviolet blue navyblue red orange yellow green )
+
+for i 1:${myspec.nrows}
+  plot2d smV$i $exfreq 10*log10(val) val>1.e-6 "$cols[i] cpts nsta same"
+end
+
+if ( $nchan < 3 )  then 
+  zny = $nchan
+  znx = 1
+else 
+  if ( $nchan < 7 )  then 
+    zny = $nchan/2
+    znx = 2
+   else 
+    zny = 3
+    znx = 3
+  endif
+endif
+
+defscript dspec 
+  zone $znx $zny 
+  for i 0:$nchan
+   disp smV$i "$cols[i]"
+  end
+endscript 
+
+defscript dspeclg 
+  zone $znx $zny 
+  for i 0:$nchan
+   disp smV$i "logy $cols[i]"
+  end
+endscript 
+
+defscript dhval 
+  zone $znx $zny 
+  for i 0:$nchan
+   disp hvalV$i "$cols[i]"
+  end
+endscript 
+
+defscript dh2
+  zone $znx $zny 
+  for i 0:$nchan
+   plot2d h2dV$i x y val>0 "notit nsta $cols[i]"
+  end
+endscript 
+
+
+set lines ( B1.V1 B1.V2 B1.V3 B1.V4 B2.V1 B2.V2 B2.V3 B2.V4 )
+textdrawer lines cols 'font=helvetica,bold,16'
+
+# settitle 'Spectre 8 voies FFT - ScalingFactor=9' ' ' 'font=helvetica,bold,18'
+
+newwin 
+dspeclg 
+newwin 
+dspec 
+newwin 
+dhval
+newwin 
+dh2
+
+echo '----> use dspec dhval and  dh2 scripts to check value histograms'
+
+
Index: /trunk/AddOn/TAcq/makefile
===================================================================
--- /trunk/AddOn/TAcq/makefile	(revision 3682)
+++ /trunk/AddOn/TAcq/makefile	(revision 3683)
@@ -6,5 +6,5 @@
 # all : traidio  tmtfft tstminifits tbrpaq tpciew tmtacq tstrdfits mfits2spec tsok 
 # all : traidio  tmtfft tstminifits tmtacq tstrdfits mfits2spec tsok mcrd
-all :  mfacq tmtacq mfits2spec mcrd svv2mtx tsok traidio tstminifits tbrpaq
+all :  mfacq vismfib tmtacq mfits2spec mcrd svv2mtx tsok traidio tstminifits tbrpaq
 
 clean :
@@ -55,13 +55,25 @@
 ## Lecture / traitement minifits multi-thread
 ##   --------------
+vismfib : $(EXE)vismfib
+	echo '---mcrd made'
+
+$(EXE)vismfib : $(OBJ)vismfib.o  $(OBJ)brparam.o $(OBJ)racqumem.o $(OBJ)brfitsrd.o $(OBJ)brproc.o $(OBJ)brbaseproc.o $(OBJ)racquproc.o $(OBJ)brpaqu.o \
+             $(OBJ)racqurw.o $(OBJ)pciewrap.o $(OBJ)minifits.o
+	$(CXXLINK) -o $(EXE)vismfib $(OBJ)vismfib.o $(OBJ)brparam.o  $(OBJ)racqumem.o $(OBJ)brfitsrd.o $(OBJ)brproc.o $(OBJ)brbaseproc.o $(OBJ)racquproc.o \
+                      $(OBJ)brpaqu.o $(OBJ)racqurw.o $(OBJ)pciewrap.o $(OBJ)minifits.o $(SOPHYAALLSLBLIST)
+
+$(OBJ)vismfib.o : vismfib.cc brfitsrd.h racqumem.h brproc.h brbaseproc.h racqurw.h
+	$(CXXCOMPILE) -c  -o $(OBJ)vismfib.o vismfib.cc 
+
+##   --------------
 mcrd : $(EXE)mcrd
 	echo '---mcrd made'
 
-$(EXE)mcrd : $(OBJ)mcrd.o  $(OBJ)brparam.o $(OBJ)racqumem.o $(OBJ)brfitsrd.o $(OBJ)brproc.o $(OBJ)racquproc.o $(OBJ)brpaqu.o \
+$(EXE)mcrd : $(OBJ)mcrd.o  $(OBJ)brparam.o $(OBJ)racqumem.o $(OBJ)brfitsrd.o $(OBJ)brproc.o $(OBJ)brbaseproc.o $(OBJ)racquproc.o $(OBJ)brpaqu.o \
              $(OBJ)racqurw.o $(OBJ)pciewrap.o $(OBJ)minifits.o
-	$(CXXLINK) -o $(EXE)mcrd $(OBJ)mcrd.o $(OBJ)brparam.o  $(OBJ)racqumem.o $(OBJ)brfitsrd.o $(OBJ)brproc.o $(OBJ)racquproc.o \
+	$(CXXLINK) -o $(EXE)mcrd $(OBJ)mcrd.o $(OBJ)brparam.o  $(OBJ)racqumem.o $(OBJ)brfitsrd.o $(OBJ)brproc.o $(OBJ)brbaseproc.o $(OBJ)racquproc.o \
                       $(OBJ)brpaqu.o $(OBJ)racqurw.o $(OBJ)pciewrap.o $(OBJ)minifits.o $(SOPHYAALLSLBLIST)
 
-$(OBJ)mcrd.o : mcrd.cc brfitsrd.h racqumem.h brproc.h racqurw.h
+$(OBJ)mcrd.o : mcrd.cc brfitsrd.h racqumem.h brproc.h brbaseproc.h racqurw.h
 	$(CXXCOMPILE) -c  -o $(OBJ)mcrd.o mcrd.cc 
 
@@ -69,6 +81,9 @@
 	$(CXXCOMPILE) -c -o $(OBJ)brfitsrd.o brfitsrd.cc 
 
-$(OBJ)brproc.o : brproc.cc brproc.h racqumem.h brpaqu.h
+$(OBJ)brproc.o : brproc.cc brproc.h  brbaseproc.h racqumem.h brpaqu.h
 	$(CXXCOMPILE) -c  -o $(OBJ)brproc.o brproc.cc 
+
+$(OBJ)brbaseproc.o : brbaseproc.cc brbaseproc.h racqumem.h brpaqu.h
+	$(CXXCOMPILE) -c  -o $(OBJ)brbaseproc.o brbaseproc.cc 
 
 ##   --------------
Index: /trunk/AddOn/TAcq/mcrd.cc
===================================================================
--- /trunk/AddOn/TAcq/mcrd.cc	(revision 3682)
+++ /trunk/AddOn/TAcq/mcrd.cc	(revision 3683)
@@ -63,4 +63,5 @@
 static double LossRate=0.1;
 
+static bool fgraw=true;  // true -> RAW data , false -> FFT data 
 static bool fg4c=false;  // true -> 4 channels (2 fibers)
 static bool fgrdfits=true;  // false -> Don't read fits files, generate paquets
@@ -71,7 +72,7 @@
 int Usage(bool fgshort=true);
 // Pour traitement (calcul FFT et visibilites (ProcA) 1 fibre, 2 voies RAW)
-int Proc1FRawA(string& outname, string& inpath, int jf1, int jf2);
+int Proc1FA(string& outname, string& inpath, int jf1, int jf2);
 // Pour traitement (calcul FFT et visibilites (ProcA,ProcB) 2 fibre, 4 voies RAW)
-int Proc2FRawAB(string& outname, string& path1, string& path2, int jf1, int jf2);
+int Proc2FAB(string& outname, string& path1, string& path2, int jf1, int jf2);
 
 //----------------------------------------------------
@@ -91,8 +92,10 @@
     fgnotrl=false;   // true -> fichier fits SANS Trailer de frame (< mai 2009)
     fghist=false;   // true -> histo des valeurs des time sample
+    fgraw=true;     // raw data 
     if (act.substr(0,2)=="-4") fg4c=true;
     if (act.length()>2) {
       for(size_t ks=2; ks<act.length(); ks++) {
-        if(act[ks]=='g') fgrdfits=false;
+	if (act[ks]=='f') fgraw=false;
+        else if(act[ks]=='g') fgrdfits=false;
         else if(act[ks]=='n') fgnotrl=true; 
         else if(act[ks]=='h') fghist=true; 
@@ -119,7 +122,7 @@
     ResourceUsage resu;
     if (fg4c) 
-      rc =  Proc2FRawAB(outname, inpath, inpath2, imin, imax); 
+      rc =  Proc2FAB(outname, inpath, inpath2, imin, imax); 
     else 
-      rc =  Proc1FRawA(outname, inpath, imin, imax); 
+      rc =  Proc1FA(outname, inpath, imin, imax); 
     cout << resu ; 
   }
@@ -147,5 +150,5 @@
 
 // Pour traitement (calcul FFT et visibilites (ProcA) 1 fibre, 2 voies RAW)
-int Proc1FRawA(string& outname, string& inpath, int imin, int imax)
+int Proc1FA(string& outname, string& inpath, int imin, int imax)
 {
   vector<string> infiles;
@@ -163,4 +166,6 @@
          << " NPaq in file=" << npaqf
          << " PaqSz=" << paqsz << " NMaxZ=" << nmaxz << " NMean=" << NMean << endl;
+    if (fgraw) cout << " ======>  RAW data processing " << endl;
+    else cout << " ======>  FFT data processing " << endl;
   }
   else {
@@ -178,7 +183,7 @@
 
   outname += "/Ch12";
-  BRProcARaw2C proc(mmgr, outname, NMean, nmaxz, fghist, NFreqSMap, fgnotrl);
-
-  cout << " mcrd/Proc1FRawA: Starting threads (reader, proc) ... " << endl;
+  BRProcA2C proc(mmgr, outname, fgraw, NMean, nmaxz, fghist, NFreqSMap, fgnotrl);
+
+  cout << " mcrd/Proc1FA: Starting threads (reader, proc) ... " << endl;
 
   if (fgrdfits) reader.start();
@@ -187,8 +192,8 @@
   proc.start();
   sleep(1);
-  cout << " mcrd/Proc1FRawA: Waiting for reader thread to finish ... " << endl;
+  cout << " mcrd/Proc1FA: Waiting for reader thread to finish ... " << endl;
   if (fgrdfits) reader.join();
   else pcird.join();
-  cout << " mcrd/Proc1FRawA: Reader finished, waiting for process thread to finish ... " << endl;
+  cout << " mcrd/Proc1FA: Reader finished, waiting for process thread to finish ... " << endl;
   sleep(2);
   mmgr.Stop();
@@ -200,5 +205,5 @@
 
 // Pour traitement (calcul FFT et visibilites (ProcA) 1 fibre, 2 voies RAW)
-int Proc2FRawAB(string& outname, string& path1, string& path2, int imin, int imax) 
+int Proc2FAB(string& outname, string& path1, string& path2, int imin, int imax) 
 {
   vector<string> infiles1;
@@ -216,12 +221,14 @@
     DecodeMiniFitsHeader(infiles1[0],paqsz, npaqf, fgnotrl); 
     nmaxz = infiles1.size()*npaqf/NPaqinZone;
-    cout << " mcrd/Proc2FRawAB/ReadFits: NZones=" << NZones << " NbPaq=" << NPaqinZone 
+    cout << " mcrd/Proc2FAB/ReadFits: NZones=" << NZones << " NbPaq=" << NPaqinZone 
          << " NPaq in file=" << npaqf
          << " PaqSz=" << paqsz << " NMaxZ=" << nmaxz << " NMean=" << NMean << endl;
+    if (fgraw) cout << " ======>  RAW data processing " << endl;
+    else cout << " ======>  FFT data processing " << endl;
   }
   else {
     paqsz = GPaqSz;
     nmaxz = NGenZ;
-    cout << " mcrd/Proc2FRawAB/GeneratePaquets: NZones=" << NZones << " NbPaq=" << NPaqinZone 
+    cout << " mcrd/Proc2FAB/GeneratePaquets: NZones=" << NZones << " NbPaq=" << NPaqinZone 
          << "  PaqSz=" << paqsz << " NMean=" << NMean << endl;
   }
@@ -245,11 +252,11 @@
   string outname1 = outname;
   outname1 += "/Ch12";
-  BRProcARaw2C proc1(mmgr1, outname1, NMean, nmaxz, fghist, NFreqSMap, fgnotrl);
+  BRProcA2C proc1(mmgr1, outname1, fgraw, NMean, nmaxz, fghist, NFreqSMap, fgnotrl);
   string outname2 = outname;
   outname2 += "/Ch34";
-  BRProcARaw2C proc2(mmgr2, outname2, NMean, nmaxz, fghist, NFreqSMap, fgnotrl,2);
+  BRProcA2C proc2(mmgr2, outname2, fgraw, NMean, nmaxz, fghist, NFreqSMap, fgnotrl,2);
   string outname12 = outname;
   outname12 += "/Ch1234";
-  BRProcBRaw4C proc12(mmgr1, mmgr2, outname12, NMean, nmaxz, fgnotrl);
+  BRProcB4C proc12(mmgr1, mmgr2, outname12, fgraw, NMean, nmaxz, fgnotrl);
 
   cout << " mcrd/Proc2FRawAB: Starting threads (reader1,2, procA1,2, procAB) ... " << endl;
@@ -302,6 +309,7 @@
     return 1;
   }
-  cout << " ACT= -2[ghn] -> 1 fiber, 2 raw channel processing (ProcA)\n"
-       << " ACT= -4[ghn] -> 2 fibers, 4 raw channels (ProcA, ProcB)\n"
+  cout << " ACT= -2[ghnf] -> 1 fiber, 2 channel processing (ProcA)\n"
+       << " ACT= -4[ghnf] -> 2 fibers, 4 channels (ProcA, ProcB)\n"
+       << "   f FFT data ( raw if not) -> \n" 
        << "   n (notrl) -> FITS files without frame trailer \n" 
        << "   g (generate paquets) -> generate paquets instead of reading fits files\n"
Index: /trunk/AddOn/TAcq/mfacq.cc
===================================================================
--- /trunk/AddOn/TAcq/mfacq.cc	(revision 3682)
+++ /trunk/AddOn/TAcq/mfacq.cc	(revision 3683)
@@ -72,5 +72,5 @@
   } 
   catch (PCIEWException& exc) {
-    cerr << " mfacq.cc catched MiniFITSException " << exc.Msg() << endl;
+    cerr << " mfacq.cc catched PCIEWException " << exc.Msg() << endl;
     rc = 75;
   }  
@@ -137,5 +137,5 @@
     cout <<"mfacq[2] CreatePCIEWrapperV6- indice " << i <<  "INIT card " << card 
 	 << " fibre " << cardfiber << endl;
-    pciwp[i] =  CreatePCIEWrapperV6(card,acpar.PatternSize(),acpar.dmasizekb,acpar.activate_pattern,cardfiber);
+    pciwp[i] =  CreatePCIEWrapperV6(card,acpar.PatternSize(),acpar.DMASizeBytes(),acpar.activate_pattern,cardfiber);
   }
 #else 
Index: /trunk/AddOn/TAcq/minifits.h
===================================================================
--- /trunk/AddOn/TAcq/minifits.h	(revision 3682)
+++ /trunk/AddOn/TAcq/minifits.h	(revision 3683)
@@ -47,4 +47,5 @@
   void Close();
 
+  inline bool IsOpen() { return (fip!=NULL) ; }
   inline MiniFITS_DT DataType() { return dtype; }
   string DataTypeToString();  
Index: /trunk/AddOn/TAcq/pciewrap.cc
===================================================================
--- /trunk/AddOn/TAcq/pciewrap.cc	(revision 3682)
+++ /trunk/AddOn/TAcq/pciewrap.cc	(revision 3683)
@@ -9,4 +9,6 @@
 #include <math.h>
 #include <iostream>
+
+using namespace SOPHYA;
 
 /* --Methode-- */
Index: /trunk/AddOn/TAcq/pciewrap.h
===================================================================
--- /trunk/AddOn/TAcq/pciewrap.h	(revision 3682)
+++ /trunk/AddOn/TAcq/pciewrap.h	(revision 3683)
@@ -64,5 +64,5 @@
   BRPaqChecker pchk_;
 //  FMTRandGen rg_;
-  ThSDR48RandGen rg_;
+  SOPHYA::ThSDR48RandGen rg_;
 };
 
Index: /trunk/AddOn/TAcq/racqumem.cc
===================================================================
--- /trunk/AddOn/TAcq/racqumem.cc	(revision 3682)
+++ /trunk/AddOn/TAcq/racqumem.cc	(revision 3683)
@@ -1,3 +1,5 @@
 #include "racqumem.h"
+
+using namespace SOPHYA;
 
 //----------------------------------------------------------------
@@ -29,5 +31,5 @@
   st.act = (uint_4)MemZA_None;
   st.stat = (uint_4)MemZS_Free;
-  for(int k=0; k<6; k++) st.nbact[k] = 0;
+  for(int k=0; k<MXNACTMZM; k++) st.nbact[k] = 0;
   uint_8 mzsz = nfibres*npaq*paqsz;
   uint_8 procmzsz = nfibres*npaq*procpaqsz;
@@ -40,4 +42,5 @@
   serial_ = 0;
   SetFinalizedMask();
+  SetProcSavedReadyMask();
 }
 
@@ -122,4 +125,40 @@
 	if (rid >= 0) states[rid].act = MemZA_ProcC;   	      	  
 	break;
+      case MemZA_ProcD:
+	for(uint_4 k=0; k<NbZones(); k++) {
+	  if ((states[k].act == MemZA_None) && (states[k].stat & MemZS_Filled) && 
+              (states[k].stat & MemZS_ProcC) && !(states[k].stat & MemZS_ProcD) ) { 
+            if (states[k].serial < bestserial) { rid=k; bestserial=states[k].serial; } 
+          }
+	}
+	if (rid >= 0) states[rid].act = MemZA_ProcD;   	      	  
+	break;
+      case MemZA_ProcE:
+	for(uint_4 k=0; k<NbZones(); k++) {
+	  if ((states[k].act == MemZA_None) && (states[k].stat & MemZS_Filled) && 
+              (states[k].stat & MemZS_ProcD) && !(states[k].stat & MemZS_ProcE) ) { 
+            if (states[k].serial < bestserial) { rid=k; bestserial=states[k].serial; } 
+          }
+	}
+	if (rid >= 0) states[rid].act = MemZA_ProcE;   	      	  
+	break;
+      case MemZA_ProcF:
+	for(uint_4 k=0; k<NbZones(); k++) {
+	  if ((states[k].act == MemZA_None) && (states[k].stat & MemZS_Filled) && 
+              (states[k].stat & MemZS_ProcE) && !(states[k].stat & MemZS_ProcF) ) { 
+            if (states[k].serial < bestserial) { rid=k; bestserial=states[k].serial; } 
+          }
+	}
+	if (rid >= 0) states[rid].act = MemZA_ProcF;   	      	  
+	break;
+      case MemZA_SaveProc:
+	for(uint_4 k=0; k<NbZones(); k++) {
+	  if ((states[k].act == MemZA_None) && 
+              (states[k].stat & mask_saveproc_ready_) && !(states[k].stat & MemZS_SavedProc) ) { 
+            if (states[k].serial < bestserial) { rid=k; bestserial=states[k].serial; } 
+          } 
+	}
+	if (rid >= 0) states[rid].act = MemZA_SaveProc; 
+	break;
       case MemZA_None:   // MTQ pour supprimer un warning
 	break;
@@ -177,10 +216,34 @@
     case MemZS_ProcC :
       if (states[id].act != MemZA_ProcC)  rc = 64;
-      else states[id].nbact[4]++;  	  
+      else states[id].nbact[5]++;  	  
       states[id].stat |= MemZS_ProcC; 
       states[id].act = MemZA_None;
       break;
+    case MemZS_ProcD :
+      if (states[id].act != MemZA_ProcD)  rc = 128;
+      else states[id].nbact[6]++;  	  
+      states[id].stat |= MemZS_ProcD; 
+      states[id].act = MemZA_None;
+      break;
+    case MemZS_ProcE :
+      if (states[id].act != MemZA_ProcE)  rc = 256;
+      else states[id].nbact[7]++;  	  
+      states[id].stat |= MemZS_ProcE; 
+      states[id].act = MemZA_None;
+      break;
+    case MemZS_ProcF :
+      if (states[id].act != MemZA_ProcF)  rc = 512;
+      else states[id].nbact[8]++;  	  
+      states[id].stat |= MemZS_ProcF; 
+      states[id].act = MemZA_None;
+      break;
+    case MemZS_SavedProc :
+      if (states[id].act != MemZA_SaveProc)  rc = 1024;
+      else states[id].nbact[9]++;  	  
+      states[id].stat |= MemZS_ProcF; 
+      states[id].act = MemZA_None;
+      break;
     default :
-      rc = 128;
+      rc = 65536;
       states[id].serial = 0;
       states[id].stat = MemZS_Free; 
@@ -193,11 +256,4 @@
 }
 
-/*  MIS en inline 
-Byte* RAcqMemZoneMgr::GetMemZone(int id)
-{
-  if ((id < 0) || (id >= memzones.size()))  return NULL;
-  return memzones[id];
-}
-*/
 ostream& RAcqMemZoneMgr::Print(ostream& os)
 {
@@ -208,9 +264,10 @@
          << " ProcZoneSize()=" << ProcZoneSize() << endl;
   else cout << " ... NO Processed Data Zones" << endl;
-  for(uint_4 k=0; k<states.size(); k++) 
+  for(uint_4 k=0; k<states.size(); k++) {
     os << " [" << k << "] Act=" << states[k].act << " Stat=" << states[k].stat 
-       << " NbAct[0..5]=" << states[k].nbact[0] << "," << states[k].nbact[1]
-       << "," << states[k].nbact[2] << "," << states[k].nbact[3] 
-       << "," << states[k].nbact[4] << "," << states[k].nbact[5] << endl; 	
+       << " NbAct[0.."<< MXNACTMZM-1 << "]=" << states[k].nbact[0];
+    for(uint_4 j=1; j<MXNACTMZM; j++)  cout << "," << states[k].nbact[j];
+    cout << endl;
+  }
   return os;   
 }
Index: /trunk/AddOn/TAcq/racqumem.h
===================================================================
--- /trunk/AddOn/TAcq/racqumem.h	(revision 3682)
+++ /trunk/AddOn/TAcq/racqumem.h	(revision 3683)
@@ -11,33 +11,35 @@
 
 
-#include "machdefs.h"
+#include "zthread.h"
 #include <string>
 #include <vector>
 #include <iostream>
-#include "sopnamsp.h"
-#include "zthread.h"
-// #include "dmamgrintf.h"
 #include "brtypes.h"
-#include "pciewrap.h"
+
 using namespace std;
 
-// Structure de gestion utilisee par la classe RAcqMemMgr
-typedef struct {
-  uint_8 serial;    // Numero de serie permettant d'ordonner en temps les zones memoire rempli
-  uint_4 act;       // Indique l'action en cours sur une zone Fill,Save ...
-  uint_4 stat;      // Champ de flag (bits) indiquant les operations effectuees sur la zone
-  uint_4 nbact[6];  // compteurs nb de fois ou (fill,save,proc,procA/B/C) a ete effectuee sur la zone 
-//  int tid;        Pas utilise pour le moment, permet l'identification du thread operant sur la zone
-} St_MemZ;
-
+//-----------------------------------------------------------------------
+// Projet BAORadio - (C) LAL/IRFU  2008-2010
+//  Structures de gestion memoire et synchronisation inter-threads
+//-----------------------------------------------------------------------
 
 // Les flags (bits) correspondant aux operations effectuees sur une zone
-// Free->libre, Filled->rempli(par DMA), Saved(ecrit sur disque), Proc(Traitement)
-// ProcA/B/C : Trois traitement qui doivent s'enchainer 
+// + Free : libre, 
+// + Filled : rempli (par DMA ou lecture fits)
+// + Saved : ecrit sur disque
+// + Proc : traite (utilise principalement pour le monitoring durant l'acquisition)
+// + ProcA/B/C/D/E/F : Un maximum de SIX traitements qui peuvent s'enchainer 
+// + ProcSaved : ecrit sur disque apres traitement
+
 enum MemZStatus { MemZS_Free=0, MemZS_Filled=1, MemZS_Saved=2, MemZS_Proc=4, 
-                  MemZS_ProcA=8, MemZS_ProcB=16, MemZS_ProcC=32 };
-// L'action en cours sur une zone 
+                  MemZS_ProcA=8, MemZS_ProcB=16, MemZS_ProcC=32,
+                  MemZS_ProcD=64, MemZS_ProcE=128, MemZS_ProcF=256,
+                  MemZS_SavedProc=16384 };
+
+// L'action en cours sur une zone (associe aux flags MemZStatus ci-dessus)
 enum MemZaction { MemZA_None=0, MemZA_Fill=1, MemZA_Save=2, MemZA_Proc=4, 
-                  MemZA_ProcA=8, MemZA_ProcB=16, MemZA_ProcC=32 };
+                  MemZA_ProcA=8, MemZA_ProcB=16, MemZA_ProcC=32,
+                  MemZA_ProcD=64, MemZA_ProcE=128, MemZA_ProcF=256,
+                  MemZA_SaveProc=16384 };
 
 // configuration du RAcqMemZoneMgr 
@@ -48,4 +50,15 @@
 enum MemZRunState { MemZR_Running=0, MemZR_Waiting=1, MemZR_Stopped=2};
 
+
+// --------------------------------------------------------------------
+// Structure de gestion utilisee par la classe RAcqMemMgr
+#define MXNACTMZM  10
+typedef struct {
+  uint_8 serial;    // Numero de serie permettant d'ordonner en temps les zones memoire rempli
+  uint_4 act;       // Indique l'action en cours sur une zone Fill,Save ...
+  uint_4 stat;      // Champ de flag (bits) indiquant les operations effectuees sur la zone
+  uint_4 nbact[MXNACTMZM];  // compteurs nb de fois ou (fill,save,proc,procA/B/C) a ete effectuee sur la zone 
+//  int tid;        Pas utilise pour le moment, permet l'identification du thread operant sur la zone
+} St_MemZ;
 
 
@@ -91,9 +104,14 @@
   inline uint_4 GetFinalizedMask() { return mask_finalized_; }
 
-  // Retourne un MemZone disponible pour une action specifique
+  // Definit l'etat des operations obligatoires avant qu'une zone 
+  // ne puissent etre sauvee apres traitement (subir l'action ProcSaved) 
+  inline void   SetProcSavedReadyMask(uint_4 mask=((uint_4)MemZS_ProcA))
+    { mask_saveproc_ready_ = mask; }
+  inline uint_4 GetProcSavedReadyMask() { return mask_saveproc_ready_; }
+
+  // Retourne l'identificateur d'une zone memoire disponible pour une action specifique
   int FindMemZoneId(MemZaction act);
   // Libere une zone memoire en marquant son etat
   int FreeMemZone(int id, MemZStatus st);
-  // Retourne le pointeur de la zone numero k pour les datas
 
   // Retourne le pointeur de la zone numero k pour les datas pour une fibre donnee
@@ -120,5 +138,7 @@
   
   ostream& Print(ostream& os);
+  inline ostream& Print() { return Print(cout); }
 
+  // Pour controler l'etat d'execution global 
   void Stop(); 
   inline MemZRunState GetRunState() 
@@ -131,5 +151,5 @@
 
   // ... variables membres
-  ZMutex mex;   
+  SOPHYA::ZMutex mex;   
   uint_4  nzones, nfibres, npaq, paqsz, procpaqsz;
 //  DMAMgrInterface &dma_;
@@ -140,4 +160,5 @@
   MemZRunState runstate_;
   uint_4 mask_finalized_;
+  uint_4 mask_saveproc_ready_;
   uint_8 serial_;  
 };
Index: /trunk/AddOn/TAcq/racquproc.cc
===================================================================
--- /trunk/AddOn/TAcq/racquproc.cc	(revision 3682)
+++ /trunk/AddOn/TAcq/racquproc.cc	(revision 3683)
@@ -17,4 +17,5 @@
 #include "fftpserver.h"
 #include "fftwserver.h"
+#include "histos.h"
 
 #include "FFTW/fftw3.h"
@@ -140,4 +141,16 @@
   fftwf_plan plan = fftwf_plan_dft_r2c_1d(vx.Size(), vx.Data(), 
 					  (fftwf_complex *)cfour.Data(), FFTW_ESTIMATE); 
+
+  // Histo pour valeurs des bytes dans les paquets 
+  Histo* phist[2*MAXNBFIB] = {NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL};
+  if (par_.fgdatafft) {    // data de type FFT   
+    for(sa_size_t lc=0; lc<2*memgr.NbFibres(); lc++)  
+      phist[lc] = new Histo(-128.5,+128.5,257);
+  }
+  else {
+    for(sa_size_t lc=0; lc<2*memgr.NbFibres(); lc++)  
+      phist[lc] = new Histo(-0.5,256.5,257);    
+  }
+
   TimeStamp ts;   
   char fname[512];
@@ -178,15 +191,23 @@
 	if (par_.fgdatafft) {    // Traitement data de type FFT 
 	  TwoByteComplex* tbcp=paq.Data1C();
-	  for(sa_size_t j=1; j<spectre_.NCols(); j++) 
+	  for(sa_size_t j=1; j<spectre_.NCols(); j++) {
+	    phist[lc]->Add((r_4)tbcp[j].realD());
+	    phist[lc]->Add((r_4)tbcp[j].imagD());
 	    spectre_(lc,j) += Zmod2(tbcp[j]);
+	  }
 	  nzm_[lc]++;  	
 	  tbcp=paq.Data2C();   lc++;
-	  for(sa_size_t j=1; j<spectre_.NCols(); j++) 
+	  for(sa_size_t j=1; j<spectre_.NCols(); j++) {
+	    phist[lc]->Add((r_4)tbcp[j].realD());
+	    phist[lc]->Add((r_4)tbcp[j].imagD());
 	    spectre_(lc,j) += Zmod2(tbcp[j]);
+	  }
 	  nzm_[lc]++;
 	}
 	else {   // Traitement RawData 
-	  for(sa_size_t j=0; j<vx.Size(); j++) 
+	  for(sa_size_t j=0; j<vx.Size(); j++) {
+	    phist[lc]->Add((r_8)(*(paq.Data1()+j)));
 	    vx(j) = (r_4)(*(paq.Data1()+j))-127.5;
+	  }
 	  fftwf_execute(plan); 
 	  //   ffts_.FFTForward(vx, cfour_);
@@ -194,6 +215,8 @@
 	    spectre_(lc,j) += Zmod2(cfour(j+1));
 	  nzm_[lc]++;      lc++;
-	  for(sa_size_t j=0; j<vx.Size(); j++) 
+	  for(sa_size_t j=0; j<vx.Size(); j++) {
+	    phist[lc]->Add((r_8)(*(paq.Data2()+j)));
 	    vx(j) = (r_4)(*(paq.Data2()+j))-127.5;
+	  }
 	  fftwf_execute(plan); 
 	  //    ffts_.FFTForward(vx, cfour_);
@@ -223,8 +246,13 @@
       nfiles_++;
       POutPersist po(fname);
-      //      po << PPFNameTag("spectre") << spectre_; 
-      po << spectre_;       
+      po << PPFNameTag("spectre") << spectre_; 
       spectre_ = (r_4)(0.);
-      for(int lc=0; lc<2*memgr.NbFibres(); lc++)  nzm_[lc]=0;
+      char buftag[32];
+      for(int lc=0; lc<2*memgr.NbFibres(); lc++)  { 
+	sprintf(buftag,"hvalV%d",(int)lc);
+	po << PPFNameTag(buftag) << (*phist[lc]);
+	phist[lc]->Zero();
+	nzm_[lc]=0;
+      }
       ts.SetNow();
       // Calcul / impression fraction des paquets avec same-framecounter
@@ -258,7 +286,13 @@
     sprintf(fname,"%s/meanspec%d.ppf",path_.c_str(),(int)nfiles_);
     POutPersist po(fname);
-    po << spectre_;       
+    po << PPFNameTag("spectre") << spectre_; 
     spectre_ = (r_4)(0.);
-    for(int lc=0; lc<2*memgr.NbFibres(); lc++)  nzm_[lc]=0;
+    char buftag[32];
+    for(int lc=0; lc<2*memgr.NbFibres(); lc++)  { 
+      sprintf(buftag,"hvalV%d",(int)lc);
+      po << PPFNameTag(buftag) << (*phist[lc]);
+      delete phist[lc];
+      nzm_[lc]=0;
+    }
     ts.SetNow();
     // Calcul / impression fraction des paquets avec same-framecounter
Index: /trunk/AddOn/TAcq/racqurw.cc
===================================================================
--- /trunk/AddOn/TAcq/racqurw.cc	(revision 3682)
+++ /trunk/AddOn/TAcq/racqurw.cc	(revision 3683)
@@ -813,4 +813,5 @@
         // Sans TRAILER de paquet mff.setDTypeNaxis(MF_Byte, paq0.DataSize()+paq0.HeaderSize(), npaqperfile); 
 	}
+	AddFitsKWStart(mff,bpar);
 	fnum++;   fgfirstfctt=true;
       }
@@ -870,5 +871,5 @@
 	  framecnt_last_[fib] = pcheck[fib].LastFrameNum(); 
 
-	AddFitsKW(mff,bpar);
+	AddFitsKWEnd(mff,bpar);
 	for(uint_4 fib=0; fib<memgr.NbFibres(); fib++) {
           header[fib].close();
@@ -906,5 +907,5 @@
 
 /* --Methode-- */
-int MultiDataSaver::AddFitsKW(MiniFITSFile* mff, BRAcqConfig& acpar)
+int MultiDataSaver::AddFitsKWStart(MiniFITSFile* mff, BRAcqConfig& acpar)
 { 
   TimeStamp ts;
@@ -913,12 +914,31 @@
   bool hassrc=false;
   if (skysrc.length()>0)  hassrc=true;
+  bool fgredpsz = acpar.GetParams().fgreducpsize;
   for(uint_4 fib=0; fib<memgr.NbFibres(); fib++) {
-    mff[fib].AddKeyS("DATE", cdtu.c_str(), " File Creation time(YYYY-MM-DDThh:mm:ss UT) ");	  
     mff[fib].AddKeyS("DATEOBS", cdtu.c_str(), " Observation Time (YYYY-MM-DDThh:mm:ss UT) ");
+    mff[fib].AddKeyS("TMSTART", cdtu.c_str(), " File Acqu. Start Time/Date  ");	  
     mff[fib].AddKeyD("ACQVER", acpar.AcqVersion(), " BAORadio Acq Software version ") ;
     mff[fib].AddKeyS("ACQMODE", acpar.GetParams().AcqMode, " BAORadio Acq run  mode" );
+    mff[fib].AddKeyS("BRPAQCFMT", BRPaquet::FmtConvToString(acpar.GetParams().GetDataConvFg()), 
+		         " BAORadio BRPaquet DataFormatConversion" );
     mff[fib].AddKeyI("FIBERNUM", acpar.GetParams().FiberNum[fib], " Fiber number/id") ;
     if (hassrc) 
       mff[fib].AddKeyS("SKYSOURC", skysrc, " Source identification" );
+    if (fgredpsz) {
+      mff[fib].AddKeyS("REDPSZMOD", BRPaquet::ReducActionToString(acpar.GetParams().pqreducmode),
+		          "PaquetSize Reduction Mode") ; 
+      mff[fib].AddKeyI("REDPSZOF", acpar.GetParams().reducoffset," PaquetSize Reduction Offset") ; 
+    }
+  }
+  return 0;
+}
+
+/* --Methode-- */
+int MultiDataSaver::AddFitsKWEnd(MiniFITSFile* mff, BRAcqConfig& acpar)
+{ 
+  TimeStamp ts;
+  string cdtu=ts.ToString();
+  for(uint_4 fib=0; fib<memgr.NbFibres(); fib++) {
+    mff[fib].AddKeyS("TMEND", cdtu.c_str(), " File Acqu. End Time/Date  ");	  
     mff[fib].AddKeyI("FCFIRST", framecnt_first_[fib], " First valid frame counter in file") ;
     mff[fib].AddKeyI("FCLAST", framecnt_last_[fib], " Last valid frame counter in file") ;
Index: /trunk/AddOn/TAcq/racqurw.h
===================================================================
--- /trunk/AddOn/TAcq/racqurw.h	(revision 3682)
+++ /trunk/AddOn/TAcq/racqurw.h	(revision 3683)
@@ -170,5 +170,6 @@
   inline void STOP() { stop_ = true; }	
 protected:
-  int  AddFitsKW(MiniFITSFile* mff, BRAcqConfig& acpar);
+  int  AddFitsKWStart(MiniFITSFile* mff, BRAcqConfig& acpar);
+  int  AddFitsKWEnd(MiniFITSFile* mff, BRAcqConfig& acpar);
 
   RAcqMemZoneMgr& memgr;
