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

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

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

File size: 11.8 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 << " [-soff2 wsz,nptfit,degpol] [-soffnt2 PPFName] \n"
45 << " [-gfilt wsz,sigma] \n"
46 << " [-bgalcut bmin,bmax] [-bgal toiname] [-bgalfile pointFitsName] \n"
47 << " [-nooutflg] [-wrtms] [-wrtifo] [-prstat] [-useseqbuff] \n"
48 << " inFitsName outFitsName \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 bolo)\n"
55 << " -wtoi sz : sets TOISeqBuff buffer size (def= 8192)\n"
56 << " -wclean wsz,nbw : sets cleaner window parameters (256,5) \n"
57 << " -soff wsz,nptfit,degpol : set SimpleOffsetEstimator parameters\n"
58 << " -soffnt PPFName : Writes out SimpleOffsetEstimator NTuple \n"
59 << " -gfilt wsz,sigma : Activate gaussian filter (par= window size, sigma) \n"
60 // << " -wfft sz : Activate Fourier filter and sets its width \n"
61 // << " -keepfft n : Keeps n spectra (if Fourier filter activated) \n"
62 // << " -killfreq bf,nharm,sigf : kills nharm frequency, basefreq=bf \n"
63 // << " with a gaussian with width=sigf \n"
64 << " -nooutflg : Don't write flags to output FITS \n"
65 << " -wrtms : Write mean/sigma TOI's from cleaner \n"
66 << " -wrtifo : Write incopie flagged TOI's from cleaner/ offset from SimpleOffsetEstimator \n"
67 << " -prstat : PrintStat with ProcSampleCounter \n"
68 << " -useseqbuff : Use TOISeqBuffered TOI's (default: TOISegmented) \n"
69 << endl;
70 }
71 if (fgerr) exit(1);
72}
73
74int main(int narg, char** arg) {
75
76 if ((narg > 1) && (strcmp(arg[1],"-h") == 0) ) Usage(false);
77
78 cout << "aksj02 starting - Decoding arguments " << " narg=" << narg << endl;
79
80 bool fgdbg = false;
81 bool fgsetstart = false;
82
83 bool fgprstat = false;
84 bool fgsegmented = true;
85
86 int dbglev = 0;
87
88 int wtoi = 8192;
89 int wdegli = 512;
90
91 int wfft = 4096;
92 int keepfft = 0;
93 int nmax = 10;
94 int istart = 0;
95 int iend = 0;
96
97 double range_min = -16000;
98 double range_max = 16000.;
99
100 // cleaner parameters
101 double clean_wsz = 256;
102 double clean_nbw = 5;
103
104 // SimpleOffsetEstimator parameters
105 int soff_mwsz = 256;
106 int soff_nptfit = 5;
107 int soff_degpol = 2;
108 bool soff_nt = false;
109 string soff_nt_ppfname = "";
110
111 // SimpleOffsetEstimator (2) parameters
112 bool soff2_dofg = false;
113 int soff2_mwsz = 256;
114 int soff2_nptfit = 5;
115 int soff2_degpol = 2;
116 bool soff2_nt = false;
117 string soff2_nt_ppfname = "";
118
119 // Gaussian filter parameters
120 bool gfilt_fg = false;
121 int gfilt_wsz = 16;
122 double gfilt_sigma = 2.;
123
124 // Coordinate file for galactic cut
125 string pointfile = "pointgal.fits";
126 double bmin = -20;
127 double bmax = 20.;
128 string bgaltoi = "bgal";
129 bool bgalcut = false;
130
131 // File names
132 string infile;
133 string outfile;
134 string outppfname;
135 string intoi = "bolo";
136
137 bool fg_wrtflag = true;
138 bool fg_wrtms = false;
139 bool fg_wrtifo = false;
140
141
142 bool fg_f_filt = false;
143 bool fg_killfreq = false;
144 int bf_killfreq = 1;
145 int nharm_killfreq = 1;
146 double sigf_killfreq = 1.;
147
148 if (narg < 4) Usage(true);
149 int ko=1;
150 // decoding arguments
151 for(int ia=1; ia<narg; ia++) {
152 if (strcmp(arg[ia],"-start") == 0) {
153 if (ia == narg-1) Usage(true); // -start est suivi d'un argument
154 istart = atoi(arg[ia+1]); ia++;
155 fgsetstart = true;
156 }
157 else if (strcmp(arg[ia],"-end") == 0) {
158 if (ia == narg-1) Usage(true);
159 iend = atoi(arg[ia+1]); ia++;
160 }
161 else if (strcmp(arg[ia],"-wtoi") == 0) {
162 if (ia == narg-1) Usage(true);
163 wtoi = atoi(arg[ia+1]); ia++;
164 }
165 else if (strcmp(arg[ia],"-wclean") == 0) {
166 if (ia == narg-1) Usage(true);
167 wdegli = atoi(arg[ia+1]); ia++;
168 sscanf(arg[ia+1],"%d,%d", &clean_wsz, &clean_nbw);
169 }
170 else if (strcmp(arg[ia],"-soff") == 0) {
171 if (ia == narg-1) Usage(true);
172 sscanf(arg[ia+1],"%d,%d,%d", &soff_mwsz, &soff_nptfit, &soff_degpol);
173 ia++;
174 }
175 else if (strcmp(arg[ia],"-soffnt") == 0) {
176 soff_nt = true;
177 soff_nt_ppfname = arg[ia+1]; ia++;
178 }
179 else if (strcmp(arg[ia],"-soff2") == 0) {
180 if (ia == narg-1) Usage(true);
181 soff2_dofg = true;
182 sscanf(arg[ia+1],"%d,%d,%d", &soff2_mwsz, &soff2_nptfit, &soff2_degpol);
183 ia++;
184 }
185 else if (strcmp(arg[ia],"-soffnt2") == 0) {
186 soff2_nt = true;
187 soff2_nt_ppfname = arg[ia+1]; ia++;
188 }
189 else if (strcmp(arg[ia],"-gfilt") == 0) {
190 if (ia == narg-1) Usage(true);
191 sscanf(arg[ia+1],"%d,%lf", &gfilt_wsz, &gfilt_sigma);
192 gfilt_fg = true;
193 ia++;
194 }
195 else if (strcmp(arg[ia],"-bgalcut") == 0) {
196 if (ia == narg-1) Usage(true);
197 sscanf(arg[ia+1],"%lf,%lf", &bmin, &bmax);
198 bgalcut = true;
199 ia++;
200 }
201 else if (strcmp(arg[ia],"-bgalfile") == 0) {
202 if (ia == narg-1) Usage(true);
203 pointfile = arg[ia+1];
204 ia++;
205 }
206 else if (strcmp(arg[ia],"-bgal") == 0) {
207 if (ia == narg-1) Usage(true);
208 bgaltoi = arg[ia+1];
209 ia++;
210 }
211 else if (strcmp(arg[ia],"-range") == 0) {
212 if (ia == narg-1) Usage(true);
213 sscanf(arg[ia+1],"%lf,%lf",&range_min, &range_max);
214 ia++;
215 }
216 else if (strcmp(arg[ia],"-intoi") == 0) {
217 if (ia == narg-1) Usage(true);
218 intoi = arg[ia+1]; ia++;
219 }
220 else if (strcmp(arg[ia],"-dbg") == 0) fgdbg = true;
221 else if (strcmp(arg[ia],"-nooutflg") == 0) fg_wrtflag = false;
222 else if (strcmp(arg[ia],"-wrtms") == 0) fg_wrtms = true;
223 else if (strcmp(arg[ia],"-wrtifo") == 0) fg_wrtifo = true;
224
225 else if (strcmp(arg[ia],"-prstat") == 0) fgprstat = true;
226 else if (strcmp(arg[ia],"-useseqbuff") == 0) fgsegmented = false;
227
228 else { ko = ia; break; } // Debut des noms
229 }
230
231 if (iend < istart) iend = istart+wtoi*(nmax+5);
232 if ((narg-ko) < 2) Usage(true);
233 infile = arg[ko];
234 outfile = arg[ko+1];
235 // outppfname = arg[ko+2];
236
237 cout << " Initializing SOPHYA ... " << endl;
238 SophyaInit();
239 SophyaConfigureSignalhandling(true);
240
241 InitTim();
242 if ((soff2_dofg == true) && (wtoi < 32768)) wtoi = 32768;
243 cout << ">>>> aksj02: Infile= " << infile << " outFile="
244 << outfile << endl;
245 cout << ">>>> Window Size WTOI= " << wtoi << " WDEGLI= " << wdegli
246 << " iStart= " << istart << " iEnd= " << iend << endl;
247 cout << ">>>> InTOIName= " << intoi << endl;
248
249 try {
250 TOIManager* mgr = TOIManager::getManager();
251
252 // mgr->setRequestedSample(11680920,11710584);
253 // mgr->setRequestedSample(104121000, 104946120);
254 if (fgsetstart)
255 mgr->setRequestedSample(istart, iend);
256
257 cout << "> Creating FITSTOIReader object - InFile=" << infile << endl;
258 FITSTOIReader r(infile);
259
260 cout << "> Creating SimpleCleaner() " << endl;
261 SimpleCleaner cleaner(clean_wsz, clean_nbw);
262 cout << " Setting Range for cleaner: " << range_min
263 << " - " << range_max << endl;
264 cleaner.SetRange(range_min, range_max);
265
266 cout << "> Creating SimpleOffsetEstimator(" << soff_mwsz << "," << soff_nptfit
267 << "," << soff_degpol << ")" << endl;
268 SimpleOffsetEstimator offes(soff_mwsz, soff_nptfit, soff_degpol);
269 offes.SavePolyNTuple(soff_nt, soff_nt_ppfname);
270
271 SimpleOffsetEstimator offes2;
272 if (soff2_dofg) {
273 cout << "> Creating 2nd SimpleOffsetEstimator(" << soff2_mwsz << "," << soff2_nptfit
274 << "," << soff2_degpol << ")" << endl;
275 offes2.SetParams(soff2_mwsz, soff2_nptfit, soff2_degpol);
276 offes2.SavePolyNTuple(soff2_nt, soff2_nt_ppfname);
277 }
278
279 if (gfilt_fg)
280 cout << "> Creating a GaussianFilter SimpleFilter Object " << endl;
281 double G_sigma = gfilt_sigma;
282 double G_a = 1./(G_sigma*sqrt(M_PI*2.));
283 SimpleFilter filt(gfilt_wsz, SimpleFilter::GaussFilter, G_a, G_sigma);
284
285
286 FITSTOIReader* rbgal = NULL;
287 if (bgalcut) { // if Galactic cut
288 cout << "> Creating bgal FITSTOIReader object - InFile=" << pointfile
289 << " bgaltoiname= " << bgaltoi << endl;
290 cout << " offes.SetBGalCut( " << bmin << "," << bmax << ")" << endl;
291 rbgal = new FITSTOIReader(pointfile);
292 offes.SetBGalCut(bmin, bmax);
293 }
294
295 cout << "> Creating FITSTOIWriter OutFitsName= " << outfile << endl;
296 FITSTOIWriter w(outfile);
297
298 CGT plombier(fgsegmented, wtoi);
299 plombier.SetDebugLevel(dbglev);
300
301 cout << "> Connecting Processors through plombier ... " << endl;
302 string inname = "in";
303 string outname = "out";
304 plombier.Connect(r, intoi, cleaner, inname);
305 plombier.Connect(cleaner, "out", offes, "in");
306
307 if (bgalcut) {
308 inname = "bgal";
309 plombier.Connect(*rbgal, bgaltoi, offes, inname);
310 }
311
312 if (soff2_dofg) {
313 inname = "in";
314 outname = "out";
315 plombier.Connect(offes, outname, offes2, inname);
316 if (bgalcut) {
317 inname = "bgal";
318 outname = "bgalcopie";
319 plombier.Connect(offes, outname, offes2, inname);
320 }
321 }
322
323 if (gfilt_fg) {
324 if (soff2_dofg)
325 plombier.Connect(offes2, "out", filt, "in");
326 else
327 plombier.Connect(offes, "out", filt, "in");
328 plombier.Connect(filt, "out", w, "outfcln", "", 0, fg_wrtflag);
329 }
330 else
331 plombier.Connect(offes, "out", w, "outcln", "", 0, fg_wrtflag);
332
333 if (fg_wrtifo) {
334 plombier.Connect(offes, "incopie", w, "inflg", "", 0, fg_wrtflag);
335 plombier.Connect(offes, "offset", w, "offset");
336 if (soff2_dofg)
337 plombier.Connect(offes2, "offset", w, "offset2");
338 }
339 if (fg_wrtms) {
340 plombier.Connect(cleaner, "mean", w, "mean");
341 plombier.Connect(cleaner, "sigma", w, "sigma");
342 }
343
344 cout << "> Plombier status before start" << endl;
345 cout << plombier ;
346
347 cout << cleaner;
348 cout << offes;
349 if (soff2_dofg) cout << offes2;
350 cout << w;
351
352 PrtTim("starting processors");
353 plombier.Start();
354
355
356 // ------------------- Impression continu de stat ------------------------
357 if (fgprstat) {
358 ProcSampleCounter<SimpleOffsetEstimator> stats(offes);
359 stats.InfoMessage() = "aksj02/Info";
360 stats.PrintStats();
361 }
362 // -----------------------------------------------------------------------
363
364 cout << cleaner;
365 cout << offes;
366 if (soff2_dofg) cout << offes2;
367 if (gfilt_fg) cout << filt;
368 cout << w;
369
370 mgr->joinAll();
371 PrtTim("End threads");
372 if (bgalcut) delete rbgal;
373
374 }
375 catch (PThrowable & exc) {
376 cerr << "\n aksj02: Catched Exception \n" << (string)typeid(exc).name()
377 << " - Msg= " << exc.Msg() << endl;
378 }
379 catch (const std::exception & sex) {
380 cerr << "\n aksj02: Catched std::exception \n"
381 << (string)typeid(sex).name() << endl;
382 }
383 catch (...) {
384 cerr << "\n aksj02: some other exception was caught ! " << endl;
385 }
386
387 return(0);
388}
Note: See TracBrowser for help on using the repository browser.