Index: trunk/AddOn/TAcq/brproc.cc
===================================================================
--- trunk/AddOn/TAcq/brproc.cc	(revision 3642)
+++ trunk/AddOn/TAcq/brproc.cc	(revision 3645)
@@ -27,16 +27,18 @@
 //---------------------------------------------------------------
 
+/* --Methode-- */
 BRProcARaw2C::BRProcARaw2C(RAcqMemZoneMgr& mem, string& path, uint_4 nmean, 
-                           uint_4 step, uint_4 nmax, bool fgnotrl)
+                           uint_4 nmax, bool fgnotrl, int card)
   :  memgr(mem) 
 {
   nmax_ = nmax;	
   nmean_ = nmean;
-  step_ = step;
   stop_ = false;	
   path_ = path;	
   fgnotrl_ = fgnotrl;
-}
-
+  card_ = card;
+}
+
+/* --Methode-- */
 void BRProcARaw2C::Stop()
 {
@@ -49,4 +51,10 @@
 { return (z.real()*z.real()+z.imag()*z.imag()); }
 
+static inline string card2name_(int card)
+{
+  if (card==2) return " (Chan3,4) ";
+  else return " (Chan1,2) ";
+}
+/* --Methode-- */
 void BRProcARaw2C::run()
 {
@@ -61,5 +69,5 @@
 
     cout << " BRProcARaw2C::run() - Starting " << ts << " NMaxMemZones=" << nmax_ 
-	 << " NMean=" << nmean_ << " Step=" << step_ << endl;	
+	 << " NMean=" << nmean_ << card2name_(card_) << endl;	
     cout << " BRProcARaw2C::run()... - Output Data Path: " << path_ << endl;
     char fname[512];
@@ -106,13 +114,13 @@
       }
 
-      for(uint_4 i=0; i<memgr.NbPaquets(); i+=step_) {
+      for(uint_4 i=0; i<memgr.NbPaquets(); i++) {
   	    BRPaquet paq(NULL, buff+i*paqsz, paqsz); 
         if (!pcheck.Check(paq)) continue;   // on ne traite que les paquets OK
 
 // Traitement voie 1  	    
-  	    for(sa_size_t j=0; j<vx.Size(); j++) 
-  	      vx(j) = (r_4)(*(paq.Data1()+j))-127.5;
+  	  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); 
+  	  fftwf_execute(plan1); 
 //        complex<r_4>* zp1 = (complex<r_4>*)(coeff1);
 //        ffts.FFTForward(vx, cfour1);
@@ -121,8 +129,8 @@
         memcpy(procbuff+i*procpaqsz, cfour1.Data(), sizeof(complex<r_4>)*cfour1.Size());
 // 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); 
+   	for(sa_size_t j=0; j<vx.Size(); j++) 
+ 	  vx(j) = (r_4)(*(paq.Data2()+j))-127.5;
+
+  	fftwf_execute(plan2); 
 
         for(sa_size_t j=0; j<spectreV2.Size(); j++) 
@@ -151,7 +159,15 @@
     	sprintf(fname,"%s_%d.ppf",path_.c_str(),(int)ifile);
         POutPersist po(fname);
-        po << PPFNameTag("specV1") << spectreV1; 
-        po << PPFNameTag("specV2") << spectreV2; 
-        po << PPFNameTag("visiV12") << visiV12; 
+        string tag1="specV1";
+        string tag2="specV2";
+        string tag12="visiV12";
+        if (card_==2) {
+          tag1 = "specV3";
+          tag2 = "specV4";
+          tag12="visiV34";
+        }
+        po << PPFNameTag(tag1) << spectreV1; 
+        po << PPFNameTag(tag2) << spectreV2; 
+        po << PPFNameTag(tag12) << visiV12; 
 	    }
         spectreV1 = (r_4)(0.);
@@ -161,10 +177,11 @@
 //        ts.SetNow();
 //        filog << ts << " :  proc file  " << fname << endl;		       
-        cout << " BRProcARaw2C::run() created file  " << fname << endl;
+        cout << " BRProcARaw2C::run() created file  " << fname << card2name_(card_) << endl;
       }   
       
       memgr.FreeMemZone(mid, MemZS_ProcA);
     }  // Fin de boucle sur les zones a traiter 
-  cout << " ------------------  BRProcARaw2C::run() END ----------------- " << endl;
+  cout << " ------------  BRProcARaw2C::run() END " << card2name_(card_) 
+       << " ------------ " << endl;
   ts.SetNow();
   tm.SplitQ();
@@ -173,5 +190,5 @@
        << " ProcDataOut=" <<  totnbytesout/(1024*1024) << " MB" << endl;    
   cout << pcheck;
