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 | static PCIEToEthernet* pPcie2Eth=NULL;
|
---|
12 | static EthernetReader* pEthRdr=NULL;
|
---|
13 |
|
---|
14 | void Stop(int s)
|
---|
15 | {
|
---|
16 | if (s == 9765) cout << " Stop after exception ..." << endl;
|
---|
17 | else printf("............. MAIN ... receive signal %d \n",s);
|
---|
18 | if (pMmgr != NULL) pMmgr->Stop();
|
---|
19 | if (pPcie2Eth !=NULL) pPcie2Eth->Stop();
|
---|
20 | if (pPcierThr !=NULL) pPcierThr->Stop();
|
---|
21 | if (pEthRdr !=NULL) pEthRdr->Stop();
|
---|
22 | }
|
---|
23 |
|
---|
24 |
|
---|
25 | //-----------------------------------------------------------------------
|
---|
26 | //-------------------- le programme principal ---------------------------
|
---|
27 | //-----------------------------------------------------------------------
|
---|
28 | int main(int narg, char* arg[])
|
---|
29 | {
|
---|
30 |
|
---|
31 | int rc = 0;
|
---|
32 | cout << " ============= BAORadio / Acquisition : mfacq =================" << endl;
|
---|
33 | cout << " ===============================================================" << endl;
|
---|
34 | cout << " ========= " <<BAOR_ACQ_VER_STR <<BAOR_ACQ_VER << " ===========" << endl;
|
---|
35 | cout << " ===============================================================" << endl;
|
---|
36 |
|
---|
37 |
|
---|
38 | InitTim();
|
---|
39 |
|
---|
40 | // Initialisation
|
---|
41 | TArrayInitiator _arri;
|
---|
42 | FitsIOServerInitiator _fiosi;
|
---|
43 |
|
---|
44 |
|
---|
45 | if ((narg > 1)&&(strcmp(arg[1],"-h"))==0) {
|
---|
46 | Usage(false);
|
---|
47 | return 1;
|
---|
48 | }
|
---|
49 | if (narg < 3) {
|
---|
50 | Usage(true);
|
---|
51 | return 3;
|
---|
52 | }
|
---|
53 |
|
---|
54 | const char* desact[3] = {"PCIE_To_Ethernet", "Ethernet_To_Disk", "PCIE_DMA_To_Disk"};
|
---|
55 | string action=arg[1];
|
---|
56 | int act = 0;
|
---|
57 | if ((action != "-pci2eth")&&(action != "-pci2disk")&&(action != "-eth2disk")) {
|
---|
58 | cout << " mfacq/Error , Bad action argument : " << action << endl;
|
---|
59 | return 2;
|
---|
60 | }
|
---|
61 | if (action == "-pci2eth") act=0;
|
---|
62 | else if (action == "-eth2disk") act=1;
|
---|
63 | else if (action == "-pci2disk") act=2;
|
---|
64 |
|
---|
65 | string pardcfile=arg[2];
|
---|
66 | #ifndef NOPCIECARD
|
---|
67 | string basedir="/Raid";
|
---|
68 | #else
|
---|
69 | string basedir="./";
|
---|
70 | #endif
|
---|
71 | vector<string> oargs;
|
---|
72 | if (narg>3) {
|
---|
73 | basedir=arg[2];
|
---|
74 | for(int jj=3; jj<narg; jj++) oargs.push_back(arg[jj]);
|
---|
75 | }
|
---|
76 | try {
|
---|
77 | // Creation/initialisation parametres Acq
|
---|
78 | BRAcqConfig acpar;
|
---|
79 | acpar.ReadParamFile(pardcfile);
|
---|
80 | acpar.GetConfig().SetBaseDirectory(basedir);
|
---|
81 | if ((act==0)&&(oargs.size()>0))
|
---|
82 | acpar.GetParams().SetEthTargets(oargs);
|
---|
83 | // Creation des repertoires
|
---|
84 | if (act > 0)
|
---|
85 | if (acpar.CreateOutputDirectories()!=0) return 9;
|
---|
86 | acpar.Print(cout);
|
---|
87 | struct sigaction siact;
|
---|
88 | if (!acpar.GetParams().fg_hard_ctrlc) {
|
---|
89 | siact.sa_handler=Stop;
|
---|
90 | sigaction(SIGINT,&siact,NULL);
|
---|
91 | }
|
---|
92 | switch (act) {
|
---|
93 | case 0:
|
---|
94 | rc = PCIEToEthernetTransfer();
|
---|
95 | break;
|
---|
96 | case 1:
|
---|
97 | rc = EthernetToMemoryAcq();
|
---|
98 | break;
|
---|
99 | case 2:
|
---|
100 | rc = MultiFibreAcq();
|
---|
101 | break;
|
---|
102 | }
|
---|
103 | }
|
---|
104 | catch (MiniFITSException& exc) {
|
---|
105 | cerr << " mfacq.cc catched MiniFITSException " << exc.Msg() << endl;
|
---|
106 | rc = 77;
|
---|
107 | }
|
---|
108 | catch (PCIEWException& exc) {
|
---|
109 | cerr << " mfacq.cc catched PCIEWException " << exc.Msg() << endl;
|
---|
110 | rc = 75;
|
---|
111 | }
|
---|
112 | catch (PThrowable& exc) {
|
---|
113 | cerr << " mfacq.cc catched Exception " << exc.Msg() << endl;
|
---|
114 | rc = 76;
|
---|
115 | }
|
---|
116 | catch (std::exception& sex) {
|
---|
117 | cerr << "\n mfacq.cc std::exception :"
|
---|
118 | << (string)typeid(sex).name() << "\n msg= "
|
---|
119 | << sex.what() << endl;
|
---|
120 | rc = 78;
|
---|
121 | }
|
---|
122 | catch (...) {
|
---|
123 | cerr << " mfacq.cc : Catched ... exception " << endl;
|
---|
124 | rc = 79;
|
---|
125 | }
|
---|
126 | cout << "mfacq[9] ----- END --- stopping acq program " << endl;
|
---|
127 | return rc;
|
---|
128 | }
|
---|
129 |
|
---|
130 |
|
---|
131 | /* --Nouvelle-Fonction-- */
|
---|
132 | void Usage(bool fgshort)
|
---|
133 | {
|
---|
134 | cout << " Usage: mfacq Action DataCardFile [BaseDirectory / TargetMachines] \n" << endl;
|
---|
135 | if (fgshort) return;
|
---|
136 | cout << " Action = -pci2disk , -pci2mem -eth2disk \n "
|
---|
137 | << " Parameters in DataCard : \n"
|
---|
138 | << " fibres outpathname skysource paqsize dmasizekb nbfiles \n"
|
---|
139 | << " nblocperfile acqmode memmgr monitor reducpaqsz "<< endl;
|
---|
140 | cout << " BaseDirectory (default= /Raid ) " << endl;
|
---|
141 | cout << " TargetMachines : List of target machines for PCIe2Ethernet " << endl;
|
---|
142 | return;
|
---|
143 | }
|
---|
144 |
|
---|
145 |
|
---|
146 | /* --Nouvelle-Fonction-- */
|
---|
147 | int MultiFibreAcq()
|
---|
148 | {
|
---|
149 | Timer tm("mfacq/MultiFibre");
|
---|
150 | cout << " ---------- mfacq/ MultiFibreAcq() ------------- " << endl;
|
---|
151 | PCIEWrapperInterface* pciwp[16]={NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
|
---|
152 | NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
|
---|
153 |
|
---|
154 | BRAcqConfig bpar;
|
---|
155 | BRParList& acpar=bpar.GetParams();
|
---|
156 |
|
---|
157 | cout << " mfacq[1]/Info: Creating RAcqMemZoneMgr for" << acpar.NbFibers << " fibers , nZones="
|
---|
158 | << acpar.nZones << " NbPaquet/Zone=" << acpar.nPaqZone
|
---|
159 | << " MmgrPaqSize=" << acpar.MMgrPaquetSize() << endl;
|
---|
160 | RAcqMemZoneMgr mmgr(acpar.nZones, bpar.NFibers(), acpar.nPaqZone, acpar.MMgrPaquetSize());
|
---|
161 | pMmgr=&mmgr;
|
---|
162 | if (acpar.fgdoProc && (acpar.stepProc>0)) {
|
---|
163 | // Dans ce cas, toutes les zones doivent passer ds le thread de monitoring
|
---|
164 | // pour etre au moins marque comme traite - seul 1/acpar.stepProc sont effectivement traite
|
---|
165 | mmgr.SetFinalizedMask(((uint_4)MemZS_Saved) | ((uint_4)MemZS_Proc));
|
---|
166 | cout << " mfacq[1.b]/Info: Mmgr.SetFinalizedMask( MemZS_Saved | MemZS_Proc )" << endl;
|
---|
167 | //mmgr.SetFinalizedMask( (uint_4)MemZS_Saved );
|
---|
168 | //cout << " mfacq[1.b]/Info: Mmgr.SetFinalizedMask( MemZS_Saved )" << endl;
|
---|
169 | }
|
---|
170 |
|
---|
171 | #ifndef NOPCIECARD
|
---|
172 | for (int i=0 ;i <acpar.NFibers() ;i++) {
|
---|
173 | UINT32 card=(acpar.FiberNum[i]-1)/2+1;
|
---|
174 | UINT32 cardfiber=(acpar.FiberNum[i]-1)%2;
|
---|
175 | cout <<"mfacq[2] CreatePCIEWrapperV6- indice " << i << "INIT card " << card
|
---|
176 | << " fibre " << cardfiber << endl;
|
---|
177 | pciwp[i] = CreatePCIEWrapperV6(card,acpar.PatternSize(),acpar.DMASizeBytes(),acpar.activate_pattern,cardfiber);
|
---|
178 | }
|
---|
179 | #else
|
---|
180 | TestPCIWrapperNODMA pciw1(bpar.RecvPaquetSize(), acpar.nopciLossRate);
|
---|
181 | TestPCIWrapperNODMA pciw2(bpar.RecvPaquetSize(), acpar.nopciLossRate);
|
---|
182 | TestPCIWrapperNODMA pciw3(bpar.RecvPaquetSize(), acpar.nopciLossRate);
|
---|
183 | TestPCIWrapperNODMA pciw4(bpar.RecvPaquetSize(), acpar.nopciLossRate);
|
---|
184 | TestPCIWrapperNODMA pciw5(bpar.RecvPaquetSize(), acpar.nopciLossRate);
|
---|
185 | TestPCIWrapperNODMA pciw6(bpar.RecvPaquetSize(), acpar.nopciLossRate);
|
---|
186 | TestPCIWrapperNODMA pciw7(bpar.RecvPaquetSize(), acpar.nopciLossRate);
|
---|
187 | TestPCIWrapperNODMA pciw8(bpar.RecvPaquetSize(), acpar.nopciLossRate);
|
---|
188 | pciwp[0] = &pciw1;
|
---|
189 | pciwp[1] = &pciw2;
|
---|
190 | pciwp[2] = &pciw3;
|
---|
191 | pciwp[3] = &pciw4;
|
---|
192 | pciwp[4] = &pciw5;
|
---|
193 | pciwp[5] = &pciw6;
|
---|
194 | pciwp[6] = &pciw7;
|
---|
195 | pciwp[7] = &pciw8;
|
---|
196 | #endif
|
---|
197 |
|
---|
198 | cout <<"mfacq[2] Creating MultiDataSaver and MonitorProc thread objects ... " << endl;
|
---|
199 | MultiDataSaver DsThr(mmgr); // Utilise les parametres globaux BRAcqConfig
|
---|
200 | string ppath=bpar.OutputDirectory();
|
---|
201 | MonitorProc PrThr(mmgr);
|
---|
202 | cout << "mfacq[3] Creating PCIEMultiReader thread object " << endl;
|
---|
203 | vector<PCIEWrapperInterface*> vec_pciw;
|
---|
204 | for (int i=0 ;i<bpar.NFibers();i++) {
|
---|
205 | vec_pciw.push_back( pciwp[i]);
|
---|
206 | // cout << " mfacq[3.b]/Debug - pciwp[" << i << "] " << hex << pciwp[i] << dec << endl;
|
---|
207 | }
|
---|
208 | PCIEMultiReader PcierThr(vec_pciw, mmgr, bpar.GetParams());
|
---|
209 | // usleep(200); attente au cas ou ...
|
---|
210 | pPcierThr=&PcierThr;
|
---|
211 | tm.Split("Threads created");
|
---|
212 | if (acpar.fgdoProc>0)
|
---|
213 | cout << "mfacq[4] - starting three threads: PCIEMultiReader, MultiDataSaver, MonitorProc ... " << endl;
|
---|
214 | else
|
---|
215 | cout << "mfacq[4] - starting two threads: PCIEMultiReader, MultiDataSaver ... " << endl;
|
---|
216 |
|
---|
217 | PcierThr.start();
|
---|
218 | DsThr.start();
|
---|
219 | if (acpar.fgdoProc>0) { // On ne demarre que si au moins NMaxProc>0
|
---|
220 | PrThr.start();
|
---|
221 | }
|
---|
222 |
|
---|
223 | // On attend avant de declencher la terminaison des threads
|
---|
224 | usleep(200000);
|
---|
225 |
|
---|
226 | cout << "mfacq[5] - Waiting for threads to finish ... " << endl;
|
---|
227 | PcierThr.join();
|
---|
228 | DsThr.join();
|
---|
229 | mmgr.Stop();
|
---|
230 | if (acpar.fgdoProc) { // On n'attend la fin que si le thread a ete demarre (NMaxProc>0)
|
---|
231 | PrThr.join();
|
---|
232 | }
|
---|
233 | pMmgr=NULL;
|
---|
234 | cout << "mfacq[6] ---------- threads finished ---------------- " << endl;
|
---|
235 | tm.Split("Threads Finished");
|
---|
236 |
|
---|
237 | mmgr.Print(cout);
|
---|
238 | #ifndef NOPCIECARD
|
---|
239 | for (int i=0 ;i <acpar.NbFibers ;i++) {
|
---|
240 | UINT32 card=(acpar.FiberNum[i]-1)/2+1;
|
---|
241 | UINT32 cardfiber=(acpar.FiberNum[i]-1)%2;
|
---|
242 | DeletePCIEWrapperV6(card,cardfiber);
|
---|
243 | }
|
---|
244 | #endif
|
---|
245 | return 0;
|
---|
246 |
|
---|
247 | }
|
---|
248 |
|
---|
249 | /* --Nouvelle-Fonction-- */
|
---|
250 | int PCIEToEthernetTransfer()
|
---|
251 | {
|
---|
252 | Timer tm("mfacq/PCIEToEthernetTransfer");
|
---|
253 | cout << " ---------- mfacq/ PCIEToEthernetTransfer() ------------- " << endl;
|
---|
254 | PCIEWrapperInterface* pciwp[16]={NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
|
---|
255 | NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
|
---|
256 |
|
---|
257 | pMmgr=NULL;
|
---|
258 | BRAcqConfig bpar;
|
---|
259 | BRParList& acpar=bpar.GetParams();
|
---|
260 |
|
---|
261 | cout << " mfacq[1]/Info: PCIEToEthernet for" << acpar.NbFibers << " fibers , nZones="
|
---|
262 | << acpar.nZones << " NbPaquet/Zone=" << acpar.nPaqZone
|
---|
263 | << " MmgrPaqSize=" << acpar.MMgrPaquetSize() << endl;
|
---|
264 |
|
---|
265 | #ifndef NOPCIECARD
|
---|
266 | for (int i=0 ;i <acpar.NFibers() ;i++) {
|
---|
267 | UINT32 card=(acpar.FiberNum[i]-1)/2+1;
|
---|
268 | UINT32 cardfiber=(acpar.FiberNum[i]-1)%2;
|
---|
269 | cout <<"mfacq[2] CreatePCIEWrapperV6- indice " << i << "INIT card " << card
|
---|
270 | << " fibre " << cardfiber << endl;
|
---|
271 | pciwp[i] = CreatePCIEWrapperV6(card,acpar.PatternSize(),acpar.DMASizeBytes(),acpar.activate_pattern,cardfiber);
|
---|
272 | }
|
---|
273 | #else
|
---|
274 | TestPCIWrapperNODMA pciw1(bpar.RecvPaquetSize(), acpar.nopciLossRate);
|
---|
275 | TestPCIWrapperNODMA pciw2(bpar.RecvPaquetSize(), acpar.nopciLossRate);
|
---|
276 | TestPCIWrapperNODMA pciw3(bpar.RecvPaquetSize(), acpar.nopciLossRate);
|
---|
277 | TestPCIWrapperNODMA pciw4(bpar.RecvPaquetSize(), acpar.nopciLossRate);
|
---|
278 | TestPCIWrapperNODMA pciw5(bpar.RecvPaquetSize(), acpar.nopciLossRate);
|
---|
279 | TestPCIWrapperNODMA pciw6(bpar.RecvPaquetSize(), acpar.nopciLossRate);
|
---|
280 | TestPCIWrapperNODMA pciw7(bpar.RecvPaquetSize(), acpar.nopciLossRate);
|
---|
281 | TestPCIWrapperNODMA pciw8(bpar.RecvPaquetSize(), acpar.nopciLossRate);
|
---|
282 | pciwp[0] = &pciw1;
|
---|
283 | pciwp[1] = &pciw2;
|
---|
284 | pciwp[2] = &pciw3;
|
---|
285 | pciwp[3] = &pciw4;
|
---|
286 | pciwp[4] = &pciw5;
|
---|
287 | pciwp[5] = &pciw6;
|
---|
288 | pciwp[6] = &pciw7;
|
---|
289 | pciwp[7] = &pciw8;
|
---|
290 | #endif
|
---|
291 |
|
---|
292 | vector<PCIEWrapperInterface*> vec_pciw;
|
---|
293 | for (int i=0 ;i<bpar.NFibers();i++) vec_pciw.push_back( pciwp[i]);
|
---|
294 | cout <<"mfacq[2] Creating PCIEToEthernet thread object " << endl;
|
---|
295 | PCIEToEthernet pci2eth(vec_pciw, bpar.GetParams().GetEthTargets(), bpar.GetParams());
|
---|
296 | // usleep(200); attente au cas ou ...
|
---|
297 | pPcie2Eth=&pci2eth;
|
---|
298 | tm.Split("Threads created");
|
---|
299 | cout << "mfacq[3] - starting one threads: PCIEToEthernet... " << endl;
|
---|
300 | pci2eth.start();
|
---|
301 |
|
---|
302 | // On attend avant de declencher la terminaison des threads
|
---|
303 | usleep(200000);
|
---|
304 |
|
---|
305 | cout << "mfacq[5] - Waiting for threads to finish ... " << endl;
|
---|
306 | pci2eth.join();
|
---|
307 | cout << "mfacq[6] ---------- threads finished ---------------- " << endl;
|
---|
308 | tm.Split("Threads Finished");
|
---|
309 |
|
---|
310 | #ifndef NOPCIECARD
|
---|
311 | for (int i=0 ;i <acpar.NbFibers ;i++) {
|
---|
312 | UINT32 card=(acpar.FiberNum[i]-1)/2+1;
|
---|
313 | UINT32 cardfiber=(acpar.FiberNum[i]-1)%2;
|
---|
314 | DeletePCIEWrapperV6(card,cardfiber);
|
---|
315 | }
|
---|
316 | #endif
|
---|
317 | return 0;
|
---|
318 | }
|
---|
319 |
|
---|
320 | /* --Nouvelle-Fonction-- */
|
---|
321 | int EthernetToMemoryAcq()
|
---|
322 | {
|
---|
323 | Timer tm("mfacq/EthernetToMemoryAcq");
|
---|
324 | cout << " ---------- mfacq/ EthernetToMemoryAcq() ------------- " << endl;
|
---|
325 |
|
---|
326 | BRAcqConfig bpar;
|
---|
327 | BRParList& acpar=bpar.GetParams();
|
---|
328 |
|
---|
329 | cout << " mfacq[1]/Info: Creating RAcqMemZoneMgr for" << acpar.NbEthLinks() << " Eth-links , nZones="
|
---|
330 | << acpar.nZones << " NbPaquet/Zone=" << acpar.nPaqZone
|
---|
331 | << " MmgrPaqSize=" << acpar.MMgrPaquetSize() << endl;
|
---|
332 | RAcqMemZoneMgr mmgr(acpar.nZones, acpar.NbEthLinks(), acpar.nPaqZone, acpar.MMgrPaquetSize());
|
---|
333 | pMmgr=&mmgr;
|
---|
334 | if (acpar.fgdoProc && (acpar.stepProc>0)) {
|
---|
335 | // Dans ce cas, toutes les zones doivent passer ds le thread de monitoring
|
---|
336 | // pour etre au moins marque comme traite - seul 1/acpar.stepProc sont effectivement traite
|
---|
337 | mmgr.SetFinalizedMask(((uint_4)MemZS_Saved) | ((uint_4)MemZS_Proc));
|
---|
338 | cout << " mfacq[1.b]/Info: Mmgr.SetFinalizedMask( MemZS_Saved | MemZS_Proc )" << endl;
|
---|
339 | }
|
---|
340 |
|
---|
341 |
|
---|
342 | cout <<"mfacq[2] Creating MultiDataSaver and MonitorProc thread objects ... " << endl;
|
---|
343 | MultiDataSaver DsThr(mmgr); // Utilise les parametres globaux BRAcqConfig
|
---|
344 | string ppath=bpar.OutputDirectory();
|
---|
345 | MonitorProc PrThr(mmgr);
|
---|
346 | cout << "mfacq[3] Creating EthernetReader thread object " << endl;
|
---|
347 | EthernetReader ethrdr(mmgr, bpar.GetParams(), bpar.GetParams().tcpportid, false);
|
---|
348 | // usleep(200); attente au cas ou ...
|
---|
349 | pEthRdr=ðrdr;
|
---|
350 | tm.Split("Threads created");
|
---|
351 | if (acpar.fgdoProc>0)
|
---|
352 | cout << "mfacq[4] - starting three threads: EthernetReader, MultiDataSaver, MonitorProc ... " << endl;
|
---|
353 | else
|
---|
354 | cout << "mfacq[4] - starting two threads: EthernetReader, MultiDataSaver ... " << endl;
|
---|
355 |
|
---|
356 | ethrdr.start();
|
---|
357 | DsThr.start();
|
---|
358 | if (acpar.fgdoProc>0) { // On ne demarre que si au moins NMaxProc>0
|
---|
359 | PrThr.start();
|
---|
360 | }
|
---|
361 |
|
---|
362 | // On attend avant de declencher la terminaison des threads
|
---|
363 | usleep(200000);
|
---|
364 |
|
---|
365 | cout << "mfacq[5] - Waiting for threads to finish ... " << endl;
|
---|
366 | ethrdr.join();
|
---|
367 | DsThr.join();
|
---|
368 | mmgr.Stop();
|
---|
369 | if (acpar.fgdoProc) { // On n'attend la fin que si le thread a ete demarre (NMaxProc>0)
|
---|
370 | PrThr.join();
|
---|
371 | }
|
---|
372 | pMmgr=NULL;
|
---|
373 | cout << "mfacq[6] ---------- threads finished ---------------- " << endl;
|
---|
374 | tm.Split("Threads Finished");
|
---|
375 |
|
---|
376 | mmgr.Print(cout);
|
---|
377 |
|
---|
378 | return 0;
|
---|
379 |
|
---|
380 | }
|
---|