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

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

Chgt calcul TOI buffer size - Reza 7/5/2001

File size: 11.7 KB
RevLine 
[1478]1/* Test de processeurs ds simtoipr.cc - Reza Avril 2001
2
3---------------- Exemple d'appel ---------------------
[1484]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
[1478]17*/
18
19
20
[1462]21#include "machdefs.h"
[1468]22#include <math.h>
[1462]23#include "array.h"
[1442]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 "toiseqbuff.h"
34#include "timing.h"
35#include "sambainit.h"
36
37void Usage(bool fgerr)
38{
39 cout << endl;
40 if (fgerr) {
[1484]41 cout << " simtst : Argument Error ! simtst -h for usage " << endl;
[1442]42 exit(1);
43 }
44 else {
[1484]45 cout << "\n Usage : simtst [-intoi toiname] [-start snb] [-end sne] \n"
46 << " [-dbg] [-wtoi sz] [-wdegli sz] [-range min,max] \n"
47 <<" [-wfft sz] [-keepfft n] [-killfreq bf,nharm,sigf \n"
[1483]48 << " inFitsName outFitsName outPPFName \n"
[1442]49 << " -dbg : sets TOISeqBuffered debug level to 1 \n"
50 << " -start snb : sets the start sample num \n"
51 << " -end sne : sets the end sample num \n"
[1454]52 << " -range min,max : sets the acceptable range for intoi \n"
53 << " default= -16000,16000\n"
[1467]54 << " -intoi toiName : select input TOI name (def boloMuV_27)\n"
55 << " -wtoi sz : sets TOISeqBuff buffer size (def= 8192)\n"
56 << " -wdegli sz : sets deglitcher window size (def= 512) \n"
[1479]57 << " -wfft sz : Activate Fourier filter and sets its width \n"
58 << " -keepfft n : Keeps n spectra (if Fourier filter activated) \n"
[1484]59 << " -killfreq bf,nharm,sigf : kills nharm frequency, basefreq=bf \n"
60 " with a gaussian with width=sigf \n"
[1442]61 << endl;
62 exit(0);
63 }
64}
65
66int main(int narg, char** arg) {
67
68 if ((narg > 1) && (strcmp(arg[1],"-h") == 0) ) Usage(false);
69
70 cout << "simtst starting - Decoding arguments " << " narg=" << narg << endl;
71
72 bool fgdbg = false;
[1483]73 bool fgsetstart = false;
[1479]74 int wtoi = 8192;
75 int wdegli = 512;
76 int wfft = 4096;
77 int keepfft = 0;
[1442]78 int nmax = 10;
[1483]79 int istart = 0;
[1442]80 int iend = 0;
[1454]81 double range_min = -16000;
82 double range_max = 16000.;
[1442]83 string infile;
84 string outfile;
[1483]85 string outppfname;
[1467]86 string intoi = "boloMuV_27";
[1479]87 bool fg_f_filt = false;
[1484]88 bool fg_killfreq = false;
89 int bf_killfreq = 1;
90 int nharm_killfreq = 1;
91 double sigf_killfreq = 1.;
[1442]92
93 if (narg < 4) Usage(true);
94 int ko=1;
95 // decoding arguments
96 for(int ia=1; ia<narg; ia++) {
97 if (strcmp(arg[ia],"-start") == 0) {
98 if (ia == narg-1) Usage(true); // -start est suivi d'un argument
99 istart = atoi(arg[ia+1]); ia++;
[1483]100 fgsetstart = true;
[1442]101 }
102 else if (strcmp(arg[ia],"-end") == 0) {
103 if (ia == narg-1) Usage(true);
104 iend = atoi(arg[ia+1]); ia++;
105 }
[1467]106 else if (strcmp(arg[ia],"-wtoi") == 0) {
[1442]107 if (ia == narg-1) Usage(true);
[1479]108 wtoi = atoi(arg[ia+1]); ia++;
[1442]109 }
[1467]110 else if (strcmp(arg[ia],"-wdegli") == 0) {
[1442]111 if (ia == narg-1) Usage(true);
[1479]112 wdegli = atoi(arg[ia+1]); ia++;
[1442]113 }
[1479]114 else if (strcmp(arg[ia],"-wfft") == 0) {
115 if (ia == narg-1) Usage(true);
116 wfft = atoi(arg[ia+1]); ia++;
117 fg_f_filt = true;
118 }
119 else if (strcmp(arg[ia],"-keepfft") == 0) {
120 if (ia == narg-1) Usage(true);
121 keepfft = atoi(arg[ia+1]); ia++;
122 }
[1484]123 else if (strcmp(arg[ia],"-killfreq") == 0) {
124 if (ia == narg-1) Usage(true);
125 sscanf(arg[ia+1],"%d,%d,%lf",&bf_killfreq, &nharm_killfreq, &sigf_killfreq);
126 fg_killfreq = true;
127 ia++;
128 }
[1454]129 else if (strcmp(arg[ia],"-range") == 0) {
130 if (ia == narg-1) Usage(true);
131 sscanf(arg[ia+1],"%lf,%lf",&range_min, &range_max);
132 ia++;
133 }
134 else if (strcmp(arg[ia],"-intoi") == 0) {
135 if (ia == narg-1) Usage(true);
136 intoi = arg[ia+1]; ia++;
137 }
[1442]138 else if (strcmp(arg[ia],"-dbg") == 0) fgdbg = true;
139
140 else { ko = ia; break; } // Debut des noms
141 }
142
[1479]143 if (iend < istart) iend = istart+wtoi*(nmax+5);
[1483]144 if ((narg-ko) < 3) Usage(true);
[1442]145 infile = arg[ko];
146 outfile = arg[ko+1];
[1483]147 outppfname = arg[ko+2];
[1442]148
149 cout << " Initializing SOPHYA ... " << endl;
150 SophyaInit();
151 InitTim();
152
[1484]153 cout << ">>>> simtst: Infile= " << infile << " outFile="
[1479]154 << outfile << endl;
155 cout << ">>>> Window Size WTOI= " << wtoi << " WDEGLI= " << wdegli
[1442]156 << " iStart= " << istart << " iEnd= " << iend << endl;
[1454]157 cout << ">>>> InTOIName= " << intoi << endl;
[1479]158
[1442]159 try {
160 TOIManager* mgr = TOIManager::getManager();
161
162 // mgr->setRequestedSample(11680920,11710584);
163 // mgr->setRequestedSample(104121000, 104946120);
[1483]164 if (fgsetstart)
165 mgr->setRequestedSample(istart, iend);
[1442]166
167 // FITSTOIReader r("/data/Archeops/bolo11.fits);
168 FITSTOIReader r(infile);
169 cout << "reader created" << endl;
170 // FITSTOIWriter w("/data/Archeops/rz.fits");
171 FITSTOIWriter w(outfile);
172 cout << "fits writer created" << endl;
173
174
[1479]175 int w1 = wtoi;
[1491]176 int w2 = (fg_f_filt) ? wfft+3*w1 : w1;
[1479]177
[1454]178 // char * colname[5] = {"MJD", "UTC","boloMuV_11","magnFlux","pivot"};
179 // char * toiname[5] = {"MJD", "UTC","bolo11","magneto","pivot"};
[1442]180 TOISeqBuffered * toiin = new TOISeqBuffered("f2in", w1);
181 if (fgdbg) toiin->setDebugLevel(1);
[1467]182 TOISeqBuffered * toidegli = new TOISeqBuffered("degli", w1);
183 if (fgdbg) toidegli->setDebugLevel(1);
[1442]184 TOISeqBuffered * toimean = new TOISeqBuffered("mean", w1);
185 if (fgdbg) toimean->setDebugLevel(1);
[1479]186 TOISeqBuffered * toisig = new TOISeqBuffered("sigma", w2);
[1442]187 if (fgdbg) toisig->setDebugLevel(1);
[1483]188 TOISeqBuffered * toiincopie = new TOISeqBuffered("incopie", w2);
[1443]189 if (fgdbg) toiincopie->setDebugLevel(1);
[1442]190
191
192
193 // Connecting TOI to FITSTOIReader Processor
194 // for(kk=0; kk<5; kk++) {
195 // r.addOutput(colname[kk], toitab[kk]);
196 // }
197
[1454]198 // int kk = 2;
199 r.addOutput(intoi, toiin);
[1442]200 // toi->dbg=true;
201 // r.addOutput("boloMuV_11", toi);
202 cout << " connecting in/out to RzTOIProcessor ... " << endl;
203
204 // TOIProcessor * filt = NULL;
205
206 cout << " Creating SimpleDeglitcher() " << endl;
[1479]207 SimpleDeglitcher degl(wdegli);
208 degl.SetDetectionParam(3.,1.5, 4, 2, 10);
[1454]209 cout << " Setting Range for deglitcher: " << range_min
210 << " - " << range_max << endl;
[1479]211
[1454]212 degl.SetRange(range_min, range_max);
[1442]213 degl.addInput("in", toiin);
[1467]214 degl.addOutput("out", toidegli);
[1442]215 degl.addOutput("mean", toimean);
216 degl.addOutput("sigma", toisig);
[1443]217 degl.addOutput("incopie", toiincopie);
[1467]218
219 cout << " Creating a FanOut SimpleFanOut Object " << endl;
220 SimpleFanOut fanout(2,2);
221 TOISeqBuffered * toidegli0 = new TOISeqBuffered("degli0", w1);
222 if (fgdbg) toidegli0->setDebugLevel(1);
[1479]223 TOISeqBuffered * toidegli1 = new TOISeqBuffered("degli1", w2);
[1442]224
[1467]225 TOISeqBuffered * toimean0 = new TOISeqBuffered("mean0", w1);
226 if (fgdbg) toimean0->setDebugLevel(1);
[1479]227 TOISeqBuffered * toimean1 = new TOISeqBuffered("mean1", w2);
[1467]228 if (fgdbg) toimean1->setDebugLevel(1);
229
230 fanout.addInput("in0", toidegli);
231 fanout.addOutput("out0_0", toidegli0);
232 fanout.addOutput("out0_1", toidegli1);
233 fanout.addInput("in1", toimean);
234 fanout.addOutput("out1_0", toimean0);
235 fanout.addOutput("out1_1", toimean1);
236
237 cout << " Creating an Adder SimpleAdder Object " << endl;
238 SimpleAdder adder(2);
239 adder.addInput("in0", toidegli0);
240 adder.addInput("in1", toimean0);
241 adder.SetGain(0, 1.);
242 adder.SetGain(1, -1.);
243 TOISeqBuffered * toideglioff = new TOISeqBuffered("deglioff", w1);
244 if (fgdbg) toideglioff->setDebugLevel(1);
245 adder.addOutput("out", toideglioff);
246
247 cout << " Creating a GaussianFilter SimpleFilter Object " << endl;
[1468]248 double G_sigma = 2.0;
249 double G_a = 1./(G_sigma*sqrt(M_PI*2.));
250 SimpleFilter filt(16, SimpleFilter::GaussFilter, G_a, G_sigma);
[1467]251
252 filt.addInput("in", toideglioff);
253 TOISeqBuffered * toiout = new TOISeqBuffered("out", w1);
254 if (fgdbg) toiout->setDebugLevel(1);
[1479]255 TOISeqBuffered * toideglioffcopie = new TOISeqBuffered("deglioffcopie", w2);
[1467]256 if (fgdbg) toideglioffcopie->setDebugLevel(1);
257 filt.addOutput("out", toiout);
258 filt.addOutput("incopie", toideglioffcopie);
259
[1484]260 Vector fcoef(wfft/2+1);
261 // fcoef = RegularSequence(1., -2./wfft);
262 fcoef = 1.;
263 for(int kfk=0; kfk<nharm_killfreq; kfk++) {
264 double cfreq = bf_killfreq*(kfk+1);
265 double xfreq = 0.;
266 for(int kfj=cfreq-3.*sigf_killfreq; kfj<= cfreq+3.*sigf_killfreq; kfj++) {
267 if ( (kfj < 0) || (kfj >= fcoef.Size() ) ) continue;
268 xfreq = (cfreq-kfj)/sigf_killfreq;
269 fcoef(kfj) -= exp(-xfreq*xfreq);
270 }
271 }
[1479]272 cout << " Creating Fourier Filter ... " << endl;
273 SimpleFourierFilter sfft(fcoef);
[1483]274 sfft.KeepSpectra(outppfname, keepfft);
[1484]275 sfft.ComputeMeanSpectra(true);
[1479]276 TOISeqBuffered * toifft = NULL;
277 TOISeqBuffered * toifiltcopie = NULL;
278
279 if (fg_f_filt) {
280 cout << " Connecting Fourier Filter ... " << endl;
281 toifft = new TOISeqBuffered("fftout", w1);
282 toifiltcopie = new TOISeqBuffered("filtcopie", w1);
283 sfft.addInput("in",toiout);
284 sfft.addOutput("out", toifft);
285 sfft.addOutput("incopie", toifiltcopie);
286 }
287
[1467]288 cout << " Connecting to output (FitsWriter) " << endl;
289
[1442]290 w.setOutFlags(true);
[1443]291 w.addInput("in", toiincopie);
[1479]292 if (fg_f_filt) {
293 w.addInput("filtout", toifiltcopie);
294 w.addInput("fftout", toifft);
295 }
[1484]296 else w.addInput("filtout", toiout);
[1467]297 w.addInput("degli", toidegli1);
298 w.addInput("deglioff", toideglioffcopie);
299 w.addInput("mean", toimean1);
[1442]300 w.addInput("sigma", toisig);
301
302 cout << " ------ FITSReaderTOI::PrintStatus() : ----- " << endl;
303 r.PrintStatus(cout);
[1467]304 cout << " ------ FanOut::PrintStatus() : ----- " << endl;
305 fanout.PrintStatus(cout);
306 cout << " ------ Adder::PrintStatus() : ----- " << endl;
307 adder.PrintStatus(cout);
308 cout << " ------ Filter::PrintStatus() : ----- " << endl;
309 filt.PrintStatus(cout);
[1442]310 cout << "----- FITSWriterTOI::PrintStatus() : ----- " << endl;
311 w.PrintStatus(cout);
312
313 PrtTim("starting threads");
314 r.start();
315 degl.start();
[1467]316 fanout.start();
317 adder.start();
318 filt.start();
[1479]319 if (fg_f_filt) sfft.start();
[1442]320 w.start();
321
[1467]322 /*
[1454]323 for(int jj=0; jj<3; jj++) {
324 cout << *toiin;
[1467]325 cout << *toimean;
326 cout << *toimean1;
[1454]327 cout << *toiout;
328 sleep(1);
329 }
[1467]330
[1454]331 */
332
[1442]333 mgr->joinAll();
334 PrtTim("End threads");
335
336 // cout << " ------ FITSReaderTOI::PrintStatus() : ----- " << endl;
337 // r.PrintStatus(cout);
338 // cout << "----- FITSWriterTOI::PrintStatus() : ----- " << endl;
339 // w.PrintStatus(cout);
340
[1467]341 cout << " ------ toiin, toidegli and toiout Status information ------- " << endl;
[1442]342 cout << *toiin;
[1467]343 cout << *toidegli;
[1442]344 cout << *toiout;
[1491]345 if (fg_f_filt) {
346 cout << *toisig;
347 cout << *toimean1;
348 }
[1467]349 cout << degl;
350 cout << filt;
351 cout << adder;
[1479]352 if (fg_f_filt) cout << sfft ;
[1467]353
[1442]354 }
355 catch (PThrowable & exc) {
356 cerr << "\nrztsttoi: Catched Exception \n" << (string)typeid(exc).name()
357 << " - Msg= " << exc.Msg() << endl;
358 }
359 catch (const std::exception & sex) {
360 cerr << "\nrztsttoi: Catched std::exception \n"
361 << (string)typeid(sex).name() << endl;
362 }
363 catch (...) {
364 cerr << "\nrztsttoi: some other exception was caught ! " << endl;
365 }
366
367 return(0);
368}
Note: See TracBrowser for help on using the repository browser.