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

Last change on this file since 3642 was 3642, checked in by cmv, 16 years ago

ajout des #include C pour compil sur dernieres versions gcc/g++, cmv 27/05/2009

File size: 6.2 KB
Line 
1#include "racquproc.h"
2
3#include <stdlib.h>
4#include <string.h>
5#include <unistd.h>
6#include <fstream>
7#include <signal.h>
8
9#include "pexceptions.h"
10#include "tvector.h"
11#include "fioarr.h"
12#include "timestamp.h"
13#include "ctimer.h"
14#include "fftpserver.h"
15#include "fftwserver.h"
16
17#include "FFTW/fftw3.h"
18
19
20#include "pciewrap.h"
21#include "brpaqu.h"
22#include "brproc.h"
23
24
25//---------------------------------------------------------------
26// Classe thread de traitement donnees ADC avec 2 voies par frame
27//---------------------------------------------------------------
28
29BRProcARaw2C::BRProcARaw2C(RAcqMemZoneMgr& mem, string& path, uint_4 nmean,
30 uint_4 step, uint_4 nmax, bool fgnotrl)
31 : memgr(mem)
32{
33 nmax_ = nmax;
34 nmean_ = nmean;
35 step_ = step;
36 stop_ = false;
37 path_ = path;
38 fgnotrl_ = fgnotrl;
39}
40
41void BRProcARaw2C::Stop()
42{
43 stop_=true;
44 // cout <<" BRProcARaw2C::Stop ... > STOP " << endl;
45}
46
47
48static inline r_4 Zmod2(complex<r_4> z)
49{ return (z.real()*z.real()+z.imag()*z.imag()); }
50
51void BRProcARaw2C::run()
52{
53 setRC(1);
54 try {
55 Timer tm("BRProcARaw2C", false);
56 TimeStamp ts;
57 BRPaqChecker pcheck(~fgnotrl_); // Verification/comptage des paquets
58
59 size_t totnbytesout = 0;
60 size_t totnbytesproc = 0;
61
62 cout << " BRProcARaw2C::run() - Starting " << ts << " NMaxMemZones=" << nmax_
63 << " NMean=" << nmean_ << " Step=" << step_ << endl;
64 cout << " BRProcARaw2C::run()... - Output Data Path: " << path_ << endl;
65 char fname[512];
66// sprintf(fname,"%s/proc.log",path_.c_str());
67// ofstream filog(fname);
68// filog << " BRProcARaw2C::run() - starting log file " << ts << endl;
69// filog << " ... NMaxMemZones=" << nmax_ << " NMean=" << nmean_ << " Step=" << step_ << endl;
70
71// Initialisation pour calcul FFT
72 TVector< complex<r_4> > cfour1; // composant TF
73 uint_4 paqsz = memgr.PaqSize();
74 uint_4 procpaqsz = memgr.ProcPaqSize();
75 BRPaquet pq(NULL, NULL, paqsz);
76 TVector<r_4> vx(pq.DataSize()/2);
77 vx = (r_4)(0.);
78 FFTPackServer ffts;
79 ffts.FFTForward(vx, cfour1);
80 TVector< complex<r_4> > cfour2(cfour1.Size());
81
82 TVector<r_4> spectreV1(cfour1.Size());
83 TVector<r_4> spectreV2(cfour1.Size());
84 TVector< complex<r_4> > visiV12( cfour1.Size() );
85
86
87 fftwf_plan plan1 = fftwf_plan_dft_r2c_1d(vx.Size(), vx.Data(),
88 (fftwf_complex*)cfour1.Data(), FFTW_ESTIMATE);
89 fftwf_plan plan2 = fftwf_plan_dft_r2c_1d(vx.Size(), vx.Data(),
90 (fftwf_complex*)cfour2.Data(), FFTW_ESTIMATE);
91
92 uint_4 ifile = 0;
93 uint_4 nzm = 0;
94 for (uint_4 kmz=0; kmz<nmax_; kmz++) {
95 if (stop_) break;
96 int mid = memgr.FindMemZoneId(MemZA_ProcA);
97 Byte* buff = memgr.GetMemZone(mid);
98 if (buff == NULL) {
99 cout << " BRProcARaw2C::run()/ERROR memgr.GetMemZone(" << mid << ") -> NULL" << endl;
100 break;
101 }
102 Byte* procbuff = memgr.GetProcMemZone(mid);
103 if (procbuff == NULL) {
104 cout << " BRProcARaw2C::run()/ERROR memgr.GetProcMemZone(" << mid << ") -> NULL" << endl;
105 break;
106 }
107
108 for(uint_4 i=0; i<memgr.NbPaquets(); i+=step_) {
109 BRPaquet paq(NULL, buff+i*paqsz, paqsz);
110 if (!pcheck.Check(paq)) continue; // on ne traite que les paquets OK
111
112// Traitement voie 1
113 for(sa_size_t j=0; j<vx.Size(); j++)
114 vx(j) = (r_4)(*(paq.Data1()+j))-127.5;
115// fftwf_complex* coeff1 = (fftwf_complex*)(procbuff+i*procpaqsz);
116 fftwf_execute(plan1);
117// complex<r_4>* zp1 = (complex<r_4>*)(coeff1);
118// ffts.FFTForward(vx, cfour1);
119 for(sa_size_t j=0; j<spectreV1.Size(); j++)
120 spectreV1(j) += Zmod2(cfour1(j));
121 memcpy(procbuff+i*procpaqsz, cfour1.Data(), sizeof(complex<r_4>)*cfour1.Size());
122// Traitement voie 2
123 for(sa_size_t j=0; j<vx.Size(); j++)
124 vx(j) = (r_4)(*(paq.Data2()+j))-127.5;
125
126 fftwf_execute(plan2);
127
128 for(sa_size_t j=0; j<spectreV2.Size(); j++)
129 spectreV2(j) += Zmod2(cfour2(j)); // Zmod2(zp2[j]);
130 memcpy(procbuff+i*procpaqsz+procpaqsz/2, cfour2.Data(), sizeof(complex<r_4>)*cfour2.Size());
131
132// Calcul correlation (visibilite V1 * V2)
133 for(sa_size_t j=0; j<visiV12.Size(); j++)
134 visiV12(j)+=cfour1(j)*conj(cfour2(j));
135// for(sa_size_t j=0; j<visiV12.Size(); j++) visiV12(j)+=zp1[j]*zp2[j];
136 nzm++;
137 totnbytesproc += paq.DataSize();
138 totnbytesout += (2*sizeof(complex<r_4>)*cfour1.Size());
139
140 } // Fin de boucle sur les paquets d'une zone
141 if ((nzm >= nmean_) || ((kmz==(nmax_-1))&&(nzm>1))) {
142 spectreV1 /= (r_4)(nzm);
143 spectreV2 /= (r_4)(nzm);
144
145 visiV12 /= complex<r_4>((r_4)nzm, 0.);
146
147 spectreV1.Info()["NPaqMoy"] = nzm;
148 spectreV2.Info()["NPaqMoy"] = nzm;
149 visiV12.Info()["NPaqMoy"] = nzm;
150 {
151 sprintf(fname,"%s_%d.ppf",path_.c_str(),(int)ifile);
152 POutPersist po(fname);
153 po << PPFNameTag("specV1") << spectreV1;
154 po << PPFNameTag("specV2") << spectreV2;
155 po << PPFNameTag("visiV12") << visiV12;
156 }
157 spectreV1 = (r_4)(0.);
158 spectreV2 = (r_4)(0.);
159 visiV12 = complex<r_4>(0., 0.);
160 nzm = 0; ifile++;
161// ts.SetNow();
162// filog << ts << " : proc file " << fname << endl;
163 cout << " BRProcARaw2C::run() created file " << fname << endl;
164 }
165
166 memgr.FreeMemZone(mid, MemZS_ProcA);
167 } // Fin de boucle sur les zones a traiter
168 cout << " ------------------ BRProcARaw2C::run() END ----------------- " << endl;
169 ts.SetNow();
170 tm.SplitQ();
171 cout << " TotalProc= " << totnbytesproc/(1024*1024) << " MBytes, rate= "
172 << (double)(totnbytesproc)/1024./tm.PartialElapsedTimems() << " MB/s"
173 << " ProcDataOut=" << totnbytesout/(1024*1024) << " MB" << endl;
174 cout << pcheck;
175 cout << " BRProcARaw2C::run()/Timing: \n";
176 tm.Print();
177 cout << " ---------------------------------------------------------- " << endl;
178
179 }
180 catch (PException& exc) {
181 cout << " BRProcARaw2C::run()/catched PException " << exc.Msg() << endl;
182 setRC(3);
183 return;
184 }
185 catch(...) {
186 cout << " BRProcARaw2C::run()/catched unknown ... exception " << endl;
187 setRC(4);
188 return;
189 }
190 setRC(0);
191 return;
192}
193
194
195
196
Note: See TracBrowser for help on using the repository browser.