Index: trunk/AddOn/TAcq/mfacq.cc
===================================================================
--- trunk/AddOn/TAcq/mfacq.cc	(revision 3767)
+++ trunk/AddOn/TAcq/mfacq.cc	(revision 3876)
@@ -52,14 +52,15 @@
   }
   
-  const char* desact[3] = {"PCIE_To_Ethernet", "Ethernet_To_Disk", "PCIE_DMA_To_Disk"};
+  const char* desact[4] = {"PCIE_To_Ethernet", "Ethernet_To_Disk", "Ethernet_To_Visibilities","PCIE_DMA_To_Disk"};
   string action=arg[1];
   int act = 0;
-  if ((action != "-pci2eth")&&(action != "-pci2disk")&&(action != "-eth2disk")) {
+  if ((action != "-pci2eth")&&(action != "-pci2disk")&&(action != "-eth2disk")&&(action != "-eth2visib")) {
     cout << " mfacq/Error , Bad action argument : " << action << endl;
     return 2;
   }
   if (action == "-pci2eth")  act=0;
-  else if (action == "-eth2disk") act=1;
-  else if (action == "-pci2disk")  act=2;
+  else if (action == "-eth2disk") act=1;  
+  else if (action == "-eth2visib") act=2; 
+  else if (action == "-pci2disk")  act=3;
 
   string pardcfile=arg[2];
@@ -84,4 +85,7 @@
     if (act > 0) 
       if (acpar.CreateOutputDirectories()!=0)  return 9;
+    acpar.GetParams().fgdoVisiC=false;
+    if (act == 2)  acpar.GetParams().fgdoVisiC=true;
+
     acpar.Print(cout);
     struct sigaction siact;  
@@ -94,8 +98,11 @@
       rc = PCIEToEthernetTransfer();
       break;
-    case 1:
-      rc = EthernetToMemoryAcq();
+    case 1:    // ethernet --> disk 
+      rc = EthernetToMemoryAcq(false);
       break;
-    case 2:
+    case 2:   // ethernet --> visibility calculation 
+      rc = EthernetToMemoryAcq(true);
+      break;
+    case 3:
       rc = MultiFibreAcq();
       break;
@@ -134,5 +141,5 @@
   cout << " Usage: mfacq Action DataCardFile [BaseDirectory / TargetMachines]" << endl;
   if (fgshort) return;
-  cout << " o Action = -pci2disk , -pci2eth , -eth2disk \n " 
+  cout << " o Action = -pci2disk , -pci2eth , -eth2disk , -eth2visib \n " 
        << "   DataCardFile : File name for parameters list (DataCards) : \n"
        << "     fibres outpathname skysource paqsize dmasizekb nbfiles \n" 
@@ -262,5 +269,4 @@
        << acpar.nZones << " NbPaquet/Zone=" << acpar.nPaqZone 
        << " MmgrPaqSize=" << acpar.MMgrPaquetSize() << endl;
-  
 #ifndef NOPCIECARD  
   for (int i=0 ;i <acpar.NFibers() ;i++) {
@@ -319,6 +325,10 @@
 }
 
+
+/* Fonction-Utilitaire : Voir en fin de fichier  */
+MemZaction ConvertMemZ_Status2Action( MemZStatus st );
+
 /* --Nouvelle-Fonction-- */
-int EthernetToMemoryAcq() 
+int EthernetToMemoryAcq(bool fgviscal) 
 {
   Timer tm("mfacq/EthernetToMemoryAcq");
@@ -327,5 +337,7 @@
   BRAcqConfig bpar;
   BRParList& acpar=bpar.GetParams();
-  
+
+  if (fgviscal)  cout << "mfacq[0]/EthernetToMemoryAcq() : On the fly Visibility Calculation " << endl;
+  else cout << "mfacq[0]/EthernetToMemoryAcq() : data dumped to disk  " << endl;  
   cout << " mfacq[1]/Info: Creating RAcqMemZoneMgr for" << acpar.NbEthLinks() << " Eth-links , nZones=" 
        << acpar.nZones << " NbPaquet/Zone=" << acpar.nPaqZone 
@@ -333,16 +345,45 @@
   RAcqMemZoneMgr mmgr(acpar.nZones, acpar.NbEthLinks(), acpar.nPaqZone, acpar.MMgrPaquetSize());
   pMmgr=&mmgr;  
-  if (acpar.fgdoProc && (acpar.stepProc>0)) {
+
+
+  string strfmask;
+  uint_4 fmask=0;
+  MemZStatus mskmon=MemZS_Proc;
+  if (fgviscal) {  // gestion de finalized_mask lors du calcul de visibilites 
+    if (acpar.nbcalgrpVisiC<1)  acpar.nbcalgrpVisiC=1;
+    if (acpar.nbcalgrpVisiC>4)  acpar.nbcalgrpVisiC=4;
+    cout << " mfacq[1.b]/Info: NbCalGrpVisiC = " << acpar.nbcalgrpVisiC << " (1<=NbCalGrpVisiC<=4)" << endl;
+    fmask=(uint_4)MemZS_ProcA;   strfmask="MemZS_ProcA";  mskmon=MemZS_ProcB;
+    if (acpar.nbcalgrpVisiC>1) 
+      { fmask |= (uint_4)MemZS_ProcB;  strfmask+=" | MemZS_ProcB";  mskmon=MemZS_ProcC; }
+    if (acpar.nbcalgrpVisiC>2) 
+      { fmask |= (uint_4)MemZS_ProcC;  strfmask+=" | MemZS_ProcC";  mskmon=MemZS_ProcD; }
+    if (acpar.nbcalgrpVisiC>3) 
+      { fmask |= (uint_4)MemZS_ProcD;  strfmask+=" | MemZS_ProcD";  mskmon=MemZS_ProcE; }
+  }
+  else { 
+    fmask=(uint_4)MemZS_Saved;  strfmask="MemZS_Saved";  mskmon=MemZS_Proc;
+  }
+  if (acpar.fgdoProc) 
+    { fmask |= (uint_4)mskmon; strfmask+=" | MemZS_Proc[Monotoring]"; }
     // Dans ce cas, toutes les zones doivent passer ds le thread de monitoring 
     // pour etre au moins marque comme traite - seul 1/acpar.stepProc sont effectivement traite 
-    mmgr.SetFinalizedMask(((uint_4)MemZS_Saved) | ((uint_4)MemZS_Proc));
-    cout << " mfacq[1.b]/Info: Mmgr.SetFinalizedMask( MemZS_Saved | MemZS_Proc )" << endl;
-  }
-  
-
-  cout <<"mfacq[2] Creating MultiDataSaver and  MonitorProc thread objects ... " << endl;
+
+  mmgr.SetFinalizedMask(fmask);
+  cout << " mfacq[1.b]/Info: Mmgr.SetFinalizedMask( " <<  strfmask << " )" << endl;
+  
+  if (fgviscal) 
+    cout <<"mfacq[2] Creating BRVisCalcGroup, NbVisibCalculator=" << acpar.nbcalgrpVisiC 
+	 << " and MonitorProc " << endl;
+  else 
+    cout <<"mfacq[2] Creating MultiDataSaver and  MonitorProc thread objects ... " << endl;
   MultiDataSaver DsThr(mmgr);   //   Utilise les parametres globaux BRAcqConfig
   string ppath=bpar.OutputDirectory();
   MonitorProc PrThr(mmgr);
+  PrThr.SetMemZAction( ConvertMemZ_Status2Action( mskmon ) );
+  BRVisCalcGroup VCGThr(acpar.nbcalgrpVisiC, mmgr, bpar.OutputDirectory(), acpar.nmeanVisiC, acpar.nthrVisiC);
+  VCGThr.SelectFreqBinning(acpar.freqminVisiC, acpar.freqmaxVisiC, acpar.nbinfreqVisiC);
+
+
   cout << "mfacq[3] Creating   EthernetReader thread object     " << endl;
   EthernetReader ethrdr(mmgr, bpar.GetParams(), bpar.GetParams().tcpportid, false);
@@ -350,13 +391,17 @@
   //  usleep(200);  attente au cas ou ...
   pEthRdr=&ethrdr;
-  tm.Split("Threads created");  
-  if (acpar.fgdoProc>0) 
-    cout << "mfacq[4] - starting three threads: EthernetReader, MultiDataSaver, MonitorProc ... " << endl;
-  else 
-    cout << "mfacq[4] - starting two threads: EthernetReader, MultiDataSaver  ... " << endl;
-
+  tm.Split("Threads created"); 
+  cout << "mfacq[4] - starting EthernetReader thread object ..." << endl;
   ethrdr.start();
-  DsThr.start();
-  if (acpar.fgdoProc>0) { // On ne demarre que si au moins NMaxProc>0
+  if (fgviscal) {
+    cout << "mfacq[4.b] - starting  Visibility calculator threads " << endl;
+    VCGThr.start();
+  }
+  else {
+    cout << "mfacq[4.b] - starting  MultiDataSaver  " << endl;
+    DsThr.start();
+  }
+  if (acpar.fgdoProc) { // demarrage (optionnel) du thread de monitoring
+    cout << " mfacq[4.c] - starting MonitorProc thread object " << endl;
     PrThr.start();
   }
@@ -367,5 +412,6 @@
   cout << "mfacq[5] -  Waiting for threads to finish ... " << endl;  
   ethrdr.join();
-  DsThr.join();
+  if (fgviscal)  VCGThr.join();
+  else DsThr.join();
   mmgr.Stop();
   if (acpar.fgdoProc) { // On n'attend la fin que si le thread a ete demarre (NMaxProc>0)
@@ -381,2 +427,42 @@
 
 }
+
+
+/* --Nouvelle-Fonction-Utilitaire */
+MemZaction ConvertMemZ_Status2Action( MemZStatus st )
+{
+  MemZaction ra=MemZA_None;
+  switch (st) {
+  case MemZS_Filled:
+    ra=MemZA_Fill;
+    break;
+  case MemZS_Saved:
+    ra=MemZA_Save;
+    break;
+  case MemZS_Proc:
+    ra=MemZA_Proc;
+    break;
+  case MemZS_ProcA:
+    ra=MemZA_ProcA;
+    break;
+  case MemZS_ProcB:
+    ra=MemZA_ProcB;
+    break;
+  case MemZS_ProcC:
+    ra=MemZA_ProcC;
+    break;
+  case MemZS_ProcD:
+    ra=MemZA_ProcD;
+    break;
+  case MemZS_ProcE:
+    ra=MemZA_ProcE;
+    break;
+  case MemZS_ProcF:
+    ra=MemZA_ProcF;
+    break;
+  default:
+    ra=MemZA_None;
+    break;
+  }
+  return ra;
+}
