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

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

Ajout programme toistat.cc - TOI 2 StatNTuple(Mean-sigma) - Reza 10/6/2002

File size: 6.8 KB
RevLine 
[2047]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] \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 << " -outppf : Write the NTuple in PPF format (default: FITS) \n"
57 << " -noprstat : DO NOT PrintStat with ProcSampleCounter \n"
58 << " -useseqbuff : Use TOISeqBuffered TOI's (default: TOISegmented) \n"
59 << endl;
60 }
61 if (fgerr) exit(1);
62}
63
64int main(int narg, char** arg) {
65
66 if ((narg > 1) && (strcmp(arg[1],"-h") == 0) ) Usage(false);
67
68 cout << "toistat starting - Decoding arguments " << " narg=" << narg << endl;
69
70 bool fgsetstart = false;
71
72 bool fgprstat = true;
73 bool fgsegmented = true;
74 bool fgoutppf = false;
75
76 int dbglev = 0;
77
78 int wtoi = 8192;
79
80 int nmax = 10;
81 int istart = 0;
82 int iend = 0;
83
84 double range_min = -16000;
85 double range_max = 16000.;
86
87 // cleaner parameters
88 int clean_wsz = 256;
89 int clean_nbw = 5;
90
91 // File names
92 string infile;
93 string outfile;
94 string intoi = "bolo";
95
96 if (narg < 3) Usage(true);
97 int ko=1;
98 // decoding arguments
99 for(int ia=1; ia<narg; ia++) {
100 if (strcmp(arg[ia],"-start") == 0) {
101 if (ia == narg-1) Usage(true); // -start est suivi d'un argument
102 istart = atoi(arg[ia+1]); ia++;
103 fgsetstart = true;
104 }
105 else if (strcmp(arg[ia],"-end") == 0) {
106 if (ia == narg-1) Usage(true);
107 iend = atoi(arg[ia+1]); ia++;
108 }
109 else if (strcmp(arg[ia],"-wtoi") == 0) {
110 if (ia == narg-1) Usage(true);
111 wtoi = atoi(arg[ia+1]); ia++;
112 }
113 else if (strcmp(arg[ia],"-wclean") == 0) {
114 if (ia == narg-1) Usage(true);
115 sscanf(arg[ia+1],"%d,%d", &clean_wsz, &clean_nbw);
116 }
117 else if (strcmp(arg[ia],"-range") == 0) {
118 if (ia == narg-1) Usage(true);
119 sscanf(arg[ia+1],"%lf,%lf",&range_min, &range_max);
120 ia++;
121 }
122 else if (strcmp(arg[ia],"-intoi") == 0) {
123 if (ia == narg-1) Usage(true);
124 intoi = arg[ia+1]; ia++;
125 }
126 else if (strcmp(arg[ia],"-outppf") == 0) fgoutppf = true;
127
128 else if (strcmp(arg[ia],"-noprstat") == 0) fgprstat = false;
129 else if (strcmp(arg[ia],"-useseqbuff") == 0) fgsegmented = false;
130
131 else { ko = ia; break; } // Debut des noms
132 }
133
134 if (iend < istart) iend = istart+wtoi*(nmax+5);
135 if ((narg-ko) < 2) Usage(true);
136 infile = arg[ko];
137 outfile = arg[ko+1];
138 // outppfname = arg[ko+2];
139
140 cout << " Initializing SOPHYA ... " << endl;
141 SophyaInit();
142 // SophyaConfigureSignalhandling(true);
143
144 InitTim();
145
146 cout << ">>>> toistat: Infile= " << infile << " outFile="
147 << outfile << endl;
148 cout << " iStart= " << istart << " iEnd= " << iend << endl;
149 cout << ">>>> InTOIName= " << intoi << endl;
150
151 try {
152 TOIManager* mgr = TOIManager::getManager();
153
154 // mgr->setRequestedSample(11680920,11710584);
155 // mgr->setRequestedSample(104121000, 104946120);
156 if (fgsetstart)
157 mgr->setRequestedSample(istart, iend);
158
159 cout << "> Creating FITSTOIReader object - InFile=" << infile << endl;
160 FITSTOIReader r(infile);
161
162 cout << "> Creating SimpleCleaner() " << endl;
163 SimpleCleaner cleaner(clean_wsz, clean_nbw);
164 cout << " Setting Range for cleaner: " << range_min
165 << " - " << range_max << endl;
166 cleaner.SetRange(range_min, range_max);
167 cleaner.FillMeanSigNTuple(true);
168
169 CGT plombier(fgsegmented, wtoi);
170 // plombier.SetDebugLevel(dbglev);
171
172 cout << "> Connecting Processors through plombier ... " << endl;
173 string inname = "in";
174 string outname = "out";
175 plombier.Connect(r, intoi, cleaner, inname);
176
177 cout << "> Plombier status before start" << endl;
178 cout << plombier ;
179
180 cout << cleaner;
181
182 PrtTim("starting processors");
183 plombier.Start();
184
185
186 // ------------------- Impression continu de stat ------------------------
187 if (fgprstat) {
188 ProcSampleCounter<SimpleCleaner> stats(cleaner);
189 stats.InfoMessage() = "toistat/Info";
190 stats.PrintStats();
191 }
192 // -----------------------------------------------------------------------
193
194 cout << cleaner;
195
196 mgr->joinAll();
197 PrtTim("End threads");
198 cleaner.GetMeanSigNTuple().Info()["TOIFILE"] = infile;
199 cleaner.GetMeanSigNTuple().Info()["TOINAME"] = intoi;
200
201 if (fgoutppf) {
202 cout << " \n --------------------------------------------------------- " << endl;
203 cout << " Saving Stats (mean-sigma) NTuple to PPF file " << outfile << endl;
204 POutPersist pos(outfile);
205 pos << cleaner.GetMeanSigNTuple();
206 cout << " \n --------------------------------------------------------- " << endl;
207 }
208 else {
209 cout << " \n --------------------------------------------------------- " << endl;
210 cout << " Saving Stats (mean-sigma NTuple to FITS file " << outfile << endl;
211 FitsOutFile fos(outfile, FitsFile::clear);
212 fos << cleaner.GetMeanSigNTuple();
213 cout << " \n --------------------------------------------------------- " << endl;
214 }
215 }
216 catch (PThrowable & exc) {
217 cerr << "\n toistat: Catched Exception \n" << (string)typeid(exc).name()
218 << " - Msg= " << exc.Msg() << endl;
219 }
220 catch (const std::exception & sex) {
221 cerr << "\n toistat: Catched std::exception \n"
222 << (string)typeid(sex).name() << endl;
223 }
224 catch (...) {
225 cerr << "\n toistat: some other exception was caught ! " << endl;
226 }
227
228 return(0);
229}
Note: See TracBrowser for help on using the repository browser.