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

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

debug deglitcher - Ajout Filtre Fourier (SimpleFourierFilter) - Reza 27/4/2001

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