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

Last change on this file since 1629 was 1629, checked in by ansari, 24 years ago
  • Ajout pthread_exit apres l'execution de run() ds TOIProcessor::ThreadStart()
  • Ajout de la classe ProcSampleCounter<T> pour affichage continu de stats ds toimanager.h .cc
  • correction mineure de toi2map.cc
  • Utilisation de ProcSampleCounter<T> ds tsttoi2map.cc et simtst.cc

Reza 8/8/2001

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