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
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 inputbolo.fits degli.fits xx.ppf
6*/
7
8
9
10#include "machdefs.h"
11#include <math.h>
12#include "array.h"
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 {
34 cout << "\n Usage : simtst [-dbg] [-start snb] [-end sne] \n"
35 << " [-wtoi sz] [-wdegli sz] [-wfft sz] [-keepfft n] \n"
36 << " inFitsName outFitsName \n"
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"
40 << " -range min,max : sets the acceptable range for intoi \n"
41 << " default= -16000,16000\n"
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"
45 << " -wfft sz : Activate Fourier filter and sets its width \n"
46 << " -keepfft n : Keeps n spectra (if Fourier filter activated) \n"
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;
59 int wtoi = 8192;
60 int wdegli = 512;
61 int wfft = 4096;
62 int keepfft = 0;
63 int nmax = 10;
64 int istart = 104121000+wtoi*5;
65 int iend = 0;
66 double range_min = -16000;
67 double range_max = 16000.;
68 string infile;
69 string outfile;
70 string intoi = "boloMuV_27";
71 bool fg_f_filt = false;
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 }
85 else if (strcmp(arg[ia],"-wtoi") == 0) {
86 if (ia == narg-1) Usage(true);
87 wtoi = atoi(arg[ia+1]); ia++;
88 }
89 else if (strcmp(arg[ia],"-wdegli") == 0) {
90 if (ia == narg-1) Usage(true);
91 wdegli = atoi(arg[ia+1]); ia++;
92 }
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 }
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 }
111 else if (strcmp(arg[ia],"-dbg") == 0) fgdbg = true;
112
113 else { ko = ia; break; } // Debut des noms
114 }
115
116 if (iend < istart) iend = istart+wtoi*(nmax+5);
117 if ((narg-ko) < 2) Usage(true);
118 infile = arg[ko];
119 outfile = arg[ko+1];
120
121 cout << " Initializing SOPHYA ... " << endl;
122 SophyaInit();
123 InitTim();
124
125 cout << ">>>> tstrztoi: Infile= " << infile << " outFile="
126 << outfile << endl;
127 cout << ">>>> Window Size WTOI= " << wtoi << " WDEGLI= " << wdegli
128 << " iStart= " << istart << " iEnd= " << iend << endl;
129 cout << ">>>> InTOIName= " << intoi << endl;
130
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
147 int w1 = wtoi;
148 int w2 = (fg_f_filt && (wfft > w1)) ? wfft : w1;
149
150 // char * colname[5] = {"MJD", "UTC","boloMuV_11","magnFlux","pivot"};
151 // char * toiname[5] = {"MJD", "UTC","bolo11","magneto","pivot"};
152 TOISeqBuffered * toiin = new TOISeqBuffered("f2in", w1);
153 if (fgdbg) toiin->setDebugLevel(1);
154 TOISeqBuffered * toidegli = new TOISeqBuffered("degli", w1);
155 if (fgdbg) toidegli->setDebugLevel(1);
156 TOISeqBuffered * toimean = new TOISeqBuffered("mean", w1);
157 if (fgdbg) toimean->setDebugLevel(1);
158 TOISeqBuffered * toisig = new TOISeqBuffered("sigma", w2);
159 if (fgdbg) toisig->setDebugLevel(1);
160 TOISeqBuffered * toiincopie = new TOISeqBuffered("incopie", w1);
161 if (fgdbg) toiincopie->setDebugLevel(1);
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
170 // int kk = 2;
171 r.addOutput(intoi, toiin);
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;
179 SimpleDeglitcher degl(wdegli);
180 degl.SetDetectionParam(3.,1.5, 4, 2, 10);
181 cout << " Setting Range for deglitcher: " << range_min
182 << " - " << range_max << endl;
183
184 degl.SetRange(range_min, range_max);
185 degl.addInput("in", toiin);
186 degl.addOutput("out", toidegli);
187 degl.addOutput("mean", toimean);
188 degl.addOutput("sigma", toisig);
189 degl.addOutput("incopie", toiincopie);
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);
195 TOISeqBuffered * toidegli1 = new TOISeqBuffered("degli1", w2);
196
197 TOISeqBuffered * toimean0 = new TOISeqBuffered("mean0", w1);
198 if (fgdbg) toimean0->setDebugLevel(1);
199 TOISeqBuffered * toimean1 = new TOISeqBuffered("mean1", w2);
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;
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);
223
224 filt.addInput("in", toideglioff);
225 TOISeqBuffered * toiout = new TOISeqBuffered("out", w1);
226 if (fgdbg) toiout->setDebugLevel(1);
227 TOISeqBuffered * toideglioffcopie = new TOISeqBuffered("deglioffcopie", w2);
228 if (fgdbg) toideglioffcopie->setDebugLevel(1);
229 filt.addOutput("out", toiout);
230 filt.addOutput("incopie", toideglioffcopie);
231
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
249 cout << " Connecting to output (FitsWriter) " << endl;
250
251 w.setOutFlags(true);
252 w.addInput("in", toiincopie);
253 if (fg_f_filt) {
254 w.addInput("filtout", toifiltcopie);
255 w.addInput("fftout", toifft);
256 }
257 else w.addInput("out", toiout);
258 w.addInput("degli", toidegli1);
259 w.addInput("deglioff", toideglioffcopie);
260 w.addInput("mean", toimean1);
261 w.addInput("sigma", toisig);
262
263 cout << " ------ FITSReaderTOI::PrintStatus() : ----- " << endl;
264 r.PrintStatus(cout);
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);
271 cout << "----- FITSWriterTOI::PrintStatus() : ----- " << endl;
272 w.PrintStatus(cout);
273
274 PrtTim("starting threads");
275 r.start();
276 degl.start();
277 fanout.start();
278 adder.start();
279 filt.start();
280 if (fg_f_filt) sfft.start();
281 w.start();
282
283 /*
284 for(int jj=0; jj<3; jj++) {
285 cout << *toiin;
286 cout << *toimean;
287 cout << *toimean1;
288 cout << *toiout;
289 sleep(1);
290 }
291
292 */
293
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
302 cout << " ------ toiin, toidegli and toiout Status information ------- " << endl;
303 cout << *toiin;
304 cout << *toidegli;
305 cout << *toiout;
306
307 cout << degl;
308 cout << filt;
309 cout << adder;
310 if (fg_f_filt) cout << sfft ;
311
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.