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

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

Ajout calcul histogramme des valeurs echantillons en temps, Reza 15/06/2009

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