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

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

PCIEWrapper renomme en PCIEWrapperInterface , Reza 21/05/2009

File size: 10.4 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) {
[3627]59 cout << "\n Usage: tmtacq CardNum PaquetSize NFrameDMA NFiles NBlocPerFile NMaxProc DataDirPath [AcqMode] [MemZoneMgr][HardCtlC]" << endl;
[3623]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;
[3627]92 cout << " - MemZoneMgr: nZones,NPaq =Number of Zones and number of paquet in each zone (Default=8,128) " << endl;
[3623]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
[3627]155 uint_4 nZones = 8; // Nombre de zones memoires
[3623]156 uint_4 nPaqZone = 128; // 128 Paquets / zone memoire - valeur par defaut
[3627]157 if (narg > 9) {
158 int ia1, ia2;
159 sscanf(arg[9],"%d,%d", &ia1, &ia2);
160 nZones = ia1; nPaqZone = ia2;
161 }
162
163 bool fg_hard_ctrlc = false;
164 if (narg > 10) // pour traiter eventuellement un arret brutal par CtlC mettre le 10eme arg a Y
165 if ((*arg[10]=='y')||(*arg[10]=='Y')) fg_hard_ctrlc=true;
166 if (!fg_hard_ctrlc) {
[3623]167 act.sa_handler=Stop;
168 sigaction(SIGINT,&act,NULL);
169 }
[3627]170
[3623]171 uint_4 PaqSZ =sizeFrame; // Taille de paquets
172 // uint_4 dmaSize = nbFrameDMA*PaqSZ ; // plantage
173 uint_4 dmaSize = nbFrameDMA*1024 ;
174 uint_4 patternSZ=0x400; // pas utilise avec la fibre
175 uint_4 NMaxBloc = NbFiles*NBlocPerFile;
176 cout << "tmtacq[0] - PaqSize = " << PaqSZ << " NbPaq/Zone=" << nPaqZone << " NZones=" << nZones << endl;
177 cout << " NbFiles=" << NbFiles << " NBloc/File=" << NBlocPerFile << " -> NMaxBloc=" << NMaxBloc << endl;
178 cout << "tmtacq[1] NbFrameDMA=" << nbFrameDMA << " DMASize=" << dmaSize << " bytes" << endl;
179 cout << "tmtacq[1] NMaxProc=" << NMaxProc << endl;
[3537]180 try {
[3623]181
182#ifdef NOPCIECARD
183 TestPCIWrapperNODMA pciw(PaqSZ);
184#else
185 DMAMgr dma1(card,patternSZ,dmaSize );
186 if (! dma1.StatusFibre() ) {
187 cout << " tmtacq[0] - fibre non accrochee -> exit " << endl;
188 throw PCIEWException(" Fibre non accrochee ");
189 }
190 else cout << " tmtacq[0] - fibre accrochee OK " << endl;
[3628]191 PCIEWrapper pciw(dma1);
[3623]192#endif
193 RAcqMemZoneMgr mmgr(nZones, nPaqZone, PaqSZ);
194 pMmgr =&mmgr;
195
196 if (monothr) {
197 cout << "tmtacq[1] single thread PCIE test PCIEReaderChecker ... ";
198 PCIEReaderChecker pcirc(pciw,dmaSize,PaqSZ ,mmgr, NMaxBloc, swapall);
199 pPcierc=&pcirc;
200 pcirc.start();
201 sleep(1);
202 pcirc.join();
203 cout << "tmtacq[2] - single thread PCIEReaderChecker finished " << endl;
204 tm.Split("Single Thread Finished");
205 mmgr.Print(cout);
206 return 0;
207 }
208 PCIEReader pcir(pciw,dmaSize,PaqSZ ,mmgr, NMaxBloc, swapall);
209 pPcier= &pcir;
210 DataSaver ds(mmgr, dir, NbFiles, NBlocPerFile, savesigfits);
211 pDs= &ds;
212 //DataBinSaver ds(mmgr, dir, NbFiles ,NBlocPerFile);
213 // DataProc1C pr(mmgr, dir, nmean, stepproc, 100); Pour processer un canal
214 int stepproc = 2;
215 int nmean = nPaqZone*NBlocPerFile/stepproc;
216 DataProc2C pr(mmgr, dir, nmean, stepproc, NMaxProc);
217 DataProcFFT2C prfft(mmgr, dir, nmean, stepproc, NMaxProc);
[3537]218 tm.Split("Threads created");
219 cout << "tmtacq[2] - starting 3 threads pcir, ds, pr ... " << endl;
[3623]220 /*
221 char test[100];
222 cout << " <CR> to continue, x to exit ..." << endl;
223 gets(test); if (test[0] == 'x') return 9;
224 */
[3537]225 pcir.start();
226 ds.start();
[3623]227 if (NMaxProc>0) { // On ne demarre que si au moins NMaxProc>0
228 if (acqmode.substr(0,5)=="fft2c") { prfft.start(); pPrfft=&prfft;}
229 else { pr.start(); pPr=&pr;}
230 }
[3537]231 cout << "tmtacq[3] - waiting for threads to finish ... " << endl;
232 sleep(1);
233 pcir.join();
234 ds.join();
235 sleep(1);
236 mmgr.Stop();
[3623]237 if (NMaxProc>0) if ( pPr != NULL) pr.join();
238 if (NMaxProc>0) if ( pPrfft != NULL) prfft.join();
[3537]239 cout << "tmtacq[4] - threads finished " << endl;
240 tm.Split("Threads Finished");
241 mmgr.Print(cout);
242 rc = 0;
243 }
244 catch (MiniFITSException& exc) {
245 cerr << " tmtacq.cc catched MiniFITSException " << exc.Msg() << endl;
246 rc = 77;
[3623]247 }
248 catch (PCIEWException& exc) {
249 cerr << "\7 tmtacq.cc catched MiniFITSException " << exc.Msg() << endl;
250 rc = 75;
[3537]251 }
252 catch (PThrowable& exc) {
253 cerr << " tmtacq.cc catched Exception " << exc.Msg() << endl;
254 rc = 76;
255 }
256 catch (std::exception& sex) {
257 cerr << "\n tmtacq.cc std::exception :"
258 << (string)typeid(sex).name() << "\n msg= "
259 << sex.what() << endl;
260 rc = 78;
261 }
262 catch (...) {
[3623]263 cerr << " tmtacq.cc : Catched ... exception " << endl;
[3537]264 rc = 79;
265 }
266 cout << "tmtacq[9] - stopping acq program " << endl;
267 return rc;
268}
[3623]269
Note: See TracBrowser for help on using the repository browser.