| 1 | #include "mfacq.h"
 | 
|---|
| 2 | 
 | 
|---|
| 3 | //---------------------------------------------------------------
 | 
|---|
| 4 | // Programme d'acquisition BAORadio multi-fibres/multi-threads 
 | 
|---|
| 5 | //  LAL -   2009 - 2010
 | 
|---|
| 6 | //     R. Ansari, M.Taurigna
 | 
|---|
| 7 | //---------------------------------------------------------------
 | 
|---|
| 8 | 
 | 
|---|
| 9 | static RAcqMemZoneMgr* pMmgr=NULL;
 | 
|---|
| 10 | static  PCIEMultiReader* pPcierThr=NULL;
 | 
|---|
| 11 | 
 | 
|---|
| 12 | void Stop(int s)
 | 
|---|
| 13 | { 
 | 
|---|
| 14 |   if (s == 9765) cout << " Stop after exception ..." << endl;
 | 
|---|
| 15 |   else printf("............. MAIN ... receive signal %d \n",s);
 | 
|---|
| 16 |   if (pMmgr != NULL) pMmgr->Stop();
 | 
|---|
| 17 |   if (pPcierThr !=NULL) pPcierThr->Stop();
 | 
|---|
| 18 | 
 | 
|---|
| 19 | }
 | 
|---|
| 20 | 
 | 
|---|
| 21 | 
 | 
|---|
| 22 | //-----------------------------------------------------------------------
 | 
|---|
| 23 | //-------------------- le programme principal ---------------------------
 | 
|---|
| 24 | //-----------------------------------------------------------------------
 | 
|---|
| 25 | int main(int narg, char* arg[])
 | 
|---|
| 26 | { 
 | 
|---|
| 27 |   
 | 
|---|
| 28 |   int rc = 0;
 | 
|---|
| 29 |   cout << " ============= BAORadio / Acquisition : mfacq  =================" << endl;
 | 
|---|
| 30 |   cout << " ===============================================================" << endl;
 | 
|---|
| 31 |   cout << " =========  " <<BAOR_ACQ_VER_STR <<BAOR_ACQ_VER << " ===========" << endl;
 | 
|---|
| 32 |   cout << " ===============================================================" << endl;
 | 
|---|
| 33 |   
 | 
|---|
| 34 |  
 | 
|---|
| 35 |   InitTim();
 | 
|---|
| 36 |  
 | 
|---|
| 37 |   // Initialisation 
 | 
|---|
| 38 |   TArrayInitiator _arri;
 | 
|---|
| 39 |   FitsIOServerInitiator _fiosi;
 | 
|---|
| 40 | 
 | 
|---|
| 41 | 
 | 
|---|
| 42 |   if ((narg < 2)||(strcmp(arg[1],"-h"))==0) {
 | 
|---|
| 43 |     Usage(false);
 | 
|---|
| 44 |     return 1;
 | 
|---|
| 45 |   }
 | 
|---|
| 46 |   
 | 
|---|
| 47 |  
 | 
|---|
| 48 |   try {
 | 
|---|
| 49 |     // Creation/initialisation parametres Acq
 | 
|---|
| 50 |     BRAcqConfig acpar;
 | 
|---|
| 51 |     acpar.ReadParamFile(arg[1]);
 | 
|---|
| 52 | #ifndef NOPCIECARD  
 | 
|---|
| 53 |     BRConfList conf("/Raid"); 
 | 
|---|
| 54 | #else
 | 
|---|
| 55 |     BRConfList conf("./"); 
 | 
|---|
| 56 | #endif
 | 
|---|
| 57 |     acpar.Set(conf);
 | 
|---|
| 58 |     // Creation des repertoires 
 | 
|---|
| 59 |     if (acpar.CreateOutputDirectories()!=0)  return 9;
 | 
|---|
| 60 |     acpar.Print(cout);
 | 
|---|
| 61 |     struct sigaction act;  
 | 
|---|
| 62 |     if (!acpar.GetParams().fg_hard_ctrlc) {
 | 
|---|
| 63 |       act.sa_handler=Stop;
 | 
|---|
| 64 |       sigaction(SIGINT,&act,NULL);        
 | 
|---|
| 65 |     }
 | 
|---|
| 66 |     rc = MultiFibreAcq();    
 | 
|---|
| 67 |   }
 | 
|---|
| 68 |   catch (MiniFITSException& exc) {
 | 
|---|
| 69 |     cerr << " mfacq.cc catched MiniFITSException " << exc.Msg() << endl;
 | 
|---|
| 70 |     rc = 77;
 | 
|---|
| 71 |   } 
 | 
|---|
| 72 |   catch (PCIEWException& exc) {
 | 
|---|
| 73 |     cerr << " mfacq.cc catched MiniFITSException " << exc.Msg() << endl;
 | 
|---|
| 74 |     rc = 75;
 | 
|---|
| 75 |   }  
 | 
|---|
| 76 |   catch (PThrowable& exc) {
 | 
|---|
| 77 |     cerr << " mfacq.cc catched Exception " << exc.Msg() << endl;
 | 
|---|
| 78 |     rc = 76;
 | 
|---|
| 79 |   }  
 | 
|---|
| 80 |   catch (std::exception& sex) {
 | 
|---|
| 81 |     cerr << "\n mfacq.cc std::exception :" 
 | 
|---|
| 82 |          << (string)typeid(sex).name() << "\n msg= " 
 | 
|---|
| 83 |          << sex.what() << endl;
 | 
|---|
| 84 |     rc = 78;
 | 
|---|
| 85 |   }
 | 
|---|
| 86 |   catch (...) {
 | 
|---|
| 87 |     cerr << "  mfacq.cc : Catched ... exception " << endl;
 | 
|---|
| 88 |     rc = 79;
 | 
|---|
| 89 |   }
 | 
|---|
| 90 |   cout << "mfacq[9] ----- END --- stopping acq program " << endl;
 | 
|---|
| 91 |   return rc;
 | 
|---|
| 92 | }
 | 
