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