-  cout << " BRProcARaw2C::run()/Timing: \n"; 
+  cout << " BRProcARaw2C::run()/Timing: " << card2name_(card_) << endl; 
   tm.Print();
   cout << " ---------------------------------------------------------- " << endl;
@@ -192,5 +209,192 @@
 }   
 
-
-
-
+//---------------------------------------------------------------------
+// Classe thread de traitement 2 x 2 voies/frames (Apres BRProcARaw2C)
+//---------------------------------------------------------------------
+
+/* --Methode-- */
+BRProcBRaw4C::BRProcBRaw4C(RAcqMemZoneMgr& mem1, RAcqMemZoneMgr& mem2, 
+                           string& path, uint_4 nmean, uint_4 nmax, bool fgnotrl)
+  :  memgr1(mem1), memgr2(mem2) 
+{
+  nmax_ = nmax;	
+  nmean_ = nmean;
+  stop_ = false;	
+  path_ = path;	
+  fgnotrl_ = fgnotrl;
+}
+
+/* --Methode-- */
+void BRProcBRaw4C::Stop()
+{
+ stop_=true;
+ // cout <<" BRProcBRaw4C::Stop ... > STOP " << endl;
+}
+
+
+/* --Methode-- */
+void BRProcBRaw4C::run()
+{
+  setRC(1);	
+  try {
+    Timer tm("BRProcBRaw4C", false);
+    TimeStamp ts; 
+    BRPaqChecker pcheck1(~fgnotrl_);  // Verification/comptage des paquets 
+    BRPaqChecker pcheck2(~fgnotrl_);  // Verification/comptage des paquets 
+
+    size_t totnbytesout = 0;
+    size_t totnbytesproc = 0;
+
+    cout << " BRProcBRaw4C::run() - Starting " << ts << " NMaxMemZones=" << nmax_ 
+	 << " NMean=" << nmean_ << endl;	
+    cout << " BRProcBRaw4C::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="
+           << paqsz << " Sz2=" << memgr2.PaqSize() << " ProcPaqSz1=" 
+           << procpaqsz << " Sz2=" << memgr2.ProcPaqSize() << " )" << endl;
+      setRC(9);	
+      return;   
+    }
+
+    TVector< complex<r_4> > cfour;  // composant TF
+    BRPaquet pq(NULL, NULL, paqsz); 
+    TVector<r_4> vx(pq.DataSize()/2);
+    vx = (r_4)(0.);
+    FFTPackServer ffts;
+    ffts.FFTForward(vx, cfour);
+    
+    TVector< complex<r_4> > visiV13( cfour.Size() );
+    TVector< complex<r_4> > visiV14( cfour.Size() );
+    TVector< complex<r_4> > visiV23( cfour.Size() );
+    TVector< complex<r_4> > visiV24( cfour.Size() );
+
+    uint_4 nzm = 0;
+    uint_4 totnoksfc = 0;
+    uint_4 totnokpaq = 0;
+    uint_4 totnpaq = 0;
+    uint_4 ifile = 0;
+    for (uint_4 kmz=0; kmz<nmax_; kmz++) {
+      uint_4 noksfc = 0;
+      uint_4 nokpaq = 0;
+      if (stop_) break;
+      int mid1 = memgr1.FindMemZoneId(MemZA_ProcB);
+      Byte* buff1 = memgr1.GetMemZone(mid1);
+      if (buff1 == NULL) {
+         cout << " BRProcBRaw4C::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;
+        break;	
+      }
+      int mid2 = memgr2.FindMemZoneId(MemZA_ProcB);
+      Byte* buff2 = memgr2.GetMemZone(mid2);
+      if (buff1 == NULL) {
+         cout << " BRProcBRaw4C::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;
+        break;	
+      }
+      uint_4 i1,i2;
+      i1=i2=0;
+      while((i1<memgr1.NbPaquets())&&(i2<memgr2.NbPaquets())) {
+	BRPaquet paq1(NULL, buff1+i1*paqsz, paqsz); 
+	BRPaquet paq2(NULL, buff2+i2*paqsz, paqsz); 
+        totnpaq++;
+//        cout << " DBG["<<kmz<<"] i1,i2=" << i1 <<","<<i2<<" FC1,FC2=" <<paq1.FrameCounter()
+//<<","<<paq2.FrameCounter()<<endl;
+        // on ne traite que les paquets OK
+        if (!pcheck1.Check(paq1)) { i1++; continue; } 
+        if (!pcheck2.Check(paq2)) { i2++; continue; }
+        nokpaq++;
+        if (paq1.FrameCounter()<paq2.FrameCounter()) { i1++; continue; }  
+        if (paq2.FrameCounter()<paq1.FrameCounter()) { i2++; continue; }  
+//        cout << " DBG["<<kmz<<"]OKOK i1,i2=" << i1 <<","<<i2<<" FC1,FC2=" <<paq1.FrameCounter()
+// <<","<<paq2.FrameCounter()<<endl;
+
+        // Les deux framecounters sont identiques ...
+        noksfc++;
+        complex<r_4>* zp1 = (complex<r_4>*)(procbuff1+i1*procpaqsz);
+        complex<r_4>* zp2 = (complex<r_4>*)(procbuff1+i1*procpaqsz+procpaqsz/2);
+        complex<r_4>* zp3 = (complex<r_4>*)(procbuff2+i2*procpaqsz);
+        complex<r_4>* zp4 = (complex<r_4>*)(procbuff2+i2*procpaqsz+procpaqsz/2);
+        for(sa_size_t j=0; j<visiV13.Size(); j++) { 
+          visiV13(j)+=zp1[j]*conj(zp3[j]);
+          visiV14(j)+=zp1[j]*conj(zp4[j]);
+          visiV23(j)+=zp2[j]*conj(zp3[j]);
+          visiV24(j)+=zp2[j]*conj(zp4[j]);
+        }
+        nzm++;  i1++; i2++;
+        totnbytesproc += 2*paq1.DataSize();
+      } // Fin de boucle sur les paquets d'une zone
+      if ((nzm >= nmean_) || ((kmz==(nmax_-1))&&(nzm>1))) {
+        visiV13 /= complex<r_4>((r_4)nzm, 0.);
+        visiV14 /= complex<r_4>((r_4)nzm, 0.);
+        visiV23 /= complex<r_4>((r_4)nzm, 0.);
+        visiV24 /= complex<r_4>((r_4)nzm, 0.);
+        visiV13.Info()["NPaqMoy"] = nzm;
+        visiV14.Info()["NPaqMoy"] = nzm;
+        visiV23.Info()["NPaqMoy"] = nzm;
+        visiV24.Info()["NPaqMoy"] = nzm;
+        char fname[512];
+	{
+    	sprintf(fname,"%s_%d.ppf",path_.c_str(),(int)ifile);
+        POutPersist po(fname);
+        po << PPFNameTag("visiV13") << visiV13; 
+        po << PPFNameTag("visiV14") << visiV14; 
+        po << PPFNameTag("visiV23") << visiV23; 
+        po << PPFNameTag("visiV24") << visiV24; 
+	}
+        visiV13 = complex<r_4>(0., 0.);
+        visiV14 = complex<r_4>(0., 0.);
+        visiV23 = complex<r_4>(0., 0.);
+        visiV24 = complex<r_4>(0., 0.);
+        nzm = 0;  
+//        ts.SetNow();
+//        filog << ts << " :  proc file  " << fname << endl;		       
+        cout << " BRProcBRaw4C::run() created file  " << fname << endl;
+      }   
+      memgr1.FreeMemZone(mid1, MemZS_ProcB);
+      memgr2.FreeMemZone(mid2, MemZS_ProcB);
+      double okfrac = (nokpaq>1)?((double)noksfc/(double)nokpaq*100.):0.;
+      cout << "BRProcBRaw2C ["<<kmz<<"] NOKPaq=" << nokpaq << " NSameFC=" << noksfc 
+           << " (" << okfrac << " %)" << endl;
+      totnokpaq += nokpaq;
+      totnoksfc += noksfc;
+    }  // Fin de boucle sur les zones a traiter 
+    cout << " ------------------  BRProcBRaw4C::run() END ----------------- " << endl;
+    ts.SetNow();
+    tm.SplitQ();
+    cout << "  TotalProc= " << totnbytesproc/(1024*1024) << " MBytes, rate= " 
+         << (double)(totnbytesproc)/1024./tm.PartialElapsedTimems() << " MB/s" << endl;
+    double totokfrac = (totnokpaq>1)?((double)totnoksfc/(double)totnokpaq*100.):0.;
+    cout << " NOkPaq1,2=" << totnokpaq << " /TotNPaq=" << totnpaq << " TotNSameFC=" 
+         << totnoksfc << " (" << totokfrac << " %)" << endl;
+//  cout << pcheck1;
+//  cout << pcheck2;
+    cout << " BRProcBRaw4C::run()/Timing: \n"; 
+    tm.Print();
+    cout << " ---------------------------------------------------------- " << endl;
+}
+  catch (PException& exc) {
+    cout << " BRProcBRaw4C::run()/catched PException " << exc.Msg() << endl;
+    setRC(3);	
+    return; 
+  }
+  catch(...) {
+    cout << " BRProcBRaw4C::run()/catched unknown ... exception " << endl;
+    setRC(4);	
+    return; 
+  }
+  setRC(0);
+  return;
+}   
+
+