|---|
| 93 | 
 | 
|---|
| 94 | 
 | 
|---|
| 95 | /* --Nouvelle-Fonction-- */
 | 
|---|
| 96 | void Usage(bool fgshort) 
 | 
|---|
| 97 | {
 | 
|---|
| 98 |   if (fgshort) {
 | 
|---|
| 99 |     cout << " Usage: mfacq DataCardFile \n" << endl;
 | 
|---|
| 100 |     cout << "parameter in DataCard :Fibres PaquetSize NFrameDMA NFiles NBlocPerFile \n"
 | 
|---|
| 101 |          << "                 NMaxProc DataDirPath acqmode nZones nPaqZones fg_hard_ctrlc" << endl;
 | 
|---|
| 102 |     cout << "   type mfacq -h for detailed usage " << endl;
 | 
|---|
| 103 |     return;
 | 
|---|
| 104 |   }
 | 
|---|
| 105 |   return;
 | 
|---|
| 106 | }
 | 
|---|
| 107 |  
 | 
|---|
| 108 |  
 | 
|---|
| 109 | /* --Nouvelle-Fonction-- */
 | 
|---|
| 110 | int MultiFibreAcq() 
 | 
|---|
| 111 | {
 | 
|---|
| 112 |   Timer tm("mfacq/MultiFibre");
 | 
|---|
| 113 |   cout << " ---------- mfacq/ MultiFibreAcq()  ------------- " << endl;
 | 
|---|
| 114 |   PCIEWrapperInterface* pciwp[4]={NULL,NULL,NULL,NULL};
 | 
|---|
| 115 |     
 | 
|---|
| 116 |   BRAcqConfig bpar;
 | 
|---|
| 117 |   BRParList& acpar=bpar.GetParams();
 | 
|---|
| 118 |   
 | 
|---|
| 119 |   cout << " mfacq[1]/Info: Creating RAcqMemZoneMgr for" << acpar.NbFibers << " fibers , nZones=" 
 | 
|---|
| 120 |        << acpar.nZones << " NbPaquet/Zone=" << acpar.nPaqZone 
 | 
|---|
| 121 |        << " mmgrPaqSize=" << acpar.MMgrPaquetSize() << endl;
 | 
|---|
| 122 |   RAcqMemZoneMgr mmgr(acpar.nZones, bpar.NFibers(), acpar.nPaqZone, acpar.MMgrPaquetSize());
 | 
|---|
| 123 |   pMmgr=&mmgr;  
 | 
|---|
| 124 |   int stepproc = 2;  
 | 
|---|
| 125 |   int nmean = acpar.nPaqZone*acpar.NBlocPerFile/stepproc;
 | 
|---|
| 126 | 
 | 
|---|
| 127 | #ifndef NOPCIECARD  
 | 
|---|
| 128 |   for (int i=0 ;i <acpar.NFibers() ;i++) {
 | 
|---|
| 129 |     UINT32 card=(acpar.FiberNum[i]-1)/2+1;
 | 
|---|
| 130 |     UINT32 cardfiber=(acpar.FiberNum[i]-1)%2
 | 
|---|
| 131 |     cout <<"mfacq[2] CreatePCIEWrapperV6- indice " << i <<  "INIT card " << card 
 | 
|---|
| 132 |          << " fibre " << cardfiber << endl;
 | 
|---|
| 133 |     pciwp[i] =  CreatePCIEWrapperV6(card,patternSZ,dmaSize,activate_pattern,cardfiber);
 | 
|---|
| 134 |   }
 | 
|---|
| 135 | #else 
 | 
|---|
| 136 |   TestPCIWrapperNODMA pciw1(bpar.RecvPaquetSize(), acpar.nopciLossRate);
 | 
|---|
| 137 |   TestPCIWrapperNODMA pciw2(bpar.RecvPaquetSize(), acpar.nopciLossRate);
 | 
|---|
| 138 |   TestPCIWrapperNODMA pciw3(bpar.RecvPaquetSize(), acpar.nopciLossRate);
 | 
|---|
| 139 |   TestPCIWrapperNODMA pciw4(bpar.RecvPaquetSize(), acpar.nopciLossRate);
 | 
|---|
| 140 |   pciwp[0] = &pciw1;
 | 
|---|
| 141 |   pciwp[1] = &pciw2;
 | 
|---|
| 142 |   pciwp[2] = &pciw3;
 | 
|---|
| 143 |   pciwp[3] = &pciw4;  
 | 
|---|
| 144 | #endif 
 | 
|---|
| 145 | 
 | 
|---|
| 146 |   cout <<"mfacq[3] Creating DataSaver and DataProc2C objects ... " << endl;
 | 
|---|
| 147 |   MultiDataSaver DsThr(mmgr);   //   Utilise les parametres globaux BRAcqConfig
 | 
|---|
| 148 |   string ppath=bpar.OutputDirectory();
 | 
|---|
| 149 |   DataProc2C PrThr(mmgr, ppath, 1280, stepproc, acpar.NMaxProc);
 | 
|---|
| 150 |   vector<PCIEWrapperInterface*> vec_pciw;
 | 
|---|
| 151 |   for  (int i=0 ;i<bpar.NFibers();i++)  vec_pciw.push_back( pciwp[i]);
 | 
|---|
| 152 |   cout << "mfacq[3] Creating   PCIEMultiReader       " << endl;
 | 
|---|
| 153 |   PCIEMultiReader PcierThr(vec_pciw, mmgr, bpar.GetParams());
 | 
|---|
| 154 |   usleep(200);  // attente au cas ou ...
 | 
|---|
| 155 |   pPcierThr=&PcierThr;
 | 
|---|
| 156 |   tm.Split("Threads created");  
 | 
|---|
| 157 |   cout << "mfacq[4] - starting 3 threads pcir, ds, pr ... " << endl;
 | 
|---|
| 158 |   PcierThr.start();
 | 
|---|
| 159 |   DsThr.start();
 | 
|---|
| 160 |   if (acpar.NMaxProc>0) { // On ne demarre que si au moins NMaxProc>0
 | 
|---|
| 161 |     PrThr.start();
 | 
|---|
| 162 |   }
 | 
|---|
| 163 |   
 | 
|---|
| 164 |   // On attend avant de declencher la terminaison des threads
 | 
|---|
| 165 |   usleep(100000);
 | 
|---|
| 166 |   
 | 
|---|
| 167 |   cout << "mfacq[5] -  Waiting for threads to finish ... " << endl;  
 | 
|---|
| 168 |   PcierThr.join();
 | 
|---|
| 169 |   DsThr.join();
 | 
|---|
| 170 |   mmgr.Stop();
 | 
|---|
| 171 |   if (acpar.NMaxProc>0) { // On ne demarre que si au moins NMaxProc>0
 | 
|---|
| 172 |     PrThr.join();
 | 
|---|
| 173 |   }
 | 
|---|
| 174 |   pMmgr=NULL;  
 | 
|---|
| 175 |   cout << "mfacq[6] ---------- threads finished ---------------- " << endl;
 | 
|---|
| 176 |   tm.Split("Threads Finished");  
 | 
|---|
| 177 |  
 | 
|---|
| 178 | #ifndef NOPCIECARD
 | 
|---|
| 179 |   for (int i=0 ;i <acpar.NbFibers ;i++) {
 | 
|---|
| 180 |     UINT32 card=(acpar.FiberNum[i]-1)/2+1;
 | 
|---|
| 181 |     UINT32 cardfiber=(acpar.FiberNum[i]-1)%2;
 | 
|---|
| 182 |     DeletePCIEWrapperV6(card,cardfiber);
 | 
|---|
| 183 |   }
 | 
|---|
| 184 | #endif    
 | 
|---|
| 185 | return 0;
 | 
|---|
| 186 | 
 | 
|---|
| 187 | }
 | 
|---|