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

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

Correction filtre gaussien - Reza 15/6/2001

File size: 14.9 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 int_8 dns_print = 1000;
90 int dns_print_fac = 50;
91 int nbmax_dns_print = 2;
92
93 double range_min = -16000;
94 double range_max = 16000.;
95
96 // Deglitcher parameters
97 double degli_ns1 = 3.;
98 double degli_ns2 = 1.5;
99 int degli_minnpt = 2;
100 int degli_maxnpt = 4;
101 int degli_wrec = 10;
102
103 // Gaussian filter parameters
104 int gfilt_wsz = 16;
105 double gfilt_sigma = 2.;
106
107 // File names
108 string infile;
109 string outfile;
110 string outppfname;
111 string intoi = "boloMuV_27";
112
113 bool fg_wrtflag = true;
114 bool fg_nowrtms = false;
115 bool fg_nowrticd = false;
116
117
118 bool fg_f_filt = false;
119 bool fg_killfreq = false;
120 int bf_killfreq = 1;
121 int nharm_killfreq = 1;
122 double sigf_killfreq = 1.;
123
124 if (narg < 4) Usage(true);
125 int ko=1;
126 // decoding arguments
127 for(int ia=1; ia<narg; ia++) {
128 if (strcmp(arg[ia],"-start") == 0) {
129 if (ia == narg-1) Usage(true); // -start est suivi d'un argument
130 istart = atoi(arg[ia+1]); ia++;
131 fgsetstart = true;
132 }
133 else if (strcmp(arg[ia],"-end") == 0) {
134 if (ia == narg-1) Usage(true);
135 iend = atoi(arg[ia+1]); ia++;
136 }
137 else if (strcmp(arg[ia],"-wtoi") == 0) {
138 if (ia == narg-1) Usage(true);
139 wtoi = atoi(arg[ia+1]); ia++;
140 }
141 else if (strcmp(arg[ia],"-wdegli") == 0) {
142 if (ia == narg-1) Usage(true);
143 wdegli = atoi(arg[ia+1]); ia++;
144 }
145 else if (strcmp(arg[ia],"-degli") == 0) {
146 if (ia == narg-1) Usage(true);
147 sscanf(arg[ia+1],"%lf,%lf,%d,%d,%d", &degli_ns1, &degli_ns2,
148 &degli_maxnpt, &degli_minnpt, &degli_wrec);
149 ia++;
150 }
151 else if (strcmp(arg[ia],"-gfilt") == 0) {
152 if (ia == narg-1) Usage(true);
153 sscanf(arg[ia+1],"%d,%lf", &gfilt_wsz, &gfilt_sigma);
154 ia++;
155 }
156 else if (strcmp(arg[ia],"-wfft") == 0) {
157 if (ia == narg-1) Usage(true);
158 wfft = atoi(arg[ia+1]); ia++;
159 fg_f_filt = true;
160 }
161 else if (strcmp(arg[ia],"-keepfft") == 0) {
162 if (ia == narg-1) Usage(true);
163 keepfft = atoi(arg[ia+1]); ia++;
164 }
165 else if (strcmp(arg[ia],"-killfreq") == 0) {
166 if (ia == narg-1) Usage(true);
167 sscanf(arg[ia+1],"%d,%d,%lf",&bf_killfreq, &nharm_killfreq, &sigf_killfreq);
168 fg_killfreq = true;
169 ia++;
170 }
171 else if (strcmp(arg[ia],"-range") == 0) {
172 if (ia == narg-1) Usage(true);
173 sscanf(arg[ia+1],"%lf,%lf",&range_min, &range_max);
174 ia++;
175 }
176 else if (strcmp(arg[ia],"-intoi") == 0) {
177 if (ia == narg-1) Usage(true);
178 intoi = arg[ia+1]; ia++;
179 }
180 else if (strcmp(arg[ia],"-dbg") == 0) fgdbg = true;
181 else if (strcmp(arg[ia],"-nooutflg") == 0) fg_wrtflag = false;
182 else if (strcmp(arg[ia],"-nowrtms") == 0) fg_nowrtms = true;
183 else if (strcmp(arg[ia],"-nowrticd") == 0) fg_nowrticd = true;
184
185 else { ko = ia; break; } // Debut des noms
186 }
187
188 if (iend < istart) iend = istart+wtoi*(nmax+5);
189 if ((narg-ko) < 3) Usage(true);
190 infile = arg[ko];
191 outfile = arg[ko+1];
192 outppfname = arg[ko+2];
193
194 cout << " Initializing SOPHYA ... " << endl;
195 SophyaInit();
196 InitTim();
197
198 cout << ">>>> simtst: Infile= " << infile << " outFile="
199 << outfile << endl;
200 cout << ">>>> Window Size WTOI= " << wtoi << " WDEGLI= " << wdegli
201 << " iStart= " << istart << " iEnd= " << iend << endl;
202 cout << ">>>> InTOIName= " << intoi << endl;
203
204 try {
205 TOIManager* mgr = TOIManager::getManager();
206
207 // mgr->setRequestedSample(11680920,11710584);
208 // mgr->setRequestedSample(104121000, 104946120);
209 if (fgsetstart) {
210 mgr->setRequestedSample(istart, iend);
211 dns_print = (iend-istart)/dns_print_fac;
212 if (dns_print < 1000) dns_print = 1000;
213 nbmax_dns_print = (iend-istart)/dns_print;
214 }
215 // FITSTOIReader r("/data/Archeops/bolo11.fits);
216 FITSTOIReader r(infile);
217 cout << "reader created" << endl;
218 // FITSTOIWriter w("/data/Archeops/rz.fits");
219 FITSTOIWriter w(outfile);
220 cout << "fits writer created" << endl;
221
222
223 int w1 = wtoi;
224 int w2 = (fg_f_filt) ? wfft+3*w1 : w1;
225
226 // char * colname[5] = {"MJD", "UTC","boloMuV_11","magnFlux","pivot"};
227 TOISeqBuffered * toiin = new TOISeqBuffered("f2in", w1);
228 if (fgdbg) toiin->setDebugLevel(1);
229 TOISeqBuffered * toidegli = new TOISeqBuffered("degli", w1);
230 if (fgdbg) toidegli->setDebugLevel(1);
231 TOISeqBuffered * toimean = new TOISeqBuffered("mean", w1);
232 if (fgdbg) toimean->setDebugLevel(1);
233 TOISeqBuffered * toisig = new TOISeqBuffered("sigma", w2);
234 if (fgdbg) toisig->setDebugLevel(1);
235 TOISeqBuffered * toiincopie = new TOISeqBuffered("incopie", w2);
236 if (fgdbg) toiincopie->setDebugLevel(1);
237
238
239
240 // Connecting TOI to FITSTOIReader Processor
241 // for(kk=0; kk<5; kk++) {
242 // r.addOutput(colname[kk], toitab[kk]);
243 // }
244
245 // int kk = 2;
246 r.addOutput(intoi, toiin);
247 // toi->dbg=true;
248 // r.addOutput("boloMuV_11", toi);
249 cout << " connecting in/out to RzTOIProcessor ... " << endl;
250
251 // TOIProcessor * filt = NULL;
252
253 cout << " Creating SimpleDeglitcher() " << endl;
254 SimpleDeglitcher degl(wdegli);
255 degl.SetDetectionParam(degli_ns1, degli_ns2, degli_maxnpt,
256 degli_minnpt, degli_wrec);
257
258 cout << " Setting Range for deglitcher: " << range_min
259 << " - " << range_max << endl;
260
261 degl.SetRange(range_min, range_max);
262 degl.addInput("in", toiin);
263 degl.addOutput("out", toidegli);
264 degl.addOutput("mean", toimean);
265 degl.addOutput("sigma", toisig);
266 degl.addOutput("incopie", toiincopie);
267
268 cout << " Creating a FanOut SimpleFanOut Object " << endl;
269 SimpleFanOut fanout(2,2);
270 TOISeqBuffered * toidegli0 = new TOISeqBuffered("degli0", w1);
271 if (fgdbg) toidegli0->setDebugLevel(1);
272 TOISeqBuffered * toidegli1 = new TOISeqBuffered("degli1", w2);
273
274 TOISeqBuffered * toimean0 = new TOISeqBuffered("mean0", w1);
275 if (fgdbg) toimean0->setDebugLevel(1);
276 TOISeqBuffered * toimean1 = new TOISeqBuffered("mean1", w2);
277 if (fgdbg) toimean1->setDebugLevel(1);
278
279 fanout.addInput("in0", toidegli);
280 fanout.addOutput("out0_0", toidegli0);
281 fanout.addOutput("out0_1", toidegli1);
282 fanout.addInput("in1", toimean);
283 fanout.addOutput("out1_0", toimean0);
284 fanout.addOutput("out1_1", toimean1);
285
286 cout << " Creating an Adder SimpleAdder Object " << endl;
287 SimpleAdder adder(2);
288 adder.addInput("in0", toidegli0);
289 adder.addInput("in1", toimean0);
290 adder.SetGain(0, 1.);
291 adder.SetGain(1, -1.);
292 TOISeqBuffered * toideglioff = new TOISeqBuffered("deglioff", w1);
293 if (fgdbg) toideglioff->setDebugLevel(1);
294 adder.addOutput("out", toideglioff);
295
296 cout << " Creating a GaussianFilter SimpleFilter Object " << endl;
297 double G_sigma = gfilt_sigma;
298 double G_a = 1./(G_sigma*sqrt(M_PI*2.));
299 SimpleFilter filt(gfilt_wsz, SimpleFilter::GaussFilter, G_a, G_sigma);
300
301 filt.addInput("in", toideglioff);
302 TOISeqBuffered * toiout = new TOISeqBuffered("out", w1);
303 if (fgdbg) toiout->setDebugLevel(1);
304 TOISeqBuffered * toideglioffcopie = new TOISeqBuffered("deglioffcopie", w2);
305 if (fgdbg) toideglioffcopie->setDebugLevel(1);
306 filt.addOutput("out", toiout);
307 filt.addOutput("incopie", toideglioffcopie);
308
309 Vector fcoef(wfft/2+1);
310 // fcoef = RegularSequence(1., -2./wfft);
311 fcoef = 1.;
312 for(int kfk=0; kfk<nharm_killfreq; kfk++) {
313 double cfreq = bf_killfreq*(kfk+1);
314 double xfreq = 0.;
315 for(int kfj=cfreq-3.*sigf_killfreq; kfj<= cfreq+3.*sigf_killfreq; kfj++) {
316 if ( (kfj < 0) || (kfj >= fcoef.Size() ) ) continue;
317 xfreq = (cfreq-kfj)/sigf_killfreq;
318 fcoef(kfj) -= exp(-xfreq*xfreq/2.0);
319 }
320 }
321 cout << " Creating Fourier Filter ... " << endl;
322 SimpleFourierFilter sfft(fcoef);
323 sfft.KeepSpectra(outppfname, keepfft);
324 sfft.ComputeMeanSpectra(true);
325 TOISeqBuffered * toifft = NULL;
326 TOISeqBuffered * toifiltcopie = NULL;
327
328 if (fg_f_filt) {
329 cout << " Connecting Fourier Filter ... " << endl;
330 toifft = new TOISeqBuffered("fftout", w1);
331 toifiltcopie = new TOISeqBuffered("filtcopie", w1);
332 sfft.addInput("in",toiout);
333 sfft.addOutput("out", toifft);
334 sfft.addOutput("incopie", toifiltcopie);
335 }
336
337 cout << " Connecting to output (FitsWriter) " << endl;
338
339 w.setOutFlags(fg_wrtflag);
340
341 // Pour connecter les lignes non connectees au FitsWriter
342 NoOpProcessor noop[3];
343
344 if (fg_nowrticd) noop[0].addInput("in", toiincopie);
345 else w.addInput("in", toiincopie);
346
347 if (fg_f_filt) {
348 w.addInput("filtout", toifiltcopie);
349 w.addInput("fftout", toifft);
350 }
351 else w.addInput("filtout", toiout);
352
353 if (fg_nowrticd) {
354 noop[1].addInput("in", toidegli1);
355 noop[1].addInput("in2", toideglioffcopie);
356 }
357 else {
358 w.addInput("degli", toidegli1);
359 w.addInput("deglioff", toideglioffcopie);
360 }
361 if (fg_nowrtms) {
362 noop[2].addInput("in", toimean1);
363 noop[2].addInput("in2", toisig);
364 }
365 else {
366 w.addInput("mean", toimean1);
367 w.addInput("sigma", toisig);
368 }
369
370 cout << " ------ FITSReaderTOI::PrintStatus() : ----- " << endl;
371 r.PrintStatus(cout);
372 cout << " ------ FanOut::PrintStatus() : ----- " << endl;
373 fanout.PrintStatus(cout);
374 cout << " ------ Adder::PrintStatus() : ----- " << endl;
375 adder.PrintStatus(cout);
376 cout << " ------ Filter::PrintStatus() : ----- " << endl;
377 filt.PrintStatus(cout);
378 cout << "----- FITSWriterTOI::PrintStatus() : ----- " << endl;
379 w.PrintStatus(cout);
380
381
382
383 PrtTim("starting threads");
384 r.start();
385 degl.start();
386 fanout.start();
387 adder.start();
388 filt.start();
389 if (fg_f_filt) sfft.start();
390 w.start();
391 if (fg_nowrticd) {
392 noop[0].start();
393 noop[1].start();
394 }
395 if (fg_nowrtms)
396 noop[2].start();
397
398
399 // ------------------- Impression continu de stat ------------------------
400 int_8 nb_dns_print = 0;
401 int nb_sleep = 0;
402 int_8 last_sample_count = 0;
403 int_8 processed_samples = 0;
404 int_8 total_sample_count = dns_print*nbmax_dns_print;
405 bool alldone = false;
406 while (!alldone) {
407 processed_samples = filt.ProcessedSampleCount();
408 if ( (processed_samples-last_sample_count > dns_print) ||
409 (processed_samples > total_sample_count-10) ) {
410 last_sample_count = processed_samples;
411 if (nb_dns_print == 0) cout << "\n";
412 nb_dns_print++;
413 cout << ">>> simtst/Info: ProcessedSampleCount()= " << last_sample_count
414 << " Frac done = " << processed_samples*100/total_sample_count << " %" << endl;
415 if (last_sample_count > total_sample_count-10) alldone = true;
416 nb_sleep = 0;
417 }
418 else if ((nb_sleep+1)%5 == 0)
419 cout << "> simtst/Info: ProcSamples()= " << processed_samples
420 << " Done = " << " %" << processed_samples*100/total_sample_count
421 << " NbSleep(1) = " << nb_sleep << endl;
422
423 sleep(1); nb_sleep++;
424 }
425
426 // -----------------------------------------------------------------------
427
428 /*
429 for(int jj=0; jj<3; jj++) {
430 cout << *toiin;
431 cout << *toimean;
432 cout << *toimean1;
433 cout << *toiout;
434 sleep(1);
435 }
436 */
437
438 mgr->joinAll();
439 PrtTim("End threads");
440
441 // cout << " ------ FITSReaderTOI::PrintStatus() : ----- " << endl;
442 // r.PrintStatus(cout);
443 // cout << "----- FITSWriterTOI::PrintStatus() : ----- " << endl;
444 // w.PrintStatus(cout);
445
446 cout << " ------ toiin, toidegli and toiout Status information ------- " << endl;
447 cout << *toiin;
448 cout << *toidegli;
449 cout << *toiout;
450 if (fg_f_filt) {
451 cout << *toisig;
452 cout << *toimean1;
453 }
454 cout << degl;
455 cout << filt;
456 cout << adder;
457 if (fg_f_filt) cout << sfft ;
458
459 }
460 catch (PThrowable & exc) {
461 cerr << "\n simtst: Catched Exception \n" << (string)typeid(exc).name()
462 << " - Msg= " << exc.Msg() << endl;
463 }
464 catch (const std::exception & sex) {
465 cerr << "\n simtst: Catched std::exception \n"
466 << (string)typeid(sex).name() << endl;
467 }
468 catch (...) {
469 cerr << "\n simtst: some other exception was caught ! " << endl;
470 }
471
472 return(0);
473}
Note: See TracBrowser for help on using the repository browser.