source: Sophya/trunk/ArchTOIPipe/TestPipes/simofftst.cc@ 2011

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

Correction bugs estimation offset par ajustement polynomial - Reza 16/5/2002

File size: 10.4 KB
Line 
1// ArchTOIPipe (C) CEA/DAPNIA/SPP IN2P3/LAL
2// Eric Aubourg
3// Christophe Magneville
4// Reza Ansari
5// $Id: simofftst.cc,v 1.2 2002-05-16 13:13:00 ansari Exp $
6
7/* Test de processeurs ds simtoipr.cc - Reza Avril 2001
8
9---------------- Exemple d'appel ---------------------
10csh> simofftst -start 104385384 -end 104399964 -range -500,500 \
11 -intoi boloMuV_26 -wtoi 8192 -wdegli 1024 \
12 inputbolo.fits filt.fits xx.ppf
13# Avec Filtre de Fourier
14csh> simofftst -start 104385384 -end 104399964 -range -500,500 \
15 -intoi boloMuV_26 -wtoi 8192 -wdegli 1024 \
16 -wfft 4096 -keepfft 5 -killfreq 15,4,2.5 \
17 inputbolo.fits filtfft.fits spectre.ppf
18# Autre exemple b545k02
19cool> ./simofftst -start 104389122 -end 104649122 -range -1000.,1000. -intoi boloMu
20V_23 -wtoi 8192 -wdegli 1024 -wfft 4096 -keepfft 5 -killfreq 15,4,2.5 Cmv/b545k02
212_16.00_16.49.fits b545.fits b545.ppf
22
23*/
24
25
26
27#include "machdefs.h"
28#include <math.h>
29#include <unistd.h>
30
31#include "toimanager.h"
32#include "cgt.h"
33#include "fitstoirdr.h"
34#include "fitstoiwtr.h"
35#include "simtoipr.h"
36#include "simoffset.h"
37#include "nooppr.h"
38#include "timing.h"
39#include "histinit.h"
40#include <stdexcept>
41
42void Usage(bool fgerr)
43{
44 cout << endl;
45 if (fgerr) {
46 cout << " simofftst : Argument Error ! simofftst -h for usage " << endl;
47 exit(1);
48 }
49 else {
50 cout << "\n Usage : simofftst [-intoi toiname] [-start snb] [-end sne] \n"
51 << " [-dbg] [-wtoi sz] [-wdegli sz] [-range min,max] \n"
52 << " [-degli ns,ns2,mxpt,mnpt,wrec] [-soff wsz,nptfit,degpol] \n"
53 << " [-soffnt PPFName] [-gfilt wsz,sigma] \n"
54 << " [-nooutflg] [-nowrtms] [-nowrticd] [-prstat] [-useseqbuff] \n"
55 << " inFitsName outFitsName \n"
56 << " -dbg : sets TOISeqBuffered debug level to 1 \n"
57 << " -start snb : sets the start sample num \n"
58 << " -end sne : sets the end sample num \n"
59 << " -range min,max : sets the acceptable range for intoi \n"
60 << " default= -16000,16000\n"
61 << " -intoi toiName : select input TOI name (def bolo)\n"
62 << " -wtoi sz : sets TOISeqBuff buffer size (def= 8192)\n"
63 << " -wdegli sz : sets deglitcher window size (def= 512) \n"
64 << " -degli ns,ns2,maxnpt,minnpt,wrec : sets deglitcher parameters\n"
65 << " -soff wsz,nptfit,degpol : set SimpleOffsetEstimator parameters\n"
66 << " -soffnt PPFName : Writes out SimpleOffsetEstimator NTuple \n"
67 << " -gfilt wsz,sigma : Activate gaussian filter (par= window size, sigma) \n"
68 // << " -wfft sz : Activate Fourier filter and sets its width \n"
69 // << " -keepfft n : Keeps n spectra (if Fourier filter activated) \n"
70 // << " -killfreq bf,nharm,sigf : kills nharm frequency, basefreq=bf \n"
71 // << " with a gaussian with width=sigf \n"
72 << " -nooutflg : Don't write flags to output FITS \n"
73 << " -wrtms : Write mean/sigma TOI's from Deglitcher \n"
74 << " -wrticd : Write incopie,degli TOI's from deglitcher \n"
75 << " -prstat : PrintStat with ProcSampleCounter \n"
76 << " -useseqbuff : Use TOISeqBuffered TOI's (default: TOISegmented) \n"
77 << endl;
78 }
79}
80
81int main(int narg, char** arg) {
82
83 if ((narg > 1) && (strcmp(arg[1],"-h") == 0) ) Usage(false);
84
85 cout << "simofftst 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 // Deglitcher parameters
108 double degli_ns1 = 3.;
109 double degli_ns2 = 1.5;
110 int degli_minnpt = 2;
111 int degli_maxnpt = 4;
112 int degli_wrec = 10;
113
114 // SimpleOffsetEstimator parameters
115 int soff_mwsz = 256;
116 int soff_nptfit = 5;
117 int soff_degpol = 2;
118 bool soff_nt = false;
119 string soff_nt_ppfname = "";
120
121 // Gaussian filter parameters
122 bool gfilt_fg = false;
123 int gfilt_wsz = 16;
124 double gfilt_sigma = 2.;
125
126 // File names
127 string infile;
128 string outfile;
129 string outppfname;
130 string intoi = "bolo";
131
132 bool fg_wrtflag = true;
133 bool fg_wrtms = false;
134 bool fg_wrticd = false;
135
136
137 bool fg_f_filt = false;
138 bool fg_killfreq = false;
139 int bf_killfreq = 1;
140 int nharm_killfreq = 1;
141 double sigf_killfreq = 1.;
142
143 if (narg < 4) Usage(true);
144 int ko=1;
145 // decoding arguments
146 for(int ia=1; ia<narg; ia++) {
147 if (strcmp(arg[ia],"-start") == 0) {
148 if (ia == narg-1) Usage(true); // -start est suivi d'un argument
149 istart = atoi(arg[ia+1]); ia++;
150 fgsetstart = true;
151 }
152 else if (strcmp(arg[ia],"-end") == 0) {
153 if (ia == narg-1) Usage(true);
154 iend = atoi(arg[ia+1]); ia++;
155 }
156 else if (strcmp(arg[ia],"-wtoi") == 0) {
157 if (ia == narg-1) Usage(true);
158 wtoi = atoi(arg[ia+1]); ia++;
159 }
160 else if (strcmp(arg[ia],"-wdegli") == 0) {
161 if (ia == narg-1) Usage(true);
162 wdegli = atoi(arg[ia+1]); ia++;
163 }
164 else if (strcmp(arg[ia],"-degli") == 0) {
165 if (ia == narg-1) Usage(true);
166 sscanf(arg[ia+1],"%lf,%lf,%d,%d,%d", &degli_ns1, &degli_ns2,
167 &degli_maxnpt, &degli_minnpt, &degli_wrec);
168 ia++;
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],"-gfilt") == 0) {
180 if (ia == narg-1) Usage(true);
181 sscanf(arg[ia+1],"%d,%lf", &gfilt_wsz, &gfilt_sigma);
182 gfilt_fg = true;
183 ia++;
184 }
185 else if (strcmp(arg[ia],"-wfft") == 0) {
186 if (ia == narg-1) Usage(true);
187 wfft = atoi(arg[ia+1]); ia++;
188 fg_f_filt = true;
189 }
190 else if (strcmp(arg[ia],"-keepfft") == 0) {
191 if (ia == narg-1) Usage(true);
192 keepfft = atoi(arg[ia+1]); ia++;
193 }
194 else if (strcmp(arg[ia],"-killfreq") == 0) {
195 if (ia == narg-1) Usage(true);
196 sscanf(arg[ia+1],"%d,%d,%lf",&bf_killfreq, &nharm_killfreq, &sigf_killfreq);
197 fg_killfreq = true;
198 ia++;
199 }
200 else if (strcmp(arg[ia],"-range") == 0) {
201 if (ia == narg-1) Usage(true);
202 sscanf(arg[ia+1],"%lf,%lf",&range_min, &range_max);
203 ia++;
204 }
205 else if (strcmp(arg[ia],"-intoi") == 0) {
206 if (ia == narg-1) Usage(true);
207 intoi = arg[ia+1]; ia++;
208 }
209 else if (strcmp(arg[ia],"-dbg") == 0) fgdbg = true;
210 else if (strcmp(arg[ia],"-nooutflg") == 0) fg_wrtflag = false;
211 else if (strcmp(arg[ia],"-wrtms") == 0) fg_wrtms = true;
212 else if (strcmp(arg[ia],"-wrticd") == 0) fg_wrticd = true;
213
214 else if (strcmp(arg[ia],"-prstat") == 0) fgprstat = true;
215 else if (strcmp(arg[ia],"-useseqbuff") == 0) fgsegmented = false;
216
217 else { ko = ia; break; } // Debut des noms
218 }
219
220 if (iend < istart) iend = istart+wtoi*(nmax+5);
221 if ((narg-ko) < 2) Usage(true);
222 infile = arg[ko];
223 outfile = arg[ko+1];
224 // outppfname = arg[ko+2];
225
226 cout << " Initializing SOPHYA ... " << endl;
227 SophyaInit();
228 InitTim();
229
230 cout << ">>>> simofftst: Infile= " << infile << " outFile="
231 << outfile << endl;
232 cout << ">>>> Window Size WTOI= " << wtoi << " WDEGLI= " << wdegli
233 << " iStart= " << istart << " iEnd= " << iend << endl;
234 cout << ">>>> InTOIName= " << intoi << endl;
235
236 try {
237 TOIManager* mgr = TOIManager::getManager();
238
239 // mgr->setRequestedSample(11680920,11710584);
240 // mgr->setRequestedSample(104121000, 104946120);
241 if (fgsetstart)
242 mgr->setRequestedSample(istart, iend);
243
244 cout << "> Creating FITSTOIReader object - InFile=" << infile << endl;
245 FITSTOIReader r(infile);
246
247 cout << "> Creating SimpleDeglitcher() " << endl;
248 SimpleDeglitcher degl(wdegli);
249 degl.SetDetectionParam(degli_ns1, degli_ns2, degli_maxnpt,
250 degli_minnpt, degli_wrec);
251 cout << " Setting Range for deglitcher: " << range_min
252 << " - " << range_max << endl;
253 degl.SetRange(range_min, range_max);
254
255 cout << "> Creating SimpleDeglitcher(" << soff_mwsz << "," << soff_nptfit
256 << "," << soff_degpol << ")" << endl;
257 SimpleOffsetEstimator offes(soff_mwsz, soff_nptfit, soff_degpol);
258 offes.SavePolyNTuple(soff_nt, soff_nt_ppfname);
259
260 if (gfilt_fg)
261 cout << "> Creating a GaussianFilter SimpleFilter Object " << endl;
262 double G_sigma = gfilt_sigma;
263 double G_a = 1./(G_sigma*sqrt(M_PI*2.));
264 SimpleFilter filt(gfilt_wsz, SimpleFilter::GaussFilter, G_a, G_sigma);
265
266 cout << "> Creating FITSTOIWriter OutFitsName= " << outfile << endl;
267 FITSTOIWriter w(outfile);
268
269 CGT plombier(fgsegmented, wtoi);
270 plombier.SetDebugLevel(dbglev);
271
272 cout << "> Connecting Processors through plombier ... " << endl;
273 string inname = "in";
274 plombier.Connect(r, intoi, degl, inname);
275 plombier.Connect(degl, "out", offes, "in");
276 if (gfilt_fg) {
277 plombier.Connect(offes, "out", filt, "in");
278 plombier.Connect(filt, "out", w, "degoffil", "", 0, fg_wrtflag);
279 }
280 else
281 plombier.Connect(offes, "out", w, "degoff", "", 0, fg_wrtflag);
282
283
284 if (fg_wrticd) {
285 plombier.Connect(degl, "incopie", w, "incopie");
286 plombier.Connect(offes, "incopie", w, "indegl");
287 }
288 if (fg_wrtms) {
289 plombier.Connect(degl, "mean", w, "meandegl");
290 plombier.Connect(degl, "sigma", w, "sigdegl");
291 }
292
293 cout << "> Plombier status before start" << endl;
294 cout << plombier ;
295
296 cout << offes;
297
298 PrtTim("starting processors");
299 plombier.Start();
300
301
302 // ------------------- Impression continu de stat ------------------------
303 if (fgprstat) {
304 ProcSampleCounter<SimpleOffsetEstimator> stats(offes);
305 stats.InfoMessage() = "simofftst/Info";
306 stats.PrintStats();
307 }
308 // -----------------------------------------------------------------------
309
310 cout << degl;
311 cout << offes;
312 if (gfilt_fg) cout << filt;
313 cout << w;
314
315 mgr->joinAll();
316 PrtTim("End threads");
317
318 }
319 catch (PThrowable & exc) {
320 cerr << "\n simofftst: Catched Exception \n" << (string)typeid(exc).name()
321 << " - Msg= " << exc.Msg() << endl;
322 }
323 catch (const std::exception & sex) {
324 cerr << "\n simofftst: Catched std::exception \n"
325 << (string)typeid(sex).name() << endl;
326 }
327 catch (...) {
328 cerr << "\n simofftst: some other exception was caught ! " << endl;
329 }
330
331 return(0);
332}
Note: See TracBrowser for help on using the repository browser.