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

Last change on this file since 3710 was 3683, checked in by ansari, 16 years ago

Mise a jour et ajout de fichier pour taritement multifibres apres

prise de donnees de Nov2009 a Pittsburgh

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