source: Sophya/trunk/ArchTOIPipe/TestPipes/aksj02.cc@ 2028

Last change on this file since 2028 was 2028, checked in by ansari, 23 years ago

Correction de pb divers (5) - Reza 30/5/2002

File size: 13.3 KB
RevLine 
[2014]1// ArchTOIPipe (C) CEA/DAPNIA/SPP IN2P3/LAL
2// Eric Aubourg
3// Christophe Magneville
4// Reza Ansari
5
6/* Traitement simple des donnees Archeops KS1-3 - Reza Juin 2002
7
8---------------- Exemple d'appel ---------------------
9csh> aksj02 -start 104385384 -end 104399964 -range -500,500 \
10 -intoi boloMuV_26 -wtoi 8192 -wclean 512,5 \
11 inputbolo.fits filt.fits xx.ppf
12*/
13
14
15
16#include "machdefs.h"
17#include <math.h>
18#include <unistd.h>
19
20#include "toimanager.h"
21#include "cgt.h"
22#include "fitstoirdr.h"
23#include "fitstoiwtr.h"
24#include "simtoipr.h"
25#include "simoffset.h"
26#include "simcleaner.h"
27#include "nooppr.h"
28#include "timing.h"
29#include "histinit.h"
30#include "psighand.h"
31#include <stdexcept>
32
33void Usage(bool fgerr)
34{
35 cout << endl;
36 if (fgerr) {
37 cout << " aksj02 : Argument Error ! aksj02 -h for usage " << endl;
38 exit(1);
39 }
40 else {
41 cout << "\n Usage : aksj02 [-intoi toiname] [-start snb] [-end sne] \n"
42 << " [-dbg] [-wtoi sz] [-wclean wsz,nbw] [-range min,max] \n"
43 << " [-soff wsz,nptfit,degpol] [-soffnt PPFName] \n"
44 << " [-bgalcut bmin,bmax] [-bgal toiname] [-bgalfile pointFitsName] \n"
[2028]45 << " [-soff2 wsz,nptfit,degpol] [-soff2nt PPFName] \n"
46 << " [-bgal2cut bmin,bmax] \n"
47 << " [-gfilt wsz,sigma] \n"
[2014]48 << " [-nooutflg] [-wrtms] [-wrtifo] [-prstat] [-useseqbuff] \n"
49 << " inFitsName outFitsName \n"
50 << " -dbg : sets TOISeqBuffered debug level to 1 \n"
51 << " -start snb : sets the start sample num \n"
52 << " -end sne : sets the end sample num \n"
53 << " -range min,max : sets the acceptable range for intoi \n"
54 << " default= -16000,16000\n"
55 << " -intoi toiName : select input TOI name (def bolo)\n"
56 << " -wtoi sz : sets TOISeqBuff buffer size (def= 8192)\n"
57 << " -wclean wsz,nbw : sets cleaner window parameters (256,5) \n"
58 << " -soff wsz,nptfit,degpol : set SimpleOffsetEstimator parameters\n"
59 << " -soffnt PPFName : Writes out SimpleOffsetEstimator NTuple \n"
[2028]60 << " -bgalcut bmin,bmax: Galactic latitude cut (in degree) for SimpleOffsetEstimator\n"
61 << " -bgal toiname: Galactic latitude toiname \n"
62 << " -bgalfile pointFitsName: Pointing FITS file name (for gal. latitude) \n"
63 << " -soff2 wsz,nptfit,degpol : set SimpleOffsetEstimator_2 parameters\n"
64 << " -soff2nt PPFName : Writes out SimpleOffsetEstimator_2 NTuple \n"
65 << " -bgal2cut bmin,bmax: Galactic latitude cut (in degree) for SimpleOffsetEstimator_2\n"
[2014]66 << " -gfilt wsz,sigma : Activate gaussian filter (par= window size, sigma) \n"
67 // << " -wfft sz : Activate Fourier filter and sets its width \n"
68 // << " -keepfft n : Keeps n spectra (if Fourier filter activated) \n"
69 // << " -killfreq bf,nharm,sigf : kills nharm frequency, basefreq=bf \n"
70 // << " with a gaussian with width=sigf \n"
71 << " -nooutflg : Don't write flags to output FITS \n"
72 << " -wrtms : Write mean/sigma TOI's from cleaner \n"
73 << " -wrtifo : Write incopie flagged TOI's from cleaner/ offset from SimpleOffsetEstimator \n"
74 << " -prstat : PrintStat with ProcSampleCounter \n"
75 << " -useseqbuff : Use TOISeqBuffered TOI's (default: TOISegmented) \n"
76 << endl;
77 }
78 if (fgerr) exit(1);
79}
80
81int main(int narg, char** arg) {
82
83 if ((narg > 1) && (strcmp(arg[1],"-h") == 0) ) Usage(false);
84
85 cout << "aksj02 starting - Decoding arguments " << " narg=" << narg << endl;
86
87 bool fgdbg = false;
88 bool fgsetstart = false;
89
90 bool fgprstat = false;
91 bool fgsegmented = true;
92
93 int dbglev = 0;
94
95 int wtoi = 8192;
96 int wdegli = 512;
97
98 int wfft = 4096;
99 int keepfft = 0;
100 int nmax = 10;
101 int istart = 0;
102 int iend = 0;
103
104 double range_min = -16000;
105 double range_max = 16000.;
106
107 // cleaner parameters
108 double clean_wsz = 256;
109 double clean_nbw = 5;
110
111 // SimpleOffsetEstimator parameters
112 int soff_mwsz = 256;
113 int soff_nptfit = 5;
114 int soff_degpol = 2;
115 bool soff_nt = false;
116 string soff_nt_ppfname = "";
117
118 // SimpleOffsetEstimator (2) parameters
119 bool soff2_dofg = false;
120 int soff2_mwsz = 256;
121 int soff2_nptfit = 5;
122 int soff2_degpol = 2;
123 bool soff2_nt = false;
124 string soff2_nt_ppfname = "";
125
126 // Gaussian filter parameters
127 bool gfilt_fg = false;
128 int gfilt_wsz = 16;
129 double gfilt_sigma = 2.;
130
131 // Coordinate file for galactic cut
132 string pointfile = "pointgal.fits";
[2028]133 double bmin = -10;
134 double bmax = 10.;
135 bool bgalcut = false;
[2014]136 string bgaltoi = "bgal";
[2028]137 bool bgalfile = false;
138 double bmin2 = -10;
139 double bmax2 = 10.;
140 bool bgal2cut = false;
[2014]141
142 // File names
143 string infile;
144 string outfile;
145 string outppfname;
146 string intoi = "bolo";
147
148 bool fg_wrtflag = true;
149 bool fg_wrtms = false;
150 bool fg_wrtifo = false;
151
152
153 bool fg_f_filt = false;
154 bool fg_killfreq = false;
155 int bf_killfreq = 1;
156 int nharm_killfreq = 1;
157 double sigf_killfreq = 1.;
158
159 if (narg < 4) Usage(true);
160 int ko=1;
161 // decoding arguments
162 for(int ia=1; ia<narg; ia++) {
163 if (strcmp(arg[ia],"-start") == 0) {
164 if (ia == narg-1) Usage(true); // -start est suivi d'un argument
165 istart = atoi(arg[ia+1]); ia++;
166 fgsetstart = true;
167 }
168 else if (strcmp(arg[ia],"-end") == 0) {
169 if (ia == narg-1) Usage(true);
170 iend = atoi(arg[ia+1]); ia++;
171 }
172 else if (strcmp(arg[ia],"-wtoi") == 0) {
173 if (ia == narg-1) Usage(true);
174 wtoi = atoi(arg[ia+1]); ia++;
175 }
176 else if (strcmp(arg[ia],"-wclean") == 0) {
177 if (ia == narg-1) Usage(true);
178 wdegli = atoi(arg[ia+1]); ia++;
179 sscanf(arg[ia+1],"%d,%d", &clean_wsz, &clean_nbw);
180 }
181 else if (strcmp(arg[ia],"-soff") == 0) {
182 if (ia == narg-1) Usage(true);
183 sscanf(arg[ia+1],"%d,%d,%d", &soff_mwsz, &soff_nptfit, &soff_degpol);
184 ia++;
185 }
186 else if (strcmp(arg[ia],"-soffnt") == 0) {
187 soff_nt = true;
188 soff_nt_ppfname = arg[ia+1]; ia++;
189 }
190 else if (strcmp(arg[ia],"-soff2") == 0) {
191 if (ia == narg-1) Usage(true);
192 soff2_dofg = true;
193 sscanf(arg[ia+1],"%d,%d,%d", &soff2_mwsz, &soff2_nptfit, &soff2_degpol);
194 ia++;
195 }
[2028]196 else if (strcmp(arg[ia],"-soff2nt") == 0) {
[2014]197 soff2_nt = true;
198 soff2_nt_ppfname = arg[ia+1]; ia++;
199 }
200 else if (strcmp(arg[ia],"-gfilt") == 0) {
201 if (ia == narg-1) Usage(true);
202 sscanf(arg[ia+1],"%d,%lf", &gfilt_wsz, &gfilt_sigma);
203 gfilt_fg = true;
204 ia++;
205 }
206 else if (strcmp(arg[ia],"-bgalcut") == 0) {
207 if (ia == narg-1) Usage(true);
208 sscanf(arg[ia+1],"%lf,%lf", &bmin, &bmax);
209 bgalcut = true;
210 ia++;
211 }
[2028]212 else if (strcmp(arg[ia],"-bgal2cut") == 0) {
213 if (ia == narg-1) Usage(true);
214 sscanf(arg[ia+1],"%lf,%lf", &bmin2, &bmax2);
215 bgal2cut = true;
216 ia++;
217 }
[2014]218 else if (strcmp(arg[ia],"-bgalfile") == 0) {
219 if (ia == narg-1) Usage(true);
220 pointfile = arg[ia+1];
[2028]221 bgalfile = true;
[2014]222 ia++;
223 }
224 else if (strcmp(arg[ia],"-bgal") == 0) {
225 if (ia == narg-1) Usage(true);
226 bgaltoi = arg[ia+1];
227 ia++;
228 }
229 else if (strcmp(arg[ia],"-range") == 0) {
230 if (ia == narg-1) Usage(true);
231 sscanf(arg[ia+1],"%lf,%lf",&range_min, &range_max);
232 ia++;
233 }
234 else if (strcmp(arg[ia],"-intoi") == 0) {
235 if (ia == narg-1) Usage(true);
236 intoi = arg[ia+1]; ia++;
237 }
238 else if (strcmp(arg[ia],"-dbg") == 0) fgdbg = true;
239 else if (strcmp(arg[ia],"-nooutflg") == 0) fg_wrtflag = false;
240 else if (strcmp(arg[ia],"-wrtms") == 0) fg_wrtms = true;
241 else if (strcmp(arg[ia],"-wrtifo") == 0) fg_wrtifo = true;
242
243 else if (strcmp(arg[ia],"-prstat") == 0) fgprstat = true;
244 else if (strcmp(arg[ia],"-useseqbuff") == 0) fgsegmented = false;
245
246 else { ko = ia; break; } // Debut des noms
247 }
248
249 if (iend < istart) iend = istart+wtoi*(nmax+5);
250 if ((narg-ko) < 2) Usage(true);
251 infile = arg[ko];
252 outfile = arg[ko+1];
253 // outppfname = arg[ko+2];
254
255 cout << " Initializing SOPHYA ... " << endl;
256 SophyaInit();
257 SophyaConfigureSignalhandling(true);
258
259 InitTim();
[2024]260 if ((soff2_dofg == true) && (wtoi < 32768)) wtoi = 32768;
[2028]261 if (!bgalfile) bgalcut = bgal2cut = false;
262
[2014]263 cout << ">>>> aksj02: Infile= " << infile << " outFile="
264 << outfile << endl;
265 cout << ">>>> Window Size WTOI= " << wtoi << " WDEGLI= " << wdegli
266 << " iStart= " << istart << " iEnd= " << iend << endl;
267 cout << ">>>> InTOIName= " << intoi << endl;
268
269 try {
270 TOIManager* mgr = TOIManager::getManager();
271
272 // mgr->setRequestedSample(11680920,11710584);
273 // mgr->setRequestedSample(104121000, 104946120);
274 if (fgsetstart)
275 mgr->setRequestedSample(istart, iend);
276
277 cout << "> Creating FITSTOIReader object - InFile=" << infile << endl;
278 FITSTOIReader r(infile);
279
280 cout << "> Creating SimpleCleaner() " << endl;
281 SimpleCleaner cleaner(clean_wsz, clean_nbw);
282 cout << " Setting Range for cleaner: " << range_min
283 << " - " << range_max << endl;
284 cleaner.SetRange(range_min, range_max);
285
286 cout << "> Creating SimpleOffsetEstimator(" << soff_mwsz << "," << soff_nptfit
287 << "," << soff_degpol << ")" << endl;
288 SimpleOffsetEstimator offes(soff_mwsz, soff_nptfit, soff_degpol);
289 offes.SavePolyNTuple(soff_nt, soff_nt_ppfname);
290
291 SimpleOffsetEstimator offes2;
292 if (soff2_dofg) {
293 cout << "> Creating 2nd SimpleOffsetEstimator(" << soff2_mwsz << "," << soff2_nptfit
294 << "," << soff2_degpol << ")" << endl;
295 offes2.SetParams(soff2_mwsz, soff2_nptfit, soff2_degpol);
296 offes2.SavePolyNTuple(soff2_nt, soff2_nt_ppfname);
297 }
298
299 if (gfilt_fg)
300 cout << "> Creating a GaussianFilter SimpleFilter Object " << endl;
301 double G_sigma = gfilt_sigma;
302 double G_a = 1./(G_sigma*sqrt(M_PI*2.));
303 SimpleFilter filt(gfilt_wsz, SimpleFilter::GaussFilter, G_a, G_sigma);
304
305
306 FITSTOIReader* rbgal = NULL;
[2028]307 if (bgalfile) { // if Galactic cut
[2014]308 cout << "> Creating bgal FITSTOIReader object - InFile=" << pointfile
309 << " bgaltoiname= " << bgaltoi << endl;
[2028]310 rbgal = new FITSTOIReader(pointfile);
311 }
312
313 if (bgalfile && bgalcut) {
[2014]314 cout << " offes.SetBGalCut( " << bmin << "," << bmax << ")" << endl;
315 offes.SetBGalCut(bmin, bmax);
316 }
[2028]317 if (soff2_dofg && bgalfile && bgal2cut) {
318 cout << " offes2.SetBGalCut( " << bmin2 << "," << bmax2 << ")" << endl;
319 offes2.SetBGalCut(bmin, bmax);
320 }
[2014]321
322 cout << "> Creating FITSTOIWriter OutFitsName= " << outfile << endl;
323 FITSTOIWriter w(outfile);
324
325 CGT plombier(fgsegmented, wtoi);
326 plombier.SetDebugLevel(dbglev);
327
328 cout << "> Connecting Processors through plombier ... " << endl;
329 string inname = "in";
330 string outname = "out";
331 plombier.Connect(r, intoi, cleaner, inname);
332 plombier.Connect(cleaner, "out", offes, "in");
[2028]333
334 if (soff2_dofg && bgalcut && bgal2cut ) {
[2014]335 inname = "bgal";
[2028]336 outname = "bgalcopie";
[2014]337 plombier.Connect(*rbgal, bgaltoi, offes, inname);
[2028]338 plombier.Connect(offes, outname, offes2, inname);
[2014]339 }
[2028]340 else if (soff2_dofg && bgal2cut) {
341 inname = "bgal";
342 plombier.Connect(*rbgal, bgaltoi, offes2, inname);
343 }
344 else if (bgalcut) {
345 inname = "bgal";
346 plombier.Connect(*rbgal, bgaltoi, offes, inname);
347 }
[2014]348
349 if (soff2_dofg) {
350 inname = "in";
351 outname = "out";
352 plombier.Connect(offes, outname, offes2, inname);
353 if (bgalcut) {
354 inname = "bgal";
355 outname = "bgalcopie";
356 plombier.Connect(offes, outname, offes2, inname);
357 }
358 }
359
360 if (gfilt_fg) {
361 if (soff2_dofg)
362 plombier.Connect(offes2, "out", filt, "in");
363 else
364 plombier.Connect(offes, "out", filt, "in");
365 plombier.Connect(filt, "out", w, "outfcln", "", 0, fg_wrtflag);
366 }
[2027]367 else {
368 if (soff2_dofg)
369 plombier.Connect(offes2, "out", w, "outcln", "", 0, fg_wrtflag);
370 else
371 plombier.Connect(offes, "out", w, "outcln", "", 0, fg_wrtflag);
372 }
[2014]373
374 if (fg_wrtifo) {
375 plombier.Connect(offes, "incopie", w, "inflg", "", 0, fg_wrtflag);
376 plombier.Connect(offes, "offset", w, "offset");
377 if (soff2_dofg)
378 plombier.Connect(offes2, "offset", w, "offset2");
379 }
380 if (fg_wrtms) {
381 plombier.Connect(cleaner, "mean", w, "mean");
382 plombier.Connect(cleaner, "sigma", w, "sigma");
383 }
384
385 cout << "> Plombier status before start" << endl;
386 cout << plombier ;
387
388 cout << cleaner;
389 cout << offes;
390 if (soff2_dofg) cout << offes2;
[2025]391 cout << w;
[2014]392
393 PrtTim("starting processors");
394 plombier.Start();
395
396
397 // ------------------- Impression continu de stat ------------------------
398 if (fgprstat) {
399 ProcSampleCounter<SimpleOffsetEstimator> stats(offes);
400 stats.InfoMessage() = "aksj02/Info";
401 stats.PrintStats();
402 }
403 // -----------------------------------------------------------------------
404
405 cout << cleaner;
406 cout << offes;
407 if (soff2_dofg) cout << offes2;
408 if (gfilt_fg) cout << filt;
409 cout << w;
410
411 mgr->joinAll();
412 PrtTim("End threads");
413 if (bgalcut) delete rbgal;
414
415 }
416 catch (PThrowable & exc) {
417 cerr << "\n aksj02: Catched Exception \n" << (string)typeid(exc).name()
418 << " - Msg= " << exc.Msg() << endl;
419 }
420 catch (const std::exception & sex) {
421 cerr << "\n aksj02: Catched std::exception \n"
422 << (string)typeid(sex).name() << endl;
423 }
424 catch (...) {
425 cerr << "\n aksj02: some other exception was caught ! " << endl;
426 }
427
428 return(0);
429}
Note: See TracBrowser for help on using the repository browser.