[3671] | 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 |
|
---|
[3674] | 47 | string pardcfile=arg[1];
|
---|
| 48 | #ifndef NOPCIECARD
|
---|
| 49 | string basedir="/Raid";
|
---|
| 50 | #else
|
---|
| 51 | string basedir="./";
|
---|
| 52 | #endif
|
---|
| 53 | if (narg>2) basedir=arg[2];
|
---|
[3671] | 54 | try {
|
---|
| 55 | // Creation/initialisation parametres Acq
|
---|
| 56 | BRAcqConfig acpar;
|
---|
[3672] | 57 | acpar.ReadParamFile(arg[1]);
|
---|
[3674] | 58 | acpar.GetConfig().SetBaseDirectory(basedir);
|
---|
[3671] | 59 | // Creation des repertoires
|
---|
| 60 | if (acpar.CreateOutputDirectories()!=0) return 9;
|
---|
| 61 | acpar.Print(cout);
|
---|
| 62 | struct sigaction act;
|
---|
| 63 | if (!acpar.GetParams().fg_hard_ctrlc) {
|
---|
| 64 | act.sa_handler=Stop;
|
---|
| 65 | sigaction(SIGINT,&act,NULL);
|
---|
| 66 | }
|
---|
| 67 | rc = MultiFibreAcq();
|
---|
| 68 | }
|
---|
| 69 | catch (MiniFITSException& exc) {
|
---|
| 70 | cerr << " mfacq.cc catched MiniFITSException " << exc.Msg() << endl;
|
---|
| 71 | rc = 77;
|
---|
| 72 | }
|
---|
| 73 | catch (PCIEWException& exc) {
|
---|
| 74 | cerr << " mfacq.cc catched MiniFITSException " << exc.Msg() << endl;
|
---|
| 75 | rc = 75;
|
---|
| 76 | }
|
---|
| 77 | catch (PThrowable& exc) {
|
---|
| 78 | cerr << " mfacq.cc catched Exception " << exc.Msg() << endl;
|
---|
| 79 | rc = 76;
|
---|
| 80 | }
|
---|
| 81 | catch (std::exception& sex) {
|
---|
| 82 | cerr << "\n mfacq.cc std::exception :"
|
---|
| 83 | << (string)typeid(sex).name() << "\n msg= "
|
---|
| 84 | << sex.what() << endl;
|
---|
| 85 | rc = 78;
|
---|
| 86 | }
|
---|
| 87 | catch (...) {
|
---|
| 88 | cerr << " mfacq.cc : Catched ... exception " << endl;
|
---|
| 89 | rc = 79;
|
---|
| 90 | }
|
---|
| 91 | cout << "mfacq[9] ----- END --- stopping acq program " << endl;
|
---|
| 92 | return rc;
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 |
|
---|
| 96 | /* --Nouvelle-Fonction-- */
|
---|
| 97 | void Usage(bool fgshort)
|
---|
| 98 | {
|
---|
| 99 | if (fgshort) {
|
---|
[3674] | 100 | cout << " Usage: mfacq DataCardFile [BaseDirectory] \n" << endl;
|
---|
| 101 | cout << " Parameters in DataCard : \n"
|
---|
| 102 | << " fibres outpathname skysource paqsize dmasizekb nbfiles \n"
|
---|
| 103 | << " nblocperfile acqmode memmgr monitor reducpaqsz "<< endl;
|
---|
| 104 | cout << " BaseDirectory (default= /Raid ) " << endl;
|
---|
[3671] | 105 | return;
|
---|
| 106 | }
|
---|
| 107 | return;
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 |
|
---|
| 111 | /* --Nouvelle-Fonction-- */
|
---|
| 112 | int MultiFibreAcq()
|
---|
| 113 | {
|
---|
| 114 | Timer tm("mfacq/MultiFibre");
|
---|
| 115 | cout << " ---------- mfacq/ MultiFibreAcq() ------------- " << endl;
|
---|
| 116 | PCIEWrapperInterface* pciwp[4]={NULL,NULL,NULL,NULL};
|
---|
| 117 |
|
---|
| 118 | BRAcqConfig bpar;
|
---|
| 119 | BRParList& acpar=bpar.GetParams();
|
---|
| 120 |
|
---|
| 121 | cout << " mfacq[1]/Info: Creating RAcqMemZoneMgr for" << acpar.NbFibers << " fibers , nZones="
|
---|
| 122 | << acpar.nZones << " NbPaquet/Zone=" << acpar.nPaqZone
|
---|
[3674] | 123 | << " MmgrPaqSize=" << acpar.MMgrPaquetSize() << endl;
|
---|
[3671] | 124 | RAcqMemZoneMgr mmgr(acpar.nZones, bpar.NFibers(), acpar.nPaqZone, acpar.MMgrPaquetSize());
|
---|
| 125 | pMmgr=&mmgr;
|
---|
| 126 | int stepproc = 2;
|
---|
| 127 | int nmean = acpar.nPaqZone*acpar.NBlocPerFile/stepproc;
|
---|
| 128 |
|
---|
| 129 | #ifndef NOPCIECARD
|
---|
| 130 | for (int i=0 ;i <acpar.NFibers() ;i++) {
|
---|
| 131 | UINT32 card=(acpar.FiberNum[i]-1)/2+1;
|
---|
| 132 | UINT32 cardfiber=(acpar.FiberNum[i]-1)%2
|
---|
| 133 | cout <<"mfacq[2] CreatePCIEWrapperV6- indice " << i << "INIT card " << card
|
---|
| 134 | << " fibre " << cardfiber << endl;
|
---|
| 135 | pciwp[i] = CreatePCIEWrapperV6(card,patternSZ,dmaSize,activate_pattern,cardfiber);
|
---|
| 136 | }
|
---|
| 137 | #else
|
---|
| 138 | TestPCIWrapperNODMA pciw1(bpar.RecvPaquetSize(), acpar.nopciLossRate);
|
---|
| 139 | TestPCIWrapperNODMA pciw2(bpar.RecvPaquetSize(), acpar.nopciLossRate);
|
---|
| 140 | TestPCIWrapperNODMA pciw3(bpar.RecvPaquetSize(), acpar.nopciLossRate);
|
---|
| 141 | TestPCIWrapperNODMA pciw4(bpar.RecvPaquetSize(), acpar.nopciLossRate);
|
---|
| 142 | pciwp[0] = &pciw1;
|
---|
| 143 | pciwp[1] = &pciw2;
|
---|
| 144 | pciwp[2] = &pciw3;
|
---|
| 145 | pciwp[3] = &pciw4;
|
---|
| 146 | #endif
|
---|
| 147 |
|
---|
| 148 | cout <<"mfacq[3] Creating DataSaver and DataProc2C objects ... " << endl;
|
---|
[3672] | 149 | MultiDataSaver DsThr(mmgr); // Utilise les parametres globaux BRAcqConfig
|
---|
[3671] | 150 | string ppath=bpar.OutputDirectory();
|
---|
| 151 | DataProc2C PrThr(mmgr, ppath, 1280, stepproc, acpar.NMaxProc);
|
---|
| 152 | vector<PCIEWrapperInterface*> vec_pciw;
|
---|
| 153 | for (int i=0 ;i<bpar.NFibers();i++) vec_pciw.push_back( pciwp[i]);
|
---|
| 154 | cout << "mfacq[3] Creating PCIEMultiReader " << endl;
|
---|
[3672] | 155 | PCIEMultiReader PcierThr(vec_pciw, mmgr, bpar.GetParams());
|
---|
[3671] | 156 | usleep(200); // attente au cas ou ...
|
---|
| 157 | pPcierThr=&PcierThr;
|
---|
| 158 | tm.Split("Threads created");
|
---|
| 159 | cout << "mfacq[4] - starting 3 threads pcir, ds, pr ... " << endl;
|
---|
| 160 | PcierThr.start();
|
---|
| 161 | DsThr.start();
|
---|
| 162 | if (acpar.NMaxProc>0) { // On ne demarre que si au moins NMaxProc>0
|
---|
| 163 | PrThr.start();
|
---|
| 164 | }
|
---|
| 165 |
|
---|
| 166 | // On attend avant de declencher la terminaison des threads
|
---|
| 167 | usleep(100000);
|
---|
| 168 |
|
---|
| 169 | cout << "mfacq[5] - Waiting for threads to finish ... " << endl;
|
---|
| 170 | PcierThr.join();
|
---|
| 171 | DsThr.join();
|
---|
| 172 | mmgr.Stop();
|
---|
| 173 | if (acpar.NMaxProc>0) { // On ne demarre que si au moins NMaxProc>0
|
---|
| 174 | PrThr.join();
|
---|
| 175 | }
|
---|
| 176 | pMmgr=NULL;
|
---|
| 177 | cout << "mfacq[6] ---------- threads finished ---------------- " << endl;
|
---|
| 178 | tm.Split("Threads Finished");
|
---|
| 179 |
|
---|
| 180 | #ifndef NOPCIECARD
|
---|
| 181 | for (int i=0 ;i <acpar.NbFibers ;i++) {
|
---|
| 182 | UINT32 card=(acpar.FiberNum[i]-1)/2+1;
|
---|
| 183 | UINT32 cardfiber=(acpar.FiberNum[i]-1)%2;
|
---|
| 184 | DeletePCIEWrapperV6(card,cardfiber);
|
---|
| 185 | }
|
---|
| 186 | #endif
|
---|
| 187 | return 0;
|
---|
| 188 |
|
---|
| 189 | }
|
---|