source: Sophya/trunk/ArchTOIPipe/TestPipes/toistat.cc@ 2054

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

corrections pour proj ds localmap - Reza 11/6/2002

File size: 7.1 KB
Line 
1// ArchTOIPipe (C) CEA/DAPNIA/SPP IN2P3/LAL
2// Eric Aubourg
3// Christophe Magneville
4// Reza Ansari
5
6/* Calcul de statistique simples sur TOI
7
8---------------- Exemple d'appel ---------------------
9csh> toistat -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 "ntuple.h"
31#include "fitsntuple.h"
32
33#include "psighand.h"
34#include <stdexcept>
35
36void Usage(bool fgerr)
37{
38 cout << endl;
39 if (fgerr) {
40 cout << " toistat : Argument Error ! toistat -h for usage " << endl;
41 exit(1);
42 }
43 else {
44 cout << " toistat : produce a stat NTuple (mean,sigma) from a TOI" << endl;
45 cout << "\n Usage : toistat [-intoi toiname] [-start snb] [-end sne] \n"
46 << " [-wtoi sz] [-wclean wsz,nbw] [-range min,max] [-cleannsig nsig] \n"
47 << " [-outppf] [-noprstat] [-useseqbuff] \n"
48 << " inFitsName outFileName \n"
49 << " -start snb : sets the start sample num \n"
50 << " -end sne : sets the end sample num \n"
51 << " -range min,max : sets the acceptable range for intoi \n"
52 << " default= -16000,16000\n"
53 << " -intoi toiName : select input TOI name (def bolo)\n"
54 << " -wtoi sz : sets TOISeqBuff buffer size (def= 8192)\n"
55 << " -wclean wsz,nbw : sets cleaner window parameters (256,5) \n"
56 << " -cleannsig nsig : Sets cleanner ThrNSig (default = 999999.) \n"
57 << " -outppf : Write the NTuple in PPF format (default: FITS) \n"
58 << " -noprstat : DO NOT PrintStat with ProcSampleCounter \n"
59 << " -useseqbuff : Use TOISeqBuffered TOI's (default: TOISegmented) \n"
60 << endl;
61 }
62 if (fgerr) exit(1);
63}
64
65int main(int narg, char** arg) {
66
67 if ((narg > 1) && (strcmp(arg[1],"-h") == 0) ) Usage(false);
68
69 cout << "toistat starting - Decoding arguments " << " narg=" << narg << endl;
70
71 bool fgsetstart = false;
72
73 bool fgprstat = true;
74 bool fgsegmented = true;
75 bool fgoutppf = false;
76
77 int dbglev = 0;
78
79 int wtoi = 8192;
80
81 int nmax = 10;
82 int istart = 0;
83 int iend = 0;
84
85 double range_min = -16000;
86 double range_max = 16000.;
87
88 // cleaner parameters
89 int clean_wsz = 256;
90 int clean_nbw = 5;
91 double clean_nsig = 999999.;
92
93 // File names
94 string infile;
95 string outfile;
96 string intoi = "bolo";
97
98 if (narg < 3) Usage(true);
99 int ko=1;
100 // decoding arguments
101 for(int ia=1; ia<narg; ia++) {
102 if (strcmp(arg[ia],"-start") == 0) {
103 if (ia == narg-1) Usage(true); // -start est suivi d'un argument
104 istart = atoi(arg[ia+1]); ia++;
105 fgsetstart = true;
106 }
107 else if (strcmp(arg[ia],"-end") == 0) {
108 if (ia == narg-1) Usage(true);
109 iend = atoi(arg[ia+1]); ia++;
110 }
111 else if (strcmp(arg[ia],"-wtoi") == 0) {
112 if (ia == narg-1) Usage(true);
113 wtoi = atoi(arg[ia+1]); ia++;
114 }
115 else if (strcmp(arg[ia],"-wclean") == 0) {
116 if (ia == narg-1) Usage(true);
117 sscanf(arg[ia+1],"%d,%d", &clean_wsz, &clean_nbw);
118 }
119 else if (strcmp(arg[ia],"-cleannsig") == 0) {
120 if (ia == narg-1) Usage(true);
121 clean_nsig = atof(arg[ia+1]); ia++;
122 }
123 else if (strcmp(arg[ia],"-range") == 0) {
124 if (ia == narg-1) Usage(true);
125 sscanf(arg[ia+1],"%lf,%lf",&range_min, &range_max);
126 ia++;
127 }
128 else if (strcmp(arg[ia],"-intoi") == 0) {
129 if (ia == narg-1) Usage(true);
130 intoi = arg[ia+1]; ia++;
131 }
132 else if (strcmp(arg[ia],"-outppf") == 0) fgoutppf = true;
133
134 else if (strcmp(arg[ia],"-noprstat") == 0) fgprstat = false;
135 else if (strcmp(arg[ia],"-prstat") == 0) fgprstat = true;
136 else if (strcmp(arg[ia],"-useseqbuff") == 0) fgsegmented = false;
137
138 else { ko = ia; break; } // Debut des noms
139 }
140
141 if (iend < istart) iend = istart+wtoi*(nmax+5);
142 if ((narg-ko) < 2) Usage(true);
143 infile = arg[ko];
144 outfile = arg[ko+1];
145 // outppfname = arg[ko+2];
146
147 cout << " Initializing SOPHYA ... " << endl;
148 SophyaInit();
149 // SophyaConfigureSignalhandling(true);
150
151 InitTim();
152
153 cout << ">>>> toistat: Infile= " << infile << " outFile="
154 << outfile << endl;
155 cout << " iStart= " << istart << " iEnd= " << iend << endl;
156 cout << ">>>> InTOIName= " << intoi << endl;
157
158 try {
159 TOIManager* mgr = TOIManager::getManager();
160
161 // mgr->setRequestedSample(11680920,11710584);
162 // mgr->setRequestedSample(104121000, 104946120);
163 if (fgsetstart)
164 mgr->setRequestedSample(istart, iend);
165
166 cout << "> Creating FITSTOIReader object - InFile=" << infile << endl;
167 FITSTOIReader r(infile);
168
169 cout << "> Creating SimpleCleaner() " << endl;
170 SimpleCleaner cleaner(clean_wsz, clean_nbw);
171 cout << " Setting Range for cleaner: " << range_min
172 << " - " << range_max << endl;
173 cleaner.SetRange(range_min, range_max);
174 cleaner.SetCleanForMeanThrNSig(clean_nsig);
175 cleaner.FillMeanSigNTuple(true);
176
177 CGT plombier(fgsegmented, wtoi);
178 // plombier.SetDebugLevel(dbglev);
179
180 cout << "> Connecting Processors through plombier ... " << endl;
181 string inname = "in";
182 string outname = "out";
183 plombier.Connect(r, intoi, cleaner, inname);
184
185 cout << "> Plombier status before start" << endl;
186 cout << plombier ;
187
188 cout << cleaner;
189
190 PrtTim("starting processors");
191 plombier.Start();
192
193
194 // ------------------- Impression continu de stat ------------------------
195 if (fgprstat) {
196 ProcSampleCounter<SimpleCleaner> stats(cleaner);
197 stats.InfoMessage() = "toistat/Info";
198 stats.PrintStats();
199 }
200 // -----------------------------------------------------------------------
201
202 cout << cleaner;
203
204 mgr->joinAll();
205 PrtTim("End threads");
206 cleaner.GetMeanSigNTuple().Info()["TOIFILE"] = infile;
207 cleaner.GetMeanSigNTuple().Info()["TOINAME"] = intoi;
208
209 if (fgoutppf) {
210 cout << " \n --------------------------------------------------------- " << endl;
211 cout << " Saving Stats (mean-sigma) NTuple to PPF file " << outfile << endl;
212 POutPersist pos(outfile);
213 pos << cleaner.GetMeanSigNTuple();
214 cout << " \n --------------------------------------------------------- " << endl;
215 }
216 else {
217 cout << " \n --------------------------------------------------------- " << endl;
218 cout << " Saving Stats (mean-sigma NTuple to FITS file " << outfile << endl;
219 FitsOutFile fos(outfile, FitsFile::clear);
220 fos << cleaner.GetMeanSigNTuple();
221 cout << " \n --------------------------------------------------------- " << endl;
222 }
223 }
224 catch (PThrowable & exc) {
225 cerr << "\n toistat: Catched Exception \n" << (string)typeid(exc).name()
226 << " - Msg= " << exc.Msg() << endl;
227 }
228 catch (const std::exception & sex) {
229 cerr << "\n toistat: Catched std::exception \n"
230 << (string)typeid(sex).name() << endl;
231 }
232 catch (...) {
233 cerr << "\n toistat: some other exception was caught ! " << endl;
234 }
235
236 return(0);
237}
Note: See TracBrowser for help on using the repository browser.