source: Sophya/trunk/AddOn/TAcq/tmtacq.cc@ 3626

Last change on this file since 3626 was 3623, checked in by ansari, 16 years ago

Modifications et ameliorations diverses pour programme acquisition/traitement multifibres

Reza 22/05/2009

1- Extension/amelioration classe BRPaquet et BRPaqChecker
2- Correction BUG dans RAcqMemZoneMgr bloquant l'utilisation a une seule zone memoire
3- Classe PCIEWrapper devenue virtuelle pure et introduction de la classe TestPCIWrapperNODMA
pour les smulations.

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