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
|
---|
45 | int 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
|
---|
57 | static int NZones=4;
|
---|
58 | static int NPaqinZone=128;
|
---|
59 | static int NMean=1024;
|
---|
60 | static int NGenZ=100;
|
---|
61 | static int GPaqSz=16424;
|
---|
62 | static double LossRate=0.1;
|
---|
63 | // ----
|
---|
64 | int Usage(bool fgshort=true);
|
---|
65 | // Pour traitement (calcul FFT et visibilites (ProcA) 1 fibre, 2 voies RAW)
|
---|
66 | int 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)
|
---|
69 | int Proc2FRawAB(string& outname, string& path1, string& path2, int jf1, int jf2,
|
---|
70 | bool fgnotrl=false, bool fgrdfile=true);
|
---|
71 |
|
---|
72 | //----------------------------------------------------
|
---|
73 | //----------------------------------------------------
|
---|
74 | int 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=true; // 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)
|
---|
137 | int 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)
|
---|
191 | int 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 | // cout << "[1]--- CR to continue ..." << endl; char ans[32]; gets(ans);
|
---|
245 | if (fgrdfile) {
|
---|
246 | reader1.start();
|
---|
247 | reader2.start();
|
---|
248 | }
|
---|
249 | else {
|
---|
250 | pcird1.start();
|
---|
251 | pcird2.start();
|
---|
252 | }
|
---|
253 | // sleep(1); mmgr1.Print(cout); mmgr2.Print(cout);
|
---|
254 | proc1.start();
|
---|
255 | proc2.start();
|
---|
256 | proc12.start();
|
---|
257 |
|
---|
258 | sleep(1);
|
---|
259 | cout << " mcrd/Proc2FRawAB: Waiting for reader threads to finish ... " << endl;
|
---|
260 | if (fgrdfile) {
|
---|
261 | reader1.join();
|
---|
262 | reader2.join();
|
---|
263 | }
|
---|
264 | else {
|
---|
265 | pcird1.join();
|
---|
266 | pcird2.join();
|
---|
267 | }
|
---|
268 | cout << " mcrd/Proc2FRawAB: Readers finished, waiting for process thread to finish ... " << endl;
|
---|
269 | sleep(2);
|
---|
270 | mmgr1.Stop();
|
---|
271 | mmgr2.Stop();
|
---|
272 | proc1.join();
|
---|
273 | proc2.join();
|
---|
274 | proc12.join();
|
---|
275 | mmgr1.Print(cout);
|
---|
276 | mmgr2.Print(cout);
|
---|
277 | return 0;
|
---|
278 | }
|
---|
279 |
|
---|
280 |
|
---|
281 | /* --Fonction-- */
|
---|
282 | int Usage(bool fgshort)
|
---|
283 | {
|
---|
284 | cout << " --- mcrd.cc : Reading/Processing BAORadio FITS files" << endl;
|
---|
285 | cout << " Usage: mcrd ACT OutPath InPath [InPath2] Imin,Imax\n"
|
---|
286 | << " [NZones,NPaqinZone] [NMean] [GPaqSz,NGenZones,LossRate]" << endl;
|
---|
287 | if (fgshort) {
|
---|
288 | cout << " mcrd -h for detailed instructions" << endl;
|
---|
289 | return 1;
|
---|
290 | }
|
---|
291 | cout << " ACT= -2 , -2g , -2nt -> 1 fiber, 2 raw channel processing (ProcA)\n"
|
---|
292 | << " ACT= -4 , -4g , -4g , -4nt -> 2 fibers, 4 raw channels (ProcA, ProcB)\n"
|
---|
293 | << " nt (notrl) -> FITS files without frame trailer \n"
|
---|
294 | << " g (generate paquets) -> generate paquets instead of reading fits files" <<endl;
|
---|
295 | cout << " OutPath : Output directory name " << endl;
|
---|
296 | cout << " InPath [InPath2] Imin,Imax: Input fits files directory name(s)\n"
|
---|
297 | << " (Inpath=Fiber1, InPath2=Fiber2) and sequence numbers \n"
|
---|
298 | << " FileNames=InPath/signalII.fits Imin<=II<=Imax \n"
|
---|
299 | << " NZones,NbPaqinZone : Number of Zones and number of paquets in one zone\n"
|
---|
300 | << " of the RAcqMemZoneMgr memory manager (default = 4,128)\n"
|
---|
301 | << " NMean: Number of packet used for spectra/visibility computation (def=1024)\n"
|
---|
302 | << " GPaqSz,NGenZones,LossRate: Paquet Size, Number of memory zones filled and\n"
|
---|
303 | << " loss rate (-2g,-4g) , default=16424,100,0.1" << endl;
|
---|
304 | return 1;
|
---|
305 | }
|
---|