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

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

Corrections ds MonitorProc , Reza 20/11/2009

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