1 | /* Test de processeurs ds simtoipr.cc - Reza Avril 2001
|
---|
2 |
|
---|
3 | ---------------- Exemple d'appel ---------------------
|
---|
4 | csh> 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 |
|
---|
26 | void 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 outPPFName \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 |
|
---|
52 | int 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 | bool fgsetstart = false;
|
---|
60 | int wtoi = 8192;
|
---|
61 | int wdegli = 512;
|
---|
62 | int wfft = 4096;
|
---|
63 | int keepfft = 0;
|
---|
64 | int nmax = 10;
|
---|
65 | int istart = 0;
|
---|
66 | int iend = 0;
|
---|
67 | double range_min = -16000;
|
---|
68 | double range_max = 16000.;
|
---|
69 | string infile;
|
---|
70 | string outfile;
|
---|
71 | string outppfname;
|
---|
72 | string intoi = "boloMuV_27";
|
---|
73 | bool fg_f_filt = false;
|
---|
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++;
|
---|
82 | fgsetstart = true;
|
---|
83 | }
|
---|
84 | else if (strcmp(arg[ia],"-end") == 0) {
|
---|
85 | if (ia == narg-1) Usage(true);
|
---|
86 | iend = atoi(arg[ia+1]); ia++;
|
---|
87 | }
|
---|
88 | else if (strcmp(arg[ia],"-wtoi") == 0) {
|
---|
89 | if (ia == narg-1) Usage(true);
|
---|
90 | wtoi = atoi(arg[ia+1]); ia++;
|
---|
91 | }
|
---|
92 | else if (strcmp(arg[ia],"-wdegli") == 0) {
|
---|
93 | if (ia == narg-1) Usage(true);
|
---|
94 | wdegli = atoi(arg[ia+1]); ia++;
|
---|
95 | }
|
---|
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 | }
|
---|
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 | }
|
---|
114 | else if (strcmp(arg[ia],"-dbg") == 0) fgdbg = true;
|
---|
115 |
|
---|
116 | else { ko = ia; break; } // Debut des noms
|
---|
117 | }
|
---|
118 |
|
---|
119 | if (iend < istart) iend = istart+wtoi*(nmax+5);
|
---|
120 | if ((narg-ko) < 3) Usage(true);
|
---|
121 | infile = arg[ko];
|
---|
122 | outfile = arg[ko+1];
|
---|
123 | outppfname = arg[ko+2];
|
---|
124 |
|
---|
125 | cout << " Initializing SOPHYA ... " << endl;
|
---|
126 | SophyaInit();
|
---|
127 | InitTim();
|
---|
128 |
|
---|
129 | cout << ">>>> tstrztoi: Infile= " << infile << " outFile="
|
---|
130 | << outfile << endl;
|
---|
131 | cout << ">>>> Window Size WTOI= " << wtoi << " WDEGLI= " << wdegli
|
---|
132 | << " iStart= " << istart << " iEnd= " << iend << endl;
|
---|
133 | cout << ">>>> InTOIName= " << intoi << endl;
|
---|
134 |
|
---|
135 | try {
|
---|
136 | TOIManager* mgr = TOIManager::getManager();
|
---|
137 |
|
---|
138 | // mgr->setRequestedSample(11680920,11710584);
|
---|
139 | // mgr->setRequestedSample(104121000, 104946120);
|
---|
140 | if (fgsetstart)
|
---|
141 | mgr->setRequestedSample(istart, iend);
|
---|
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 |
|
---|
151 | int w1 = wtoi;
|
---|
152 | int w2 = (fg_f_filt) ? 2*wfft+w1 : w1;
|
---|
153 |
|
---|
154 | // char * colname[5] = {"MJD", "UTC","boloMuV_11","magnFlux","pivot"};
|
---|
155 | // char * toiname[5] = {"MJD", "UTC","bolo11","magneto","pivot"};
|
---|
156 | TOISeqBuffered * toiin = new TOISeqBuffered("f2in", w1);
|
---|
157 | if (fgdbg) toiin->setDebugLevel(1);
|
---|
158 | TOISeqBuffered * toidegli = new TOISeqBuffered("degli", w1);
|
---|
159 | if (fgdbg) toidegli->setDebugLevel(1);
|
---|
160 | TOISeqBuffered * toimean = new TOISeqBuffered("mean", w1);
|
---|
161 | if (fgdbg) toimean->setDebugLevel(1);
|
---|
162 | TOISeqBuffered * toisig = new TOISeqBuffered("sigma", w2);
|
---|
163 | if (fgdbg) toisig->setDebugLevel(1);
|
---|
164 | TOISeqBuffered * toiincopie = new TOISeqBuffered("incopie", w2);
|
---|
165 | if (fgdbg) toiincopie->setDebugLevel(1);
|
---|
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 |
|
---|
174 | // int kk = 2;
|
---|
175 | r.addOutput(intoi, toiin);
|
---|
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;
|
---|
183 | SimpleDeglitcher degl(wdegli);
|
---|
184 | degl.SetDetectionParam(3.,1.5, 4, 2, 10);
|
---|
185 | cout << " Setting Range for deglitcher: " << range_min
|
---|
186 | << " - " << range_max << endl;
|
---|
187 |
|
---|
188 | degl.SetRange(range_min, range_max);
|
---|
189 | degl.addInput("in", toiin);
|
---|
190 | degl.addOutput("out", toidegli);
|
---|
191 | degl.addOutput("mean", toimean);
|
---|
192 | degl.addOutput("sigma", toisig);
|
---|
193 | degl.addOutput("incopie", toiincopie);
|
---|
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);
|
---|
199 | TOISeqBuffered * toidegli1 = new TOISeqBuffered("degli1", w2);
|
---|
200 |
|
---|
201 | TOISeqBuffered * toimean0 = new TOISeqBuffered("mean0", w1);
|
---|
202 | if (fgdbg) toimean0->setDebugLevel(1);
|
---|
203 | TOISeqBuffered * toimean1 = new TOISeqBuffered("mean1", w2);
|
---|
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;
|
---|
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);
|
---|
227 |
|
---|
228 | filt.addInput("in", toideglioff);
|
---|
229 | TOISeqBuffered * toiout = new TOISeqBuffered("out", w1);
|
---|
230 | if (fgdbg) toiout->setDebugLevel(1);
|
---|
231 | TOISeqBuffered * toideglioffcopie = new TOISeqBuffered("deglioffcopie", w2);
|
---|
232 | if (fgdbg) toideglioffcopie->setDebugLevel(1);
|
---|
233 | filt.addOutput("out", toiout);
|
---|
234 | filt.addOutput("incopie", toideglioffcopie);
|
---|
235 |
|
---|
236 | Vector fcoef(wfft/2);
|
---|
237 | fcoef = RegularSequence(1., -2./wfft);
|
---|
238 | cout << " Creating Fourier Filter ... " << endl;
|
---|
239 | SimpleFourierFilter sfft(fcoef);
|
---|
240 | sfft.KeepSpectra(outppfname, keepfft);
|
---|
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 |
|
---|
253 | cout << " Connecting to output (FitsWriter) " << endl;
|
---|
254 |
|
---|
255 | w.setOutFlags(true);
|
---|
256 | w.addInput("in", toiincopie);
|
---|
257 | if (fg_f_filt) {
|
---|
258 | w.addInput("filtout", toifiltcopie);
|
---|
259 | w.addInput("fftout", toifft);
|
---|
260 | }
|
---|
261 | else w.addInput("out", toiout);
|
---|
262 | w.addInput("degli", toidegli1);
|
---|
263 | w.addInput("deglioff", toideglioffcopie);
|
---|
264 | w.addInput("mean", toimean1);
|
---|
265 | w.addInput("sigma", toisig);
|
---|
266 |
|
---|
267 | cout << " ------ FITSReaderTOI::PrintStatus() : ----- " << endl;
|
---|
268 | r.PrintStatus(cout);
|
---|
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);
|
---|
275 | cout << "----- FITSWriterTOI::PrintStatus() : ----- " << endl;
|
---|
276 | w.PrintStatus(cout);
|
---|
277 |
|
---|
278 | PrtTim("starting threads");
|
---|
279 | r.start();
|
---|
280 | degl.start();
|
---|
281 | fanout.start();
|
---|
282 | adder.start();
|
---|
283 | filt.start();
|
---|
284 | if (fg_f_filt) sfft.start();
|
---|
285 | w.start();
|
---|
286 |
|
---|
287 | /*
|
---|
288 | for(int jj=0; jj<3; jj++) {
|
---|
289 | cout << *toiin;
|
---|
290 | cout << *toimean;
|
---|
291 | cout << *toimean1;
|
---|
292 | cout << *toiout;
|
---|
293 | sleep(1);
|
---|
294 | }
|
---|
295 |
|
---|
296 | */
|
---|
297 |
|
---|
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 |
|
---|
306 | cout << " ------ toiin, toidegli and toiout Status information ------- " << endl;
|
---|
307 | cout << *toiin;
|
---|
308 | cout << *toidegli;
|
---|
309 | cout << *toiout;
|
---|
310 |
|
---|
311 | cout << degl;
|
---|
312 | cout << filt;
|
---|
313 | cout << adder;
|
---|
314 | if (fg_f_filt) cout << sfft ;
|
---|
315 |
|
---|
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 | }
|
---|