source: Sophya/trunk/ArchTOIPipe/TestPipes/tstdemopipe.cc@ 2064

Last change on this file since 2064 was 1769, checked in by ansari, 24 years ago

compil sur SGI-CC - Reza 15/11/01

File size: 13.5 KB
Line 
1/**************************************************************
2 >>>>>>>> usage: tstdemo [snum1,snum2]
3 Test et demonstration du Pipe.
4 "demo1.fits": fits table avec sampleNum,boloMuV_10,fg_boloMuV_10,boloMuV_20
5 samplenum=[100001,105000]
6 "demo2.fits": fits table avec sampleNum,boloMuV_30,fg_boloMuV_30
7 samplenum=[100101,105100]
8 Operation: sortir un fichier "demo.fits" ou on ecrit:
9 Toutes les donnees des 2 fichiers d'entree ET :
10 boloSum = boloMuV_10 + boloMuV_20 + boloMuV_30
11 fg_boloSum = fg_boloMuV_10 | fg_boloMuV_20 | fg_boloMuV_30
12 boloMul = boloMuV_10 * boloMuV_20 * boloMuV_30
13 fg_boloMul = fg_boloMuV_10 | fg_boloMuV_20 | fg_boloMuV_30
14
15 Structure:
16
17 demo1.fits demo2.fits
18 | |
19 ---------- ----------
20 | Reader | | Reader |
21 | rfits1 | | rfits2 |
22 ---------- ----------
23 "boloMuV_10" "boloMuV_20" "boloMuV_30"
24 | | |
25 t| t| t|
26 u| u| u|
27 y| y| y|
28 a| a| a|
29 u| u| u|
30 | | |
31 b| b| b|
32 o| o| o|
33 l| l| l|
34 o| o| o|
35 | | |
36 1| 2| 3|
37 0| 0| 0|
38 | | |
39 | | |
40 /| /| /|
41 / | / | / |
42 / | / | / |
43 / | / | / |
44 / | / | / |
45 _____/ | / | / |
46 |_________ | ____/ | / /
47 |||_______ | __________ | ___________________/ /
48 ||| | | /
49 ||| | | /
50 ||| | | /
51 ||| | / /
52 ||| | / /
53 ||| | _______/ /
54 ||| / / ___________________/
55 ||| / / ________/
56 ||| / / /_________________________________
57 ||| / / / | DemoPipe Processor: |
58 ||| / / / | =================== |
59 ||| / / |---| entree_bolo_3 |
60 ||| | | | sortie_bolo_sum |_______
61 ||| | |-------| entree_bolo_2 | |
62 ||| | | sortie_bolo_mul | ___ |
63 ||| |---------| entree_bolo_1 | | |
64 ||| |_______________________________| | |
65 ||| | |
66 ||| | |
67 ||| --------------- | |
68 ||| | | | |
69 |||--------"boloMuv_30" | Writter | "boloMul" -- |
70 ||---------"boloMuv_20" | rfitsw | "boloSum" ------
71 |----------"boloMuV_10" | |
72 ---------------
73 |
74 demo.fits
75
76**************************************************************/
77
78#include "toi.h"
79#include "toiprocessor.h"
80#include "fitstoirdr.h"
81#include "fitstoiwtr.h"
82#include "toimanager.h"
83#include "toisegment.h"
84#include "sophyainit.h"
85#include <stdexcept>
86
87void crefits(void); // Juste pour le test, rien a voir avec TOI
88
89////////////////////////////////////////////////////////////////
90// Le INCLUDE de la classe du processeur (peut etre mis a part)
91class DemoPipe : public TOIProcessor {
92public:
93 DemoPipe(void);
94 virtual ~DemoPipe();
95
96 virtual void init(void);
97 virtual void run(void);
98
99 void PrintStatus(::ostream & os);
100
101 inline int_8 ProcessedSampleCount() const {return totnscount;}
102protected:
103 int_8 nread,nwrite,totnscount;
104};
105
106////////////////////////////////////////////////////////////////
107// Le code de la classe du processeur (peut etre mis a part)
108DemoPipe::DemoPipe(void)
109: nread(0), nwrite(0),totnscount(0)
110{
111}
112
113DemoPipe::~DemoPipe()
114{
115}
116
117void DemoPipe::PrintStatus(::ostream & os)
118{
119 os<<"DemoPipe::Print -- nread = "<<nread<<endl
120 <<" -- nwrite = "<<nwrite<<endl;
121}
122
123void DemoPipe::init() {
124 // Declaration des tuyaux a connecter. L'ordre de declaration compte!
125 cout << "DemoPipe::init" << endl;
126 declareInput("entree_bolo_1"); // input index 0
127 declareInput("entree_bolo_2"); // input index 1
128 declareInput("entree_bolo_3"); // input index 2
129 declareOutput("sortie_bolo_sum"); // output index 0
130 declareOutput("sortie_bolo_mul"); // output index 1
131}
132
133void DemoPipe::run()
134{
135 // Verification des connections en entree
136 if(!checkInputTOIIndex(0) || !checkInputTOIIndex(1) || !checkInputTOIIndex(2)) {
137 cout<<"DemoPipe::run() - Input TOI (entree_bolo_1/2/3) not connected! "<<endl;
138 throw ParmError("DemoPipe::run() Output TOI (entree_bolo_1/2/3) not connected!");
139 }
140
141 // Verification des connections en sortie
142 if(!checkOutputTOIIndex(0) || !checkOutputTOIIndex(1)) {
143 cout<<"DemoPipe::run() - Output TOI (boloSum/Mul) not connected! "<<endl;
144 throw ParmError("DemoPipe::run() Output TOI (boloSum/Mul) not connected!");
145 }
146
147 // On recupere les sample numbers
148 int snb = getMinIn();
149 int sne = getMaxIn();
150 cout<<"DemoPipe::run: sn="<<snb<<" sne="<<sne<<endl;
151 if(snb>sne) {
152 cout<<"DemoPipe::run() - Bad sample interval"<<snb<<" , "<<sne<<endl;
153 throw ParmError("DemoPipe::run() - Bad sample interval ");
154 }
155
156 //---------------------------------------------------------
157 uint_8 flb1,flb2,flb3,flbs,flbm;
158 double b1,b2,b3,bs,bm;
159
160 for(int k=snb;k<=sne;k++) {
161 totnscount++;
162
163 getData(0,k,b1,flb1);
164 getData(1,k,b2,flb2);
165 getData(2,k,b3,flb3);
166 nread++;
167
168 bs = b1 + b2 + b3;
169 flbs = flb1 | flb2 | flb3;
170 bm = b1 * b2 * b3;
171 flbm = flb1 | flb2 | flb3;
172 /*
173 cout<<"b1="<<b1<<" flb1 "<<flb1
174 <<" / b2="<<b2<<" flb2 "<<flb2
175 <<" / b3="<<b3<<" flb3 "<<flb3<<endl;
176 cout<<"...bs="<<bs<<" flbs "<<flbs<<" bm="<<bm<<" flbm "<<flbm<<endl;
177 */
178
179 putData(0,k,bs,flbs);
180 putData(1,k,bm,flbm);
181 nwrite++;
182 }
183 cout<<"DemoPipe::run: end"<<endl;
184}
185
186
187////////////////////////////////////////////////////////////////
188////////////////////////////////////////////////////////////////
189////////////////////////////////////////////////////////////////
190////////////////////////////////////////////////////////////////
191// Le main program
192int main(int narg, char** arg)
193{
194 // Initialisation de Sophya
195 SophyaInit();
196
197 // Creation des fichiers fits utilises par la demo (Rien a voir avec le Pipe!)
198 crefits();
199
200 // Ouverture du gestionnaire de TOI.
201 TOIManager* mgr = TOIManager::getManager();
202
203 // Selection eventuelle des sample num a traiter
204 long sdeb=1,sfin=-1;
205 if(narg>1) sscanf(arg[1],"%ld,%ld",&sdeb,&sfin);
206 if(sfin>=sdeb) mgr->setRequestedSample(sdeb,sfin);
207
208 //--------------------------------------------------------------------
209 try { // On met tous ca dans un bloc "try" pour recuperer les exceptions
210 //--------------------------------------------------------------------
211
212 ////////////////////////////////////////////////////////
213 //////// Creation des lecteurs de fichiers fits ////////
214 ////////////////////////////////////////////////////////
215
216 // FITS reader du premier fichier
217 FITSTOIReader rfits1("demo1.fits");
218 int ncol1 = rfits1.getNOut();
219 cout<<"Lecteur_1: Number of columns in fits : "<<ncol1<<endl;
220 if(ncol1<1) exit(-1);
221
222 // FITS reader du deuxieme fichier
223 FITSTOIReader rfits2("demo2.fits");
224 int ncol2 = rfits2.getNOut();
225 cout<<"Lecteur_2: Number of columns in fits : "<<ncol2<<endl;
226 if(ncol1<2) exit(-1);
227
228 /////////////////////////////////////////////////////////
229 //////// Creation de l'ecriveur de fichiers fits ////////
230 /////////////////////////////////////////////////////////
231
232 FITSTOIWriter wfits("!demo.fits");
233 cout<<"Ecriveur: created"<<endl;
234
235 ////////////////////////////////////////////////////
236 //////// Creation du (/des) TOI processeurs ////////
237 ////////////////////////////////////////////////////
238
239 DemoPipe demo;
240
241 //////////////////////////////////////////////////////////////////
242 //////// Creation des tuyaux et des connections associees ////////
243 //////////////////////////////////////////////////////////////////
244
245 int taille = 8192;
246 bool writeflag;
247
248 // tuyau bolo10 pour entree processeur
249 TOISegmented * bolo10 = new TOISegmented("tuyau_bolo_10",taille);
250 // connection a la colonne correspondante du lecteur fits
251 rfits1.addOutput("boloMuV_10",bolo10);
252 // connection a l'entree correspondante du processeur
253 demo.addInput("entree_bolo_1",bolo10);
254 // connection directe a l'ecriveur
255 writeflag = true;
256 wfits.addInput("boloMuV_10",bolo10,writeflag);
257
258 // tuyau bolo20 pour entree processeur (idem cf au dessus)
259 TOISegmented * bolo20 = new TOISegmented("tuyau_bolo_20",taille);
260 rfits1.addOutput("boloMuV_20",bolo20);
261 demo.addInput("entree_bolo_2",bolo20);
262 writeflag = false;
263 wfits.addInput("boloMuV_20",bolo20,writeflag);
264
265 // tuyau bolo30 pour entree processeur (idem cf au dessus)
266 TOISegmented * bolo30 = new TOISegmented("tuyau_bolo_30",taille);
267 rfits2.addOutput("boloMuV_30",bolo30);
268 demo.addInput("entree_bolo_3",bolo30);
269 writeflag = true;
270 wfits.addInput("boloMuV_30",bolo30,writeflag);
271
272 // tuyau bolosum pour sortie processeur
273 TOISegmented * bolosum = new TOISegmented("tuyau_bolo_sum",taille);
274 demo.addOutput("sortie_bolo_sum",bolosum);
275 writeflag = true;
276 wfits.addInput("boloSum",bolosum,writeflag);
277
278 // tuyau bolomul pour sortie processeur
279 TOISegmented * bolomul = new TOISegmented("tuyau_bolo_mul",taille);
280 demo.addOutput("sortie_bolo_mul",bolomul);
281 writeflag = true;
282 wfits.addInput("boloMul",bolomul,writeflag);
283
284 // Print de status avant lancement des taches:
285 cout<<"----- FITSReaderTOI::PrintStatus() 1 : -----"<<endl;
286 rfits1.PrintStatus(cout);
287 cout<<"----- FITSReaderTOI::PrintStatus() 2 : -----"<<endl;
288 rfits2.PrintStatus(cout);
289 cout<<"----- FITSWriterTOI::PrintStatus() : -----"<<endl;
290 wfits.PrintStatus(cout);
291 cout<<"----- TOISegmented::PrintStatus() : -----"<<endl;
292 bolo10->PrintStatus(cout);
293 bolo20->PrintStatus(cout);
294 bolo30->PrintStatus(cout);
295 cout<<"----- DemoPipe::PrintStatus() : -----"<<endl;
296 demo.PrintStatus(cout);
297
298 //////////////////////////////////////
299 //////// Lancement des taches ////////
300 //////////////////////////////////////
301
302 rfits1.start();
303 rfits2.start();
304 wfits.start();
305 demo.start();
306
307 // Affichage de l'avancement des TOIProcessors (optionnel)
308 // ProcSampleCounter<FITSTOIReader> statr(rfits1);
309 // statr.InfoMessage() = "tstdemopipe/Info rfits1";
310 // statr.PrintStats();
311
312 // ProcSampleCounter<FITSTOIWriter> statw(wfits);
313 // statw.InfoMessage() = "tstdemopipe/Info wfits";
314 // statw.PrintStats();
315
316 // ProcSampleCounter<DemoPipe> statp(demo);
317 // statp.InfoMessage() = "tstdemopipe/Info DemoPipe";
318 // statp.PrintStats();
319
320 // Gestion de la re-connection des threads
321 mgr->joinAll();
322 cout<<"End threads"<<endl;
323
324 //--------------------------------------------------------------------
325 // Que fait on avec les exceptions qui ont ete lancees ?
326 } catch (PThrowable & exc) { // Sophya exceptions
327 cout<<"\ntstdemopipe: Catched Exception \n"<<(string)typeid(exc).name()
328 <<" - Msg= "<<exc.Msg()<<endl;
329 } catch (const std::exception & sex) { // Standard exceptions
330 cout<<"\ntstdemopipe: Catched std::exception \n"
331 <<(string)typeid(sex).name()<<endl;
332 } catch (...) { // Other exceptions
333 cout<<"\ntstdemopipe: some other exception was caught ! "<<endl;
334 }
335 //--------------------------------------------------------------------
336
337 return(0);
338}
339
340
341///////////////////////////////////////////////////////////
342//////// Just for the test, NOT CONNECTED WITH THE PIPE !
343///////////////////////////////////////////////////////////
344#include "srandgen.h"
345#include "fabtwriter.h"
346void crefits(void)
347{
348 const long nro = 500000;
349 const long sn1 = 1000001;
350 const long sn2 = 1000001+100;
351 FitsABTWriter fw1("!demo1.fits",BINARY_TBL);
352 fw1.SetExtName("MON_EXTENSION1");
353 fw1.AddCol("sampleNum",NULL,"integer",TDOUBLE);
354 fw1.AddCol("boloMuV_10",NULL,"double",TDOUBLE);
355 fw1.AddCol("fg_boloMuV_10",NULL,"UInt_8Flag",TLONG);
356 fw1.AddCol("boloMuV_20",NULL,"double",TDOUBLE);
357 //fw1.AddCol("fg_boloMuV_20",NULL,"UInt_8Flag",TLONG);
358 long i;
359 for(i=0;i<nro;i++) {
360 fw1.Write(0,i,(double) sn1+i);
361 fw1.Write(1,i,10.+NorRand());
362 fw1.Write(2,i,((frand01()<0.5) ? 1: 0)); // 1 pt/10 flaggue
363 fw1.Write(3,i,20.+NorRand());
364 //fw1.Write(4,i,((frand01()<0.5) ? 2: 0)); // 1 pt/10 flaggue
365 }
366
367 FitsABTWriter fw2("!demo2.fits",BINARY_TBL);
368 fw2.SetExtName("MON_EXTENSION2");
369 fw2.AddCol("sampleNum",NULL,"integer",TDOUBLE);
370 fw2.AddCol("boloMuV_30",NULL,"double",TDOUBLE);
371 fw2.AddCol("fg_boloMuV_30",NULL,"UInt_8Flag",TLONG);
372 for(i=0;i<nro;i++) {
373 fw2.Write(0,i,(double) sn2+i);
374 fw2.Write(1,i,30.+NorRand());
375 fw2.Write(2,i,((frand01()<0.5) ? 4: 0));
376 }
377}
Note: See TracBrowser for help on using the repository browser.