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

Last change on this file since 3777 was 3729, checked in by cmv, 16 years ago
  • ajout des Histo2D imag%real (from Pittsburgh Nov09) fait 11/09
  • ajout des histos de l'exposant FFT (continu) fait 06/01/10

rz + cmv , 06/01/2010

File size: 23.3 KB
Line 
1#include "racquproc.h"
2
3/* ----------------------------------------
4 Projet BAORadio --- LAL
5 2008 - 2010
6------------------------------------------- */
7
8#include <stdlib.h>
9#include <unistd.h>
10#include <fstream>
11#include <signal.h>
12
13#include "pexceptions.h"
14#include "tvector.h"
15#include "fioarr.h"
16#include "timestamp.h"
17#include "fftpserver.h"
18#include "fftwserver.h"
19#include "histos.h"
20#include "histos2.h"
21
22#include "FFTW/fftw3.h"
23
24
25#include "pciewrap.h"
26#include "brpaqu.h"
27#include "minifits.h"
28
29/* Fonction, module^2 des nombres complexes */
30static inline r_4 Zmod2(complex<r_4> z)
31{ return (z.real()*z.real()+z.imag()*z.imag()); }
32static inline r_8 Zmod2(complex<r_8> z)
33{ return (z.real()*z.real()+z.imag()*z.imag()); }
34static inline r_4 Zmod2(TwoByteComplex z)
35{ return ((r_4)z.realB()*(r_4)z.realB()+(r_4)z.imagB()*(r_4)z.imagB()); }
36
37//---------------------------------------------------------------------
38// Classe thread de traitement/monitoring multifibre Raw/FFT
39//---------------------------------------------------------------------
40/* --Methode-- */
41MonitorProc::MonitorProc(RAcqMemZoneMgr& mem)
42 : memgr(mem)
43{
44 BRAcqConfig bpar;
45 par_.Set(bpar.GetParams());
46 nmax_ = par_.nmaxProc;
47 if (nmax_==0) nmax_=par_.MaxNbBlocs();
48 nmean_ = par_.nmeanProc;
49 step_ = par_.stepProc;
50 stop_ = false;
51 path_ = bpar.OutputDirectory();
52 nfiles_ = 0;
53 nblocproc_ = 0;
54 nprocpaq_=0;
55 npaqsamefc_=0;
56 totnprocpaq_=0;
57 totnpaqsamefc_=0;
58 curfc_.SetSize(memgr.NbFibres(), memgr.NbPaquets());
59 cpaqok_.SetSize(memgr.NbFibres(), memgr.NbPaquets());
60}
61
62/* --Methode-- */
63MonitorProc::~MonitorProc()
64{
65 // cout << " **** DBG ***** MonitorProc::~MonitorProc() " << endl;
66}
67
68/* --Methode-- */
69void MonitorProc::Stop()
70{
71 stop_=true;
72}
73
74/* --Methode-- */
75void MonitorProc::run()
76{
77 setRC(1);
78 int rc=0;
79 try {
80 TimeStamp ts;
81 cout << " MonitorProc::run() - Starting " << ts << " NMaxMemZones=" << nmax_
82 << " NMean=" << nmean_ << " Step=" << step_ << endl;
83 cout << " MonitorProc::run()... - Output Data Path: " << path_ << endl;
84 char fname[512];
85 sprintf(fname,"%s/monproc.log",path_.c_str());
86 ofstream filog(fname);
87 filog << " MonitorProc::run() - starting log file " << ts << endl;
88 filog << " ... NMaxMemZones=" << nmax_ << " NMean=" << nmean_ << " Step=" << step_ << endl;
89 uint_4 paqsz = memgr.PaqSize();
90 BRPaquet pq(paqsz);
91 if (par_.fgsinglechannel) {
92 spectre_.SetSize(memgr.NbFibres(), pq.DataSize()/2);
93 for(int kc=0; kc<memgr.NbFibres(); kc++) nzm_.push_back(0);
94 rc=procData1C(filog);
95 }
96 else {
97 spectre_.SetSize(2*memgr.NbFibres(), pq.DataSize()/4);
98 for(int kc=0; kc<2*memgr.NbFibres(); kc++) nzm_.push_back(0);
99 rc=procData2C(filog);
100 }
101 cout << " ---- MonitorProc::run()/End NBlocProcessed=" << nblocproc_
102 << " NFiles=" << nfiles_ << " Rc=" << rc << endl;
103 ts.SetNow();
104 filog << " ---- MonitorProc::run()/End " << ts << endl;
105 filog << " --------- MonitorProc::run()/End NBlocProcessed=" << nblocproc_
106 << " NFiles=" << nfiles_ << " Rc=" << rc << endl;
107 }
108 catch (std::exception& exc) {
109 cout << " MonitorProc::run()/catched std::exception " << exc.what() << endl;
110 setRC(98);
111 return;
112 }
113 catch(...) {
114 cout << " MonitorProc::run()/catched unknown ... exception " << endl;
115 setRC(99);
116 return;
117 }
118
119 setRC(rc);
120 return;
121}
122
123/* --Methode-- */
124int MonitorProc::procData1C(ofstream& logf)
125{
126 cout << " MonitorProc::procData1C() - NOT IMPLEMENTED -> Rc=67" << endl;
127 logf << " MonitorProc::procData1C() - NOT IMPLEMENTED -> Rc=67" << endl;
128 return 67;
129}
130
131/* --Methode-- */
132int MonitorProc::procData2C(ofstream& filog)
133{
134 BRPaqChecker pcheck[MAXNBFIB]; // Verification/comptage des paquets
135// Initialisation pour calcul FFT
136 uint_4 paqsz = memgr.PaqSize();
137 BRPaquet pq(paqsz);
138 TVector<r_4> vx(pq.DataSize()/2);
139 vx = (r_4)(0.);
140 TVector< complex<r_4> > cfour(pq.DataSize()/4+1); // composant TF
141
142 fftwf_plan plan = fftwf_plan_dft_r2c_1d(vx.Size(), vx.Data(),
143 (fftwf_complex *)cfour.Data(), FFTW_ESTIMATE);
144
145 // Histo pour valeurs des bytes dans les paquets
146 Histo* phist[2*MAXNBFIB] = {NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL};
147 Histo2D* ph2[2*MAXNBFIB] = {NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL};
148 Histo* phexp[2*MAXNBFIB] = {NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL};
149 if (par_.fgdatafft) { // data de type FFT
150 for(sa_size_t lc=0; lc<2*memgr.NbFibres(); lc++) {
151 phist[lc] = new Histo(-128.5,+128.5,257);
152 ph2[lc] = new Histo2D(-128.5,+128.5,257, -128.5,+128.5,257);
153 phexp[lc] = new Histo(-128.5,+128.5,257);
154 }
155 }
156 else {
157 for(sa_size_t lc=0; lc<2*memgr.NbFibres(); lc++)
158 phist[lc] = new Histo(-0.5,256.5,257);
159 }
160
161 TimeStamp ts;
162 char fname[512];
163 nfiles_ = 0;
164 for (uint_4 kmz=0; kmz<nmax_; kmz++) {
165 if (stop_) break;
166 if (memgr.GetRunState() == MemZR_Stopped) break;
167
168 int mid = memgr.FindMemZoneId(MemZA_Proc);
169 Byte* buffg = memgr.GetMemZone(mid);
170 if (buffg == NULL) {
171 cout << " MonitorProc::procData2C()/ERROR memgr.GetMemZone(" << mid << ") -> NULL" << endl;
172 break;
173 }
174 if ((step_>1)&&(kmz%step_ != 0)) {
175 memgr.FreeMemZone(mid, MemZS_Proc);
176 continue;
177 }
178 sa_size_t lc=0;
179 Byte* fbuff[MAXNBFIB];
180 for(uint_4 fib=0; fib<memgr.NbFibres(); fib++) { // Boucle sur les fibres
181 fbuff[fib] = memgr.GetMemZone(mid,fib);
182 if (fbuff[fib] == NULL) { // cela ne devrait pas arriver
183 cout << " MonitorProc::procData2C()/ERROR memgr.GetMemZone(" << mid << "," << fib << ") -> NULL" << endl;
184 return 9;
185 }
186 }
187
188 cpaqok_ = (uint_1)0;
189 curfc_ = (uint_8)0;
190 for(uint_4 fib=0; fib<memgr.NbFibres(); fib++) {
191 for(uint_4 i=0; i<memgr.NbPaquets(); i++) {
192 BRPaquet paq(fbuff[fib]+i*paqsz, paqsz);
193 bool pqok=pcheck[fib].Check(paq,curfc_(fib,i)); // Verification du paquet / FrameCounter
194 if (!pqok) continue;
195 cpaqok_(fib,i) = 1;
196 sa_size_t lc=2*fib;
197 if (par_.fgdatafft) { // Traitement data de type FFT
198 TwoByteComplex* tbcp=paq.Data1C();
199 phexp[lc]->Add((r_4)tbcp[0].realD());
200 for(sa_size_t j=1; j<spectre_.NCols(); j++) {
201 phist[lc]->Add((r_4)tbcp[j].realD());
202 phist[lc]->Add((r_4)tbcp[j].imagD());
203 ph2[lc]->Add((r_4)tbcp[j].realD(), (r_4)tbcp[j].imagD());
204 spectre_(lc,j) += Zmod2(tbcp[j]);
205 }
206 nzm_[lc]++;
207 tbcp=paq.Data2C(); lc++;
208 phexp[lc]->Add((r_4)tbcp[0].realD());
209 for(sa_size_t j=1; j<spectre_.NCols(); j++) {
210 phist[lc]->Add((r_4)tbcp[j].realD());
211 phist[lc]->Add((r_4)tbcp[j].imagD());
212 ph2[lc]->Add((r_4)tbcp[j].realD(), (r_4)tbcp[j].imagD());
213 spectre_(lc,j) += Zmod2(tbcp[j]);
214 }
215 nzm_[lc]++;
216 }
217 else { // Traitement RawData
218 for(sa_size_t j=0; j<vx.Size(); j++) {
219 phist[lc]->Add((r_8)(*(paq.Data1()+j)));
220 vx(j) = (r_4)(*(paq.Data1()+j))-127.5;
221 }
222 fftwf_execute(plan);
223 // ffts_.FFTForward(vx, cfour_);
224 for(sa_size_t j=0; j<spectre_.NCols(); j++)
225 spectre_(lc,j) += Zmod2(cfour(j+1));
226 nzm_[lc]++; lc++;
227 for(sa_size_t j=0; j<vx.Size(); j++) {
228 phist[lc]->Add((r_8)(*(paq.Data2()+j)));
229 vx(j) = (r_4)(*(paq.Data2()+j))-127.5;
230 }
231 fftwf_execute(plan);
232 // ffts_.FFTForward(vx, cfour_);
233 for(sa_size_t j=0; j<spectre_.NCols(); j++)
234 spectre_(lc,j) += Zmod2(cfour(j+1));
235 nzm_[lc]++;
236 }
237 } // FIN de la boucle sur les paquets
238 } // Boucle sur les fibres
239 memgr.FreeMemZone(mid, MemZS_Proc);
240 CheckFrameCounters();
241
242 nblocproc_ ++;
243 totnprocpaq_ += memgr.NbPaquets(); nprocpaq_ += memgr.NbPaquets();
244 bool fgnzm=true;
245 for(int lc=0; lc<2*memgr.NbFibres(); lc++)
246 if (nzm_[lc]<nmean_) fgnzm=false;
247
248 if (fgnzm) {
249 char buff[32];
250 for(sa_size_t lc=0; lc<2*memgr.NbFibres(); lc++) {
251 spectre_.Row(lc) /= (r_4)nzm_[lc];
252 sprintf(buff,"NPaqMoy%d",(int)lc);
253 spectre_.Info()[buff] = nzm_[lc];
254 }
255 sprintf(fname,"%s/meanspec%d.ppf",path_.c_str(),(int)nfiles_);
256 nfiles_++;
257 POutPersist po(fname);
258 po << PPFNameTag("spectre") << spectre_;
259 spectre_ = (r_4)(0.);
260 char buftag[32];
261 for(int lc=0; lc<2*memgr.NbFibres(); lc++) {
262 sprintf(buftag,"hvalV%d",(int)lc);
263 po << PPFNameTag(buftag) << (*phist[lc]);
264 phist[lc]->Zero();
265 if (par_.fgdatafft) { // data de type FFT
266 sprintf(buftag,"h2dV%d",(int)lc);
267 po << PPFNameTag(buftag) << (*ph2[lc]);
268 ph2[lc]->Zero();
269 sprintf(buftag,"hexpV%d",(int)lc);
270 po << PPFNameTag(buftag) << (*phexp[lc]);
271 phexp[lc]->Zero();
272 }
273 nzm_[lc]=0;
274 }
275 ts.SetNow();
276 // Calcul / impression fraction des paquets avec same-framecounter
277 int fracsame=0;
278 if (nprocpaq_>0) fracsame=100*npaqsamefc_/nprocpaq_;
279 int totfracsame=0;
280 if (totnprocpaq_>0) totfracsame=100*totnpaqsamefc_/totnprocpaq_;
281 filog << ts << " : proc file (meanspectra) " << fname << endl;
282 filog << " NBlocProcessed=" << nblocproc_ << " NSameFC=" << totnpaqsamefc_ << " / " << totnprocpaq_
283 << " -> " << totfracsame << " % (LastPqs: " << npaqsamefc_ << " / " << nprocpaq_
284 << " -> " << fracsame << " % )" << endl;
285 cout << " MonitorProc::procData2C() " << ts << " : created file " << fname << endl;
286 cout << " NBlocProcessed=" << nblocproc_ << " NSameFC=" << totnpaqsamefc_ << " / " << totnprocpaq_
287 << " -> " << totfracsame << " % (LastPqs: " << npaqsamefc_ << " / " << nprocpaq_
288 << " -> " << fracsame << " % )" << endl;
289 nprocpaq_=npaqsamefc_=0;
290 }
291 } // Fin de boucle sur les kmz ( bloc MemZoneMgr a traiter )
292
293 bool fgnzm=false;
294 for(int lc=0; lc<2*memgr.NbFibres(); lc++)
295 if (nzm_[lc]>0) fgnzm=true;
296
297 if (fgnzm) {
298 char buff[32];
299 for(sa_size_t lc=0; lc<2*memgr.NbFibres(); lc++) {
300 if (nzm_[lc]>0) spectre_.Row(lc) /= (r_4)nzm_[lc];
301 sprintf(buff,"NPaqMoy%d",(int)lc);
302 spectre_.Info()[buff] = nzm_[lc];
303 }
304 sprintf(fname,"%s/meanspec%d.ppf",path_.c_str(),(int)nfiles_);
305 POutPersist po(fname);
306 po << PPFNameTag("spectre") << spectre_;
307 spectre_ = (r_4)(0.);
308 char buftag[32];
309 for(int lc=0; lc<2*memgr.NbFibres(); lc++) {
310 sprintf(buftag,"hvalV%d",(int)lc);
311 po << PPFNameTag(buftag) << (*phist[lc]);
312 delete phist[lc];
313 if (par_.fgdatafft) { // data de type FFT
314 sprintf(buftag,"h2dV%d",(int)lc);
315 po << PPFNameTag(buftag) << (*ph2[lc]);
316 delete ph2[lc];
317 sprintf(buftag,"hexpV%d",(int)lc);
318 po << PPFNameTag(buftag) << (*phexp[lc]);
319 delete phexp[lc];
320 }
321 nzm_[lc]=0;
322 }
323 ts.SetNow();
324 // Calcul / impression fraction des paquets avec same-framecounter
325 int fracsame=0;
326 if (nprocpaq_>0) fracsame=100*npaqsamefc_/nprocpaq_;
327 int totfracsame=0;
328 if (totnprocpaq_>0) totfracsame=100*totnpaqsamefc_/totnprocpaq_;
329 filog << ts << " : proc file (meanspectra) " << fname << endl;
330 filog << " NBlocProcessed=" << nblocproc_ << " NSameFC=" << totnpaqsamefc_ << " / " << totnprocpaq_
331 << " -> " << totfracsame << " % (LastPqs: " << npaqsamefc_ << " / " << nprocpaq_
332 << " -> " << fracsame << " % )" << endl;
333 cout << " MonitorProc::procData2C() " << ts << " : created file " << fname << endl;
334 cout << " NBlocProcessed=" << nblocproc_ << " NSameFC=" << totnpaqsamefc_ << " / " << totnprocpaq_
335 << " -> " << totfracsame << " % (LastPqs: " << npaqsamefc_ << " / " << nprocpaq_
336 << " -> " << fracsame << " % )" << endl;
337 }
338 return 0;
339}
340
341/* --Methode-- */
342int MonitorProc::CheckFrameCounters()
343{
344 if (memgr.NbFibres()<2) {
345 npaqsamefc_++; totnpaqsamefc_++;
346 return 99;
347 }
348 sa_size_t pidx[MAXNBFIB];
349 sa_size_t maxidx=curfc_.NCols();
350 uint_8 cfc=0;
351 for(uint_4 fib=0; fib<curfc_.NRows(); fib++) {
352 pidx[fib]=0;
353 while((pidx[fib]<maxidx)&&(cpaqok_(fib,pidx[fib])==0)) pidx[fib]++;
354 }
355
356 bool fgsuite=true;
357 while (fgsuite) { // Boucle sur l'ensemble des paquets
358 for(uint_4 fib=0; fib<curfc_.NRows(); fib++) {
359 if ((pidx[fib]>=maxidx)||(cpaqok_(fib,pidx[fib])==0)) { fgsuite=false; break; }
360 }
361 if (!fgsuite) break;
362 cfc=curfc_(0,pidx[0]);
363 bool fgsame=true;
364 for(uint_4 fib=1; fib<curfc_.NRows(); fib++) {
365 if (curfc_(fib,pidx[fib])!=cfc) {
366 fgsame=false;
367 if (curfc_(fib,pidx[fib]) > cfc) cfc=curfc_(fib,pidx[fib]);
368 }
369 }
370 if (fgsame) {
371 npaqsamefc_++; totnpaqsamefc_++;
372 for(uint_4 fib=0; fib<curfc_.NRows(); fib++) {
373 pidx[fib]++;
374 while((pidx[fib]<maxidx)&&(cpaqok_(fib,pidx[fib])==0)) pidx[fib]++;
375 }
376 } // fin if (fgsame)
377 else { // else !fgsame
378 for(uint_4 fib=0; fib<memgr.NbFibres(); fib++) {
379 if (curfc_(fib,pidx[fib])<cfc) {
380 pidx[fib]++;
381 while((pidx[fib]<maxidx)&&(cpaqok_(fib,pidx[fib])==0)) pidx[fib]++;
382 }
383 }
384 } // fin de else !fgsame
385 } // Fin de while sur l'ensemble des paquets
386 return 0;
387}
388
389
390static struct sigaction act;
391//-------------------------------------------------------
392// Classe thread de traitement avec 1 voie par frame
393//-------------------------------------------------------
394
395void DataProcSignal(int s)
396{
397 cout <<"............................................... receive CtrlC" << endl;
398
399}
400
401DataProc::DataProc(RAcqMemZoneMgr& mem, string& path, uint_4 nmean, uint_4 step, uint_4 nmax)
402 : memgr(mem)
403{
404 nmax_ = nmax;
405 nmean_ = nmean;
406 step_ = step;
407 stop_ = false;
408 path_ = path;
409 act.sa_handler=DataProcSignal;
410}
411
412
413void DataProc::Stop()
414{
415 stop_=true;
416 // cout <<" DataProc::Stop ... > STOP " << endl;
417}
418
419void DataProc::run()
420{
421
422 // sigaddset(&act.sa_mask,SIGINT); // pour proteger le transfert DMA
423 // sigaction(SIGINT,&act,NULL);
424 setRC(1);
425 try {
426 TimeStamp ts;
427 cout << " DataProc::run() - Starting " << ts << " NMaxMemZones=" << nmax_
428 << " NMean=" << nmean_ << " Step=" << step_ << endl;
429 cout << " DataProc::run()... - Output Data Path: " << path_ << endl;
430 char fname[512];
431 sprintf(fname,"%s/proc.log",path_.c_str());
432 ofstream filog(fname);
433 filog << " DataProc::run() - starting log file " << ts << endl;
434 filog << " ... NMaxMemZones=" << nmax_ << " NMean=" << nmean_ << " Step=" << step_ << endl;
435
436// Initialisation pour clcul FFT
437 TVector< complex<r_4> > cfour; // composant TF
438 uint_4 paqsz = memgr.PaqSize();
439 BRPaquet pq(NULL, NULL, paqsz);
440 TVector<r_4> vx(pq.DataSize());
441 vx = (r_4)(0.);
442 FFTPackServer ffts;
443 ffts.FFTForward(vx, cfour);
444 TVector<r_4> spectre;
445 spectre.ReSize(cfour.Size());
446
447 fftwf_plan plan = fftwf_plan_dft_r2c_1d(vx.Size(), vx.Data(),
448 (fftwf_complex *)cfour.Data(), FFTW_ESTIMATE);
449
450 uint_4 ifile = 0;
451 uint_4 nzm = 0;
452 for (uint_4 kmz=0; kmz<nmax_; kmz++) {
453 if (stop_) break;
454 int mid = memgr.FindMemZoneId(MemZA_Proc);
455 Byte* buff = memgr.GetMemZone(mid);
456 if (buff == NULL) {
457 cout << " DataProc::run()/ERROR memgr.GetMemZone(" << mid << ") -> NULL" << endl;
458 setRC(2);
459 return;
460 }
461 BRPaquet paq0(NULL, buff, paqsz);
462 for(uint_4 i=0; i<memgr.NbPaquets(); i+=step_) {
463 BRPaquet paq(NULL, buff+i*paqsz, paqsz);
464 Byte min = 255;
465 Byte max = 0;
466
467 for(sa_size_t j=0; j<vx.Size(); j++)
468 vx(j) = (r_4)(*(paq.Data1()+j))-127.5;
469 fftwf_execute(plan);
470 // ffts_.FFTForward(vx, cfour_);
471 for(sa_size_t j=0; j<spectre.Size(); j++)
472 spectre(j) += Zmod2(cfour(j));
473 nzm++;
474 }
475 if ((nzm >= nmean_) ||(kmz==(nmax_-1))) {
476 spectre /= (r_4)(nzm);
477 spectre.Info()["NPaqMoy"] = nzm;
478 sprintf(fname,"%s/spectre%d.ppf",path_.c_str(),(int)ifile);
479 POutPersist po(fname);
480 po << spectre;
481 spectre = (r_4)(0.);
482 nzm = 0; ifile++;
483 ts.SetNow();
484 filog << ts << " : proc file " << fname << endl;
485 cout << " DataProc::run() " << ts << " : created file " << fname << endl;
486 }
487
488 memgr.FreeMemZone(mid, MemZS_Proc);
489 }
490 }
491 catch (std::exception& exc) {
492 cout << " DataProc::run()/catched std::exception " << exc.what() << endl;
493 setRC(3);
494 return;
495 }
496 catch(...) {
497 cout << " DataProc::run()/catched unknown ... exception " << endl;
498 setRC(4);
499 return;
500 }
501 setRC(0);
502 return;
503}
504
505//---------------------------------------------------------------
506// Classe thread de traitement donnees ADC avec 2 voies par frame
507//---------------------------------------------------------------
508
509DataProc2C::DataProc2C(RAcqMemZoneMgr& mem, string& path, uint_4 nmean, uint_4 step, uint_4 nmax)
510 : memgr(mem)
511{
512 nmax_ = nmax;
513 nmean_ = nmean;
514 step_ = step;
515 stop_ = false;
516 path_ = path;
517 act.sa_handler=DataProcSignal;
518}
519void DataProc2C::Stop()
520{
521 stop_=true;
522 // cout <<" DataProc2C::Stop ... > STOP " << endl;
523}
524
525void DataProc2C::run()
526{
527 // sigaction(SIGINT,&act,NULL);
528 setRC(1);
529 try {
530 TimeStamp ts;
531 cout << " DataProc2C::run() - Starting " << ts << " NMaxMemZones=" << nmax_
532 << " NMean=" << nmean_ << " Step=" << step_ << endl;
533 cout << " DataProc::run()... - Output Data Path: " << path_ << endl;
534 char fname[512];
535 sprintf(fname,"%s/proc.log",path_.c_str());
536 ofstream filog(fname);
537 filog << " DataProc2C::run() - starting log file " << ts << endl;
538 filog << " ... NMaxMemZones=" << nmax_ << " NMean=" << nmean_ << " Step=" << step_ << endl;
539
540// Initialisation pour clcul FFT
541 TVector< complex<r_4> > cfour; // composant TF
542 uint_4 paqsz = memgr.PaqSize();
543 BRPaquet pq(NULL, NULL, paqsz);
544 TVector<r_4> vx(pq.DataSize()/2);
545 vx = (r_4)(0.);
546 FFTPackServer ffts;
547 ffts.FFTForward(vx, cfour);
548 TVector<r_4> spectreV1, spectreV2;
549 spectreV1.ReSize(cfour.Size());
550 spectreV2.ReSize(cfour.Size());
551
552 fftwf_plan plan = fftwf_plan_dft_r2c_1d(vx.Size(), vx.Data(),
553 (fftwf_complex *)cfour.Data(), FFTW_ESTIMATE);
554
555 uint_4 ifile = 0;
556 uint_4 nzm = 0;
557 for (uint_4 kmz=0; kmz<nmax_; kmz++) {
558 if (stop_) break;
559 int mid = memgr.FindMemZoneId(MemZA_Proc);
560 Byte* buff = memgr.GetMemZone(mid);
561 if (buff == NULL) {
562 cout << " DataProc2C::run()/ERROR memgr.GetMemZone(" << mid << ") -> NULL" << endl;
563 setRC(2);
564 return;
565 }
566 BRPaquet paq0(NULL, buff, paqsz);
567 for(uint_4 i=0; i<memgr.NbPaquets(); i+=step_) {
568 BRPaquet paq(NULL, buff+i*paqsz, paqsz);
569 Byte min = 255;
570 Byte max = 0;
571
572 for(sa_size_t j=0; j<vx.Size(); j++)
573 vx(j) = (r_4)(*(paq.Data1()+j))-127.5;
574 fftwf_execute(plan);
575 // ffts_.FFTForward(vx, cfour_);
576 for(sa_size_t j=0; j<spectreV1.Size(); j++)
577 spectreV1(j) += Zmod2(cfour(j));
578
579 for(sa_size_t j=0; j<vx.Size(); j++)
580 vx(j) = (r_4)(*(paq.Data2()+j))-127.5;
581 fftwf_execute(plan);
582 // ffts_.FFTForward(vx, cfour_);
583 for(sa_size_t j=0; j<spectreV2.Size(); j++)
584 spectreV2(j) += Zmod2(cfour(j));
585
586 nzm++;
587 }
588 if ((nzm >= nmean_) ||(kmz==(nmax_-1))) {
589 spectreV1 /= (r_4)(nzm);
590 spectreV2 /= (r_4)(nzm);
591 spectreV1.Info()["NPaqMoy"] = nzm;
592 spectreV2.Info()["NPaqMoy"] = nzm;
593 {
594 sprintf(fname,"%s/spectre2C_%d.ppf",path_.c_str(),(int)ifile);
595 POutPersist po(fname);
596 po << PPFNameTag("specV1") << spectreV1;
597 po << PPFNameTag("specV2") << spectreV2;
598 }
599 spectreV1 = (r_4)(0.);
600 spectreV2 = (r_4)(0.);
601 nzm = 0; ifile++;
602 ts.SetNow();
603 filog << ts << " : proc file " << fname << endl;
604 cout << " DataProc2C::run() " << ts << " : created file " << fname << endl;
605 }
606
607 memgr.FreeMemZone(mid, MemZS_Proc);
608 }
609 }
610 catch (std::exception& exc) {
611 cout << " DataProc::run()/catched std::exception " << exc.what() << endl;
612 setRC(3);
613 return;
614 }
615 catch(...) {
616 cout << " DataProc2C::run()/catched unknown ... exception " << endl;
617 setRC(4);
618 return;
619 }
620 setRC(0);
621 return;
622}
623
624
625
626
627//---------------------------------------------------------------
628// Classe thread de traitement donnees FFT avec 2 voies par frame
629//---------------------------------------------------------------
630
631inline r_4 Zmod2TwoByte(TwoByteComplex z)
632{ return (z.realD()*z.realD()+z.imagD()*z.imagD()); }
633
634DataProcFFT2C::DataProcFFT2C(RAcqMemZoneMgr& mem, string& path, uint_4 nmean, uint_4 step, uint_4 nmax)
635 : memgr(mem)
636{
637 nmax_ = nmax;
638 nmean_ = nmean;
639 step_ = step;
640 stop_ = false;
641 path_ = path;
642 act.sa_handler=DataProcSignal;
643}
644void DataProcFFT2C::Stop()
645{
646 stop_=true;
647 // cout <<" DataProcFFT2C::Stop ... > STOP " << endl;
648}
649
650void DataProcFFT2C::run()
651{
652 // sigaction(SIGINT,&act,NULL);
653 setRC(1);
654 try {
655 TimeStamp ts;
656 cout << " DataProcFFT2C::run() - Starting " << ts << " NMaxMemZones=" << nmax_
657 << " NMean=" << nmean_ << " Step=" << step_ << endl;
658 cout << " DataProc::run()... - Output Data Path: " << path_ << endl;
659 char fname[512];
660 sprintf(fname,"%s/proc.log",path_.c_str());
661 ofstream filog(fname);
662 filog << " DataProcFFT2C::run() - starting log file " << ts << endl;
663 filog << " ... NMaxMemZones=" << nmax_ << " NMean=" << nmean_ << " Step=" << step_ << endl;
664
665// Initialisation pour clcul FFT
666 TVector< complex<r_4> > cfour; // composant TF
667 uint_4 paqsz = memgr.PaqSize();
668 BRPaquet pq(NULL, NULL, paqsz);
669
670 TVector<r_4> spectreV1(pq.DataSize()/4+1), spectreV2(pq.DataSize()/4+1);
671
672 uint_4 ifile = 0;
673 for (uint_4 kmz=0; kmz<nmax_; kmz++) {
674 if (stop_ ) break;
675 int mid = memgr.FindMemZoneId(MemZA_Proc);
676 Byte* buff = memgr.GetMemZone(mid);
677 if (buff == NULL) {
678 cout << " DataProcFFT2C::run()/ERROR memgr.GetMemZone(" << mid << ") -> NULL" << endl;
679 setRC(2);
680 return;
681 }
682 BRPaquet paq0(NULL, buff, paqsz);
683 uint_4 nzm = 0;
684 for(uint_4 i=0; i<memgr.NbPaquets(); i+=step_) {
685 BRPaquet paq(NULL, buff+i*paqsz, paqsz);
686 Byte min = 255;
687 Byte max = 0;
688
689 TwoByteComplex* zz;
690 // Traitement Voie 1
691 zz = (TwoByteComplex*)paq.Data1();
692 spectreV1(0) += zz[0].realD()*zz[0].realD(); // Composante continue, partie reelle uniquement
693 for(sa_size_t j=1; j<spectreV1.Size()-1; j++) spectreV1(j) += Zmod2TwoByte(zz[j]);
694
695 spectreV1(spectreV1.Size()-1) += zz[0].imagD()*zz[0].imagD(); // Freq. Nyquist a N/2
696
697 // Traitement Voie 2
698 zz = (TwoByteComplex*)paq.Data2();
699 spectreV2(0) += zz[0].realD()*zz[0].realD(); // Composante continue, partie reelle uniquement
700 for(sa_size_t j=1; j<spectreV2.Size()-1; j++) spectreV2(j) += Zmod2TwoByte(zz[j]);
701
702 spectreV2(spectreV2.Size()-1) += zz[0].imagD()*zz[0].imagD(); // Freq. Nyquist a N/2
703
704 nzm++;
705 }
706 if ((nzm >= nmean_) ||(kmz==(nmax_-1))) {
707 spectreV1 /= (r_4)(nzm);
708 spectreV2 /= (r_4)(nzm);
709 spectreV1.Info()["NPaqMoy"] = nzm;
710 spectreV2.Info()["NPaqMoy"] = nzm;
711 {
712 sprintf(fname,"%s/spectreFFT2C_%d.ppf",path_.c_str(),(int)ifile);
713 POutPersist po(fname);
714 po << PPFNameTag("specV1") << spectreV1;
715 po << PPFNameTag("specV2") << spectreV2;
716 }
717 spectreV1 = (r_4)(0.);
718 spectreV2 = (r_4)(0.);
719 nzm = 0; ifile++;
720 ts.SetNow();
721 filog << ts << " : proc file " << fname << endl;
722 cout << " DataProcFFT2C::run() " << ts << " : created file " << fname << endl;
723 }
724
725 memgr.FreeMemZone(mid, MemZS_Proc);
726 }
727 }
728 catch (std::exception& exc) {
729 cout << " DataProc::run()/catched std::exception " << exc.what() << endl;
730 setRC(3);
731 return;
732 }
733 catch(...) {
734 cout << " DataProcFFT2C::run()/catched unknown ... exception " << endl;
735 setRC(4);
736 return;
737 }
738 setRC(0);
739 return;
740}
Note: See TracBrowser for help on using the repository browser.