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

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

1/ Gestion multi-fibre ds RAcqMemZoneMgr et les DMAReader/DiskWriter (brproc.cc)
2/ Possibilite d'ajout de mot cle ds l'entete FITS par la classe MiniFITSFile

Reza , 18/10/2009

File size: 10.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 NFreqSMap=0; // binning en frequences cartes 2D temps-freq, 0-> NoMap 2D spectres
61static int NGenZ=100;
62static int GPaqSz=16424;
63static double LossRate=0.1;
64
65static bool fg4c=false; // true -> 4 channels (2 fibers)
66static bool fgrdfits=true; // false -> Don't read fits files, generate paquets
67static bool fgnotrl=false; // true -> fichier fits SANS Trailer de frame (< mai 2009)
68static bool fghist=false; // true -> histo des valeurs des time sample
69
70// ----
71int Usage(bool fgshort=true);
72// Pour traitement (calcul FFT et visibilites (ProcA) 1 fibre, 2 voies RAW)
73int Proc1FRawA(string& outname, string& inpath, int jf1, int jf2);
74// Pour traitement (calcul FFT et visibilites (ProcA,ProcB) 2 fibre, 4 voies RAW)
75int Proc2FRawAB(string& outname, string& path1, string& path2, int jf1, int jf2);
76
77//----------------------------------------------------
78//----------------------------------------------------
79int main(int narg, char* arg[])
80{
81 if ((narg>1)&&(strcmp(arg[1],"-h")==0)) return Usage(false);
82 if (narg<5) return Usage(true);
83
84 TArrayInitiator _inia;
85
86 int rc = 0;
87 try {
88 string act = arg[1];
89 fg4c=false; // true -> 4 channels (2 fibers)
90 fgrdfits=true; // false -> Don't read fits files, generate paquets
91 fgnotrl=false; // true -> fichier fits SANS Trailer de frame (< mai 2009)
92 fghist=false; // true -> histo des valeurs des time sample
93 if (act.substr(0,2)=="-4") fg4c=true;
94 if (act.length()>2) {
95 for(size_t ks=2; ks<act.length(); ks++) {
96 if(act[ks]=='g') fgrdfits=false;
97 else if(act[ks]=='n') fgnotrl=true;
98 else if(act[ks]=='h') fghist=true;
99 }
100 }
101 if (fg4c && (narg<6)) return Usage(true);
102
103 string outname = arg[2];
104 string inpath2;
105 string inpath = arg[3];
106 int offa=4;
107 if(fg4c) {
108 inpath2=arg[4]; offa=5;
109 }
110 int imin=0;
111 int imax=0;
112 sscanf(arg[offa],"%d,%d",&imin,&imax);
113 if (narg>offa+1) sscanf(arg[offa+1],"%d,%d",&NZones,&NPaqinZone);
114 if (narg>offa+2) NMean=atoi(arg[offa+2]);
115 if (narg>offa+3) NFreqSMap=atoi(arg[offa+3]);
116 if (narg>offa+4) sscanf(arg[offa+4],"%d,%d,%lg",&GPaqSz,&NGenZ,&LossRate);
117
118 cout << " ---------- mcrd.cc Start - ACT= " << act << " ------------- " << endl;
119 ResourceUsage resu;
120 if (fg4c)
121 rc = Proc2FRawAB(outname, inpath, inpath2, imin, imax);
122 else
123 rc = Proc1FRawA(outname, inpath, imin, imax);
124 cout << resu ;
125 }
126 catch (MiniFITSException& exc) {
127 cerr << " mcrd.cc catched MiniFITSException " << exc.Msg() << endl;
128 rc = 77;
129 }
130 catch (std::exception& sex) {
131 cerr << "\n mcrd.cc std::exception :"
132 << (string)typeid(sex).name() << "\n msg= "
133 << sex.what() << endl;
134 rc = 78;
135 }
136 catch (...) {
137 cerr << " mcrd.cc catched unknown (...) exception " << endl;
138 rc = 79;
139 }
140
141 cout << ">>>> mcrd.cc ------- END ----------- RC=" << rc << endl;
142 return rc;
143
144}
145
146
147
148// Pour traitement (calcul FFT et visibilites (ProcA) 1 fibre, 2 voies RAW)
149int Proc1FRawA(string& outname, string& inpath, int imin, int imax)
150{
151 vector<string> infiles;
152 char nbuff[1024];
153 for(int ii=imin; ii<=imax; ii++) {
154 sprintf(nbuff,"%s/signal%d.fits",inpath.c_str(),ii);
155 infiles.push_back(nbuff);
156 }
157 uint_4 nmaxz;
158 uint_4 paqsz, npaqf;
159 if (fgrdfits) {
160 DecodeMiniFitsHeader(infiles[0],paqsz, npaqf, fgnotrl);
161 nmaxz = infiles.size()*npaqf/NPaqinZone;
162 cout << " mcrd/Proc1FRawA/ReadFits: NZones=" << NZones << " NbPaq=" << NPaqinZone
163 << " NPaq in file=" << npaqf
164 << " PaqSz=" << paqsz << " NMaxZ=" << nmaxz << " NMean=" << NMean << endl;
165 }
166 else {
167 paqsz = GPaqSz;
168 nmaxz = NGenZ;
169 cout << " mcrd/Proc1FRawA/GeneratePaquets: NZones=" << NZones << " NbPaq=" << NPaqinZone
170 << " PaqSz=" << paqsz << " NMean=" << NMean << endl;
171 }
172 RAcqMemZoneMgr mmgr(NZones, 1, NPaqinZone, paqsz, sizeof(complex<r_4>)*paqsz);
173 mmgr.SetFinalizedMask((uint_4)MemZS_ProcA);
174
175 BRFitsReader reader(mmgr, infiles, fgnotrl);
176 TestPCIWrapperNODMA pciw(paqsz,LossRate);
177 PCIEReader pcird(pciw, paqsz, paqsz, mmgr, nmaxz, BR_Copy);
178
179 outname += "/Ch12";
180 BRProcARaw2C proc(mmgr, outname, NMean, nmaxz, fghist, NFreqSMap, fgnotrl);
181
182 cout << " mcrd/Proc1FRawA: Starting threads (reader, proc) ... " << endl;
183
184 if (fgrdfits) reader.start();
185 else pcird.start();
186
187 proc.start();
188 sleep(1);
189 cout << " mcrd/Proc1FRawA: Waiting for reader thread to finish ... " << endl;
190 if (fgrdfits) reader.join();
191 else pcird.join();
192 cout << " mcrd/Proc1FRawA: Reader finished, waiting for process thread to finish ... " << endl;
193 sleep(2);
194 mmgr.Stop();
195 proc.join();
196 mmgr.Print(cout);
197 return 0;
198}
199
200
201// Pour traitement (calcul FFT et visibilites (ProcA) 1 fibre, 2 voies RAW)
202int Proc2FRawAB(string& outname, string& path1, string& path2, int imin, int imax)
203{
204 vector<string> infiles1;
205 vector<string> infiles2;
206 char nbuff[1024];
207 for(int ii=imin; ii<=imax; ii++) {
208 sprintf(nbuff,"%s/signal%d.fits",path1.c_str(),ii);
209 infiles1.push_back(nbuff);
210 sprintf(nbuff,"%s/signal%d.fits",path2.c_str(),ii);
211 infiles2.push_back(nbuff);
212 }
213 uint_4 nmaxz;
214 uint_4 paqsz, npaqf;
215 if (fgrdfits) {
216 DecodeMiniFitsHeader(infiles1[0],paqsz, npaqf, fgnotrl);
217 nmaxz = infiles1.size()*npaqf/NPaqinZone;
218 cout << " mcrd/Proc2FRawAB/ReadFits: NZones=" << NZones << " NbPaq=" << NPaqinZone
219 << " NPaq in file=" << npaqf
220 << " PaqSz=" << paqsz << " NMaxZ=" << nmaxz << " NMean=" << NMean << endl;
221 }
222 else {
223 paqsz = GPaqSz;
224 nmaxz = NGenZ;
225 cout << " mcrd/Proc2FRawAB/GeneratePaquets: NZones=" << NZones << " NbPaq=" << NPaqinZone
226 << " PaqSz=" << paqsz << " NMean=" << NMean << endl;
227 }
228 RAcqMemZoneMgr mmgr1(NZones, 1, NPaqinZone, paqsz, sizeof(complex<r_4>)*paqsz);
229 mmgr1.SetFinalizedMask((uint_4)(MemZS_ProcA)|(uint_4)(MemZS_ProcB));
230// mmgr1.SetFinalizedMask((uint_4)(MemZS_ProcA));
231 RAcqMemZoneMgr mmgr2(NZones, 1, NPaqinZone, paqsz, sizeof(complex<r_4>)*paqsz);
232 mmgr2.SetFinalizedMask((uint_4)(MemZS_ProcA)|(uint_4)(MemZS_ProcB));
233// mmgr2.SetFinalizedMask((uint_4)(MemZS_ProcA));
234
235//-- Lecture des fichiers
236 BRFitsReader reader1(mmgr1, infiles1, fgnotrl);
237 BRFitsReader reader2(mmgr2, infiles2, fgnotrl);
238
239//-- Generation de paquets
240 TestPCIWrapperNODMA pciw1(paqsz,LossRate);
241 PCIEReader pcird1(pciw1, paqsz, paqsz, mmgr1, nmaxz, BR_Copy);
242 TestPCIWrapperNODMA pciw2(paqsz,LossRate);
243 PCIEReader pcird2(pciw2, paqsz, paqsz, mmgr2, nmaxz, BR_Copy);
244
245 string outname1 = outname;
246 outname1 += "/Ch12";
247 BRProcARaw2C proc1(mmgr1, outname1, NMean, nmaxz, fghist, NFreqSMap, fgnotrl);
248 string outname2 = outname;
249 outname2 += "/Ch34";
250 BRProcARaw2C proc2(mmgr2, outname2, NMean, nmaxz, fghist, NFreqSMap, fgnotrl,2);
251 string outname12 = outname;
252 outname12 += "/Ch1234";
253 BRProcBRaw4C proc12(mmgr1, mmgr2, outname12, NMean, nmaxz, fgnotrl);
254
255 cout << " mcrd/Proc2FRawAB: Starting threads (reader1,2, procA1,2, procAB) ... " << endl;
256// cout << "[1]--- CR to continue ..." << endl; char ans[32]; gets(ans);
257 if (fgrdfits) {
258 reader1.start();
259 reader2.start();
260 }
261 else {
262 pcird1.start();
263 pcird2.start();
264 }
265// sleep(1); mmgr1.Print(cout); mmgr2.Print(cout);
266 proc1.start();
267 proc2.start();
268 proc12.start();
269
270 sleep(1);
271 cout << " mcrd/Proc2FRawAB: Waiting for reader threads to finish ... " << endl;
272 if (fgrdfits) {
273 reader1.join();
274 reader2.join();
275 }
276 else {
277 pcird1.join();
278 pcird2.join();
279 }
280 cout << " mcrd/Proc2FRawAB: Readers finished, waiting for process thread to finish ... " << endl;
281 sleep(2);
282 mmgr1.Stop();
283 mmgr2.Stop();
284 proc1.join();
285 proc2.join();
286 proc12.join();
287 mmgr1.Print(cout);
288 mmgr2.Print(cout);
289 return 0;
290}
291
292
293/* --Fonction-- */
294int Usage(bool fgshort)
295{
296 cout << " --- mcrd.cc : Reading/Processing BAORadio FITS files" << endl;
297 cout << " Usage: mcrd ACT OutPath InPath [InPath2] Imin,Imax\n"
298 << " [NZones,NPaqinZone] [NMean] [NFreqSMap]\n"
299 << " [GPaqSz,NGenZones,LossRate]" << endl;
300 if (fgshort) {
301 cout << " mcrd -h for detailed instructions" << endl;
302 return 1;
303 }
304 cout << " ACT= -2[ghn] -> 1 fiber, 2 raw channel processing (ProcA)\n"
305 << " ACT= -4[ghn] -> 2 fibers, 4 raw channels (ProcA, ProcB)\n"
306 << " n (notrl) -> FITS files without frame trailer \n"
307 << " g (generate paquets) -> generate paquets instead of reading fits files\n"
308 << " h (time sample histograms) -> compute time sample histograms also \n"
309 << " Example: ACT = -2h 1 fiber, 2 raw channels and compute time sample histograms" <<endl;
310 cout << " OutPath : Output directory name " << endl;
311 cout << " InPath [InPath2] Imin,Imax: Input fits files directory name(s)\n"
312 << " (Inpath=Fiber1, InPath2=Fiber2) and sequence numbers \n"
313 << " FileNames=InPath/signalII.fits Imin<=II<=Imax \n"
314 << " NZones,NbPaqinZone : Number of Zones and number of paquets in one zone\n"
315 << " of the RAcqMemZoneMgr memory manager (default = 4,128)\n"
316 << " NMean: Number of packet used for spectra/visibility computation (def=1024)\n"
317 << " NFreqSMap: Frequency binning for 2D (time-freq) spectra maps (def=0->No maps)\n"
318 << " GPaqSz,NGenZones,LossRate: Paquet Size, Number of memory zones filled and\n"
319 << " loss rate (-2g,-4g) , default=16424,100,0.1" << endl;
320 return 1;
321}
Note: See TracBrowser for help on using the repository browser.