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

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

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

File size: 13.5 KB
Line 
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"
45 << " [-soff2 wsz,nptfit,degpol] [-soff2nt PPFName] \n"
46 << " [-bgal2cut bmin,bmax] \n"
47 << " [-gfilt wsz,sigma] \n"
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"
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"
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";
133 double bmin = -10;
134 double bmax = 10.;
135 bool bgalcut = false;
136 string bgaltoi = "bgal";
137 bool bgalfile = false;
138 double bmin2 = -10;
139 double bmax2 = 10.;
140 bool bgal2cut = false;
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 }
196 else if (strcmp(arg[ia],"-soff2nt") == 0) {
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 }
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 }
218 else if (strcmp(arg[ia],"-bgalfile") == 0) {
219 if (ia == narg-1) Usage(true);
220 pointfile = arg[ia+1];
221 bgalfile = true;
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();
260 if ((soff2_dofg == true) && (wtoi < 32768)) wtoi = 32768;
261 if (!bgalfile) bgalcut = bgal2cut = false;
262
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 = new SimpleOffsetEstimator(soff2_mwsz, soff2_nptfit, soff2_degpol);
296 offes2->SavePolyNTuple(soff2_nt, soff2_nt_ppfname);
297 }
298
299 SimpleFilter *filt = NULL;
300 if (gfilt_fg) {
301 cout << "> Creating a GaussianFilter SimpleFilter Object " << endl;
302 double G_sigma = gfilt_sigma;
303 double G_a = 1./(G_sigma*sqrt(M_PI*2.));
304 filt = new SimpleFilter(gfilt_wsz, SimpleFilter::GaussFilter, G_a, G_sigma);
305 }
306
307 FITSTOIReader* rbgal = NULL;
308 if (bgalfile) { // if Galactic cut
309 cout << "> Creating bgal FITSTOIReader object - InFile=" << pointfile
310 << " bgaltoiname= " << bgaltoi << endl;
311 rbgal = new FITSTOIReader(pointfile);
312 }
313
314 if (bgalfile && bgalcut) {
315 cout << " offes.SetBGalCut( " << bmin << "," << bmax << ")" << endl;
316 offes.SetBGalCut(bmin, bmax);
317 }
318 if (soff2_dofg && bgalfile && bgal2cut) {
319 cout << " offes2.SetBGalCut( " << bmin2 << "," << bmax2 << ")" << endl;
320 offes2->SetBGalCut(bmin, bmax);
321 }
322
323 cout << "> Creating FITSTOIWriter OutFitsName= " << outfile << endl;
324 FITSTOIWriter w(outfile);
325
326 CGT plombier(fgsegmented, wtoi);
327 plombier.SetDebugLevel(dbglev);
328
329 cout << "> Connecting Processors through plombier ... " << endl;
330 string inname = "in";
331 string outname = "out";
332 plombier.Connect(r, intoi, cleaner, inname);
333 plombier.Connect(cleaner, "out", offes, "in");
334
335 if (soff2_dofg && bgalcut && bgal2cut ) {
336 inname = "bgal";
337 outname = "bgalcopie";
338 plombier.Connect(*rbgal, bgaltoi, offes, inname);
339 plombier.Connect(offes, outname, *offes2, inname);
340 }
341 else if (soff2_dofg && bgal2cut) {
342 inname = "bgal";
343 plombier.Connect(*rbgal, bgaltoi, *offes2, inname);
344 }
345 else if (bgalcut) {
346 inname = "bgal";
347 plombier.Connect(*rbgal, bgaltoi, offes, inname);
348 }
349
350 if (soff2_dofg) {
351 inname = "in";
352 outname = "out";
353 plombier.Connect(offes, outname, *offes2, inname);
354 if (bgalcut) {
355 inname = "bgal";
356 outname = "bgalcopie";
357 plombier.Connect(offes, outname, *offes2, inname);
358 }
359 }
360
361 if (gfilt_fg) {
362 if (soff2_dofg)
363 plombier.Connect(*offes2, "out", *filt, "in");
364 else
365 plombier.Connect(offes, "out", *filt, "in");
366 plombier.Connect(*filt, "out", w, "outfcln", "", 0, fg_wrtflag);
367 }
368 else {
369 if (soff2_dofg)
370 plombier.Connect(*offes2, "out", w, "outcln", "", 0, fg_wrtflag);
371 else
372 plombier.Connect(offes, "out", w, "outcln", "", 0, fg_wrtflag);
373 }
374
375 if (fg_wrtifo) {
376 plombier.Connect(offes, "incopie", w, "inflg", "", 0, fg_wrtflag);
377 plombier.Connect(offes, "offset", w, "offset");
378 if (soff2_dofg)
379 plombier.Connect(*offes2, "offset", w, "offset2");
380 }
381 if (fg_wrtms) {
382 plombier.Connect(cleaner, "mean", w, "mean");
383 plombier.Connect(cleaner, "sigma", w, "sigma");
384 }
385
386 cout << "> Plombier status before start" << endl;
387 cout << plombier ;
388
389 cout << cleaner;
390 cout << offes;
391 if (soff2_dofg) cout << *offes2;
392 cout << w;
393
394 PrtTim("starting processors");
395 plombier.Start();
396
397
398 // ------------------- Impression continu de stat ------------------------
399 if (fgprstat) {
400 ProcSampleCounter<SimpleOffsetEstimator> stats(offes);
401 stats.InfoMessage() = "aksj02/Info";
402 stats.PrintStats();
403 }
404 // -----------------------------------------------------------------------
405
406 cout << cleaner;
407 cout << offes;
408 if (soff2_dofg) cout << *offes2;
409 if (gfilt_fg) cout << *filt;
410 cout << w;
411
412 mgr->joinAll();
413 PrtTim("End threads");
414 if (bgalcut) delete rbgal;
415 if (gfilt_fg) delete filt;
416 if (soff2_dofg) delete offes2;
417 }
418 catch (PThrowable & exc) {
419 cerr << "\n aksj02: Catched Exception \n" << (string)typeid(exc).name()
420 << " - Msg= " << exc.Msg() << endl;
421 }
422 catch (const std::exception & sex) {
423 cerr << "\n aksj02: Catched std::exception \n"
424 << (string)typeid(sex).name() << endl;
425 }
426 catch (...) {
427 cerr << "\n aksj02: some other exception was caught ! " << endl;
428 }
429
430 return(0);
431}
Note: See TracBrowser for help on using the repository browser.