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 \
|
---|
6 | inputbolo.fits filt.fits xx.ppf
|
---|
7 | # Avec Filtre de Fourier
|
---|
8 | csh> 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
|
---|
13 | cool> ./simtst -start 104389122 -end 104649122 -range -1000.,1000. -intoi boloMu
|
---|
14 | V_23 -wtoi 8192 -wdegli 1024 -wfft 4096 -keepfft 5 -killfreq 15,4,2.5 Cmv/b545k02
|
---|
15 | 2_16.00_16.49.fits b545.fits b545.ppf
|
---|
16 |
|
---|
17 | */
|
---|
18 |
|
---|
19 |
|
---|
20 |
|
---|
21 | #include "machdefs.h"
|
---|
22 | #include <math.h>
|
---|
23 | #include "array.h"
|
---|
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 |
|
---|
37 | void Usage(bool fgerr)
|
---|
38 | {
|
---|
39 | cout << endl;
|
---|
40 | if (fgerr) {
|
---|
41 | cout << " simtst : Argument Error ! simtst -h for usage " << endl;
|
---|
42 | exit(1);
|
---|
43 | }
|
---|
44 | else {
|
---|
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"
|
---|
48 | << " inFitsName outFitsName outPPFName \n"
|
---|
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"
|
---|
52 | << " -range min,max : sets the acceptable range for intoi \n"
|
---|
53 | << " default= -16000,16000\n"
|
---|
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"
|
---|
57 | << " -wfft sz : Activate Fourier filter and sets its width \n"
|
---|
58 | << " -keepfft n : Keeps n spectra (if Fourier filter activated) \n"
|
---|
59 | << " -killfreq bf,nharm,sigf : kills nharm frequency, basefreq=bf \n"
|
---|
60 | " with a gaussian with width=sigf \n"
|
---|
61 | << endl;
|
---|
62 | exit(0);
|
---|
63 | }
|
---|
64 | }
|
---|
65 |
|
---|
66 | int 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;
|
---|
73 | bool fgsetstart = false;
|
---|
74 | int wtoi = 8192;
|
---|
75 | int wdegli = 512;
|
---|
76 | int wfft = 4096;
|
---|
77 | int keepfft = 0;
|
---|
78 | int nmax = 10;
|
---|
79 | int istart = 0;
|
---|
80 | int iend = 0;
|
---|
81 | double range_min = -16000;
|
---|
82 | double range_max = 16000.;
|
---|
83 | string infile;
|
---|
84 | string outfile;
|
---|
85 | string outppfname;
|
---|
86 | string intoi = "boloMuV_27";
|
---|
87 | bool fg_f_filt = false;
|
---|
88 | bool fg_killfreq = false;
|
---|
89 | int bf_killfreq = 1;
|
---|
90 | int nharm_killfreq = 1;
|
---|
91 | double sigf_killfreq = 1.;
|
---|
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++;
|
---|
100 | fgsetstart = true;
|
---|
101 | }
|
---|
102 | else if (strcmp(arg[ia],"-end") == 0) {
|
---|
103 | if (ia == narg-1) Usage(true);
|
---|
104 | iend = atoi(arg[ia+1]); ia++;
|
---|
105 | }
|
---|
106 | else if (strcmp(arg[ia],"-wtoi") == 0) {
|
---|
107 | if (ia == narg-1) Usage(true);
|
---|
108 | wtoi = atoi(arg[ia+1]); ia++;
|
---|
109 | }
|
---|
110 | else if (strcmp(arg[ia],"-wdegli") == 0) {
|
---|
111 | if (ia == narg-1) Usage(true);
|
---|
112 | wdegli = atoi(arg[ia+1]); ia++;
|
---|
113 | }
|
---|
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 | }
|
---|
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 | }
|
---|
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 | }
|
---|
138 | else if (strcmp(arg[ia],"-dbg") == 0) fgdbg = true;
|
---|
139 |
|
---|
140 | else { ko = ia; break; } // Debut des noms
|
---|
141 | }
|
---|
142 |
|
---|
143 | if (iend < istart) iend = istart+wtoi*(nmax+5);
|
---|
144 | if ((narg-ko) < 3) Usage(true);
|
---|
145 | infile = arg[ko];
|
---|
146 | outfile = arg[ko+1];
|
---|
147 | outppfname = arg[ko+2];
|
---|
148 |
|
---|
149 | cout << " Initializing SOPHYA ... " << endl;
|
---|
150 | SophyaInit();
|
---|
151 | InitTim();
|
---|
152 |
|
---|
153 | cout << ">>>> simtst: Infile= " << infile << " outFile="
|
---|
154 | << outfile << endl;
|
---|
155 | cout << ">>>> Window Size WTOI= " << wtoi << " WDEGLI= " << wdegli
|
---|
156 | << " iStart= " << istart << " iEnd= " << iend << endl;
|
---|
157 | cout << ">>>> InTOIName= " << intoi << endl;
|
---|
158 |
|
---|
159 | try {
|
---|
160 | TOIManager* mgr = TOIManager::getManager();
|
---|
161 |
|
---|
162 | // mgr->setRequestedSample(11680920,11710584);
|
---|
163 | // mgr->setRequestedSample(104121000, 104946120);
|
---|
164 | if (fgsetstart)
|
---|
165 | mgr->setRequestedSample(istart, iend);
|
---|
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 |
|
---|
175 | int w1 = wtoi;
|
---|
176 | int w2 = (fg_f_filt) ? wfft+w1 : w1;
|
---|
177 |
|
---|
178 | // char * colname[5] = {"MJD", "UTC","boloMuV_11","magnFlux","pivot"};
|
---|
179 | // char * toiname[5] = {"MJD", "UTC","bolo11","magneto","pivot"};
|
---|
180 | TOISeqBuffered * toiin = new TOISeqBuffered("f2in", w1);
|
---|
181 | if (fgdbg) toiin->setDebugLevel(1);
|
---|
182 | TOISeqBuffered * toidegli = new TOISeqBuffered("degli", w1);
|
---|
183 | if (fgdbg) toidegli->setDebugLevel(1);
|
---|
184 | TOISeqBuffered * toimean = new TOISeqBuffered("mean", w1);
|
---|
185 | if (fgdbg) toimean->setDebugLevel(1);
|
---|
186 | TOISeqBuffered * toisig = new TOISeqBuffered("sigma", w2);
|
---|
187 | if (fgdbg) toisig->setDebugLevel(1);
|
---|
188 | TOISeqBuffered * toiincopie = new TOISeqBuffered("incopie", w2);
|
---|
189 | if (fgdbg) toiincopie->setDebugLevel(1);
|
---|
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 |
|
---|
198 | // int kk = 2;
|
---|
199 | r.addOutput(intoi, toiin);
|
---|
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;
|
---|
207 | SimpleDeglitcher degl(wdegli);
|
---|
208 | degl.SetDetectionParam(3.,1.5, 4, 2, 10);
|
---|
209 | cout << " Setting Range for deglitcher: " << range_min
|
---|
210 | << " - " << range_max << endl;
|
---|
211 |
|
---|
212 | degl.SetRange(range_min, range_max);
|
---|
213 | degl.addInput("in", toiin);
|
---|
214 | degl.addOutput("out", toidegli);
|
---|
215 | degl.addOutput("mean", toimean);
|
---|
216 | degl.addOutput("sigma", toisig);
|
---|
217 | degl.addOutput("incopie", toiincopie);
|
---|
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);
|
---|
223 | TOISeqBuffered * toidegli1 = new TOISeqBuffered("degli1", w2);
|
---|
224 |
|
---|
225 | TOISeqBuffered * toimean0 = new TOISeqBuffered("mean0", w1);
|
---|
226 | if (fgdbg) toimean0->setDebugLevel(1);
|
---|
227 | TOISeqBuffered * toimean1 = new TOISeqBuffered("mean1", w2);
|
---|
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;
|
---|
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);
|
---|
251 |
|
---|
252 | filt.addInput("in", toideglioff);
|
---|
253 | TOISeqBuffered * toiout = new TOISeqBuffered("out", w1);
|
---|
254 | if (fgdbg) toiout->setDebugLevel(1);
|
---|
255 | TOISeqBuffered * toideglioffcopie = new TOISeqBuffered("deglioffcopie", w2);
|
---|
256 | if (fgdbg) toideglioffcopie->setDebugLevel(1);
|
---|
257 | filt.addOutput("out", toiout);
|
---|
258 | filt.addOutput("incopie", toideglioffcopie);
|
---|
259 |
|
---|
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 | }
|
---|
272 | cout << " Creating Fourier Filter ... " << endl;
|
---|
273 | SimpleFourierFilter sfft(fcoef);
|
---|
274 | sfft.KeepSpectra(outppfname, keepfft);
|
---|
275 | sfft.ComputeMeanSpectra(true);
|
---|
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 |
|
---|
288 | cout << " Connecting to output (FitsWriter) " << endl;
|
---|
289 |
|
---|
290 | w.setOutFlags(true);
|
---|
291 | w.addInput("in", toiincopie);
|
---|
292 | if (fg_f_filt) {
|
---|
293 | w.addInput("filtout", toifiltcopie);
|
---|
294 | w.addInput("fftout", toifft);
|
---|
295 | }
|
---|
296 | else w.addInput("filtout", toiout);
|
---|
297 | w.addInput("degli", toidegli1);
|
---|
298 | w.addInput("deglioff", toideglioffcopie);
|
---|
299 | w.addInput("mean", toimean1);
|
---|
300 | w.addInput("sigma", toisig);
|
---|
301 |
|
---|
302 | cout << " ------ FITSReaderTOI::PrintStatus() : ----- " << endl;
|
---|
303 | r.PrintStatus(cout);
|
---|
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);
|
---|
310 | cout << "----- FITSWriterTOI::PrintStatus() : ----- " << endl;
|
---|
311 | w.PrintStatus(cout);
|
---|
312 |
|
---|
313 | PrtTim("starting threads");
|
---|
314 | r.start();
|
---|
315 | degl.start();
|
---|
316 | fanout.start();
|
---|
317 | adder.start();
|
---|
318 | filt.start();
|
---|
319 | if (fg_f_filt) sfft.start();
|
---|
320 | w.start();
|
---|
321 |
|
---|
322 | /*
|
---|
323 | for(int jj=0; jj<3; jj++) {
|
---|
324 | cout << *toiin;
|
---|
325 | cout << *toimean;
|
---|
326 | cout << *toimean1;
|
---|
327 | cout << *toiout;
|
---|
328 | sleep(1);
|
---|
329 | }
|
---|
330 |
|
---|
331 | */
|
---|
332 |
|
---|
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 |
|
---|
341 | cout << " ------ toiin, toidegli and toiout Status information ------- " << endl;
|
---|
342 | cout << *toiin;
|
---|
343 | cout << *toidegli;
|
---|
344 | cout << *toiout;
|
---|
345 |
|
---|
346 | cout << degl;
|
---|
347 | cout << filt;
|
---|
348 | cout << adder;
|
---|
349 | if (fg_f_filt) cout << sfft ;
|
---|
350 |
|
---|
351 | }
|
---|
352 | catch (PThrowable & exc) {
|
---|
353 | cerr << "\nrztsttoi: Catched Exception \n" << (string)typeid(exc).name()
|
---|
354 | << " - Msg= " << exc.Msg() << endl;
|
---|
355 | }
|
---|
356 | catch (const std::exception & sex) {
|
---|
357 | cerr << "\nrztsttoi: Catched std::exception \n"
|
---|
358 | << (string)typeid(sex).name() << endl;
|
---|
359 | }
|
---|
360 | catch (...) {
|
---|
361 | cerr << "\nrztsttoi: some other exception was caught ! " << endl;
|
---|
362 | }
|
---|
363 |
|
---|
364 | return(0);
|
---|
365 | }
|
---|