Index: trunk/AddOn/TAcq/mfacq.cc
===================================================================
--- trunk/AddOn/TAcq/mfacq.cc	(revision 3683)
+++ trunk/AddOn/TAcq/mfacq.cc	(revision 3757)
@@ -9,4 +9,6 @@
 static RAcqMemZoneMgr* pMmgr=NULL;
 static  PCIEMultiReader* pPcierThr=NULL;
+static  PCIEToEthernet* pPcie2Eth=NULL;
+static  EthernetReader* pEthRdr=NULL;
 
 void Stop(int s)
@@ -15,6 +17,7 @@
   else printf("............. MAIN ... receive signal %d \n",s);
   if (pMmgr != NULL) pMmgr->Stop();
+  if (pPcie2Eth !=NULL) pPcie2Eth->Stop();
   if (pPcierThr !=NULL) pPcierThr->Stop();
-
+  if (pEthRdr !=NULL) pEthRdr->Stop();
 }
 
@@ -40,10 +43,25 @@
 
 
-  if ((narg < 2)||(strcmp(arg[1],"-h"))==0) {
+  if ((narg > 1)&&(strcmp(arg[1],"-h"))==0) {
     Usage(false);
     return 1;
   }
-  
-  string pardcfile=arg[1];
+  if (narg < 3) {
+    Usage(true);
+    return 3;
+  }
+  
+  const char* desact[3] = {"PCIE_To_Ethernet", "Ethernet_To_Disk", "PCIE_DMA_To_Disk"};
+  string action=arg[1];
+  int act = 0;
+  if ((action != "-pci2eth")&&(action != "-pci2disk")&&(action != "-eth2disk")) {
+    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;
+
+  string pardcfile=arg[2];
 #ifndef NOPCIECARD  
   string basedir="/Raid";
@@ -51,19 +69,36 @@
   string basedir="./";
 #endif 
-  if (narg>2)  basedir=arg[2];
+  vector<string> oargs;
+  if (narg>3)  {
+    basedir=arg[2];
+    for(int jj=2; jj<narg; jj++)  oargs.push_back(arg[jj]);
+  }
   try {
     // Creation/initialisation parametres Acq
     BRAcqConfig acpar;
-    acpar.ReadParamFile(arg[1]);
+    acpar.ReadParamFile(pardcfile);
     acpar.GetConfig().SetBaseDirectory(basedir); 
+    if ((act==0)&&(oargs.size()>0))
+      acpar.GetParams().SetEthTargets(oargs);
     // Creation des repertoires 
-    if (acpar.CreateOutputDirectories()!=0)  return 9;
+    if (act > 0) 
+      if (acpar.CreateOutputDirectories()!=0)  return 9;
     acpar.Print(cout);
-    struct sigaction act;  
+    struct sigaction siact;  
     if (!acpar.GetParams().fg_hard_ctrlc) {
-      act.sa_handler=Stop;
-      sigaction(SIGINT,&act,NULL);        
+      siact.sa_handler=Stop;
+      sigaction(SIGINT,&siact,NULL);        
     }
-    rc = MultiFibreAcq();    
+    switch (act) {
+    case 0:
+      rc = PCIEToEthernetTransfer();
+      break;
+    case 1:
+      rc = EthernetToMemoryAcq();
+      break;
+    case 2:
+      rc = MultiFibreAcq();
+      break;
+    }    
   }
   catch (MiniFITSException& exc) {
@@ -97,12 +132,12 @@
 void Usage(bool fgshort) 
 {
-  if (fgshort) {
-    cout << " Usage: mfacq DataCardFile [BaseDirectory] \n" << endl;
-    cout << "   Parameters in DataCard : \n"
-	 << "       fibres outpathname skysource paqsize dmasizekb nbfiles \n" 
-	 << "       nblocperfile acqmode memmgr monitor reducpaqsz "<< endl;
-    cout << "   BaseDirectory (default= /Raid ) " << endl;
-    return;
-  }
+  cout << " Usage: mfacq Action DataCardFile [BaseDirectory / TargetMachines] \n" << endl;
+  if (fgshort) return;
+  cout << "   Action = -pci2disk , -pci2mem -eth2disk \n " 
+       << "   Parameters in DataCard : \n"
+       << "       fibres outpathname skysource paqsize dmasizekb nbfiles \n" 
+       << "       nblocperfile acqmode memmgr monitor reducpaqsz "<< endl;
+  cout << "   BaseDirectory (default= /Raid ) " << endl;
+  cout << "   TargetMachines : List of target machines for PCIe2Ethernet " << endl;
   return;
 }
@@ -114,5 +149,6 @@
   Timer tm("mfacq/MultiFibre");
   cout << " ---------- mfacq/ MultiFibreAcq()  ------------- " << endl;
-  PCIEWrapperInterface* pciwp[4]={NULL,NULL,NULL,NULL};
+  PCIEWrapperInterface* pciwp[16]={NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
+				   NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
     
   BRAcqConfig bpar;
@@ -144,8 +180,16 @@
   TestPCIWrapperNODMA pciw3(bpar.RecvPaquetSize(), acpar.nopciLossRate);
   TestPCIWrapperNODMA pciw4(bpar.RecvPaquetSize(), acpar.nopciLossRate);
+  TestPCIWrapperNODMA pciw5(bpar.RecvPaquetSize(), acpar.nopciLossRate);
+  TestPCIWrapperNODMA pciw6(bpar.RecvPaquetSize(), acpar.nopciLossRate);
+  TestPCIWrapperNODMA pciw7(bpar.RecvPaquetSize(), acpar.nopciLossRate);
+  TestPCIWrapperNODMA pciw8(bpar.RecvPaquetSize(), acpar.nopciLossRate);
   pciwp[0] = &pciw1;
   pciwp[1] = &pciw2;
   pciwp[2] = &pciw3;
-  pciwp[3] = &pciw4;  
+  pciwp[3] = &pciw4;
+  pciwp[4] = &pciw5;
+  pciwp[5] = &pciw6;  
+  pciwp[6] = &pciw7;
+  pciwp[7] = &pciw8;  
 #endif 
 
@@ -197,2 +241,135 @@
 
 }
+
+/* --Nouvelle-Fonction-- */
+int PCIEToEthernetTransfer()
+{
+  Timer tm("mfacq/PCIEToEthernetTransfer");
+  cout << " ---------- mfacq/ PCIEToEthernetTransfer()  ------------- " << endl;
+  PCIEWrapperInterface* pciwp[16]={NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
+				   NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
+
+  pMmgr=NULL;    
+  BRAcqConfig bpar;
+  BRParList& acpar=bpar.GetParams();
+  
+  cout << " mfacq[1]/Info: PCIEToEthernet for" << acpar.NbFibers << " fibers , nZones=" 
+       << acpar.nZones << " NbPaquet/Zone=" << acpar.nPaqZone 
+       << " MmgrPaqSize=" << acpar.MMgrPaquetSize() << endl;
+  
+#ifndef NOPCIECARD  
+  for (int i=0 ;i <acpar.NFibers() ;i++) {
+    UINT32 card=(acpar.FiberNum[i]-1)/2+1;
+    UINT32 cardfiber=(acpar.FiberNum[i]-1)%2;
+    cout <<"mfacq[2] CreatePCIEWrapperV6- indice " << i <<  "INIT card " << card 
+	 << " fibre " << cardfiber << endl;
+    pciwp[i] =  CreatePCIEWrapperV6(card,acpar.PatternSize(),acpar.DMASizeBytes(),acpar.activate_pattern,cardfiber);
+  }
+#else 
+  TestPCIWrapperNODMA pciw1(bpar.RecvPaquetSize(), acpar.nopciLossRate);
+  TestPCIWrapperNODMA pciw2(bpar.RecvPaquetSize(), acpar.nopciLossRate);
+  TestPCIWrapperNODMA pciw3(bpar.RecvPaquetSize(), acpar.nopciLossRate);
+  TestPCIWrapperNODMA pciw4(bpar.RecvPaquetSize(), acpar.nopciLossRate);
+  TestPCIWrapperNODMA pciw5(bpar.RecvPaquetSize(), acpar.nopciLossRate);
+  TestPCIWrapperNODMA pciw6(bpar.RecvPaquetSize(), acpar.nopciLossRate);
+  TestPCIWrapperNODMA pciw7(bpar.RecvPaquetSize(), acpar.nopciLossRate);
+  TestPCIWrapperNODMA pciw8(bpar.RecvPaquetSize(), acpar.nopciLossRate);
+  pciwp[0] = &pciw1;
+  pciwp[1] = &pciw2;
+  pciwp[2] = &pciw3;
+  pciwp[3] = &pciw4;
+  pciwp[4] = &pciw5;
+  pciwp[5] = &pciw6;  
+  pciwp[6] = &pciw7;
+  pciwp[7] = &pciw8;  
+#endif 
+
+  vector<PCIEWrapperInterface*> vec_pciw;
+  for  (int i=0 ;i<bpar.NFibers();i++)  vec_pciw.push_back( pciwp[i]);
+  cout <<"mfacq[2] Creating PCIEToEthernet  thread object " << endl;
+  PCIEToEthernet pci2eth(vec_pciw, bpar.GetParams().GetEthTargets(), bpar.GetParams());
+  //  usleep(200);  attente au cas ou ...
+  pPcie2Eth=&pci2eth;
+  tm.Split("Threads created");  
+  cout << "mfacq[3] - starting one threads: PCIEToEthernet... " << endl;
+  pci2eth.start();
+  
+  // On attend avant de declencher la terminaison des threads
+  usleep(200000);
+  
+  cout << "mfacq[5] -  Waiting for threads to finish ... " << endl;  
+  pci2eth.join();
+  cout << "mfacq[6] ---------- threads finished ---------------- " << endl;
+  tm.Split("Threads Finished");  
+ 
+#ifndef NOPCIECARD
+  for (int i=0 ;i <acpar.NbFibers ;i++) {
+    UINT32 card=(acpar.FiberNum[i]-1)/2+1;
+    UINT32 cardfiber=(acpar.FiberNum[i]-1)%2;
+    DeletePCIEWrapperV6(card,cardfiber);
+  }
+#endif    
+return 0;
+}
+
+/* --Nouvelle-Fonction-- */
+int EthernetToMemoryAcq() 
+{
+  Timer tm("mfacq/EthernetToMemoryAcq");
+  cout << " ---------- mfacq/ EthernetToMemoryAcq()  ------------- " << endl;
+    
+  BRAcqConfig bpar;
+  BRParList& acpar=bpar.GetParams();
+  
+  cout << " mfacq[1]/Info: Creating RAcqMemZoneMgr for" << acpar.NbEthLinks() << " Eth-links , nZones=" 
+       << acpar.nZones << " NbPaquet/Zone=" << acpar.nPaqZone 
+       << " MmgrPaqSize=" << acpar.MMgrPaquetSize() << endl;
+  RAcqMemZoneMgr mmgr(acpar.nZones, acpar.NbEthLinks(), acpar.nPaqZone, acpar.MMgrPaquetSize());
+  pMmgr=&mmgr;  
+  if (acpar.fgdoProc && (acpar.stepProc>0)) {
+    // 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;
+  MultiDataSaver DsThr(mmgr);   //   Utilise les parametres globaux BRAcqConfig
+  string ppath=bpar.OutputDirectory();
+  MonitorProc PrThr(mmgr);
+  cout << "mfacq[3] Creating   EthernetReader thread object     " << endl;
+  EthernetReader ethrdr(mmgr, bpar.GetParams(), bpar.GetParams().tcpportid, false);
+  //  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;
+
+  ethrdr.start();
+  DsThr.start();
+  if (acpar.fgdoProc>0) { // On ne demarre que si au moins NMaxProc>0
+    PrThr.start();
+  }
+  
+  // On attend avant de declencher la terminaison des threads
+  usleep(200000);
+  
+  cout << "mfacq[5] -  Waiting for threads to finish ... " << endl;  
+  ethrdr.join();
+  DsThr.join();
+  mmgr.Stop();
+  if (acpar.fgdoProc) { // On n'attend la fin que si le thread a ete demarre (NMaxProc>0)
+    PrThr.join();
+  }
+  pMmgr=NULL;  
+  cout << "mfacq[6] ---------- threads finished ---------------- " << endl;
+  tm.Split("Threads Finished");  
+ 
+  mmgr.Print(cout);
+
+return 0;
+
+}
