Index: trunk/AddOn/TAcq/brproc.cc
===================================================================
--- trunk/AddOn/TAcq/brproc.cc	(revision 3658)
+++ 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; 
