source: Sophya/trunk/AddOn/TAcq/mcrd.cc@ 3645

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

Traitement 4 canaux ds brproc.cc, mcrd.cc , mais il reste des problemes - Reza 01/06/2009

File size: 9.7 KB
Line 
1// Utilisation de SOPHYA pour faciliter les tests ...
2#include "sopnamsp.h"
3#include "machdefs.h"
4
5/* ----------------------------------------------------------
6 Programme de lecture multi canaux pour BAORadio
7 R. Ansari, C. Magneville
8 V : Mai 2009
9 ---------------------------------------------------------- */
10
11// include standard c/c++
12#include <math.h>
13#include <stdio.h>
14#include <stdlib.h>
15#include <string.h>
16
17#include <iostream>
18#include <string>
19
20#include "pexceptions.h"
21#include "tvector.h"
22#include "fioarr.h"
23#include "tarrinit.h"
24#include "timestamp.h"
25#include "fftpserver.h"
26#include "fftwserver.h"
27
28#include "FFTW/fftw3.h"
29
30// include sophya mesure ressource CPU/memoire ...
31#include "resusage.h"
32#include "ctimer.h"
33#include "timing.h"
34
35
36// include mini-fits lib , et structure paquet BAORadio
37#include "minifits.h"
38#include "brpaqu.h"
39#include "brfitsrd.h"
40#include "brproc.h"
41#include "racqurw.h"
42
43
44//--- Fonctions de ce fichier
45int DecodeMiniFitsHeader(string& filename, uint_4& paqsz, uint_4& npaq, bool fgnotrl=false)
46{
47 MiniFITSFile mff(filename, MF_Read);
48 cout << "DecodeMiniFitsHeader()... Type=" << mff.DataTypeToString() << " NAxis1=" << mff.NAxis1()
49 << " NAxis2=" << mff.NAxis2() << endl;
50 paqsz = mff.NAxis1();
51 npaq = mff.NAxis2();
52 if (fgnotrl) paqsz += 16;
53 return 0;
54}
55
56//-- Parametres globaux
57static int NZones=4;
58static int NPaqinZone=128;
59static int NMean=1024;
60static int NGenZ=100;
61static int GPaqSz=16424;
62static double LossRate=0.1;
63// ----
64int Usage(bool fgshort=true);
65// Pour traitement (calcul FFT et visibilites (ProcA) 1 fibre, 2 voies RAW)
66int Proc1FRawA(string& outname, string& inpath, int jf1, int jf2, bool fgnotrl=false,
67 bool fgrdfile=true);
68// Pour traitement (calcul FFT et visibilites (ProcA,ProcB) 2 fibre, 4 voies RAW)
69int Proc2FRawAB(string& outname, string& path1, string& path2, int jf1, int jf2,
70 bool fgnotrl=false, bool fgrdfile=true);
71
72//----------------------------------------------------
73//----------------------------------------------------
74int main(int narg, char* arg[])
75{
76 if ((narg>1)&&(strcmp(arg[1],"-h")==0)) return Usage(false);
77 if (narg<5) return Usage(true);
78
79 TArrayInitiator _inia;
80
81 int rc = 0;
82 try {
83 string act = arg[1];
84 bool fg4c=false; // true -> 4 channels (2 fibers)
85 bool fgrdfits=false; // false -> Don't read fits files, generate paquets
86 bool fgnotrl=false; // true -> fichier fits SANS Trailer de frame (< mai 2009)
87 if (act.substr(0,2)=="-4") fg4c=true;
88 if (act.substr(2)=="g") fgrdfits=false;
89 else if (act.substr(2)=="nt") fgnotrl=true;
90 if (fg4c && (narg<6)) return Usage(true);
91
92 string outname = arg[2];
93 string inpath2;
94 string inpath = arg[3];
95 int offa=4;
96 if(fg4c) {
97 inpath2=arg[4]; offa=5;
98 }
99 int imin=0;
100 int imax=0;
101 sscanf(arg[offa],"%d,%d",&imin,&imax);
102 if (narg>offa+1) sscanf(arg[offa+1],"%d,%d",&NZones,&NPaqinZone);
103 if (narg>offa+2) NMean=atoi(arg[offa+2]);
104 if (narg>offa+3) sscanf(arg[offa+3],"%d,%d,%lg",&GPaqSz,&NGenZ,&LossRate);
105
106 cout << " ---------- mcrd.cc Start - ACT= " << act << " ------------- " << endl;
107 ResourceUsage resu;
108 if (fg4c)
109 rc = Proc2FRawAB(outname, inpath, inpath2, imin, imax, fgnotrl, fgrdfits);
110 else
111 rc = Proc1FRawA(outname, inpath, imin, imax, fgnotrl, fgrdfits);
112 cout << resu ;
113 }
114 catch (MiniFITSException& exc) {
115 cerr << " mcrd.cc catched MiniFITSException " << exc.Msg() << endl;
116 rc = 77;
117 }
118 catch (std::exception& sex) {
119 cerr << "\n mcrd.cc std::exception :"
120 << (string)typeid(sex).name() << "\n msg= "
121 << sex.what() << endl;
122 rc = 78;
123 }
124 catch (...) {
125 cerr << " mcrd.cc catched unknown (...) exception " << endl;
126 rc = 79;
127 }
128
129 cout << ">>>> mcrd.cc ------- END ----------- RC=" << rc << endl;
130 return rc;
131
132}
133
134
135
136// Pour traitement (calcul FFT et visibilites (ProcA) 1 fibre, 2 voies RAW)
137int Proc1FRawA(string& outname, string& inpath, int imin, int imax,
138 bool fgnotrl, bool fgrdfile)
139{
140 vector<string> infiles;
141 char nbuff[1024];
142 for(int ii=imin; ii<=imax; ii++) {
143 sprintf(nbuff,"%s/signal%d.fits",inpath.c_str(),ii);
144 infiles.push_back(nbuff);
145 }
146 uint_4 nmaxz;
147 uint_4 paqsz, npaqf;
148 if (fgrdfile) {
149 DecodeMiniFitsHeader(infiles[0],paqsz, npaqf, fgnotrl);
150 nmaxz = infiles.size()*npaqf/NPaqinZone;
151 cout << " mcrd/Proc1FRawA/ReadFits: NZones=" << NZones << " NbPaq=" << NPaqinZone
152 << " NPaq in file=" << npaqf
153 << " PaqSz=" << paqsz << " NMaxZ=" << nmaxz << " NMean=" << NMean << endl;
154 }
155 else {
156 paqsz = GPaqSz;
157 nmaxz = NGenZ;
158 cout << " mcrd/Proc1FRawA/GeneratePaquets: NZones=" << NZones << " NbPaq=" << NPaqinZone
159 << " PaqSz=" << paqsz << " NMean=" << NMean << endl;
160 }
161 RAcqMemZoneMgr mmgr(NZones, NPaqinZone, paqsz, sizeof(complex<r_4>)*paqsz);
162 mmgr.SetFinalizedMask((uint_4)MemZS_ProcA);
163
164 BRFitsReader reader(mmgr, infiles, fgnotrl);
165 TestPCIWrapperNODMA pciw(paqsz,LossRate);
166 PCIEReader pcird(pciw, paqsz, paqsz, mmgr, nmaxz, BR_Copy);
167
168 outname += "/Ch12";
169 BRProcARaw2C proc(mmgr, outname, NMean, nmaxz, fgnotrl);
170
171 cout << " mcrd/Proc1FRawA: Starting threads (reader, proc) ... " << endl;
172
173 if (fgrdfile) reader.start();
174 else pcird.start();
175
176 proc.start();
177 sleep(1);
178 cout << " mcrd/Proc1FRawA: Waiting for reader thread to finish ... " << endl;
179 if (fgrdfile) reader.join();
180 else pcird.join();
181 cout << " mcrd/Proc1FRawA: Reader finished, waiting for process thread to finish ... " << endl;
182 sleep(2);
183 mmgr.Stop();
184 proc.join();
185 mmgr.Print(cout);
186 return 0;
187}
188
189
190// Pour traitement (calcul FFT et visibilites (ProcA) 1 fibre, 2 voies RAW)
191int Proc2FRawAB(string& outname, string& path1, string& path2, int imin, int imax,
192 bool fgnotrl, bool fgrdfile)
193{
194 vector<string> infiles1;
195 vector<string> infiles2;
196 char nbuff[1024];
197 for(int ii=imin; ii<=imax; ii++) {
198 sprintf(nbuff,"%s/signal%d.fits",path1.c_str(),ii);
199 infiles1.push_back(nbuff);
200 sprintf(nbuff,"%s/signal%d.fits",path2.c_str(),ii);
201 infiles2.push_back(nbuff);
202 }
203 uint_4 nmaxz;
204 uint_4 paqsz, npaqf;
205 if (fgrdfile) {
206 DecodeMiniFitsHeader(infiles1[0],paqsz, npaqf, fgnotrl);
207 nmaxz = infiles1.size()*npaqf/NPaqinZone;
208 cout << " mcrd/Proc2FRawAB/ReadFits: NZones=" << NZones << " NbPaq=" << NPaqinZone
209 << " NPaq in file=" << npaqf
210 << " PaqSz=" << paqsz << " NMaxZ=" << nmaxz << " NMean=" << NMean << endl;
211 }
212 else {
213 paqsz = GPaqSz;
214 nmaxz = NGenZ;
215 cout << " mcrd/Proc2FRawAB/GeneratePaquets: NZones=" << NZones << " NbPaq=" << NPaqinZone
216 << " PaqSz=" << paqsz << " NMean=" << NMean << endl;
217 }
218 RAcqMemZoneMgr mmgr1(NZones, NPaqinZone, paqsz, sizeof(complex<r_4>)*paqsz);
219 mmgr1.SetFinalizedMask((uint_4)(MemZS_ProcA)|(uint_4)(MemZS_ProcB));
220// mmgr1.SetFinalizedMask((uint_4)(MemZS_ProcA));
221 RAcqMemZoneMgr mmgr2(NZones, NPaqinZone, paqsz, sizeof(complex<r_4>)*paqsz);
222 mmgr2.SetFinalizedMask((uint_4)(MemZS_ProcA)|(uint_4)(MemZS_ProcB));
223// mmgr2.SetFinalizedMask((uint_4)(MemZS_ProcA));
224
225 BRFitsReader reader1(mmgr1, infiles1, fgnotrl);
226 BRFitsReader reader2(mmgr1, infiles2, fgnotrl);
227
228 TestPCIWrapperNODMA pciw1(paqsz,LossRate);
229 PCIEReader pcird1(pciw1, paqsz, paqsz, mmgr1, nmaxz, BR_Copy);
230 TestPCIWrapperNODMA pciw2(paqsz,LossRate);
231 PCIEReader pcird2(pciw2, paqsz, paqsz, mmgr2, nmaxz, BR_Copy);
232
233 string outname1 = outname;
234 outname1 += "/Ch12";
235 BRProcARaw2C proc1(mmgr1, outname1, NMean, nmaxz, fgnotrl);
236 string outname2 = outname;
237 outname2 += "/Ch34";
238 BRProcARaw2C proc2(mmgr2, outname2, NMean, nmaxz, fgnotrl,2);
239 string outname12 = outname;
240 outname12 += "/Ch1234";
241 BRProcBRaw4C proc12(mmgr1, mmgr2, outname12, NMean, nmaxz, fgnotrl);
242
243 cout << " mcrd/Proc2FRawAB: Starting threads (reader1,2, procA1,2, procAB) ... " << endl;
244
245 if (fgrdfile) {
246 reader1.start();
247 reader2.start();
248 }
249 else {
250 pcird1.start();
251 pcird2.start();
252 }
253 proc1.start();
254 proc2.start();
255 proc12.start();
256
257 sleep(1);
258 cout << " mcrd/Proc2FRawAB: Waiting for reader threads to finish ... " << endl;
259 if (fgrdfile) {
260 reader1.join();
261 reader2.join();
262 }
263 else {
264 pcird1.join();
265 pcird2.join();
266 }
267 cout << " mcrd/Proc2FRawAB: Readers finished, waiting for process thread to finish ... " << endl;
268 sleep(2);
269 mmgr1.Stop();
270 mmgr2.Stop();
271 proc1.join();
272 proc2.join();
273 proc12.join();
274 mmgr1.Print(cout);
275 mmgr2.Print(cout);
276 return 0;
277}
278
279
280/* --Fonction-- */
281int Usage(bool fgshort)
282{
283 cout << " --- mcrd.cc : Reading/Processing BAORadio FITS files" << endl;
284 cout << " Usage: mcrd ACT OutPath InPath [InPath2] Imin,Imax\n"
285 << " [NZones,NPaqinZone] [NMean] [GPaqSz,NGenZones,LossRate]" << endl;
286 if (fgshort) {
287 cout << " mcrd -h for detailed instructions" << endl;
288 return 1;
289 }
290 cout << " ACT= -2 , -2g , -2nt -> 1 fiber, 2 raw channel processing (ProcA)\n"
291 << " ACT= -4 , -4g , -4g , -4nt -> 2 fibers, 4 raw channels (ProcA, ProcB)\n"
292 << " nt (notrl) -> FITS files without frame trailer \n"
293 << " g (generate paquets) -> generate paquets instead of reading fits files" <<endl;
294 cout << " OutPath : Output directory name " << endl;
295 cout << " InPath [InPath2] Imin,Imax: Input fits files directory name(s)\n"
296 << " (Inpath=Fiber1, InPath2=Fiber2) and sequence numbers \n"
297 << " FileNames=InPath/signalII.fits Imin<=II<=Imax \n"
298 << " NZones,NbPaqinZone : Number of Zones and number of paquets in one zone\n"
299 << " of the RAcqMemZoneMgr memory manager (default = 4,128)\n"
300 << " NMean: Number of packet used for spectra/visibility computation (def=1024)\n"
301 << " GPaqSz,NGenZones,LossRate: Paquet Size, Number of memory zones filled and\n"
302 << " loss rate (-2g,-4g) , default=16424,100,0.1" << endl;
303 return 1;
304}
Note: See TracBrowser for help on using the repository browser.