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

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

Ajout classe de traitement en ligne (monitoring) 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]);
182 nzm_[lc]++;
183 tbcp=paq.Data2C();
184 for(sa_size_t j=1; j<spectre_.NCols(); j++)
185 spectre_(lc,j) += Zmod2(tbcp[j]);
186 nzm_[lc+1]++;
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));
195 nzm_[lc]++;
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));
202 nzm_[lc+1]++;
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);
225 po << PPFNameTag("spectre") << spectre_;
226 spectre_ = (r_4)(0.);
227 for(int lc=0; lc<2*memgr.NbFibres(); lc++) nzm_[lc]=0;
228 ts.SetNow();
229 // Calcul / impression fraction des paquets avec same-framecounter
230 int fracsame=0;
231 if (nprocpaq_>0) fracsame=100*npaqsamefc_/nprocpaq_;
232 int totfracsame=0;
233 if (totnprocpaq_>0) totfracsame=100*totnpaqsamefc_/totnprocpaq_;
234 filog << ts << " : proc file (meanspectra) " << fname << endl;
235 filog << " NBlocProcessed=" << nblocproc_ << " NSameFC=" << totnpaqsamefc_ << " / " << totnprocpaq_
236 << " -> " << totfracsame << " % (LastPqs: " << npaqsamefc_ << " / " << nprocpaq_
237 << " -> " << fracsame << " % )" << endl;
238 cout << " MonitorProc::procData2C() " << ts << " : created file " << fname << endl;
239 cout << " NBlocProcessed=" << nblocproc_ << " NSameFC=" << totnpaqsamefc_ << " / " << totnprocpaq_
240 << " -> " << totfracsame << " % (LastPqs: " << npaqsamefc_ << " / " << nprocpaq_
241 << " -> " << fracsame << " % )" << endl;
242 nprocpaq_=npaqsamefc_=0;
243 }
244 } // Fin de boucle sur les kmz ( bloc MemZoneMgr a traiter )
245
246 bool fgnzm=false;
247 for(int lc=0; lc<2*memgr.NbFibres(); lc++)
248 if (nzm_[lc]>0) fgnzm=true;
249
250 if (fgnzm) {
251 char buff[32];
252 for(sa_size_t lc=0; lc<2*memgr.NbFibres(); lc++) {
253 if (nzm_[lc]>0) spectre_.Row(lc) /= (r_4)nzm_[lc];
254 sprintf(buff,"NPaqMoy%d",(int)lc);
255 spectre_.Info()[buff] = nzm_[lc];
256 }
257 sprintf(fname,"%s/meanspec%d.ppf",path_.c_str(),(int)nfiles_);
258 POutPersist po(fname);
259 po << PPFNameTag("spectre") << spectre_;
260 spectre_ = (r_4)(0.);
261 for(int lc=0; lc<2*memgr.NbFibres(); lc++) nzm_[lc]=0;
262 ts.SetNow();
263 // Calcul / impression fraction des paquets avec same-framecounter
264 int fracsame=0;
265 if (nprocpaq_>0) fracsame=100*npaqsamefc_/nprocpaq_;
266 int totfracsame=0;
267 if (totnprocpaq_>0) totfracsame=100*totnpaqsamefc_/totnprocpaq_;
268 filog << ts << " : proc file (meanspectra) " << fname << endl;
269 filog << " NBlocProcessed=" << nblocproc_ << " NSameFC=" << totnpaqsamefc_ << " / " << totnprocpaq_
270 << " -> " << totfracsame << " % (LastPqs: " << npaqsamefc_ << " / " << nprocpaq_
271 << " -> " << fracsame << " % )" << endl;
272 cout << " MonitorProc::procData2C() " << ts << " : created file " << fname << endl;
273 cout << " NBlocProcessed=" << nblocproc_ << " NSameFC=" << totnpaqsamefc_ << " / " << totnprocpaq_
274 << " -> " << totfracsame << " % (LastPqs: " << npaqsamefc_ << " / " << nprocpaq_
275 << " -> " << fracsame << " % )" << endl;
276 }
277 return 0;
278}
279
280/* --Methode-- */
281int MonitorProc::CheckFrameCounters()
282{
283 if (memgr.NbFibres()<2) {
284 npaqsamefc_++; totnpaqsamefc_++;
285 return 99;
286 }
287 sa_size_t pidx[MAXNBFIB];
288 sa_size_t maxidx=curfc_.NCols();
289 uint_8 cfc=0;
290 for(uint_4 fib=0; fib<curfc_.NRows(); fib++) {
291 pidx[fib]=0;
292 while((pidx[fib]<maxidx)&&(cpaqok_(fib,pidx[fib])==0)) pidx[fib]++;
293 }
294
295 bool fgsuite=true;
296 while (fgsuite) { // Boucle sur l'ensemble des paquets
297 for(uint_4 fib=0; fib<curfc_.NRows(); fib++) {
298 if ((pidx[fib]>=maxidx)||(cpaqok_(fib,pidx[fib])==0)) { fgsuite=false; break; }
299 }
300 if (!fgsuite) break;
301 cfc=curfc_(0,pidx[0]);
302 bool fgsame=true;
303 for(uint_4 fib=1; fib<curfc_.NRows(); fib++) {
304 if (curfc_(fib,pidx[fib])!=cfc) {
305 fgsame=false;
306 if (curfc_(fib,pidx[fib]) > cfc) cfc=curfc_(fib,pidx[fib]);
307 }
308 }
309 if (fgsame) {
310 npaqsamefc_++; totnpaqsamefc_++;
311 for(uint_4 fib=0; fib<curfc_.NRows(); fib++) {
312 pidx[fib]++;
313 while((pidx[fib]<maxidx)&&(cpaqok_(fib,pidx[fib])==0)) pidx[fib]++;
314 }
315 } // fin if (fgsame)
316 else { // else !fgsame
317 for(uint_4 fib=0; fib<memgr.NbFibres(); fib++) {
318 if (curfc_(fib,pidx[fib])<cfc) {
319 pidx[fib]++;
320 while((pidx[fib]<maxidx)&&(cpaqok_(fib,pidx[fib])==0)) pidx[fib]++;
321 }
322 }
323 } // fin de else !fgsame
324 } // Fin de while sur l'ensemble des paquets
325 return 0;
326}
327
328
329static struct sigaction act;
[3537]330//-------------------------------------------------------
[3623]331// Classe thread de traitement avec 1 voie par frame
[3537]332//-------------------------------------------------------
333
[3623]334void DataProcSignal(int s)
335{
336 cout <<"............................................... receive CtrlC" << endl;
337
338}
339
340DataProc::DataProc(RAcqMemZoneMgr& mem, string& path, uint_4 nmean, uint_4 step, uint_4 nmax)
[3537]341 : memgr(mem)
342{
343 nmax_ = nmax;
344 nmean_ = nmean;
[3623]345 step_ = step;
[3537]346 stop_ = false;
347 path_ = path;
[3623]348 act.sa_handler=DataProcSignal;
[3537]349}
350
351
[3623]352void DataProc::Stop()
353{
354 stop_=true;
355 // cout <<" DataProc::Stop ... > STOP " << endl;
356}
357
[3537]358void DataProc::run()
359{
[3623]360
361 // sigaddset(&act.sa_mask,SIGINT); // pour proteger le transfert DMA
362 // sigaction(SIGINT,&act,NULL);
[3537]363 setRC(1);
364 try {
365 TimeStamp ts;
[3623]366 cout << " DataProc::run() - Starting " << ts << " NMaxMemZones=" << nmax_
367 << " NMean=" << nmean_ << " Step=" << step_ << endl;
[3634]368 cout << " DataProc::run()... - Output Data Path: " << path_ << endl;
[3537]369 char fname[512];
370 sprintf(fname,"%s/proc.log",path_.c_str());
371 ofstream filog(fname);
372 filog << " DataProc::run() - starting log file " << ts << endl;
[3623]373 filog << " ... NMaxMemZones=" << nmax_ << " NMean=" << nmean_ << " Step=" << step_ << endl;
[3537]374
375// Initialisation pour clcul FFT
376 TVector< complex<r_4> > cfour; // composant TF
377 uint_4 paqsz = memgr.PaqSize();
378 BRPaquet pq(NULL, NULL, paqsz);
379 TVector<r_4> vx(pq.DataSize());
380 vx = (r_4)(0.);
381 FFTPackServer ffts;
382 ffts.FFTForward(vx, cfour);
383 TVector<r_4> spectre;
384 spectre.ReSize(cfour.Size());
385
[3623]386 fftwf_plan plan = fftwf_plan_dft_r2c_1d(vx.Size(), vx.Data(),
387 (fftwf_complex *)cfour.Data(), FFTW_ESTIMATE);
[3537]388
389 uint_4 ifile = 0;
[3623]390 uint_4 nzm = 0;
[3537]391 for (uint_4 kmz=0; kmz<nmax_; kmz++) {
[3623]392 if (stop_) break;
[3537]393 int mid = memgr.FindMemZoneId(MemZA_Proc);
394 Byte* buff = memgr.GetMemZone(mid);
395 if (buff == NULL) {
396 cout << " DataProc::run()/ERROR memgr.GetMemZone(" << mid << ") -> NULL" << endl;
397 setRC(2);
398 return;
399 }
400 BRPaquet paq0(NULL, buff, paqsz);
[3623]401 for(uint_4 i=0; i<memgr.NbPaquets(); i+=step_) {
[3537]402 BRPaquet paq(NULL, buff+i*paqsz, paqsz);
403 Byte min = 255;
404 Byte max = 0;
405
406 for(sa_size_t j=0; j<vx.Size(); j++)
[3623]407 vx(j) = (r_4)(*(paq.Data1()+j))-127.5;
[3537]408 fftwf_execute(plan);
[3623]409 // ffts_.FFTForward(vx, cfour_);
[3537]410 for(sa_size_t j=0; j<spectre.Size(); j++)
411 spectre(j) += Zmod2(cfour(j));
412 nzm++;
413 }
[3623]414 if ((nzm >= nmean_) ||(kmz==(nmax_-1))) {
[3537]415 spectre /= (r_4)(nzm);
[3623]416 spectre.Info()["NPaqMoy"] = nzm;
[3537]417 sprintf(fname,"%s/spectre%d.ppf",path_.c_str(),(int)ifile);
418 POutPersist po(fname);
419 po << spectre;
420 spectre = (r_4)(0.);
421 nzm = 0; ifile++;
422 ts.SetNow();
423 filog << ts << " : proc file " << fname << endl;
424 cout << " DataProc::run() " << ts << " : created file " << fname << endl;
425 }
426
427 memgr.FreeMemZone(mid, MemZS_Proc);
428 }
429 }
[3671]430 catch (std::exception& exc) {
431 cout << " DataProc::run()/catched std::exception " << exc.what() << endl;
[3537]432 setRC(3);
433 return;
434 }
435 catch(...) {
436 cout << " DataProc::run()/catched unknown ... exception " << endl;
437 setRC(4);
438 return;
439 }
440 setRC(0);
441 return;
442}
[3623]443
444//---------------------------------------------------------------
445// Classe thread de traitement donnees ADC avec 2 voies par frame
446//---------------------------------------------------------------
447
448DataProc2C::DataProc2C(RAcqMemZoneMgr& mem, string& path, uint_4 nmean, uint_4 step, uint_4 nmax)
449 : memgr(mem)
450{
451 nmax_ = nmax;
452 nmean_ = nmean;
453 step_ = step;
454 stop_ = false;
455 path_ = path;
456 act.sa_handler=DataProcSignal;
457}
458void DataProc2C::Stop()
459{
460 stop_=true;
461 // cout <<" DataProc2C::Stop ... > STOP " << endl;
462}
463
464void DataProc2C::run()
465{
466 // sigaction(SIGINT,&act,NULL);
467 setRC(1);
468 try {
469 TimeStamp ts;
470 cout << " DataProc2C::run() - Starting " << ts << " NMaxMemZones=" << nmax_
471 << " NMean=" << nmean_ << " Step=" << step_ << endl;
[3634]472 cout << " DataProc::run()... - Output Data Path: " << path_ << endl;
[3623]473 char fname[512];
474 sprintf(fname,"%s/proc.log",path_.c_str());
475 ofstream filog(fname);
476 filog << " DataProc2C::run() - starting log file " << ts << endl;
477 filog << " ... NMaxMemZones=" << nmax_ << " NMean=" << nmean_ << " Step=" << step_ << endl;
478
479// Initialisation pour clcul FFT
480 TVector< complex<r_4> > cfour; // composant TF
481 uint_4 paqsz = memgr.PaqSize();
482 BRPaquet pq(NULL, NULL, paqsz);
483 TVector<r_4> vx(pq.DataSize()/2);
484 vx = (r_4)(0.);
485 FFTPackServer ffts;
486 ffts.FFTForward(vx, cfour);
487 TVector<r_4> spectreV1, spectreV2;
488 spectreV1.ReSize(cfour.Size());
489 spectreV2.ReSize(cfour.Size());
490
491 fftwf_plan plan = fftwf_plan_dft_r2c_1d(vx.Size(), vx.Data(),
492 (fftwf_complex *)cfour.Data(), FFTW_ESTIMATE);
493
494 uint_4 ifile = 0;
495 uint_4 nzm = 0;
496 for (uint_4 kmz=0; kmz<nmax_; kmz++) {
497 if (stop_) break;
498 int mid = memgr.FindMemZoneId(MemZA_Proc);
499 Byte* buff = memgr.GetMemZone(mid);
500 if (buff == NULL) {
501 cout << " DataProc2C::run()/ERROR memgr.GetMemZone(" << mid << ") -> NULL" << endl;
502 setRC(2);
503 return;
504 }
505 BRPaquet paq0(NULL, buff, paqsz);
506 for(uint_4 i=0; i<memgr.NbPaquets(); i+=step_) {
507 BRPaquet paq(NULL, buff+i*paqsz, paqsz);
508 Byte min = 255;
509 Byte max = 0;
510
511 for(sa_size_t j=0; j<vx.Size(); j++)
512 vx(j) = (r_4)(*(paq.Data1()+j))-127.5;
513 fftwf_execute(plan);
514 // ffts_.FFTForward(vx, cfour_);
515 for(sa_size_t j=0; j<spectreV1.Size(); j++)
516 spectreV1(j) += Zmod2(cfour(j));
517
518 for(sa_size_t j=0; j<vx.Size(); j++)
519 vx(j) = (r_4)(*(paq.Data2()+j))-127.5;
520 fftwf_execute(plan);
521 // ffts_.FFTForward(vx, cfour_);
522 for(sa_size_t j=0; j<spectreV2.Size(); j++)
523 spectreV2(j) += Zmod2(cfour(j));
524
525 nzm++;
526 }
527 if ((nzm >= nmean_) ||(kmz==(nmax_-1))) {
528 spectreV1 /= (r_4)(nzm);
529 spectreV2 /= (r_4)(nzm);
530 spectreV1.Info()["NPaqMoy"] = nzm;
531 spectreV2.Info()["NPaqMoy"] = nzm;
532 {
533 sprintf(fname,"%s/spectre2C_%d.ppf",path_.c_str(),(int)ifile);
534 POutPersist po(fname);
535 po << PPFNameTag("specV1") << spectreV1;
536 po << PPFNameTag("specV2") << spectreV2;
537 }
538 spectreV1 = (r_4)(0.);
539 spectreV2 = (r_4)(0.);
540 nzm = 0; ifile++;
541 ts.SetNow();
542 filog << ts << " : proc file " << fname << endl;
543 cout << " DataProc2C::run() " << ts << " : created file " << fname << endl;
544 }
545
546 memgr.FreeMemZone(mid, MemZS_Proc);
547 }
548 }
[3671]549 catch (std::exception& exc) {
550 cout << " DataProc::run()/catched std::exception " << exc.what() << endl;
[3623]551 setRC(3);
552 return;
553 }
554 catch(...) {
555 cout << " DataProc2C::run()/catched unknown ... exception " << endl;
556 setRC(4);
557 return;
558 }
559 setRC(0);
560 return;
561}
562
563
564
565
566//---------------------------------------------------------------
567// Classe thread de traitement donnees FFT avec 2 voies par frame
568//---------------------------------------------------------------
569
570inline r_4 Zmod2TwoByte(TwoByteComplex z)
571{ return (z.realD()*z.realD()+z.imagD()*z.imagD()); }
572
573DataProcFFT2C::DataProcFFT2C(RAcqMemZoneMgr& mem, string& path, uint_4 nmean, uint_4 step, uint_4 nmax)
574 : memgr(mem)
575{
576 nmax_ = nmax;
577 nmean_ = nmean;
578 step_ = step;
579 stop_ = false;
580 path_ = path;
581 act.sa_handler=DataProcSignal;
582}
583void DataProcFFT2C::Stop()
584{
585 stop_=true;
586 // cout <<" DataProcFFT2C::Stop ... > STOP " << endl;
587}
588
589void DataProcFFT2C::run()
590{
591 // sigaction(SIGINT,&act,NULL);
592 setRC(1);
593 try {
594 TimeStamp ts;
595 cout << " DataProcFFT2C::run() - Starting " << ts << " NMaxMemZones=" << nmax_
596 << " NMean=" << nmean_ << " Step=" << step_ << endl;
[3634]597 cout << " DataProc::run()... - Output Data Path: " << path_ << endl;
[3623]598 char fname[512];
599 sprintf(fname,"%s/proc.log",path_.c_str());
600 ofstream filog(fname);
601 filog << " DataProcFFT2C::run() - starting log file " << ts << endl;
602 filog << " ... NMaxMemZones=" << nmax_ << " NMean=" << nmean_ << " Step=" << step_ << endl;
603
604// Initialisation pour clcul FFT
605 TVector< complex<r_4> > cfour; // composant TF
606 uint_4 paqsz = memgr.PaqSize();
607 BRPaquet pq(NULL, NULL, paqsz);
608
609 TVector<r_4> spectreV1(pq.DataSize()/4+1), spectreV2(pq.DataSize()/4+1);
610
611 uint_4 ifile = 0;
612 for (uint_4 kmz=0; kmz<nmax_; kmz++) {
613 if (stop_ ) break;
614 int mid = memgr.FindMemZoneId(MemZA_Proc);
615 Byte* buff = memgr.GetMemZone(mid);
616 if (buff == NULL) {
617 cout << " DataProcFFT2C::run()/ERROR memgr.GetMemZone(" << mid << ") -> NULL" << endl;
618 setRC(2);
619 return;
620 }
621 BRPaquet paq0(NULL, buff, paqsz);
622 uint_4 nzm = 0;
623 for(uint_4 i=0; i<memgr.NbPaquets(); i+=step_) {
624 BRPaquet paq(NULL, buff+i*paqsz, paqsz);
625 Byte min = 255;
626 Byte max = 0;
627
628 TwoByteComplex* zz;
629 // Traitement Voie 1
630 zz = (TwoByteComplex*)paq.Data1();
631 spectreV1(0) += zz[0].realD()*zz[0].realD(); // Composante continue, partie reelle uniquement
632 for(sa_size_t j=1; j<spectreV1.Size()-1; j++) spectreV1(j) += Zmod2TwoByte(zz[j]);
633
634 spectreV1(spectreV1.Size()-1) += zz[0].imagD()*zz[0].imagD(); // Freq. Nyquist a N/2
635
636 // Traitement Voie 2
637 zz = (TwoByteComplex*)paq.Data2();
638 spectreV2(0) += zz[0].realD()*zz[0].realD(); // Composante continue, partie reelle uniquement
639 for(sa_size_t j=1; j<spectreV2.Size()-1; j++) spectreV2(j) += Zmod2TwoByte(zz[j]);
640
641 spectreV2(spectreV2.Size()-1) += zz[0].imagD()*zz[0].imagD(); // Freq. Nyquist a N/2
642
643 nzm++;
644 }
645 if ((nzm >= nmean_) ||(kmz==(nmax_-1))) {
646 spectreV1 /= (r_4)(nzm);
647 spectreV2 /= (r_4)(nzm);
648 spectreV1.Info()["NPaqMoy"] = nzm;
649 spectreV2.Info()["NPaqMoy"] = nzm;
650 {
651 sprintf(fname,"%s/spectreFFT2C_%d.ppf",path_.c_str(),(int)ifile);
652 POutPersist po(fname);
653 po << PPFNameTag("specV1") << spectreV1;
654 po << PPFNameTag("specV2") << spectreV2;
655 }
656 spectreV1 = (r_4)(0.);
657 spectreV2 = (r_4)(0.);
658 nzm = 0; ifile++;
659 ts.SetNow();
660 filog << ts << " : proc file " << fname << endl;
661 cout << " DataProcFFT2C::run() " << ts << " : created file " << fname << endl;
662 }
663
664 memgr.FreeMemZone(mid, MemZS_Proc);
665 }
666 }
[3671]667 catch (std::exception& exc) {
668 cout << " DataProc::run()/catched std::exception " << exc.what() << endl;
[3623]669 setRC(3);
670 return;
671 }
672 catch(...) {
673 cout << " DataProcFFT2C::run()/catched unknown ... exception " << endl;
674 setRC(4);
675 return;
676 }
677 setRC(0);
678 return;
679}
Note: See TracBrowser for help on using the repository browser.