1 | #include <iostream>
|
---|
2 |
|
---|
3 | #include "tmtacq.h"
|
---|
4 | #include "racqumem.h"
|
---|
5 | #include "racqurw.h"
|
---|
6 | #ifndef NOPCIECARD
|
---|
7 | #include "racquwbin.h"
|
---|
8 | #include "dmamgrv3.h"
|
---|
9 | #endif
|
---|
10 | #include "racquproc.h"
|
---|
11 |
|
---|
12 |
|
---|
13 | #include "pciewrap.h"
|
---|
14 | #include "brpaqu.h"
|
---|
15 | #include "minifits.h"
|
---|
16 |
|
---|
17 | #include "resusage.h"
|
---|
18 | #include "ctimer.h"
|
---|
19 | #include "timing.h"
|
---|
20 |
|
---|
21 | #include "tarrinit.h"
|
---|
22 | #include "fiosinit.h"
|
---|
23 |
|
---|
24 | using namespace std;
|
---|
25 | using namespace SOPHYA;
|
---|
26 |
|
---|
27 | static DataSaver *pDs;
|
---|
28 | static PCIEReaderChecker *pPcierc;
|
---|
29 | static PCIEReader *pPcier;
|
---|
30 | static DataProcFFT2C *pPrfft;
|
---|
31 | static DataProc2C *pPr;
|
---|
32 | static RAcqMemZoneMgr *pMmgr;
|
---|
33 | //--------------------------------------------------------
|
---|
34 | // Programme test acquisition BAORadio multi-thread
|
---|
35 | // LAL - R. Ansari Juillet - 2008
|
---|
36 | //--------------------------------------------------------
|
---|
37 | void Stop(int s)
|
---|
38 | {
|
---|
39 | printf("............. MAIN ... receive signal %d \n",s);
|
---|
40 | if (pPcierc != NULL) pPcierc->Stop();
|
---|
41 | if (pPcier != NULL) pPcier->Stop();
|
---|
42 | if (pPr !=NULL) pPr->Stop();
|
---|
43 | if (pPrfft !=NULL) pPrfft->Stop();
|
---|
44 | if (pDs != NULL) pDs->Stop();
|
---|
45 | if (pMmgr !=NULL) pMmgr->Stop();
|
---|
46 |
|
---|
47 | }
|
---|
48 |
|
---|
49 | int main(int narg, char* arg[])
|
---|
50 | {
|
---|
51 |
|
---|
52 | struct sigaction act;
|
---|
53 |
|
---|
54 | int rc = 0;
|
---|
55 | cout << " ===============================================================" << endl;
|
---|
56 | cout << " ========= " <<BAOR_ACQ_VER_STR <<BAOR_ACQ_VER <<" ===========" << endl;
|
---|
57 | cout << " ===============================================================" << endl;
|
---|
58 |
|
---|
59 | if (narg < 8) {
|
---|
60 | cout << "\n Usage: tmtacq CardNum PaquetSize NFrameDMA NFiles NBlocPerFile NMaxProc DataDirPath [AcqMode] [MemZoneMgr][HardCtlC]" << endl;
|
---|
61 | cout << " - CardNum : PCI-Express card number (=1,2)" << endl;
|
---|
62 | cout << " - PaquetSize or FrameSize (=DATA+HDR+TRL_Size) " << endl;
|
---|
63 | cout << " - NFrameDMA = DMASize= NFrameDMA*1024 , 4KO<=MaxDMASize<=64 ko " << endl;
|
---|
64 | cout << " - NFiles = Number of data files produced " << endl;
|
---|
65 | cout << " - NBlocPerFile = Number of memory data bloc in one file " << endl;
|
---|
66 | cout << " - NMaxProc = Max number of memory data blocs processed (FFT ...) " << endl;
|
---|
67 | cout << " NMaxProc=0 -> No Processing " << endl;
|
---|
68 | cout << " - DataDirPath : Subdirectory of /Raid " << endl;
|
---|
69 | cout << " Pour la version du firmware qui ne swappe pas les paquets" << endl;
|
---|
70 | cout << " - AcqMode: = swapall , fft1c , fft2c, swh , nof , mxs , mono , monosw (default=std)" << endl;
|
---|
71 | cout << " swapall -> SwapAll+SaveData , swh->swap header only " << endl;
|
---|
72 | cout << " fft1c , ff2c -> reorder data for 1 channel/2channel FFT " << endl;
|
---|
73 | cout << " fft1cnof , ff2cnof -> reorder FFT data, but DONT write files " << endl;
|
---|
74 | cout << endl;
|
---|
75 | cout << " Pour la version du firmware qui swappe partiellement " << endl;
|
---|
76 | cout << " -AcqMode : swap32 ,fft1c32 , fft2c32,fft1cnof32 , fft2cnof32 " <<endl;
|
---|
77 | cout << " fft1c32 , fft2c32 -> reorder data for 1 channel/2channel FFT " << endl;
|
---|
78 | cout << " fft1cnof32 , ff2cnof32 -> reorder FFT data, but DONT write files " << endl << endl;
|
---|
79 | cout << endl;
|
---|
80 | cout << " Pour la version du firmware qui ne swappe plus " << endl;
|
---|
81 | cout << " -AcqMode : nosw,fft1cnosw , fft2cnosw" <<endl;
|
---|
82 | cout << " fft1cnosw , fft2cnosw -> reorder data for 1 channel/2channel FFT " << endl;
|
---|
83 | cout << " fft1cnofnosw , ff2cnofnosw -> reorder FFT data, but DONT write files " << endl << endl;
|
---|
84 |
|
---|
85 |
|
---|
86 | cout << " Option pour debug ou test performance swapp initial (std)" << endl ;
|
---|
87 | cout << " nof->Don't write signal fits files , mxs->swh+nof: swap header only + no fits " << endl;
|
---|
88 | cout << " mono->Test with a single thread PCIEReaderChecker " << endl;
|
---|
89 | cout << " monosw->Test with a single thread PCIEReaderChecker, But swap all packet " << endl;
|
---|
90 | cout << endl;
|
---|
91 | cout << " mononsw->Test with a single thread PCIEReaderChecker, But no swap paquet " << endl;
|
---|
92 | cout << endl;
|
---|
93 | cout << " - MemZoneMgr: nZones,NPaq =Number of Zones and number of paquet in each zone (Default=8,128) " << endl;
|
---|
94 | cout << " -HardCtlC : Y y (direct interrpution by CtrlC ) default (no) " << endl;
|
---|
95 | return 1;
|
---|
96 | }
|
---|
97 |
|
---|
98 | InitTim();
|
---|
99 |
|
---|
100 | // Initialisation
|
---|
101 | TArrayInitiator _arri;
|
---|
102 | FitsIOServerInitiator _fiosi;
|
---|
103 | Timer tm("tmtacq");
|
---|
104 |
|
---|
105 | string acqmode = "std";
|
---|
106 | if (narg > 8) acqmode = arg[8];
|
---|
107 | bool savesigfits = true;
|
---|
108 | // BRDataFmtConv swapall = BR_SwapAll;
|
---|
109 | BRDataFmtConv swapall = BR_Copy;
|
---|
110 | bool monothr = false;
|
---|
111 | if (acqmode == "swapall") swapall = BR_SwapAll;
|
---|
112 | if (acqmode == "fft1c") swapall = BR_FFTOneChan;
|
---|
113 | if (acqmode == "fft2c") swapall = BR_FFTTwoChan;
|
---|
114 | if (acqmode == "fft1cnof") { swapall = BR_FFTOneChan; savesigfits = false; }
|
---|
115 | if (acqmode == "fft2cnof") { swapall = BR_FFTTwoChan; savesigfits = false; }
|
---|
116 | if ((acqmode == "swh") || (acqmode == "mxs") || (acqmode == "mono") ) swapall = BR_SwapHDR;
|
---|
117 | if ((acqmode == "nof") || (acqmode == "mxs") || (acqmode == "mono")) savesigfits = false;
|
---|
118 | if (acqmode == "mono") { monothr = true; swapall = BR_SwapHDR;; }
|
---|
119 | if (acqmode == "monosw") { monothr = true; swapall = BR_SwapAll; }
|
---|
120 | if (acqmode == "mononsw") { monothr = true; swapall = BR_Copy; }
|
---|
121 |
|
---|
122 | if (acqmode == "swap32") swapall = BR_Swap32 ;
|
---|
123 | if (acqmode == "fft1c32") swapall = BR_FFTOneChan32;
|
---|
124 | if (acqmode == "fft2c32") swapall = BR_FFTTwoChan32;
|
---|
125 | if (acqmode == "fft1cnof32") { swapall = BR_FFTOneChan32; savesigfits = false; }
|
---|
126 | if (acqmode == "fft2cnof32") { swapall = BR_FFTTwoChan32; savesigfits = false; }
|
---|
127 |
|
---|
128 | if (acqmode == "nosw") swapall = BR_Copy ;
|
---|
129 | if (acqmode == "fft1cnosw") swapall = BR_FFTOneChanNoSwap;
|
---|
130 | if (acqmode == "fft2cnosw") swapall = BR_FFTTwoChanNoSwap;
|
---|
131 | if (acqmode == "fft1cnofnosw") { swapall = BR_FFTOneChanNoSwap; savesigfits = false; }
|
---|
132 | if (acqmode == "fft2cnofnosw") { swapall = BR_FFTTwoChanNoSwap; savesigfits = false; }
|
---|
133 |
|
---|
134 | #ifdef NOPCIECARD
|
---|
135 | string dir = string(arg[7])+"/";
|
---|
136 | #else
|
---|
137 | string dir =string("/Raid/")+arg[7]+"/";
|
---|
138 | #endif
|
---|
139 | cout << " DataDirpath=" << dir << " SwapMode=" << BRPaquet::FmtConvToString(swapall)
|
---|
140 | << " DataSaveMode=" << ((savesigfits)?"Yes/FitsFile":"NO") << endl;
|
---|
141 |
|
---|
142 | char cmd[192];
|
---|
143 | sprintf(cmd,"mkdir %s",dir.c_str());
|
---|
144 | if (system(cmd) < 0) {
|
---|
145 | cout << "tmtacq/Error: Can not create subdirectory " << dir << " -> exit" << endl;
|
---|
146 | return 2;
|
---|
147 | }
|
---|
148 | int card = atoi(arg[1]);
|
---|
149 | unsigned int sizeFrame = atoi(arg[2]);
|
---|
150 | unsigned int nbFrameDMA = atoi(arg[3]);
|
---|
151 | int NbFiles = atoi(arg[4]);
|
---|
152 | int NBlocPerFile = atoi(arg[5]);
|
---|
153 | int NMaxProc = atoi(arg[6]); // Nombre de blocs traites par le thread de calcul
|
---|
154 | cout << "tmtacq[1] - starting acq program under card " << card << " FrameSize= " << sizeFrame << endl;
|
---|
155 |
|
---|
156 | uint_4 nZones = 8; // Nombre de zones memoires
|
---|
157 | uint_4 nPaqZone = 128; // 128 Paquets / zone memoire - valeur par defaut
|
---|
158 | if (narg > 9) {
|
---|
159 | int ia1, ia2;
|
---|
160 | sscanf(arg[9],"%d,%d", &ia1, &ia2);
|
---|
161 | nZones = ia1; nPaqZone = ia2;
|
---|
162 | }
|
---|
163 |
|
---|
164 | bool fg_hard_ctrlc = false;
|
---|
165 | if (narg > 10) // pour traiter eventuellement un arret brutal par CtlC mettre le 10eme arg a Y
|
---|
166 | if ((*arg[10]=='y')||(*arg[10]=='Y')) fg_hard_ctrlc=true;
|
---|
167 | if (!fg_hard_ctrlc) {
|
---|
168 | act.sa_handler=Stop;
|
---|
169 | sigaction(SIGINT,&act,NULL);
|
---|
170 | }
|
---|
171 |
|
---|
172 | uint_4 PaqSZ =sizeFrame; // Taille de paquets
|
---|
173 | // uint_4 dmaSize = nbFrameDMA*PaqSZ ; // plantage
|
---|
174 | uint_4 dmaSize = nbFrameDMA*1024 ;
|
---|
175 | uint_4 patternSZ=0x400; // pas utilise avec la fibre
|
---|
176 | uint_4 NMaxBloc = NbFiles*NBlocPerFile;
|
---|
177 | cout << "tmtacq[0] - PaqSize = " << PaqSZ << " NbPaq/Zone=" << nPaqZone << " NZones=" << nZones << endl;
|
---|
178 | cout << " NbFiles=" << NbFiles << " NBloc/File=" << NBlocPerFile << " -> NMaxBloc=" << NMaxBloc << endl;
|
---|
179 | cout << "tmtacq[1] NbFrameDMA=" << nbFrameDMA << " DMASize=" << dmaSize << " bytes" << endl;
|
---|
180 | cout << "tmtacq[1] NMaxProc=" << NMaxProc << endl;
|
---|
181 | try {
|
---|
182 |
|
---|
183 | #ifdef NOPCIECARD
|
---|
184 | TestPCIWrapperNODMA pciw(PaqSZ);
|
---|
185 | #else
|
---|
186 | DMAMgr dma1(card,patternSZ,dmaSize );
|
---|
187 | if (! dma1.StatusFibre() ) {
|
---|
188 | cout << " tmtacq[0] - fibre non accrochee -> exit " << endl;
|
---|
189 | throw PCIEWException(" Fibre non accrochee ");
|
---|
190 | }
|
---|
191 | else cout << " tmtacq[0] - fibre accrochee OK " << endl;
|
---|
192 | PCIEWrapper pciw(dma1);
|
---|
193 | #endif
|
---|
194 | RAcqMemZoneMgr mmgr(nZones, nPaqZone, PaqSZ);
|
---|
195 | pMmgr =&mmgr;
|
---|
196 |
|
---|
197 | if (monothr) {
|
---|
198 | cout << "tmtacq[1] single thread PCIE test PCIEReaderChecker ... ";
|
---|
199 | PCIEReaderChecker pcirc(pciw,dmaSize,PaqSZ ,mmgr, NMaxBloc, swapall);
|
---|
200 | pPcierc=&pcirc;
|
---|
201 | pcirc.start();
|
---|
202 | sleep(1);
|
---|
203 | pcirc.join();
|
---|
204 | cout << "tmtacq[2] - single thread PCIEReaderChecker finished " << endl;
|
---|
205 | tm.Split("Single Thread Finished");
|
---|
206 | mmgr.Print(cout);
|
---|
207 | return 0;
|
---|
208 | }
|
---|
209 | PCIEReader pcir(pciw,dmaSize,PaqSZ ,mmgr, NMaxBloc, swapall);
|
---|
210 | pPcier= &pcir;
|
---|
211 | DataSaver ds(mmgr, dir, NbFiles, NBlocPerFile, savesigfits);
|
---|
212 | pDs= &ds;
|
---|
213 | //DataBinSaver ds(mmgr, dir, NbFiles ,NBlocPerFile);
|
---|
214 | // DataProc1C pr(mmgr, dir, nmean, stepproc, 100); Pour processer un canal
|
---|
215 | int stepproc = 2;
|
---|
216 | int nmean = nPaqZone*NBlocPerFile/stepproc;
|
---|
217 | DataProc2C pr(mmgr, dir, nmean, stepproc, NMaxProc);
|
---|
218 | DataProcFFT2C prfft(mmgr, dir, nmean, stepproc, NMaxProc);
|
---|
219 | tm.Split("Threads created");
|
---|
220 | cout << "tmtacq[2] - starting 3 threads pcir, ds, pr ... " << endl;
|
---|
221 | /*
|
---|
222 | char test[100];
|
---|
223 | cout << " <CR> to continue, x to exit ..." << endl;
|
---|
224 | gets(test); if (test[0] == 'x') return 9;
|
---|
225 | */
|
---|
226 | pcir.start();
|
---|
227 | ds.start();
|
---|
228 | if (NMaxProc>0) { // On ne demarre que si au moins NMaxProc>0
|
---|
229 | if (acqmode.substr(0,5)=="fft2c") { prfft.start(); pPrfft=&prfft;}
|
---|
230 | else { pr.start(); pPr=≺}
|
---|
231 | }
|
---|
232 | cout << "tmtacq[3] - waiting for threads to finish ... " << endl;
|
---|
233 | sleep(1);
|
---|
234 | pcir.join();
|
---|
235 | ds.join();
|
---|
236 | sleep(1);
|
---|
237 | mmgr.Stop();
|
---|
238 | if (NMaxProc>0) if ( pPr != NULL) pr.join();
|
---|
239 | if (NMaxProc>0) if ( pPrfft != NULL) prfft.join();
|
---|
240 | cout << "tmtacq[4] - threads finished " << endl;
|
---|
241 | tm.Split("Threads Finished");
|
---|
242 | mmgr.Print(cout);
|
---|
243 | rc = 0;
|
---|
244 | }
|
---|
245 | catch (MiniFITSException& exc) {
|
---|
246 | cerr << " tmtacq.cc catched MiniFITSException " << exc.Msg() << endl;
|
---|
247 | rc = 77;
|
---|
248 | }
|
---|
249 | catch (PCIEWException& exc) {
|
---|
250 | cerr << "\7 tmtacq.cc catched MiniFITSException " << exc.Msg() << endl;
|
---|
251 | rc = 75;
|
---|
252 | }
|
---|
253 | catch (PThrowable& exc) {
|
---|
254 | cerr << " tmtacq.cc catched Exception " << exc.Msg() << endl;
|
---|
255 | rc = 76;
|
---|
256 | }
|
---|
257 | catch (std::exception& sex) {
|
---|
258 | cerr << "\n tmtacq.cc std::exception :"
|
---|
259 | << (string)typeid(sex).name() << "\n msg= "
|
---|
260 | << sex.what() << endl;
|
---|
261 | rc = 78;
|
---|
262 | }
|
---|
263 | catch (...) {
|
---|
264 | cerr << " tmtacq.cc : Catched ... exception " << endl;
|
---|
265 | rc = 79;
|
---|
266 | }
|
---|
267 | cout << "tmtacq[9] - stopping acq program " << endl;
|
---|
268 | return rc;
|
---|
269 | }
|
---|
270 |
|
---|