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

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

Petites amelioration SimpleFourierFilter - Reza 30/4/2001

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