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

Last change on this file since 2193 was 1760, checked in by aubourg, 24 years ago

salete de magique

File size: 14.1 KB
Line 
1// ArchTOIPipe (C) CEA/DAPNIA/SPP IN2P3/LAL
2// Eric Aubourg
3// Christophe Magneville
4// Reza Ansari
5// $Id: simtst.cc,v 1.18 2001-11-13 16:01:39 aubourg Exp $
6
7/* Test de processeurs ds simtoipr.cc - Reza Avril 2001
8
9---------------- Exemple d'appel ---------------------
10csh> simtst -start 104385384 -end 104399964 -range -500,500 \
11 -intoi boloMuV_26 -wtoi 8192 -wdegli 1024 \
12 inputbolo.fits filt.fits xx.ppf
13# Avec Filtre de Fourier
14csh> simtst -start 104385384 -end 104399964 -range -500,500 \
15 -intoi boloMuV_26 -wtoi 8192 -wdegli 1024 \
16 -wfft 4096 -keepfft 5 -killfreq 15,4,2.5 \
17 inputbolo.fits filtfft.fits spectre.ppf
18# Autre exemple b545k02
19cool> ./simtst -start 104389122 -end 104649122 -range -1000.,1000. -intoi boloMu
20V_23 -wtoi 8192 -wdegli 1024 -wfft 4096 -keepfft 5 -killfreq 15,4,2.5 Cmv/b545k02
212_16.00_16.49.fits b545.fits b545.ppf
22
23*/
24
25
26
27#include "machdefs.h"
28#include <math.h>
29#include "array.h"
30#include <unistd.h>
31#include "toi.h"
32#include "toiprocessor.h"
33#include "fitstoirdr.h"
34#include "fitstoiwtr.h"
35#include "toisqfilter.h"
36#include "toimanager.h"
37#include "simtoipr.h"
38#include "nooppr.h"
39#include "toiseqbuff.h"
40#include "timing.h"
41#include "sambainit.h"
42#include <stdexcept>
43
44void Usage(bool fgerr)
45{
46 cout << endl;
47 if (fgerr) {
48 cout << " simtst : Argument Error ! simtst -h for usage " << endl;
49 exit(1);
50 }
51 else {
52 cout << "\n Usage : simtst [-intoi toiname] [-start snb] [-end sne] \n"
53 << " [-dbg] [-wtoi sz] [-wdegli sz] [-range min,max] \n"
54 << " [-degli ns,ns2,mxpt,mnpt,wrec] [-gfilt wsz,sigma] \n"
55 << " [-wfft sz] [-keepfft n] [-killfreq bf,nharm,sigf] \n"
56 << " [-nooutflg] [-nowrtms] [-nowrticd] \n"
57 << " inFitsName outFitsName outPPFName \n"
58 << " -dbg : sets TOISeqBuffered debug level to 1 \n"
59 << " -start snb : sets the start sample num \n"
60 << " -end sne : sets the end sample num \n"
61 << " -range min,max : sets the acceptable range for intoi \n"
62 << " default= -16000,16000\n"
63 << " -intoi toiName : select input TOI name (def boloMuV_27)\n"
64 << " -wtoi sz : sets TOISeqBuff buffer size (def= 8192)\n"
65 << " -wdegli sz : sets deglitcher window size (def= 512) \n"
66 << " -degli ns,ns2,maxnpt,minnpt,wrec : sets deglitcher parameters\n"
67 << " -gfilt wsz,sigma : Gaussian filter window size and sigma\n"
68 << " -wfft sz : Activate Fourier filter and sets its width \n"
69 << " -keepfft n : Keeps n spectra (if Fourier filter activated) \n"
70 << " -killfreq bf,nharm,sigf : kills nharm frequency, basefreq=bf \n"
71 << " with a gaussian with width=sigf \n"
72 << " -nooutflg : Don't write flags to output FITS \n"
73 << " -nowrtms : Don't write mean/sigma TOI's \n"
74 << " -nowrticd : Don't write incopie,degli,deglioffset TOI's \n"
75 << endl;
76 }
77}
78
79int main(int narg, char** arg) {
80
81 if ((narg > 1) && (strcmp(arg[1],"-h") == 0) ) Usage(false);
82
83 cout << "simtst starting - Decoding arguments " << " narg=" << narg << endl;
84
85 bool fgdbg = false;
86 bool fgsetstart = false;
87 int wtoi = 8192;
88 int wdegli = 512;
89
90 int wfft = 4096;
91 int keepfft = 0;
92 int nmax = 10;
93 int istart = 0;
94 int iend = 0;
95
96 double range_min = -16000;
97 double range_max = 16000.;
98
99 // Deglitcher parameters
100 double degli_ns1 = 3.;
101 double degli_ns2 = 1.5;
102 int degli_minnpt = 2;
103 int degli_maxnpt = 4;
104 int degli_wrec = 10;
105
106 // Gaussian filter parameters
107 int gfilt_wsz = 16;
108 double gfilt_sigma = 2.;
109
110 // File names
111 string infile;
112 string outfile;
113 string outppfname;
114 string intoi = "boloMuV_27";
115
116 bool fg_wrtflag = true;
117 bool fg_nowrtms = false;
118 bool fg_nowrticd = false;
119
120
121 bool fg_f_filt = false;
122 bool fg_killfreq = false;
123 int bf_killfreq = 1;
124 int nharm_killfreq = 1;
125 double sigf_killfreq = 1.;
126
127 if (narg < 4) Usage(true);
128 int ko=1;
129 // decoding arguments
130 for(int ia=1; ia<narg; ia++) {
131 if (strcmp(arg[ia],"-start") == 0) {
132 if (ia == narg-1) Usage(true); // -start est suivi d'un argument
133 istart = atoi(arg[ia+1]); ia++;
134 fgsetstart = true;
135 }
136 else if (strcmp(arg[ia],"-end") == 0) {
137 if (ia == narg-1) Usage(true);
138 iend = atoi(arg[ia+1]); ia++;
139 }
140 else if (strcmp(arg[ia],"-wtoi") == 0) {
141 if (ia == narg-1) Usage(true);
142 wtoi = atoi(arg[ia+1]); ia++;
143 }
144 else if (strcmp(arg[ia],"-wdegli") == 0) {
145 if (ia == narg-1) Usage(true);
146 wdegli = atoi(arg[ia+1]); ia++;
147 }
148 else if (strcmp(arg[ia],"-degli") == 0) {
149 if (ia == narg-1) Usage(true);
150 sscanf(arg[ia+1],"%lf,%lf,%d,%d,%d", &degli_ns1, &degli_ns2,
151 &degli_maxnpt, &degli_minnpt, &degli_wrec);
152 ia++;
153 }
154 else if (strcmp(arg[ia],"-gfilt") == 0) {
155 if (ia == narg-1) Usage(true);
156 sscanf(arg[ia+1],"%d,%lf", &gfilt_wsz, &gfilt_sigma);
157 ia++;
158 }
159 else if (strcmp(arg[ia],"-wfft") == 0) {
160 if (ia == narg-1) Usage(true);
161 wfft = atoi(arg[ia+1]); ia++;
162 fg_f_filt = true;
163 }
164 else if (strcmp(arg[ia],"-keepfft") == 0) {
165 if (ia == narg-1) Usage(true);
166 keepfft = atoi(arg[ia+1]); ia++;
167 }
168 else if (strcmp(arg[ia],"-killfreq") == 0) {
169 if (ia == narg-1) Usage(true);
170 sscanf(arg[ia+1],"%d,%d,%lf",&bf_killfreq, &nharm_killfreq, &sigf_killfreq);
171 fg_killfreq = true;
172 ia++;
173 }
174 else if (strcmp(arg[ia],"-range") == 0) {
175 if (ia == narg-1) Usage(true);
176 sscanf(arg[ia+1],"%lf,%lf",&range_min, &range_max);
177 ia++;
178 }
179 else if (strcmp(arg[ia],"-intoi") == 0) {
180 if (ia == narg-1) Usage(true);
181 intoi = arg[ia+1]; ia++;
182 }
183 else if (strcmp(arg[ia],"-dbg") == 0) fgdbg = true;
184 else if (strcmp(arg[ia],"-nooutflg") == 0) fg_wrtflag = false;
185 else if (strcmp(arg[ia],"-nowrtms") == 0) fg_nowrtms = true;
186 else if (strcmp(arg[ia],"-nowrticd") == 0) fg_nowrticd = true;
187
188 else { ko = ia; break; } // Debut des noms
189 }
190
191 if (iend < istart) iend = istart+wtoi*(nmax+5);
192 if ((narg-ko) < 3) Usage(true);
193 infile = arg[ko];
194 outfile = arg[ko+1];
195 outppfname = arg[ko+2];
196
197 cout << " Initializing SOPHYA ... " << endl;
198 SophyaInit();
199 InitTim();
200
201 cout << ">>>> simtst: Infile= " << infile << " outFile="
202 << outfile << endl;
203 cout << ">>>> Window Size WTOI= " << wtoi << " WDEGLI= " << wdegli
204 << " iStart= " << istart << " iEnd= " << iend << endl;
205 cout << ">>>> InTOIName= " << intoi << endl;
206
207 try {
208 TOIManager* mgr = TOIManager::getManager();
209
210 // mgr->setRequestedSample(11680920,11710584);
211 // mgr->setRequestedSample(104121000, 104946120);
212 if (fgsetstart)
213 mgr->setRequestedSample(istart, iend);
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
340 // Pour connecter les lignes non connectees au FitsWriter
341 NoOpProcessor noop[3];
342
343 if (fg_nowrticd) noop[0].addInput("in", toiincopie);
344 else w.addInput("in", toiincopie);
345
346 if (fg_f_filt) {
347 w.addInput("filtout", toifiltcopie, fg_wrtflag);
348 w.addInput("fftout", toifft, fg_wrtflag);
349 }
350 else w.addInput("filtout", toiout, fg_wrtflag);
351
352 if (fg_nowrticd) {
353 noop[1].addInput("in", toidegli1);
354 noop[1].addInput("in2", toideglioffcopie);
355 }
356 else {
357 w.addInput("degli", toidegli1);
358 w.addInput("deglioff", toideglioffcopie);
359 }
360 if (fg_nowrtms) {
361 noop[2].addInput("in", toimean1);
362 noop[2].addInput("in2", toisig);
363 }
364 else {
365 w.addInput("mean", toimean1);
366 w.addInput("sigma", toisig);
367 }
368
369 cout << " ------ FITSReaderTOI::PrintStatus() : ----- " << endl;
370 r.PrintStatus(cout);
371 cout << " ------ FanOut::PrintStatus() : ----- " << endl;
372 fanout.PrintStatus(cout);
373 cout << " ------ Adder::PrintStatus() : ----- " << endl;
374 adder.PrintStatus(cout);
375 cout << " ------ Filter::PrintStatus() : ----- " << endl;
376 filt.PrintStatus(cout);
377 cout << "----- FITSWriterTOI::PrintStatus() : ----- " << endl;
378 w.PrintStatus(cout);
379
380
381
382 PrtTim("starting threads");
383 r.start();
384 degl.start();
385 fanout.start();
386 adder.start();
387 filt.start();
388 if (fg_f_filt) sfft.start();
389 w.start();
390 if (fg_nowrticd) {
391 noop[0].start();
392 noop[1].start();
393 }
394 if (fg_nowrtms)
395 noop[2].start();
396
397
398 // ------------------- Impression continu de stat ------------------------
399 ProcSampleCounter<SimpleFilter> stats(filt);
400 stats.InfoMessage() = "simtst/Info";
401 stats.PrintStats();
402 // -----------------------------------------------------------------------
403
404 /*
405 for(int jj=0; jj<3; jj++) {
406 cout << *toiin;
407 cout << *toimean;
408 cout << *toimean1;
409 cout << *toiout;
410 sleep(1);
411 }
412 */
413
414 mgr->joinAll();
415 PrtTim("End threads");
416
417 // cout << " ------ FITSReaderTOI::PrintStatus() : ----- " << endl;
418 // r.PrintStatus(cout);
419 // cout << "----- FITSWriterTOI::PrintStatus() : ----- " << endl;
420 // w.PrintStatus(cout);
421
422 cout << " ------ toiin, toidegli and toiout Status information ------- " << endl;
423 cout << *toiin;
424 cout << *toidegli;
425 cout << *toiout;
426 if (fg_f_filt) {
427 cout << *toisig;
428 cout << *toimean1;
429 }
430 cout << degl;
431 cout << filt;
432 cout << adder;
433 if (fg_f_filt) cout << sfft ;
434
435 }
436 catch (PThrowable & exc) {
437 cerr << "\n simtst: Catched Exception \n" << (string)typeid(exc).name()
438 << " - Msg= " << exc.Msg() << endl;
439 }
440 catch (const std::exception & sex) {
441 cerr << "\n simtst: Catched std::exception \n"
442 << (string)typeid(sex).name() << endl;
443 }
444 catch (...) {
445 cerr << "\n simtst: some other exception was caught ! " << endl;
446 }
447
448 return(0);
449}
Note: See TracBrowser for help on using the repository browser.