source: Sophya/trunk/ArchTOIPipe/TestPipes/simtst.cc@ 1500

Last change on this file since 1500 was 1500, checked in by ansari, 24 years ago

Rajout d'options ds simtst.cc - Reza 18/5/2001

File size: 13.6 KB
Line 
1/* Test de processeurs ds simtoipr.cc - Reza Avril 2001
2
3---------------- Exemple d'appel ---------------------
4csh> simtst -start 104385384 -end 104399964 -range -500,500 \
5 -intoi boloMuV_26 -wtoi 8192 -wdegli 1024 \
6 inputbolo.fits filt.fits xx.ppf
7# Avec Filtre de Fourier
8csh> simtst -start 104385384 -end 104399964 -range -500,500 \
9 -intoi boloMuV_26 -wtoi 8192 -wdegli 1024 \
10 -wfft 4096 -keepfft 5 -killfreq 15,4,2.5 \
11 inputbolo.fits filtfft.fits spectre.ppf
12# Autre exemple b545k02
13cool> ./simtst -start 104389122 -end 104649122 -range -1000.,1000. -intoi boloMu
14V_23 -wtoi 8192 -wdegli 1024 -wfft 4096 -keepfft 5 -killfreq 15,4,2.5 Cmv/b545k02
152_16.00_16.49.fits b545.fits b545.ppf
16
17*/
18
19
20
21#include "machdefs.h"
22#include <math.h>
23#include "array.h"
24#include <unistd.h>
25#include <stdexcept>
26#include "toi.h"
27#include "toiprocessor.h"
28#include "fitstoirdr.h"
29#include "fitstoiwtr.h"
30#include "toisqfilter.h"
31#include "toimanager.h"
32#include "simtoipr.h"
33#include "nooppr.h"
34#include "toiseqbuff.h"
35#include "timing.h"
36#include "sambainit.h"
37
38void Usage(bool fgerr)
39{
40 cout << endl;
41 if (fgerr) {
42 cout << " simtst : Argument Error ! simtst -h for usage " << endl;
43 exit(1);
44 }
45 else {
46 cout << "\n Usage : simtst [-intoi toiname] [-start snb] [-end sne] \n"
47 << " [-dbg] [-wtoi sz] [-wdegli sz] [-range min,max] \n"
48 << " [-degli ns,ns2,mxpt,mnpt,wrec] [-gfilt wsz,sigma] \n"
49 << " [-wfft sz] [-keepfft n] [-killfreq bf,nharm,sigf] \n"
50 << " [-nooutflg] [-nowrtms] [-nowrticd] \n"
51 << " inFitsName outFitsName outPPFName \n"
52 << " -dbg : sets TOISeqBuffered debug level to 1 \n"
53 << " -start snb : sets the start sample num \n"
54 << " -end sne : sets the end sample num \n"
55 << " -range min,max : sets the acceptable range for intoi \n"
56 << " default= -16000,16000\n"
57 << " -intoi toiName : select input TOI name (def boloMuV_27)\n"
58 << " -wtoi sz : sets TOISeqBuff buffer size (def= 8192)\n"
59 << " -wdegli sz : sets deglitcher window size (def= 512) \n"
60 << " -degli ns,ns2,maxnpt,minnpt,wrec : sets deglitcher parameters\n"
61 << " -gfilt wsz,sigma : Gaussian filter window size and sigma\n"
62 << " -wfft sz : Activate Fourier filter and sets its width \n"
63 << " -keepfft n : Keeps n spectra (if Fourier filter activated) \n"
64 << " -killfreq bf,nharm,sigf : kills nharm frequency, basefreq=bf \n"
65 << " with a gaussian with width=sigf \n"
66 << " -nooutflg : Don't write flags to output FITS \n"
67 << " -nowrtms : Don't write mean/sigma TOI's \n"
68 << " -nowrticd : Don't write incopie,degli,deglioffset TOI's \n"
69 << endl;
70 }
71}
72
73int main(int narg, char** arg) {
74
75 if ((narg > 1) && (strcmp(arg[1],"-h") == 0) ) Usage(false);
76
77 cout << "simtst starting - Decoding arguments " << " narg=" << narg << endl;
78
79 bool fgdbg = false;
80 bool fgsetstart = false;
81 int wtoi = 8192;
82 int wdegli = 512;
83
84 int wfft = 4096;
85 int keepfft = 0;
86 int nmax = 10;
87 int istart = 0;
88 int iend = 0;
89 double range_min = -16000;
90 double range_max = 16000.;
91
92 // Deglitcher parameters
93 double degli_ns1 = 3.;
94 double degli_ns2 = 1.5;
95 int degli_minnpt = 2;
96 int degli_maxnpt = 4;
97 int degli_wrec = 10;
98
99 // Gaussian filter parameters
100 int gfilt_wsz = 16;
101 double gfilt_sigma = 2.;
102
103 // File names
104 string infile;
105 string outfile;
106 string outppfname;
107 string intoi = "boloMuV_27";
108
109 bool fg_wrtflag = true;
110 bool fg_nowrtms = false;
111 bool fg_nowrticd = false;
112
113
114 bool fg_f_filt = false;
115 bool fg_killfreq = false;
116 int bf_killfreq = 1;
117 int nharm_killfreq = 1;
118 double sigf_killfreq = 1.;
119
120 if (narg < 4) Usage(true);
121 int ko=1;
122 // decoding arguments
123 for(int ia=1; ia<narg; ia++) {
124 if (strcmp(arg[ia],"-start") == 0) {
125 if (ia == narg-1) Usage(true); // -start est suivi d'un argument
126 istart = atoi(arg[ia+1]); ia++;
127 fgsetstart = true;
128 }
129 else if (strcmp(arg[ia],"-end") == 0) {
130 if (ia == narg-1) Usage(true);
131 iend = atoi(arg[ia+1]); ia++;
132 }
133 else if (strcmp(arg[ia],"-wtoi") == 0) {
134 if (ia == narg-1) Usage(true);
135 wtoi = atoi(arg[ia+1]); ia++;
136 }
137 else if (strcmp(arg[ia],"-wdegli") == 0) {
138 if (ia == narg-1) Usage(true);
139 wdegli = atoi(arg[ia+1]); ia++;
140 }
141 else if (strcmp(arg[ia],"-degli") == 0) {
142 if (ia == narg-1) Usage(true);
143 sscanf(arg[ia+1],"%lf,%lf,%d,%d,%d", &degli_ns1, &degli_ns2,
144 &degli_maxnpt, &degli_minnpt, &degli_wrec);
145 ia++;
146 }
147 else if (strcmp(arg[ia],"-gfilt") == 0) {
148 if (ia == narg-1) Usage(true);
149 sscanf(arg[ia+1],"%d,%lf", &gfilt_wsz, &gfilt_sigma);
150 ia++;
151 }
152 else if (strcmp(arg[ia],"-wfft") == 0) {
153 if (ia == narg-1) Usage(true);
154 wfft = atoi(arg[ia+1]); ia++;
155 fg_f_filt = true;
156 }
157 else if (strcmp(arg[ia],"-keepfft") == 0) {
158 if (ia == narg-1) Usage(true);
159 keepfft = atoi(arg[ia+1]); ia++;
160 }
161 else if (strcmp(arg[ia],"-killfreq") == 0) {
162 if (ia == narg-1) Usage(true);
163 sscanf(arg[ia+1],"%d,%d,%lf",&bf_killfreq, &nharm_killfreq, &sigf_killfreq);
164 fg_killfreq = true;
165 ia++;
166 }
167 else if (strcmp(arg[ia],"-range") == 0) {
168 if (ia == narg-1) Usage(true);
169 sscanf(arg[ia+1],"%lf,%lf",&range_min, &range_max);
170 ia++;
171 }
172 else if (strcmp(arg[ia],"-intoi") == 0) {
173 if (ia == narg-1) Usage(true);
174 intoi = arg[ia+1]; ia++;
175 }
176 else if (strcmp(arg[ia],"-dbg") == 0) fgdbg = true;
177 else if (strcmp(arg[ia],"-nooutflg") == 0) fg_wrtflag = false;
178 else if (strcmp(arg[ia],"-nowrtms") == 0) fg_nowrtms = true;
179 else if (strcmp(arg[ia],"-nowrticd") == 0) fg_nowrticd = true;
180
181 else { ko = ia; break; } // Debut des noms
182 }
183
184 if (iend < istart) iend = istart+wtoi*(nmax+5);
185 if ((narg-ko) < 3) Usage(true);
186 infile = arg[ko];
187 outfile = arg[ko+1];
188 outppfname = arg[ko+2];
189
190 cout << " Initializing SOPHYA ... " << endl;
191 SophyaInit();
192 InitTim();
193
194 cout << ">>>> simtst: Infile= " << infile << " outFile="
195 << outfile << endl;
196 cout << ">>>> Window Size WTOI= " << wtoi << " WDEGLI= " << wdegli
197 << " iStart= " << istart << " iEnd= " << iend << endl;
198 cout << ">>>> InTOIName= " << intoi << endl;
199
200 try {
201 TOIManager* mgr = TOIManager::getManager();
202
203 // mgr->setRequestedSample(11680920,11710584);
204 // mgr->setRequestedSample(104121000, 104946120);
205 if (fgsetstart)
206 mgr->setRequestedSample(istart, iend);
207
208 // FITSTOIReader r("/data/Archeops/bolo11.fits);
209 FITSTOIReader r(infile);
210 cout << "reader created" << endl;
211 // FITSTOIWriter w("/data/Archeops/rz.fits");
212 FITSTOIWriter w(outfile);
213 cout << "fits writer created" << endl;
214
215
216 int w1 = wtoi;
217 int w2 = (fg_f_filt) ? wfft+3*w1 : w1;
218
219 // char * colname[5] = {"MJD", "UTC","boloMuV_11","magnFlux","pivot"};
220 TOISeqBuffered * toiin = new TOISeqBuffered("f2in", w1);
221 if (fgdbg) toiin->setDebugLevel(1);
222 TOISeqBuffered * toidegli = new TOISeqBuffered("degli", w1);
223 if (fgdbg) toidegli->setDebugLevel(1);
224 TOISeqBuffered * toimean = new TOISeqBuffered("mean", w1);
225 if (fgdbg) toimean->setDebugLevel(1);
226 TOISeqBuffered * toisig = new TOISeqBuffered("sigma", w2);
227 if (fgdbg) toisig->setDebugLevel(1);
228 TOISeqBuffered * toiincopie = new TOISeqBuffered("incopie", w2);
229 if (fgdbg) toiincopie->setDebugLevel(1);
230
231
232
233 // Connecting TOI to FITSTOIReader Processor
234 // for(kk=0; kk<5; kk++) {
235 // r.addOutput(colname[kk], toitab[kk]);
236 // }
237
238 // int kk = 2;
239 r.addOutput(intoi, toiin);
240 // toi->dbg=true;
241 // r.addOutput("boloMuV_11", toi);
242 cout << " connecting in/out to RzTOIProcessor ... " << endl;
243
244 // TOIProcessor * filt = NULL;
245
246 cout << " Creating SimpleDeglitcher() " << endl;
247 SimpleDeglitcher degl(wdegli);
248 degl.SetDetectionParam(degli_ns1, degli_ns2, degli_maxnpt,
249 degli_minnpt, degli_wrec);
250
251 cout << " Setting Range for deglitcher: " << range_min
252 << " - " << range_max << endl;
253
254 degl.SetRange(range_min, range_max);
255 degl.addInput("in", toiin);
256 degl.addOutput("out", toidegli);
257 degl.addOutput("mean", toimean);
258 degl.addOutput("sigma", toisig);
259 degl.addOutput("incopie", toiincopie);
260
261 cout << " Creating a FanOut SimpleFanOut Object " << endl;
262 SimpleFanOut fanout(2,2);
263 TOISeqBuffered * toidegli0 = new TOISeqBuffered("degli0", w1);
264 if (fgdbg) toidegli0->setDebugLevel(1);
265 TOISeqBuffered * toidegli1 = new TOISeqBuffered("degli1", w2);
266
267 TOISeqBuffered * toimean0 = new TOISeqBuffered("mean0", w1);
268 if (fgdbg) toimean0->setDebugLevel(1);
269 TOISeqBuffered * toimean1 = new TOISeqBuffered("mean1", w2);
270 if (fgdbg) toimean1->setDebugLevel(1);
271
272 fanout.addInput("in0", toidegli);
273 fanout.addOutput("out0_0", toidegli0);
274 fanout.addOutput("out0_1", toidegli1);
275 fanout.addInput("in1", toimean);
276 fanout.addOutput("out1_0", toimean0);
277 fanout.addOutput("out1_1", toimean1);
278
279 cout << " Creating an Adder SimpleAdder Object " << endl;
280 SimpleAdder adder(2);
281 adder.addInput("in0", toidegli0);
282 adder.addInput("in1", toimean0);
283 adder.SetGain(0, 1.);
284 adder.SetGain(1, -1.);
285 TOISeqBuffered * toideglioff = new TOISeqBuffered("deglioff", w1);
286 if (fgdbg) toideglioff->setDebugLevel(1);
287 adder.addOutput("out", toideglioff);
288
289 cout << " Creating a GaussianFilter SimpleFilter Object " << endl;
290 double G_sigma = 2.0;
291 double G_a = 1./(G_sigma*sqrt(M_PI*2.));
292 SimpleFilter filt(16, SimpleFilter::GaussFilter, G_a, G_sigma);
293
294 filt.addInput("in", toideglioff);
295 TOISeqBuffered * toiout = new TOISeqBuffered("out", w1);
296 if (fgdbg) toiout->setDebugLevel(1);
297 TOISeqBuffered * toideglioffcopie = new TOISeqBuffered("deglioffcopie", w2);
298 if (fgdbg) toideglioffcopie->setDebugLevel(1);
299 filt.addOutput("out", toiout);
300 filt.addOutput("incopie", toideglioffcopie);
301
302 Vector fcoef(wfft/2+1);
303 // fcoef = RegularSequence(1., -2./wfft);
304 fcoef = 1.;
305 for(int kfk=0; kfk<nharm_killfreq; kfk++) {
306 double cfreq = bf_killfreq*(kfk+1);
307 double xfreq = 0.;
308 for(int kfj=cfreq-3.*sigf_killfreq; kfj<= cfreq+3.*sigf_killfreq; kfj++) {
309 if ( (kfj < 0) || (kfj >= fcoef.Size() ) ) continue;
310 xfreq = (cfreq-kfj)/sigf_killfreq;
311 fcoef(kfj) -= exp(-xfreq*xfreq);
312 }
313 }
314 cout << " Creating Fourier Filter ... " << endl;
315 SimpleFourierFilter sfft(fcoef);
316 sfft.KeepSpectra(outppfname, keepfft);
317 sfft.ComputeMeanSpectra(true);
318 TOISeqBuffered * toifft = NULL;
319 TOISeqBuffered * toifiltcopie = NULL;
320
321 if (fg_f_filt) {
322 cout << " Connecting Fourier Filter ... " << endl;
323 toifft = new TOISeqBuffered("fftout", w1);
324 toifiltcopie = new TOISeqBuffered("filtcopie", w1);
325 sfft.addInput("in",toiout);
326 sfft.addOutput("out", toifft);
327 sfft.addOutput("incopie", toifiltcopie);
328 }
329
330 cout << " Connecting to output (FitsWriter) " << endl;
331
332 w.setOutFlags(fg_wrtflag);
333
334 // Pour connecter les lignes non connectees au FitsWriter
335 NoOpProcessor noop[3];
336
337 if (fg_nowrticd) noop[0].addInput("in", toiincopie);
338 else w.addInput("in", toiincopie);
339
340 if (fg_f_filt) {
341 w.addInput("filtout", toifiltcopie);
342 w.addInput("fftout", toifft);
343 }
344 else w.addInput("filtout", toiout);
345
346 if (fg_nowrticd) {
347 noop[1].addInput("in", toidegli1);
348 noop[1].addInput("in2", toideglioffcopie);
349 }
350 else {
351 w.addInput("degli", toidegli1);
352 w.addInput("deglioff", toideglioffcopie);
353 }
354 if (fg_nowrtms) {
355 noop[2].addInput("in", toimean1);
356 noop[2].addInput("in2", toisig);
357 }
358 else {
359 w.addInput("mean", toimean1);
360 w.addInput("sigma", toisig);
361 }
362
363 cout << " ------ FITSReaderTOI::PrintStatus() : ----- " << endl;
364 r.PrintStatus(cout);
365 cout << " ------ FanOut::PrintStatus() : ----- " << endl;
366 fanout.PrintStatus(cout);
367 cout << " ------ Adder::PrintStatus() : ----- " << endl;
368 adder.PrintStatus(cout);
369 cout << " ------ Filter::PrintStatus() : ----- " << endl;
370 filt.PrintStatus(cout);
371 cout << "----- FITSWriterTOI::PrintStatus() : ----- " << endl;
372 w.PrintStatus(cout);
373
374 PrtTim("starting threads");
375 r.start();
376 degl.start();
377 fanout.start();
378 adder.start();
379 filt.start();
380 if (fg_f_filt) sfft.start();
381 w.start();
382 if (fg_nowrticd) {
383 noop[0].start();
384 noop[1].start();
385 }
386 if (fg_nowrtms)
387 noop[2].start();
388
389 /*
390 for(int jj=0; jj<3; jj++) {
391 cout << *toiin;
392 cout << *toimean;
393 cout << *toimean1;
394 cout << *toiout;
395 sleep(1);
396 }
397
398 */
399
400 mgr->joinAll();
401 PrtTim("End threads");
402
403 // cout << " ------ FITSReaderTOI::PrintStatus() : ----- " << endl;
404 // r.PrintStatus(cout);
405 // cout << "----- FITSWriterTOI::PrintStatus() : ----- " << endl;
406 // w.PrintStatus(cout);
407
408 cout << " ------ toiin, toidegli and toiout Status information ------- " << endl;
409 cout << *toiin;
410 cout << *toidegli;
411 cout << *toiout;
412 if (fg_f_filt) {
413 cout << *toisig;
414 cout << *toimean1;
415 }
416 cout << degl;
417 cout << filt;
418 cout << adder;
419 if (fg_f_filt) cout << sfft ;
420
421 }
422 catch (PThrowable & exc) {
423 cerr << "\n simtst: Catched Exception \n" << (string)typeid(exc).name()
424 << " - Msg= " << exc.Msg() << endl;
425 }
426 catch (const std::exception & sex) {
427 cerr << "\n simtst: Catched std::exception \n"
428 << (string)typeid(sex).name() << endl;
429 }
430 catch (...) {
431 cerr << "\n simtst: some other exception was caught ! " << endl;
432 }
433
434 return(0);
435}
Note: See TracBrowser for help on using the repository browser.