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

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

Mise a jour et ajout de fichier pour taritement multifibres apres

prise de donnees de Nov2009 a Pittsburgh

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