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

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

job de demo pour utilisateur cmv 05/10/01

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