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

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

Cecile ... marche presque !

File size: 8.3 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(void);
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};
109
110////////////////////////////////////////////////////////////////
111// Le code de la classe du processeur (peut etre mis a part)
112AddRing::AddRing(void)
113: nread(0), nwrite(0),totnscount(0)
114{
115}
116
117AddRing::~AddRing()
118{
119}
120
121void AddRing::PrintStatus(::ostream & os)
122{
123 os<<"AddRing::Print -- nread = "<<nread<<endl
124 <<" -- nwrite = "<<nwrite<<endl;
125}
126
127void AddRing::init() {
128// - 2 ringprocessors qui fabriquent des rings de bruit
129// - 1 ringprocessor qui les ajoute
130// - 1 ring processor qui les affiche
131
132
133
134 // Declaration des tuyaux a connecter. L'ordre de declaration compte!
135 cout << "AddRing::init" << endl;
136 declareRingInput("entree_bolo_1"); // input index 0
137 declareRingInput("entree_bolo_2"); // input index 1
138 declareRingOutput("sortie_bolo_sum"); // output index 0
139}
140
141void AddRing::run()
142{
143// // Verification des connections en entree
144 if(!getInputRing(0) || !getInputRing(1) ) {
145 cout<<"AddRing::run() - Input TOI (entree_bolo_1/2/3) not connected! "<<endl;
146 throw ParmError("AddRing::run() Output TOI (entree_bolo_1/2/3) not connected!");
147 }
148
149 // Verification des connections en sortie
150 if(!getOutputRing(0) ) {
151 cout<<"AddRing::run() - Output TOI (boloSum/Mul) not connected! "<<endl;
152 throw ParmError("AddRing::run() Output TOI (boloSum/Mul) not connected!");
153 }
154
155 // On recupere les sample numbers
156 int snb,sne;
157 getRingRange(snb,sne);
158
159 cout<<"AddRing::run: sn="<<snb<<" sne="<<sne<<endl;
160 if(snb>sne) {
161 cout<<"AddRing::run() - Bad sample interval"<<snb<<" , "<<sne<<endl;
162 throw ParmError("AddRing::run() - Bad sample interval ");
163 }
164
165 //---------------------------------------------------------
166 Ring const *r1,*r2;
167
168
169 for(int k=snb;k<=sne;k++) {
170 totnscount++;
171
172 r1 = getRing(0,k);
173 r2 = getRing(1,k);
174 nread++;
175
176
177 putRing(0,k,r1.getData(k)+r2.getData(k));
178 nwrite++;
179 }
180 cout<<"AddRing::run: end"<<endl;
181}
182
183
184
185////////////////////////////////////////////////////////////////
186////////////////////////////////////////////////////////////////
187////////////////////////////////////////////////////////////////
188////////////////////////////////////////////////////////////////
189class PrintRing : public RingProcessor {
190public:
191 PrintRing();
192 virtual ~PrintRing();
193
194 virtual void init(void);
195 virtual void run(void);
196
197 void PrintStatus(::ostream & os);
198
199 inline int_8 ProcessedSampleCount() const {return totnscount;}
200protected:
201 int_8 nread,nwrite,totnscount;
202};
203
204PrintRing::PrintRing()
205: nread(0), nwrite(0),totnscount(0)
206{
207}
208
209PrintRing::~PrintRing()
210{
211}
212
213void PrintRing::PrintStatus(::ostream & os)
214{
215 os<<"PrintRing::Print -- nread = "<<nread<<endl
216 <<" -- nwrite = "<<nwrite<<endl;
217}
218
219void PrintRing::init() {
220// - 2 ringprocessors qui fabriquent des rings de bruit
221// - 1 ringprocessor qui les ajoute
222// - 1 ring processor qui les affiche
223
224
225
226 // Declaration des tuyaux a connecter. L'ordre de declaration compte!
227 cout << "PrintRing::init" << endl;
228 declareRingInput("entree_bolo"); // output index 0
229}
230
231void PrintRing::run()
232{
233
234 // Verification des connections en sortie
235 if(!getInputRing(0) ) {
236 cout<<"PrintRing::run() - Input TOI not connected! "<<endl;
237 throw ParmError("PrintRing::run() Input TOI not connected!");
238 }
239
240 //---------------------------------------------------------
241 int min,max;
242 getRingRange(min,max);
243
244 for(int k=min;k<=max;k++) {
245 totnscount++;
246 cout << k << " " << getRing(0,k);
247 nwrite++;
248 }
249 cout<<"PrintRing::run: end"<<endl;
250}
251
252
253////////////////////////////////////////////////////////////////
254////////////////////////////////////////////////////////////////
255////////////////////////////////////////////////////////////////
256////////////////////////////////////////////////////////////////
257void usage(void);
258void usage(void) {
259 cout<<"tstringpipe ";
260 cout<<" "<<endl;
261 return;
262}
263
264////////////////////////////////////////////////////////////////
265int main(int narg, char** arg) {
266
267TOIManager* mgr = TOIManager::getManager();
268
269//-- Decodage arguments
270
271SophyaInit();
272InitTim();
273
274//--------------------------------------------------------------------
275try {
276//--------------------------------------------------------------------
277
278// bool fgsegmented = true;
279// int wsize = 512;
280// CGT plombier(fgsegmented,wsize);
281// plombier.SetDebugLevel(99);
282
283 // FITS reader et writer
284 int nsamples=1024;
285
286 double theta = 12.;
287 double phi = 0.;
288 double aperture = 85.;
289 CreateRing cr1(nsamples,theta,phi,aperture);
290 CreateRing cr2(nsamples,theta,phi,aperture);
291 AddRing addring();
292 PrintRing p();
293
294 RingPipe *ring1;
295 RingPipe *ring2;
296 RingPipe *ring3;
297 cr1.addRingOutput("sortie_bolo", ring1);
298 cr2.addRingOutput("sortie_bolo", ring2);
299 addring.addRingInput("entree_bolo_1",ring1);
300 addring.addRingInput("entree_bolo_2",ring2);
301 addring.addRingOutput("sortie_bolo_sum",ring3);
302 p.addRingInput("entree_bolo",ring3);
303
304 cr1.start();
305 cr2.start();
306 addring.start();
307 p.start();
308
309// plombier.Connect(cr1,"sortie_bolo",AddRing,"entree_bolo_1");
310// plombier.Connect(cr2,"sortie_bolo",AddRing,"entree_bolo_2");
311// plombier.Connect(AddRing,"sortie_bolo_sum",PrintRing,"entree_bolo");
312// plombier.Start();
313// plombier.ListTOIs(cout, 1);
314 cout << "Joining ..." << endl;
315
316 mgr->joinAll();
317 PrtTim("End threads");
318
319//--------------------------------------------------------------------
320} catch (PThrowable & exc) {
321 cout<<"\ntsttoi2ring: Catched Exception \n"<<(string)typeid(exc).name()
322 <<" - Msg= "<<exc.Msg()<<endl;
323} catch (const std::exception & sex) {
324 cout<<"\ntsttoi2ring: Catched std::exception \n"
325 <<(string)typeid(sex).name()<<endl;
326} catch (...) {
327 cout<<"\ntsttoi2ring: some other exception was caught ! "<<endl;
328}
329//--------------------------------------------------------------------
330
331exit(0);
332}
Note: See TracBrowser for help on using the repository browser.