source: Sophya/trunk/AddOn/TAcq/brproc.cc@ 3635

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

Amelioration/ correction diverses, introduction du programme de lecture / traitement multi-thread mcrd.cc - Reza 26/05/2009

File size: 5.0 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 "ctimer.h"
13#include "fftpserver.h"
14#include "fftwserver.h"
15
16#include "FFTW/fftw3.h"
17
18
19#include "pciewrap.h"
20#include "brpaqu.h"
21#include "brproc.h"
22
23
24//---------------------------------------------------------------
25// Classe thread de traitement donnees ADC avec 2 voies par frame
26//---------------------------------------------------------------
27
28BRProcARaw2C::BRProcARaw2C(RAcqMemZoneMgr& mem, string& path, uint_4 nmean, uint_4 step, uint_4 nmax)
29 : memgr(mem)
30{
31 nmax_ = nmax;
32 nmean_ = nmean;
33 step_ = step;
34 stop_ = false;
35 path_ = path;
36}
37
38void BRProcARaw2C::Stop()
39{
40 stop_=true;
41 // cout <<" BRProcARaw2C::Stop ... > STOP " << endl;
42}
43
44
45static inline r_4 Zmod2(complex<r_4> z)
46{ return (z.real()*z.real()+z.imag()*z.imag()); }
47
48void BRProcARaw2C::run()
49{
50 setRC(1);
51 try {
52 Timer tm("BRProcARaw2C");
53 TimeStamp ts;
54 cout << " BRProcARaw2C::run() - Starting " << ts << " NMaxMemZones=" << nmax_
55 << " NMean=" << nmean_ << " Step=" << step_ << endl;
56 cout << " BRProcARaw2C::run()... - Output Data Path: " << path_ << endl;
57 char fname[512];
58// sprintf(fname,"%s/proc.log",path_.c_str());
59// ofstream filog(fname);
60// filog << " BRProcARaw2C::run() - starting log file " << ts << endl;
61// filog << " ... NMaxMemZones=" << nmax_ << " NMean=" << nmean_ << " Step=" << step_ << endl;
62
63// Initialisation pour calcul FFT
64 TVector< complex<r_4> > cfour; // composant TF
65 uint_4 paqsz = memgr.PaqSize();
66 uint_4 procpaqsz = memgr.ProcPaqSize();
67 BRPaquet pq(NULL, NULL, paqsz);
68 TVector<r_4> vx(pq.DataSize()/2);
69 vx = (r_4)(0.);
70 FFTPackServer ffts;
71 ffts.FFTForward(vx, cfour);
72 TVector<r_4> spectreV1, spectreV2;
73
74 spectreV1.ReSize(cfour.Size());
75 spectreV2.ReSize(cfour.Size());
76
77 TVector< complex<r_4> > visiV12( cfour.Size() );
78
79
80 uint_4 ifile = 0;
81 uint_4 nzm = 0;
82 for (uint_4 kmz=0; kmz<nmax_; kmz++) {
83 if (stop_) break;
84 int mid = memgr.FindMemZoneId(MemZA_ProcA);
85 Byte* buff = memgr.GetMemZone(mid);
86 if (buff == NULL) {
87 cout << " BRProcARaw2C::run()/ERROR memgr.GetMemZone(" << mid << ") -> NULL" << endl;
88 break;
89 }
90 Byte* procbuff = memgr.GetProcMemZone(mid);
91 if (procbuff == NULL) {
92 cout << " BRProcARaw2C::run()/ERROR memgr.GetProcMemZone(" << mid << ") -> NULL" << endl;
93 break;
94 }
95 BRPaquet paq0(NULL, buff, paqsz);
96 for(uint_4 i=0; i<memgr.NbPaquets(); i+=step_) {
97 BRPaquet paq(NULL, buff+i*paqsz, paqsz);
98 Byte min = 255;
99 Byte max = 0;
100
101// Traitement voie 1
102 for(sa_size_t j=0; j<vx.Size(); j++)
103 vx(j) = (r_4)(*(paq.Data1()+j))-127.5;
104 fftwf_complex* coeff1 = (fftwf_complex*)(procbuff+i*procpaqsz);
105 fftwf_plan plan = fftwf_plan_dft_r2c_1d(vx.Size(), vx.Data(), coeff1, FFTW_ESTIMATE);
106 fftwf_execute(plan);
107 // ffts_.FFTForward(vx, cfour_);
108 complex<r_4>* zp1 = (complex<r_4>*)(coeff1);
109 for(sa_size_t j=0; j<spectreV1.Size(); j++)
110 spectreV1(j) += Zmod2(zp1[j]);
111
112// Traitement voie 2
113 for(sa_size_t j=0; j<vx.Size(); j++)
114 vx(j) = (r_4)(*(paq.Data2()+j))-127.5;
115 fftwf_complex* coeff2 = (fftwf_complex*)(procbuff+i*procpaqsz+procpaqsz/2);
116 plan = fftwf_plan_dft_r2c_1d(vx.Size(), vx.Data(), coeff2, FFTW_ESTIMATE);
117 fftwf_execute(plan);
118 // ffts_.FFTForward(vx, cfour_);
119 complex<r_4>* zp2 = (complex<r_4>*)(coeff2);
120 for(sa_size_t j=0; j<spectreV2.Size(); j++)
121 spectreV2(j) += Zmod2(zp2[j]);
122
123// Calcul correlation (visibilite V1 * V2)
124 for(sa_size_t j=0; j<visiV12.Size(); j++) visiV12(j)+=zp1[j]*zp2[j];
125
126 nzm++;
127 }
128 if ((nzm >= nmean_) ||(kmz==(nmax_-1))) {
129 spectreV1 /= (r_4)(nzm);
130 spectreV2 /= (r_4)(nzm);
131
132 visiV12 /= complex<r_4>((r_4)nzm, 0.);
133
134 spectreV1.Info()["NPaqMoy"] = nzm;
135 spectreV2.Info()["NPaqMoy"] = nzm;
136 visiV12.Info()["NPaqMoy"] = nzm;
137 {
138 sprintf(fname,"%s_%d.ppf",path_.c_str(),(int)ifile);
139 POutPersist po(fname);
140 po << PPFNameTag("specV1") << spectreV1;
141 po << PPFNameTag("specV2") << spectreV2;
142 po << PPFNameTag("visiV12") << visiV12;
143 }
144 spectreV1 = (r_4)(0.);
145 spectreV2 = (r_4)(0.);
146 visiV12 = complex<r_4>(0., 0.);
147 nzm = 0; ifile++;
148// ts.SetNow();
149// filog << ts << " : proc file " << fname << endl;
150 cout << " BRProcARaw2C::run() created file " << fname << endl;
151 }
152
153 memgr.FreeMemZone(mid, MemZS_ProcA);
154 }
155 }
156 catch (PException& exc) {
157 cout << " BRProcARaw2C::run()/catched PException " << exc.Msg() << endl;
158 setRC(3);
159 return;
160 }
161 catch(...) {
162 cout << " BRProcARaw2C::run()/catched unknown ... exception " << endl;
163 setRC(4);
164 return;
165 }
166 setRC(0);
167 return;
168}
169
170
171
172
Note: See TracBrowser for help on using the repository browser.