source: Sophya/trunk/AddOn/TAcq/racquproc.cc@ 3629

Last change on this file since 3629 was 3623, checked in by ansari, 16 years ago

Modifications et ameliorations diverses pour programme acquisition/traitement multifibres

Reza 22/05/2009

1- Extension/amelioration classe BRPaquet et BRPaqChecker
2- Correction BUG dans RAcqMemZoneMgr bloquant l'utilisation a une seule zone memoire
3- Classe PCIEWrapper devenue virtuelle pure et introduction de la classe TestPCIWrapperNODMA
pour les smulations.

File size: 10.9 KB
Line 
1#include "racquproc.h"
2
3#include <stdlib.h>
4#include <unistd.h>
5#include <fstream>
6#include <signal.h>
7
8#include "pexceptions.h"
9#include "tvector.h"
10#include "fioarr.h"
11#include "timestamp.h"
12#include "fftpserver.h"
13#include "fftwserver.h"
14
15#include "FFTW/fftw3.h"
16
17
18#include "pciewrap.h"
19#include "brpaqu.h"
20#include "minifits.h"
21struct sigaction act;
22
23//-------------------------------------------------------
24// Classe thread de traitement avec 1 voie par frame
25//-------------------------------------------------------
26
27void DataProcSignal(int s)
28{
29 cout <<"............................................... receive CtrlC" << endl;
30
31}
32
33DataProc::DataProc(RAcqMemZoneMgr& mem, string& path, uint_4 nmean, uint_4 step, uint_4 nmax)
34 : memgr(mem)
35{
36 nmax_ = nmax;
37 nmean_ = nmean;
38 step_ = step;
39 stop_ = false;
40 path_ = path;
41 act.sa_handler=DataProcSignal;
42}
43
44inline r_4 Zmod2(complex<r_4> z)
45{ return (z.real()*z.real()+z.imag()*z.imag()); }
46
47void DataProc::Stop()
48{
49 stop_=true;
50 // cout <<" DataProc::Stop ... > STOP " << endl;
51}
52
53void DataProc::run()
54{
55
56 // sigaddset(&act.sa_mask,SIGINT); // pour proteger le transfert DMA
57 // sigaction(SIGINT,&act,NULL);
58 setRC(1);
59 try {
60 TimeStamp ts;
61 cout << " DataProc::run() - Starting " << ts << " NMaxMemZones=" << nmax_
62 << " NMean=" << nmean_ << " Step=" << step_ << endl;
63 char fname[512];
64 sprintf(fname,"%s/proc.log",path_.c_str());
65 ofstream filog(fname);
66 filog << " DataProc::run() - starting log file " << ts << endl;
67 filog << " ... NMaxMemZones=" << nmax_ << " NMean=" << nmean_ << " Step=" << step_ << endl;
68
69// Initialisation pour clcul FFT
70 TVector< complex<r_4> > cfour; // composant TF
71 uint_4 paqsz = memgr.PaqSize();
72 BRPaquet pq(NULL, NULL, paqsz);
73 TVector<r_4> vx(pq.DataSize());
74 vx = (r_4)(0.);
75 FFTPackServer ffts;
76 ffts.FFTForward(vx, cfour);
77 TVector<r_4> spectre;
78 spectre.ReSize(cfour.Size());
79
80 fftwf_plan plan = fftwf_plan_dft_r2c_1d(vx.Size(), vx.Data(),
81 (fftwf_complex *)cfour.Data(), FFTW_ESTIMATE);
82
83 uint_4 ifile = 0;
84 uint_4 nzm = 0;
85 for (uint_4 kmz=0; kmz<nmax_; kmz++) {
86 if (stop_) break;
87 int mid = memgr.FindMemZoneId(MemZA_Proc);
88 Byte* buff = memgr.GetMemZone(mid);
89 if (buff == NULL) {
90 cout << " DataProc::run()/ERROR memgr.GetMemZone(" << mid << ") -> NULL" << endl;
91 setRC(2);
92 return;
93 }
94 BRPaquet paq0(NULL, buff, paqsz);
95 for(uint_4 i=0; i<memgr.NbPaquets(); i+=step_) {
96 BRPaquet paq(NULL, buff+i*paqsz, paqsz);
97 Byte min = 255;
98 Byte max = 0;
99
100 for(sa_size_t j=0; j<vx.Size(); j++)
101 vx(j) = (r_4)(*(paq.Data1()+j))-127.5;
102 fftwf_execute(plan);
103 // ffts_.FFTForward(vx, cfour_);
104 for(sa_size_t j=0; j<spectre.Size(); j++)
105 spectre(j) += Zmod2(cfour(j));
106 nzm++;
107 }
108 if ((nzm >= nmean_) ||(kmz==(nmax_-1))) {
109 spectre /= (r_4)(nzm);
110 spectre.Info()["NPaqMoy"] = nzm;
111 sprintf(fname,"%s/spectre%d.ppf",path_.c_str(),(int)ifile);
112 POutPersist po(fname);
113 po << spectre;
114 spectre = (r_4)(0.);
115 nzm = 0; ifile++;
116 ts.SetNow();
117 filog << ts << " : proc file " << fname << endl;
118 cout << " DataProc::run() " << ts << " : created file " << fname << endl;
119 }
120
121 memgr.FreeMemZone(mid, MemZS_Proc);
122 }
123 }
124 catch (PException& exc) {
125 cout << " DataProc::run()/catched PException " << exc.Msg() << endl;
126 setRC(3);
127 return;
128 }
129 catch(...) {
130 cout << " DataProc::run()/catched unknown ... exception " << endl;
131 setRC(4);
132 return;
133 }
134 setRC(0);
135 return;
136}
137
138//---------------------------------------------------------------
139// Classe thread de traitement donnees ADC avec 2 voies par frame
140//---------------------------------------------------------------
141
142DataProc2C::DataProc2C(RAcqMemZoneMgr& mem, string& path, uint_4 nmean, uint_4 step, uint_4 nmax)
143 : memgr(mem)
144{
145 nmax_ = nmax;
146 nmean_ = nmean;
147 step_ = step;
148 stop_ = false;
149 path_ = path;
150 act.sa_handler=DataProcSignal;
151}
152void DataProc2C::Stop()
153{
154 stop_=true;
155 // cout <<" DataProc2C::Stop ... > STOP " << endl;
156}
157
158void DataProc2C::run()
159{
160 // sigaction(SIGINT,&act,NULL);
161 setRC(1);
162 try {
163 TimeStamp ts;
164 cout << " DataProc2C::run() - Starting " << ts << " NMaxMemZones=" << nmax_
165 << " NMean=" << nmean_ << " Step=" << step_ << endl;
166 char fname[512];
167 sprintf(fname,"%s/proc.log",path_.c_str());
168 ofstream filog(fname);
169 filog << " DataProc2C::run() - starting log file " << ts << endl;
170 filog << " ... NMaxMemZones=" << nmax_ << " NMean=" << nmean_ << " Step=" << step_ << endl;
171
172// Initialisation pour clcul FFT
173 TVector< complex<r_4> > cfour; // composant TF
174 uint_4 paqsz = memgr.PaqSize();
175 BRPaquet pq(NULL, NULL, paqsz);
176 TVector<r_4> vx(pq.DataSize()/2);
177 vx = (r_4)(0.);
178 FFTPackServer ffts;
179 ffts.FFTForward(vx, cfour);
180 TVector<r_4> spectreV1, spectreV2;
181 spectreV1.ReSize(cfour.Size());
182 spectreV2.ReSize(cfour.Size());
183
184 fftwf_plan plan = fftwf_plan_dft_r2c_1d(vx.Size(), vx.Data(),
185 (fftwf_complex *)cfour.Data(), FFTW_ESTIMATE);
186
187 uint_4 ifile = 0;
188 uint_4 nzm = 0;
189 for (uint_4 kmz=0; kmz<nmax_; kmz++) {
190 if (stop_) break;
191 int mid = memgr.FindMemZoneId(MemZA_Proc);
192 Byte* buff = memgr.GetMemZone(mid);
193 if (buff == NULL) {
194 cout << " DataProc2C::run()/ERROR memgr.GetMemZone(" << mid << ") -> NULL" << endl;
195 setRC(2);
196 return;
197 }
198 BRPaquet paq0(NULL, buff, paqsz);
199 for(uint_4 i=0; i<memgr.NbPaquets(); i+=step_) {
200 BRPaquet paq(NULL, buff+i*paqsz, paqsz);
201 Byte min = 255;
202 Byte max = 0;
203
204 for(sa_size_t j=0; j<vx.Size(); j++)
205 vx(j) = (r_4)(*(paq.Data1()+j))-127.5;
206 fftwf_execute(plan);
207 // ffts_.FFTForward(vx, cfour_);
208 for(sa_size_t j=0; j<spectreV1.Size(); j++)
209 spectreV1(j) += Zmod2(cfour(j));
210
211 for(sa_size_t j=0; j<vx.Size(); j++)
212 vx(j) = (r_4)(*(paq.Data2()+j))-127.5;
213 fftwf_execute(plan);
214 // ffts_.FFTForward(vx, cfour_);
215 for(sa_size_t j=0; j<spectreV2.Size(); j++)
216 spectreV2(j) += Zmod2(cfour(j));
217
218 nzm++;
219 }
220 if ((nzm >= nmean_) ||(kmz==(nmax_-1))) {
221 spectreV1 /= (r_4)(nzm);
222 spectreV2 /= (r_4)(nzm);
223 spectreV1.Info()["NPaqMoy"] = nzm;
224 spectreV2.Info()["NPaqMoy"] = nzm;
225 {
226 sprintf(fname,"%s/spectre2C_%d.ppf",path_.c_str(),(int)ifile);
227 POutPersist po(fname);
228 po << PPFNameTag("specV1") << spectreV1;
229 po << PPFNameTag("specV2") << spectreV2;
230 }
231 spectreV1 = (r_4)(0.);
232 spectreV2 = (r_4)(0.);
233 nzm = 0; ifile++;
234 ts.SetNow();
235 filog << ts << " : proc file " << fname << endl;
236 cout << " DataProc2C::run() " << ts << " : created file " << fname << endl;
237 }
238
239 memgr.FreeMemZone(mid, MemZS_Proc);
240 }
241 }
242 catch (PException& exc) {
243 cout << " DataProc2C::run()/catched PException " << exc.Msg() << endl;
244 setRC(3);
245 return;
246 }
247 catch(...) {
248 cout << " DataProc2C::run()/catched unknown ... exception " << endl;
249 setRC(4);
250 return;
251 }
252 setRC(0);
253 return;
254}
255
256
257
258
259//---------------------------------------------------------------
260// Classe thread de traitement donnees FFT avec 2 voies par frame
261//---------------------------------------------------------------
262
263inline r_4 Zmod2TwoByte(TwoByteComplex z)
264{ return (z.realD()*z.realD()+z.imagD()*z.imagD()); }
265
266DataProcFFT2C::DataProcFFT2C(RAcqMemZoneMgr& mem, string& path, uint_4 nmean, uint_4 step, uint_4 nmax)
267 : memgr(mem)
268{
269 nmax_ = nmax;
270 nmean_ = nmean;
271 step_ = step;
272 stop_ = false;
273 path_ = path;
274 act.sa_handler=DataProcSignal;
275}
276void DataProcFFT2C::Stop()
277{
278 stop_=true;
279 // cout <<" DataProcFFT2C::Stop ... > STOP " << endl;
280}
281
282void DataProcFFT2C::run()
283{
284 // sigaction(SIGINT,&act,NULL);
285 setRC(1);
286 try {
287 TimeStamp ts;
288 cout << " DataProcFFT2C::run() - Starting " << ts << " NMaxMemZones=" << nmax_
289 << " NMean=" << nmean_ << " Step=" << step_ << endl;
290 char fname[512];
291 sprintf(fname,"%s/proc.log",path_.c_str());
292 ofstream filog(fname);
293 filog << " DataProcFFT2C::run() - starting log file " << ts << endl;
294 filog << " ... NMaxMemZones=" << nmax_ << " NMean=" << nmean_ << " Step=" << step_ << endl;
295
296// Initialisation pour clcul FFT
297 TVector< complex<r_4> > cfour; // composant TF
298 uint_4 paqsz = memgr.PaqSize();
299 BRPaquet pq(NULL, NULL, paqsz);
300
301 TVector<r_4> spectreV1(pq.DataSize()/4+1), spectreV2(pq.DataSize()/4+1);
302
303 uint_4 ifile = 0;
304 for (uint_4 kmz=0; kmz<nmax_; kmz++) {
305 if (stop_ ) break;
306 int mid = memgr.FindMemZoneId(MemZA_Proc);
307 Byte* buff = memgr.GetMemZone(mid);
308 if (buff == NULL) {
309 cout << " DataProcFFT2C::run()/ERROR memgr.GetMemZone(" << mid << ") -> NULL" << endl;
310 setRC(2);
311 return;
312 }
313 BRPaquet paq0(NULL, buff, paqsz);
314 uint_4 nzm = 0;
315 for(uint_4 i=0; i<memgr.NbPaquets(); i+=step_) {
316 BRPaquet paq(NULL, buff+i*paqsz, paqsz);
317 Byte min = 255;
318 Byte max = 0;
319
320 TwoByteComplex* zz;
321 // Traitement Voie 1
322 zz = (TwoByteComplex*)paq.Data1();
323 spectreV1(0) += zz[0].realD()*zz[0].realD(); // Composante continue, partie reelle uniquement
324 for(sa_size_t j=1; j<spectreV1.Size()-1; j++) spectreV1(j) += Zmod2TwoByte(zz[j]);
325
326 spectreV1(spectreV1.Size()-1) += zz[0].imagD()*zz[0].imagD(); // Freq. Nyquist a N/2
327
328 // Traitement Voie 2
329 zz = (TwoByteComplex*)paq.Data2();
330 spectreV2(0) += zz[0].realD()*zz[0].realD(); // Composante continue, partie reelle uniquement
331 for(sa_size_t j=1; j<spectreV2.Size()-1; j++) spectreV2(j) += Zmod2TwoByte(zz[j]);
332
333 spectreV2(spectreV2.Size()-1) += zz[0].imagD()*zz[0].imagD(); // Freq. Nyquist a N/2
334
335 nzm++;
336 }
337 if ((nzm >= nmean_) ||(kmz==(nmax_-1))) {
338 spectreV1 /= (r_4)(nzm);
339 spectreV2 /= (r_4)(nzm);
340 spectreV1.Info()["NPaqMoy"] = nzm;
341 spectreV2.Info()["NPaqMoy"] = nzm;
342 {
343 sprintf(fname,"%s/spectreFFT2C_%d.ppf",path_.c_str(),(int)ifile);
344 POutPersist po(fname);
345 po << PPFNameTag("specV1") << spectreV1;
346 po << PPFNameTag("specV2") << spectreV2;
347 }
348 spectreV1 = (r_4)(0.);
349 spectreV2 = (r_4)(0.);
350 nzm = 0; ifile++;
351 ts.SetNow();
352 filog << ts << " : proc file " << fname << endl;
353 cout << " DataProcFFT2C::run() " << ts << " : created file " << fname << endl;
354 }
355
356 memgr.FreeMemZone(mid, MemZS_Proc);
357 }
358 }
359 catch (PException& exc) {
360 cout << " DataProcFFT2C::run()/catched PException " << exc.Msg() << endl;
361 setRC(3);
362 return;
363 }
364 catch(...) {
365 cout << " DataProcFFT2C::run()/catched unknown ... exception " << endl;
366 setRC(4);
367 return;
368 }
369 setRC(0);
370 return;
371}
Note: See TracBrowser for help on using the repository browser.