source: Sophya/trunk/ArchTOIPipe/TestPipes/tgenw.cc@ 4003

Last change on this file since 4003 was 1760, checked in by aubourg, 24 years ago

salete de magique

File size: 10.7 KB
Line 
1// ArchTOIPipe (C) CEA/DAPNIA/SPP IN2P3/LAL
2// Eric Aubourg
3// Christophe Magneville
4// Reza Ansari
5// $Id: tgenw.cc,v 1.7 2001-11-13 16:01:39 aubourg Exp $
6
7/* Test de GenWindowTOIProcessor (generic processor with window)
8---------------- Exemple d'appel ---------------------
9csh> time ./tgenw -intoi bolo -start 1 -end 50000 -wgen 16,1,64 -wlcr 0,0,0 \
10 -dbg 0 toto.fits xx.fits
11*/
12
13#include "machdefs.h"
14#include <math.h>
15#include "array.h"
16#include <unistd.h>
17#include "toi.h"
18#include "toiprocessor.h"
19#include "fitstoirdr.h"
20#include "fitstoiwtr.h"
21#include "toimanager.h"
22#include "genwproc.h"
23#include "toiseqbuff.h"
24#include "timing.h"
25#include "sambainit.h"
26#include <stdexcept>
27
28// ----- Classe de test heritant de GenWindowTOIProcessor -----
29class TGenWProc : public GenWindowTOIProcessor {
30public:
31 TGenWProc(int ntoiout, int wsz, int step, int wt);
32 virtual void UserInit(int_8 kstart);
33 virtual void UserProc(int_8 ks);
34 virtual void UserEnd(int_8 kend);
35protected:
36 int_8 SNRunning;
37};
38
39TGenWProc::TGenWProc(int ntoiout,int wsz, int step, int wt)
40 : GenWindowTOIProcessor(1,ntoiout,wsz,step,wt)
41{
42 SNRunning = 1;
43}
44void TGenWProc::UserInit(int_8 kstart)
45{
46 cout << "TGenWProc::UserInit(" << kstart << ")" << endl;
47}
48void TGenWProc::UserEnd(int_8 kend)
49{
50 cout << "TGenWProc::UserEnd(" << kend << ")" << endl;
51}
52
53void TGenWProc::UserProc(int_8 ks)
54{
55 if( ks==StartSampleNum() || ks>=EndSampleNum()-1 || ks%1000==0 )
56 cout<<"TGenWProc::UserProc("<<ks<<") CenterSample="<<GetWCenterSample()<<endl;
57
58 // Test pour fichier cmv toto.fits (sn=100000+i, bolo=i)
59 r_8 * datatest = GetWDataPointer();
60 for(int_4 i=0;i<WSize;i++) {
61 int_8 k=ks-WSize/2+i;
62 if(k<SNbegin || k>SNend) continue;
63 if(datatest[i]!=k-100000) {cout<<"PROBLEME ks="<<ks<<endl; break;}
64 }
65
66 if(!NbOutput) return;
67
68 if(GetWStep()==1) {
69 // Cas ou on a un step de 1
70 r_8 data;
71 uint_8 flag;
72 GetData(ks,data,flag);
73 PutWData(ks,data,flag);
74
75 } else if(GetWStep()<GetWSize()) {
76 // Cas ou on a un step plus petit que la fenetre:
77 // on peut donc reconstituer le TOI original en sortie
78 // (ca marche aussi pour WStep==1 mais test different)
79 // ATTENTION: l'ordre d'ecriture depend de la taille relative
80 // de WSize et WStep.
81 // Il faut en plus faire attention au premier echantillon et au dernier
82 // Visiblement il faut ecrire autant de donnees en sortie que lues en entree (??)
83 // ===> Conduit a une logique d'une simplicite extreme:
84 // ATTENTION: dans certains cas ca bloque car il peut arriver que
85 // SNend ne soit jamais atteint selon les valeurs de WSize/WStep !
86 // et on ne peut donc pas ecrire autant de valeurs en sortie que lues en entree
87 TVector<r_8> data;
88 TVector<uint_8> flag;
89 int_4 ideb,ifin,isndeb;
90 if(GetWStep()<=GetWSize()/2+1) {
91 // ------|------
92 // ------|------
93 // : :
94 // WStep
95 // : :
96 // d..f
97 ideb = GetWCenterIndex();
98 isndeb = GetWCenterSample();
99 ifin = ideb + GetWStep()-1;
100 } else {
101 // ------|------
102 // ------|------
103 // : :
104 // WStep
105 // : :
106 // d.........f
107 ifin = GetWSize()-1;
108 ideb = ifin - GetWStep()+1;
109 isndeb = GetWStartSample() + ideb;
110 }
111 if(isndeb<StartSampleNum()) {
112 cout<<"........ ideb="<<ideb<<" isndeb="<<isndeb<<endl;
113 ideb = StartSampleNum() - GetWStartSample();
114 isndeb = StartSampleNum();
115 }
116 if(GetWStartSample()+ifin>EndSampleNum()) {
117 cout<<"........ ifin="<<ifin<<endl;
118 ifin = EndSampleNum() - GetWStartSample();
119 }
120 cout<<".... ideb="<<ideb<<" ifin="<<ifin<<" isndeb="<<isndeb<<endl;
121 data = GetWData()(Range(ideb,ifin));
122 flag = GetWFlag()(Range(ideb,ifin));
123 PutWData(isndeb,data,flag);
124 } else {
125 // Cas ou on ne peut reproduire le TOI initial
126 // On renumerote les samples
127 // ATTENTION: faut en mettre autant en sortie que lu en entree (???)
128 // ATTENTION: dans certains cas ca bloque car il peut arriver que
129 // SNend ne soit jamais atteint selon les valeurs de WSize/WStep !
130 // et on ne peut donc pas ecrire autant de valeurs en sortie que lues en entree
131 // CA NE MARCHE PAS DANS CE CAS
132 TVector<r_8> data;
133 TVector<uint_8> flag;
134 int_4 ideb=0, ifin=GetWSize()-1;
135 int_8 ilen = EndSampleNum() - StartSampleNum() + 1;
136 if(GetWStartSample()+ideb<StartSampleNum()) {
137 cout<<"........ ideb="<<ideb<<endl;
138 ideb = StartSampleNum() - GetWStartSample();
139 }
140 if(GetWStartSample()+ifin>EndSampleNum()) {
141 cout<<"........ ifin="<<ifin<<endl;
142 ifin = EndSampleNum() - GetWStartSample();
143 }
144 data = GetWData()(Range(ideb,ifin));
145 flag = GetWFlag()(Range(ideb,ifin));
146 cout<<".... ideb="<<ideb<<" ifin="<<ifin<<" SNRunning="<<SNRunning<<endl;
147 PutWData(SNRunning,data,flag);
148 SNRunning += ifin-ideb+1;
149 if(SNRunning<=ilen && GetWStep()-GetWSize()>0) {
150 for(int_4 i=0;i<GetWStep()-GetWSize() && SNRunning<=ilen;i++)
151 {PutWData(SNRunning,0.,0); SNRunning++;}
152 // De toute facon impossible a faire puisque
153 // ce putwdata efface le vecteur du putwdata precedent
154 }
155 cout<<".................... SNRunning="<<SNRunning<<endl;
156 }
157 // Oh que voila une logique simple et utilisable par tout un chacun !!!
158}
159
160void Usage(bool fgerr)
161{
162 cout << endl;
163 if (fgerr) {
164 cout << " tgenw : Argument Error ! tgenw -h for usage " << endl;
165 exit(1);
166 }
167 else {
168 cout << "\n Usage : tgenw [-prt] [-dbg dbg] [-start snb] [-end sne] [-intoi name] \n"
169 << " [-wtoi sz] [-wgen sz,step,szt] inFitsName outFitsName \n"
170 << " -prt : sets TOISeqBuffered debug level to 1 \n"
171 << " -dbg : debug level for GenWProc \n"
172 << " -start snb : sets the start sample num \n"
173 << " -end sne : sets the end sample num \n"
174 << " -intoi toiName : select input TOI name (def boloMuV_27)\n"
175 << " -wtoi sz : sets TOISeqBuff buffer size (def= 8192)\n"
176 << " -wgen sz,step,szt : sets GenWProc window size, step total size \n"
177 << " -wlcr szl,szc,szr : sets LCR Window \n"
178 << endl;
179 exit(0);
180 }
181}
182
183int main(int narg, char** arg) {
184
185 if ((narg > 1) && (strcmp(arg[1],"-h") == 0) ) Usage(false);
186
187 cout << "tgenw starting - Decoding arguments " << " narg=" << narg << endl;
188
189 bool fgdbg = false;
190 bool fgsetstart = false;
191 int dbglevel = 0;
192 int wtoi = 8192;
193 int wgen = 16;
194 int stepgen = 1;
195 int wgl = 0, wgc = 0, wgr = 0;
196 int wtotgen = 0;
197 int istart = 0;
198 int iend = 0;
199 string infile;
200 string outfile = "";
201 string outppfname;
202 string intoi = "boloMuV_27";
203
204 if (narg < 2) Usage(true);
205 int ko=1;
206 // decoding arguments
207 for(int ia=1; ia<narg; ia++) {
208 if (strcmp(arg[ia],"-start") == 0) {
209 if (ia == narg-1) Usage(true); // -start est suivi d'un argument
210 istart = atoi(arg[ia+1]); ia++;
211 fgsetstart = true;
212 }
213 else if (strcmp(arg[ia],"-end") == 0) {
214 if (ia == narg-1) Usage(true);
215 iend = atoi(arg[ia+1]); ia++;
216 }
217 else if (strcmp(arg[ia],"-wtoi") == 0) {
218 if (ia == narg-1) Usage(true);
219 wtoi = atoi(arg[ia+1]); ia++;
220 }
221 else if (strcmp(arg[ia],"-wgen") == 0) {
222 if (ia == narg-1) Usage(true);
223 sscanf(arg[ia+1],"%d,%d,%d",&wgen,&stepgen,&wtotgen); ia++;
224 }
225 else if (strcmp(arg[ia],"-wlcr") == 0) {
226 if (ia == narg-1) Usage(true);
227 sscanf(arg[ia+1],"%d,%d,%d",&wgl,&wgc,&wgr); ia++;
228 }
229 else if (strcmp(arg[ia],"-intoi") == 0) {
230 if (ia == narg-1) Usage(true);
231 intoi = arg[ia+1]; ia++;
232 }
233 else if (strcmp(arg[ia],"-dbg") == 0) {
234 if (ia == narg-1) Usage(true);
235 sscanf(arg[ia+1],"%d",&dbglevel); ia++;
236 }
237 else if (strcmp(arg[ia],"-prt") == 0) fgdbg = true;
238
239 else { ko = ia; break; } // Debut des noms
240 }
241
242 if (iend < istart) iend = istart+wtoi*10;
243 if ((narg-ko) < 1) Usage(true);
244 infile = arg[ko];
245 if(ko+1<narg) outfile = arg[ko+1];
246 // outppfname = arg[ko+2];
247
248 cout << " Initializing SOPHYA ... " << endl;
249 SophyaInit();
250 InitTim();
251
252 cout << ">> tgenw: Infile= " << infile << " outFile="
253 << outfile << endl;
254 cout << ">>> Window Size WTOI= " << wtoi << " WGenSz= " << wgen
255 << " StepGen=" << stepgen << " WTot=" << wtotgen
256 << " Wglcr=" << wgl << "," << wgc << "," << wgr << endl;
257 cout << ">>>> InTOIName= " << intoi
258 << " iStart= " << istart << " iEnd= " << iend << endl;
259
260 try {
261 TOIManager* mgr = TOIManager::getManager();
262
263 // mgr->setRequestedSample(11680920,11710584);
264 // mgr->setRequestedSample(104121000, 104946120);
265 if (fgsetstart)
266 mgr->setRequestedSample(istart, iend);
267
268 FITSTOIReader r(infile);
269 cout << "reader created" << endl;
270
271 int ntoiout=0;
272 FITSTOIWriter* w=NULL;
273 if(outfile.size()>0) {
274 ntoiout=1;
275 w = new FITSTOIWriter(outfile);
276 cout << "fits writer created" << endl;
277 }
278
279 TOISeqBuffered * toiin = new TOISeqBuffered("f2in", wtoi);
280 if (fgdbg) toiin->setDebugLevel(1);
281
282 TOISeqBuffered * toiout = NULL;
283 if(w) {
284 toiout = new TOISeqBuffered("genout", wtoi);
285 if (fgdbg) toiout->setDebugLevel(1);
286 }
287
288 TGenWProc tgenp(ntoiout, wgen, stepgen, wtotgen);
289 tgenp.SetWSizeLCR(wgl,wgc,wgr);
290 tgenp.SetDbgLevel(dbglevel);
291
292 cout << " Connecting to FitsReader ... " << endl;
293 r.addOutput(intoi, toiin);
294
295 if(w && toiout) {
296 cout << " Connecting to FitsWriter ... " << endl;
297 w->addInput("genout",toiout,true);
298 }
299
300 cout << " Connecting TGenWProc ... " << endl;
301 tgenp.addInput("in0",toiin);
302 if(toiout) tgenp.addOutput("out0",toiout);
303 tgenp.PrintStatus(cout);
304
305 PrtTim("starting threads");
306 r.start();
307 tgenp.start();
308 if(w) w->start();
309
310 /*
311 for(int jj=0; jj<3; jj++) {
312 cout << *toiin;
313 if(toiout) cout << *toiout;
314 sleep(1);
315 }
316 */
317
318 mgr->joinAll();
319 PrtTim("End threads");
320
321 // cout << " ------ FITSReaderTOI::PrintStatus() : ----- " << endl;
322 // r.PrintStatus(cout);
323 // cout << "----- FITSWriterTOI::PrintStatus() : ----- " << endl;
324 // w->PrintStatus(cout);
325
326 cout << " ------ toiin, toiout Status information ------- " << endl;
327 cout << *toiin;
328 if(toiout) cout << *toiout;
329 tgenp.PrintStatus(cout);
330
331 // Fermeture du fitswriter
332 if(w) delete w;;
333
334 }
335 catch (PThrowable & exc) {
336 cerr << "\n tgenw: Catched Exception \n" << (string)typeid(exc).name()
337 << " - Msg= " << exc.Msg() << endl;
338 }
339 catch (const std::exception & sex) {
340 cerr << "\n tgenw: Catched std::exception \n"
341 << (string)typeid(sex).name() << endl;
342 }
343 catch (...) {
344 cerr << "\n tgenw: some other exception was caught ! " << endl;
345 }
346
347 return(0);
348}
Note: See TracBrowser for help on using the repository browser.