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

Last change on this file since 1502 was 1502, checked in by cmv, 24 years ago

definition des flags pour TOI flagtoidef.h (added)
Un peu plus pour GenWindowTOIProcessor.
commit mais classe inutilisable en l'etat. cmv 18/5/2001

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