source: Sophya/trunk/ArchTOIPipe/TestPipes/tstringpipe.cc@ 2414

Last change on this file since 2414 was 2390, checked in by cecile, 22 years ago

ca compile !

File size: 8.8 KB
Line 
1#include <unistd.h>
2#include "toi.h"
3#include "cgt.h"
4#include "toiprocessor.h"
5#include "toimanager.h"
6#ifdef TOISEQBUFFERED
7#include "toiseqbuff.h"
8#else
9#include "toisegment.h"
10#endif
11
12#include "sambainit.h"
13#include "timing.h"
14#include <stdexcept>
15#include "ring.h"
16#include "ringpipe.h"
17#include "ringprocessor.h"
18
19////////////////////////////////////////////////////////////////
20// Le INCLUDE de la classe du processeur (peut etre mis a part)
21////////////////////////////////////////////////////////////////
22////////////////////////////////////////////////////////////////
23////////////////////////////////////////////////////////////////
24////////////////////////////////////////////////////////////////
25class CreateRing : public RingProcessor {
26public:
27 CreateRing(int nsamples, double theta, double phi, double aperture);
28 virtual ~CreateRing();
29
30 virtual void init(void);
31 virtual void run(void);
32
33 void PrintStatus(::ostream & os);
34
35 inline int_8 ProcessedSampleCount() const {return totnscount;}
36protected:
37 Ring r;
38 int_8 nread,nwrite,totnscount;
39};
40
41CreateRing::CreateRing(int nsamples, double theta, double phi, double aperture)
42: r(nsamples,theta,phi,aperture),nread(0), nwrite(0),totnscount(0)
43{
44}
45
46CreateRing::~CreateRing()
47{
48}
49
50void CreateRing::PrintStatus(::ostream & os)
51{
52 os<<"CreateRing::Print -- nread = "<<nread<<endl
53 <<" -- nwrite = "<<nwrite<<endl;
54}
55
56void CreateRing::init() {
57// - 2 ringprocessors qui fabriquent des rings de bruit
58// - 1 ringprocessor qui les ajoute
59// - 1 ring processor qui les affiche
60
61
62
63 // Declaration des tuyaux a connecter. L'ordre de declaration compte!
64 cout << "CreateRing::init" << endl;
65 declareRingOutput("sortie_bolo"); // output index 0
66}
67
68void CreateRing::run()
69{
70
71 // Verification des connections en sortie
72 if(!getOutputRing(0) ) {
73 cout<<"CreateRing::run() - Output TOI (boloSum/Mul) not connected! "<<endl;
74 throw ParmError("CreateRing::run() Output TOI (boloSum/Mul) not connected!");
75 }
76
77 //---------------------------------------------------------
78
79 for(int k=0;k<=r.getNSamples();k++) {
80 totnscount++;
81 r.setData(k,0.1*k);
82 nwrite++;
83 putRing(0,k,&r);
84 }
85
86 cout<<"CreateRing::run: end"<<endl;
87}
88
89////////////////////////////////////////////////////////////////
90////////////////////////////////////////////////////////////////
91////////////////////////////////////////////////////////////////
92////////////////////////////////////////////////////////////////
93
94
95class AddRing : public RingProcessor {
96public:
97 AddRing(double coef);
98 virtual ~AddRing();
99
100 virtual void init(void);
101 virtual void run(void);
102
103 void PrintStatus(::ostream & os);
104
105 inline int_8 ProcessedSampleCount() const {return totnscount;}
106protected:
107 int_8 nread,nwrite,totnscount;
108 double Coef;
109
110};
111
112////////////////////////////////////////////////////////////////
113// Le code de la classe du processeur (peut etre mis a part)
114AddRing::AddRing(double coef)
115 : nread(0), nwrite(0),totnscount(0),Coef(coef)
116{
117}
118
119AddRing::~AddRing()
120{
121}
122
123void AddRing::PrintStatus(::ostream & os)
124{
125 os<<"AddRing::Print -- nread = "<<nread<<endl
126 <<" -- nwrite = "<<nwrite<<endl;
127}
128
129void AddRing::init() {
130// - 2 ringprocessors qui fabriquent des rings de bruit
131// - 1 ringprocessor qui les ajoute
132// - 1 ring processor qui les affiche
133
134
135
136 // Declaration des tuyaux a connecter. L'ordre de declaration compte!
137 cout << "AddRing::init" << endl;
138 declareRingInput("entree_bolo_1"); // input index 0
139 declareRingInput("entree_bolo_2"); // input index 1
140 declareRingOutput("sortie_bolo_sum"); // output index 0
141}
142
143void AddRing::run()
144{
145// // Verification des connections en entree
146 if(!getInputRing(0) || !getInputRing(1) ) {
147 cout<<"AddRing::run() - Input TOI (entree_bolo_1/2/3) not connected! "<<endl;
148 throw ParmError("AddRing::run() Output TOI (entree_bolo_1/2/3) not connected!");
149 }
150
151 // Verification des connections en sortie
152 if(!getOutputRing(0) ) {
153 cout<<"AddRing::run() - Output TOI (boloSum/Mul) not connected! "<<endl;
154 throw ParmError("AddRing::run() Output TOI (boloSum/Mul) not connected!");
155 }
156
157 // On recupere les sample numbers
158 int snb,sne;
159 getRingRange(snb,sne);
160
161 cout<<"AddRing::run: sn="<<snb<<" sne="<<sne<<endl;
162 if(snb>sne) {
163 cout<<"AddRing::run() - Bad sample interval"<<snb<<" , "<<sne<<endl;
164 throw ParmError("AddRing::run() - Bad sample interval ");
165 }
166
167 //---------------------------------------------------------
168 Ring const *r1,*r2;
169
170 for(int k=snb;k<=sne;k++) {
171 totnscount++;
172
173 r1 = getRing(0,k);
174 r2 = getRing(1,k);
175 nread++;
176 }
177
178 Ring r(r1->getNSamples(),r1->getTheta(),r1->getPhi(),r1->getAperture());
179 for(int k=snb;k<=sne;k++) {
180 r.setData(k, r1->getData(k) + Coef * r2->getData(k));
181 putRing(0,k,&r);
182 nwrite++;
183 }
184 cout<<"AddRing::run: end"<<endl;
185}
186
187
188
189////////////////////////////////////////////////////////////////
190////////////////////////////////////////////////////////////////
191////////////////////////////////////////////////////////////////
192////////////////////////////////////////////////////////////////
193class PrintRing : public RingProcessor {
194public:
195 PrintRing(int toto);
196 virtual ~PrintRing();
197
198 virtual void init(void);
199 virtual void run(void);
200
201 void PrintStatus(::ostream & os);
202
203 inline int_8 ProcessedSampleCount() const {return totnscount;}
204protected:
205 int_8 nread,nwrite,totnscount,truc;
206};
207
208PrintRing::PrintRing(int toto)
209 : nread(0), nwrite(0),totnscount(0),truc(toto)
210{
211}
212
213PrintRing::~PrintRing()
214{
215}
216
217void PrintRing::PrintStatus(::ostream & os)
218{
219 os<<"PrintRing::Print -- nread = "<<nread<<endl
220 <<" -- nwrite = "<<nwrite<<endl;
221}
222
223void PrintRing::init() {
224// - 2 ringprocessors qui fabriquent des rings de bruit
225// - 1 ringprocessor qui les ajoute
226// - 1 ring processor qui les affiche
227
228
229
230 // Declaration des tuyaux a connecter. L'ordre de declaration compte!
231 cout << "PrintRing::init" << endl;
232 declareRingInput("entree_bolo"); // output index 0
233}
234
235void PrintRing::run()
236{
237
238 // Verification des connections en sortie
239 if(!getInputRing(0) ) {
240 cout<<"PrintRing::run() - Input TOI not connected! "<<endl;
241 throw ParmError("PrintRing::run() Input TOI not connected!");
242 }
243
244 //---------------------------------------------------------
245 int min,max;
246 getRingRange(min,max);
247
248 for(int k=min;k<=max;k++) {
249 totnscount++;
250 cout << k << " " << getRing(0,k);
251 nwrite++;
252 }
253 cout<<"PrintRing::run: end"<<endl;
254}
255
256
257////////////////////////////////////////////////////////////////
258////////////////////////////////////////////////////////////////
259////////////////////////////////////////////////////////////////
260////////////////////////////////////////////////////////////////
261void usage(void);
262void usage(void) {
263 cout<<"tstringpipe ";
264 cout<<" "<<endl;
265 return;
266}
267
268////////////////////////////////////////////////////////////////
269int main(int narg, char** arg) {
270
271TOIManager* mgr = TOIManager::getManager();
272
273//-- Decodage arguments
274
275SophyaInit();
276InitTim();
277
278//--------------------------------------------------------------------
279try {
280//--------------------------------------------------------------------
281
282// bool fgsegmented = true;
283// int wsize = 512;
284// CGT plombier(fgsegmented,wsize);
285// plombier.SetDebugLevel(99);
286
287 // FITS reader et writer
288 int nsamples=1024;
289
290 double theta = 12.;
291 double phi = 0.;
292 double aperture = 85.;
293 cout << " CREATIONS PROCESSORS " << endl;
294 CreateRing cr1(nsamples,theta,phi,aperture);
295 CreateRing cr2(nsamples,theta,phi,aperture);
296 AddRing addring(1.);
297 PrintRing p(0);
298
299 cout << " RING PIPES " << endl;
300 RingPipe *ring1;
301 RingPipe *ring2;
302 RingPipe *ring3;
303 cout << " BRANCHEMENTS " << endl;
304 cr1.addRingOutput("sortie_bolo", ring1);
305 cr2.addRingOutput("sortie_bolo", ring2);
306 addring.addRingInput("entree_bolo_1",ring1);
307 addring.addRingInput("entree_bolo_2",ring2);
308 addring.addRingOutput("sortie_bolo_sum",ring3);
309 p.addRingInput("entree_bolo",ring3);
310
311 cout << " PRINT STATUS " << endl;
312 cr1.PrintStatus(cout);
313 cr2.PrintStatus(cout);
314 addring.PrintStatus(cout);
315 p.PrintStatus(cout);
316
317 cr1.start();
318 cr2.start();
319 addring.start();
320 p.start();
321
322// plombier.Connect(cr1,"sortie_bolo",AddRing,"entree_bolo_1");
323// plombier.Connect(cr2,"sortie_bolo",AddRing,"entree_bolo_2");
324// plombier.Connect(AddRing,"sortie_bolo_sum",PrintRing,"entree_bolo");
325// plombier.Start();
326// plombier.ListTOIs(cout, 1);
327 cout << "Joining ..." << endl;
328
329 mgr->joinAll();
330 PrtTim("End threads");
331
332//--------------------------------------------------------------------
333} catch (PThrowable & exc) {
334 cout<<"\ntsttoi2ring: Catched Exception \n"<<(string)typeid(exc).name()
335 <<" - Msg= "<<exc.Msg()<<endl;
336} catch (const std::exception & sex) {
337 cout<<"\ntsttoi2ring: Catched std::exception \n"
338 <<(string)typeid(sex).name()<<endl;
339} catch (...) {
340 cout<<"\ntsttoi2ring: some other exception was caught ! "<<endl;
341}
342//--------------------------------------------------------------------
343
344exit(0);
345}
Note: See TracBrowser for help on using the repository browser.