| 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& filog)
|
|---|
| 158 | {
|
|---|
| 159 | BRPaqChecker pcheck[MAXNBFIB]; // Verification/comptage des paquets
|
|---|
| 160 | // Initialisation pour calcul FFT
|
|---|
| 161 | uint_4 paqsz = memgr.PaqSize();
|
|---|
| 162 | BRPaquet pq(paqsz);
|
|---|
| 163 | TVector<r_4> vx(pq.DataSize());
|
|---|
| 164 | vx = (r_4)(0.);
|
|---|
| 165 | TVector< complex<r_4> > cfour(pq.DataSize()/2+1); // composant TF
|
|---|
| 166 |
|
|---|
| 167 | fftwf_plan plan = fftwf_plan_dft_r2c_1d(vx.Size(), vx.Data(),
|
|---|
| 168 | (fftwf_complex *)cfour.Data(), FFTW_ESTIMATE);
|
|---|
| 169 |
|
|---|
| 170 | // Histo pour valeurs des bytes dans les paquets
|
|---|
| 171 | Histo* phist[MAXNBFIB];
|
|---|
| 172 | Histo2D* ph2[MAXNBFIB];
|
|---|
| 173 | Histo* phexp[MAXNBFIB];
|
|---|
| 174 | TMatrix<r_4>* psatur[MAXNBFIB];
|
|---|
| 175 | TVector<uint_4>* pvsatfreq[MAXNBFIB];
|
|---|
| 176 | for(int ifib=0; ifib<MAXNBFIB; ifib++) {
|
|---|
| 177 | phist[ifib]=NULL; ph2[ifib]=NULL; phexp[ifib]=NULL; psatur[ifib]=NULL;
|
|---|
| 178 | }
|
|---|
| 179 | if (par_.fgdatafft) { // data de type FFT
|
|---|
| 180 | for(sa_size_t lc=0; lc<memgr.NbFibres(); lc++) {
|
|---|
| 181 | phist[lc] = new Histo(-128.5,+128.5,257);
|
|---|
| 182 | ph2[lc] = new Histo2D(-128.5,+128.5,257, -128.5,+128.5,257);
|
|---|
| 183 | phexp[lc] = new Histo(-128.5,+128.5,257);
|
|---|
| 184 | psatur[lc] = new TMatrix<r_4>(3,3);
|
|---|
| 185 | pvsatfreq[lc] = new TVector<uint_4>(spectre_.NCols());
|
|---|
| 186 | *psatur[lc] = 0.;
|
|---|
| 187 | }
|
|---|
| 188 | }
|
|---|
| 189 | else {
|
|---|
| 190 | for(sa_size_t lc=0; lc<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::procData1C()/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::procData1C()/ERROR memgr.GetMemZone(" << mid << "," << fib << ") -> NULL" << endl;
|
|---|
| 217 | return 9;
|
|---|
| 218 | }
|
|---|
| 219 | }
|
|---|
| 220 |
|
|---|
| 221 | // DBG-ATTENTION : freq 0 pour expo full FFT si reordonne
|
|---|
| 222 | // int idxexpo=(par_.fgfftshrink)?1023:0; // exposant FFT shrink 1024 freq, ou freq 0 pour full-FFT
|
|---|
| 223 | int idxexpo=0;
|
|---|
| 224 |
|
|---|
| 225 | cpaqok_ = (uint_1)0;
|
|---|
| 226 | curfc_ = (uint_8)0;
|
|---|
| 227 | for(uint_4 fib=0; fib<memgr.NbFibres(); fib++) {
|
|---|
| 228 | for(uint_4 i=0; i<memgr.NbPaquets(); i++) {
|
|---|
| 229 | BRPaquet paq(fbuff[fib]+i*paqsz, paqsz);
|
|---|
| 230 | bool pqok=pcheck[fib].Check(paq,curfc_(fib,i)); // Verification du paquet / FrameCounter
|
|---|
| 231 | if (!pqok) continue;
|
|---|
| 232 | cpaqok_(fib,i) = 1;
|
|---|
| 233 | sa_size_t lc=fib;
|
|---|
| 234 | if (par_.fgdatafft) { // Traitement data de type FFT
|
|---|
| 235 | TwoByteComplex* tbcp=paq.Data1C();
|
|---|
| 236 |
|
|---|
| 237 | // exposant FFT
|
|---|
| 238 | phexp[lc]->Add((r_4)tbcp[idxexpo].realD());
|
|---|
| 239 |
|
|---|
| 240 | for(sa_size_t j=1; j<spectre_.NCols(); j++) {
|
|---|
| 241 | phist[lc]->Add((r_4)tbcp[j].realD());
|
|---|
| 242 | phist[lc]->Add((r_4)tbcp[j].imagD());
|
|---|
| 243 | ph2[lc]->Add((r_4)tbcp[j].realD(), (r_4)tbcp[j].imagD());
|
|---|
| 244 | // comptage saturation
|
|---|
| 245 | int sir=0, sii=0; // saturation partie reelle, partie imaginaire
|
|---|
| 246 | if (tbcp[j].realI()==-128) sir=-1;
|
|---|
| 247 | else if (tbcp[j].realI()==127) sir=1;
|
|---|
| 248 | if (tbcp[j].imagI()==-128) sii=-1;
|
|---|
| 249 | else if (tbcp[j].imagI()==127) sii=1;
|
|---|
| 250 | (*psatur[lc])(sir+1,sii+1)+=1.;
|
|---|
| 251 | if ((sir!=0)||(sii!=0)) (*pvsatfreq[lc])(j)+=1;
|
|---|
| 252 | spectre_(lc,j) += Zmod2(tbcp[j]);
|
|---|
| 253 | }
|
|---|
| 254 | nzm_[lc]++;
|
|---|
| 255 | }
|
|---|
| 256 | else { // Traitement RawData
|
|---|
| 257 | for(sa_size_t j=0; j<vx.Size(); j++) {
|
|---|
| 258 | phist[lc]->Add((r_8)(*(paq.Data1()+j)));
|
|---|
| 259 | vx(j) = (r_4)(*(paq.Data1()+j))-127.5;
|
|---|
| 260 | }
|
|---|
| 261 | fftwf_execute(plan);
|
|---|
| 262 | // ffts_.FFTForward(vx, cfour_);
|
|---|
| 263 | for(sa_size_t j=0; j<spectre_.NCols(); j++)
|
|---|
| 264 | spectre_(lc,j) += Zmod2(cfour(j+1));
|
|---|
| 265 | nzm_[lc]++; lc++;
|
|---|
| 266 | }
|
|---|
| 267 | } // FIN de la boucle sur les paquets
|
|---|
| 268 | } // Boucle sur les fibres
|
|---|
| 269 | memgr.FreeMemZone(mid, mmsta_); // MemZS_Proc);
|
|---|
| 270 | CheckFrameCounters();
|
|---|
| 271 |
|
|---|
| 272 | nblocproc_ ++;
|
|---|
| 273 | totnprocpaq_ += memgr.NbPaquets(); nprocpaq_ += memgr.NbPaquets();
|
|---|
| 274 | bool fgnzm=true;
|
|---|
| 275 | for(int lc=0; lc<memgr.NbFibres(); lc++)
|
|---|
| 276 | if (nzm_[lc]<nmean_) fgnzm=false;
|
|---|
| 277 |
|
|---|
| 278 | if (fgnzm) {
|
|---|
| 279 | char buff[32];
|
|---|
| 280 | for(sa_size_t lc=0; lc<memgr.NbFibres(); lc++) {
|
|---|
| 281 | spectre_.Row(lc) /= (r_4)nzm_[lc];
|
|---|
| 282 | sprintf(buff,"NPaqMoy%d",(int)lc);
|
|---|
| 283 | spectre_.Info()[buff] = nzm_[lc];
|
|---|
| 284 | }
|
|---|
| 285 | sprintf(fname,"%s/meanspec%d.ppf",path_.c_str(),(int)nfiles_);
|
|---|
| 286 | nfiles_++;
|
|---|
| 287 | POutPersist po(fname);
|
|---|
| 288 | po << PPFNameTag("spectre") << spectre_;
|
|---|
| 289 | spectre_ = (r_4)(0.);
|
|---|
| 290 | char buftag[32];
|
|---|
| 291 | for(int lc=0; lc<memgr.NbFibres(); lc++) {
|
|---|
| 292 | sprintf(buftag,"hvalV%d",(int)lc);
|
|---|
| 293 | po << PPFNameTag(buftag) << (*phist[lc]);
|
|---|
| 294 | phist[lc]->Zero();
|
|---|
| 295 | if (par_.fgdatafft) { // data de type FFT
|
|---|
| 296 | sprintf(buftag,"h2dV%d",(int)lc);
|
|---|
| 297 | po << PPFNameTag(buftag) << (*ph2[lc]);
|
|---|
| 298 | ph2[lc]->Zero();
|
|---|
| 299 | sprintf(buftag,"hexpV%d",(int)lc);
|
|---|
| 300 | po << PPFNameTag(buftag) << (*phexp[lc]);
|
|---|
| 301 | phexp[lc]->Zero();
|
|---|
| 302 | sprintf(buftag,"saturV%d",(int)lc);
|
|---|
| 303 | po << PPFNameTag(buftag) << (*psatur[lc]);
|
|---|
| 304 | (*psatur[lc])=0.;
|
|---|
| 305 | sprintf(buftag,"satfreqV%d",(int)lc);
|
|---|
| 306 | po << PPFNameTag(buftag) << (*pvsatfreq[lc]);
|
|---|
| 307 | (*pvsatfreq[lc])=0;
|
|---|
| 308 | }
|
|---|
| 309 | nzm_[lc]=0;
|
|---|
| 310 | }
|
|---|
| 311 | ts.SetNow();
|
|---|
| 312 | // Calcul / impression fraction des paquets avec same-framecounter
|
|---|
| 313 | int fracsame=0;
|
|---|
| 314 | if (nprocpaq_>0) fracsame=100*npaqsamefc_/nprocpaq_;
|
|---|
| 315 | int totfracsame=0;
|
|---|
| 316 | if (totnprocpaq_>0) totfracsame=100*totnpaqsamefc_/totnprocpaq_;
|
|---|
| 317 | filog << ts << " : proc file (meanspectra) " << fname << endl;
|
|---|
| 318 | filog << " NBlocProcessed=" << nblocproc_ << " NSameFC=" << totnpaqsamefc_ << " / " << totnprocpaq_
|
|---|
| 319 | << " -> " << totfracsame << " % (LastPqs: " << npaqsamefc_ << " / " << nprocpaq_
|
|---|
| 320 | << " -> " << fracsame << " % )" << endl;
|
|---|
| 321 | cout << " MonitorProc::procData1C() " << ts << " : created file " << fname << endl;
|
|---|
| 322 | cout << " NBlocProcessed=" << nblocproc_ << " NSameFC=" << totnpaqsamefc_ << " / " << totnprocpaq_
|
|---|
| 323 | << " -> " << totfracsame << " % (LastPqs: " << npaqsamefc_ << " / " << nprocpaq_
|
|---|
| 324 | << " -> " << fracsame << " % )" << endl;
|
|---|
| 325 | nprocpaq_=npaqsamefc_=0;
|
|---|
| 326 | }
|
|---|
| 327 | } // Fin de boucle sur les kmz ( bloc MemZoneMgr a traiter )
|
|---|
| 328 |
|
|---|
| 329 | bool fgnzm=false;
|
|---|
| 330 | for(int lc=0; lc<memgr.NbFibres(); lc++)
|
|---|
| 331 | if (nzm_[lc]>0) fgnzm=true;
|
|---|
| 332 |
|
|---|
| 333 | if (fgnzm) {
|
|---|
| 334 | char buff[32];
|
|---|
| 335 | for(sa_size_t lc=0; lc<memgr.NbFibres(); lc++) {
|
|---|
| 336 | if (nzm_[lc]>0) spectre_.Row(lc) /= (r_4)nzm_[lc];
|
|---|
| 337 | sprintf(buff,"NPaqMoy%d",(int)lc);
|
|---|
| 338 | spectre_.Info()[buff] = nzm_[lc];
|
|---|
| 339 | }
|
|---|
| 340 | sprintf(fname,"%s/meanspec%d.ppf",path_.c_str(),(int)nfiles_);
|
|---|
| 341 | POutPersist po(fname);
|
|---|
| 342 | po << PPFNameTag("spectre") << spectre_;
|
|---|
| 343 | spectre_ = (r_4)(0.);
|
|---|
| 344 | char buftag[32];
|
|---|
| 345 | for(int lc=0; lc<memgr.NbFibres(); lc++) {
|
|---|
| 346 | sprintf(buftag,"hvalV%d",(int)lc);
|
|---|
| 347 | po << PPFNameTag(buftag) << (*phist[lc]);
|
|---|
| 348 | delete phist[lc];
|
|---|
| 349 | if (par_.fgdatafft) { // data de type FFT
|
|---|
| 350 | sprintf(buftag,"h2dV%d",(int)lc);
|
|---|
| 351 | po << PPFNameTag(buftag) << (*ph2[lc]);
|
|---|
| 352 | delete ph2[lc];
|
|---|
| 353 | sprintf(buftag,"hexpV%d",(int)lc);
|
|---|
| 354 | po << PPFNameTag(buftag) << (*phexp[lc]);
|
|---|
| 355 | delete phexp[lc];
|
|---|
| 356 | sprintf(buftag,"saturV%d",(int)lc);
|
|---|
| 357 | po << PPFNameTag(buftag) << (*psatur[lc]);
|
|---|
| 358 | sprintf(buftag,"satfreqV%d",(int)lc);
|
|---|
| 359 | po << PPFNameTag(buftag) << (*pvsatfreq[lc]);
|
|---|
| 360 | delete psatur[lc];
|
|---|
| 361 | delete pvsatfreq[lc];
|
|---|
| 362 | }
|
|---|
| 363 | nzm_[lc]=0;
|
|---|
| 364 | }
|
|---|
| 365 | ts.SetNow();
|
|---|
| 366 | // Calcul / impression fraction des paquets avec same-framecounter
|
|---|
| 367 | int fracsame=0;
|
|---|
| 368 | if (nprocpaq_>0) fracsame=100*npaqsamefc_/nprocpaq_;
|
|---|
| 369 | int totfracsame=0;
|
|---|
| 370 | if (totnprocpaq_>0) totfracsame=100*totnpaqsamefc_/totnprocpaq_;
|
|---|
| 371 | filog << ts << " : proc file (meanspectra) " << fname << endl;
|
|---|
| 372 | filog << " NBlocProcessed=" << nblocproc_ << " NSameFC=" << totnpaqsamefc_ << " / " << totnprocpaq_
|
|---|
| 373 | << " -> " << totfracsame << " % (LastPqs: " << npaqsamefc_ << " / " << nprocpaq_
|
|---|
| 374 | << " -> " << fracsame << " % )" << endl;
|
|---|
| 375 | cout << " MonitorProc::procData1C() " << ts << " : created file " << fname << endl;
|
|---|
| 376 | cout << " NBlocProcessed=" << nblocproc_ << " NSameFC=" << totnpaqsamefc_ << " / " << totnprocpaq_
|
|---|
| 377 | << " -> " << totfracsame << " % (LastPqs: " << npaqsamefc_ << " / " << nprocpaq_
|
|---|
| 378 | << " -> " << fracsame << " % )" << endl;
|
|---|
| 379 | }
|
|---|
| 380 | return 0;
|
|---|
| 381 | }
|
|---|
| 382 |
|
|---|
| 383 | /* --Methode-- */
|
|---|
| 384 | int MonitorProc::procData2C(ofstream& filog)
|
|---|
| 385 | {
|
|---|
| 386 | BRPaqChecker pcheck[MAXNBFIB]; // Verification/comptage des paquets
|
|---|
| 387 | // Initialisation pour calcul FFT
|
|---|
| 388 | uint_4 paqsz = memgr.PaqSize();
|
|---|
| 389 | BRPaquet pq(paqsz);
|
|---|
| 390 | TVector<r_4> vx(pq.DataSize()/2);
|
|---|
| 391 | vx = (r_4)(0.);
|
|---|
| 392 | TVector< complex<r_4> > cfour(pq.DataSize()/4+1); // composant TF
|
|---|
| 393 |
|
|---|
| 394 | fftwf_plan plan = fftwf_plan_dft_r2c_1d(vx.Size(), vx.Data(),
|
|---|
| 395 | (fftwf_complex *)cfour.Data(), FFTW_ESTIMATE);
|
|---|
| 396 |
|
|---|
| 397 | // Histo pour valeurs des bytes dans les paquets
|
|---|
| 398 | Histo* phist[2*MAXNBFIB];
|
|---|
| 399 | Histo2D* ph2[2*MAXNBFIB];
|
|---|
| 400 | Histo* phexp[2*MAXNBFIB];
|
|---|
| 401 | TMatrix<r_4>* psatur[2*MAXNBFIB];
|
|---|
| 402 | TVector<uint_4>* pvsatfreq[2*MAXNBFIB];
|
|---|
| 403 | for(int ifib=0; ifib<2*MAXNBFIB; ifib++) {
|
|---|
| 404 | phist[ifib]=NULL; ph2[ifib]=NULL; phexp[ifib]=NULL; psatur[ifib]=NULL;
|
|---|
| 405 | }
|
|---|
| 406 | if (par_.fgdatafft) { // data de type FFT
|
|---|
| 407 | for(sa_size_t lc=0; lc<2*memgr.NbFibres(); lc++) {
|
|---|
| 408 | phist[lc] = new Histo(-128.5,+128.5,257);
|
|---|
| 409 | ph2[lc] = new Histo2D(-128.5,+128.5,257, -128.5,+128.5,257);
|
|---|
| 410 | phexp[lc] = new Histo(-128.5,+128.5,257);
|
|---|
| 411 | psatur[lc] = new TMatrix<r_4>(3,3);
|
|---|
| 412 | pvsatfreq[lc] = new TVector<uint_4>(spectre_.NCols());
|
|---|
| 413 | *psatur[lc] = 0.;
|
|---|
| 414 | }
|
|---|
| 415 | }
|
|---|
| 416 | else {
|
|---|
| 417 | for(sa_size_t lc=0; lc<2*memgr.NbFibres(); lc++)
|
|---|
| 418 | phist[lc] = new Histo(-0.5,256.5,257);
|
|---|
| 419 | }
|
|---|
| 420 |
|
|---|
| 421 | TimeStamp ts;
|
|---|
| 422 | char fname[512];
|
|---|
| 423 | nfiles_ = 0;
|
|---|
| 424 | for (uint_4 kmz=0; kmz<nmax_; kmz++) {
|
|---|
| 425 | if (stop_) break;
|
|---|
| 426 | if (memgr.GetRunState() == MemZR_Stopped) break;
|
|---|
| 427 |
|
|---|
| 428 | int mid = memgr.FindMemZoneId(mmact_); // MemZA_Proc
|
|---|
| 429 | Byte* buffg = memgr.GetMemZone(mid);
|
|---|
| 430 | if (buffg == NULL) {
|
|---|
| 431 | cout << " MonitorProc::procData2C()/ERROR memgr.GetMemZone(" << mid << ") -> NULL" << endl;
|
|---|
| 432 | break;
|
|---|
| 433 | }
|
|---|
| 434 | if ((step_>1)&&(kmz%step_ != 0)) {
|
|---|
| 435 | memgr.FreeMemZone(mid, mmsta_); // MemZS_Proc);
|
|---|
| 436 | continue;
|
|---|
| 437 | }
|
|---|
| 438 | sa_size_t lc=0;
|
|---|
| 439 | Byte* fbuff[MAXNBFIB];
|
|---|
| 440 | for(uint_4 fib=0; fib<memgr.NbFibres(); fib++) { // Boucle sur les fibres
|
|---|
| 441 | fbuff[fib] = memgr.GetMemZone(mid,fib);
|
|---|
| 442 | if (fbuff[fib] == NULL) { // cela ne devrait pas arriver
|
|---|
| 443 | cout << " MonitorProc::procData2C()/ERROR memgr.GetMemZone(" << mid << "," << fib << ") -> NULL" << endl;
|
|---|
| 444 | return 9;
|
|---|
| 445 | }
|
|---|
| 446 | }
|
|---|
| 447 |
|
|---|
| 448 | // DBG-ATTENTION : freq 0 pour expo full FFT si reordonne
|
|---|
| 449 | int idxexpo=(par_.fgfftshrink)?1023:0; // exposant FFT shrink 1024 freq, ou freq 0 pour full-FFT
|
|---|
| 450 |
|
|---|
| 451 | cpaqok_ = (uint_1)0;
|
|---|
| 452 | curfc_ = (uint_8)0;
|
|---|
| 453 | for(uint_4 fib=0; fib<memgr.NbFibres(); fib++) {
|
|---|
| 454 | for(uint_4 i=0; i<memgr.NbPaquets(); i++) {
|
|---|
| 455 | BRPaquet paq(fbuff[fib]+i*paqsz, paqsz);
|
|---|
| 456 | bool pqok=pcheck[fib].Check(paq,curfc_(fib,i)); // Verification du paquet / FrameCounter
|
|---|
| 457 | if (!pqok) continue;
|
|---|
| 458 | cpaqok_(fib,i) = 1;
|
|---|
| 459 | sa_size_t lc=2*fib;
|
|---|
| 460 | if (par_.fgdatafft) { // Traitement data de type FFT
|
|---|
| 461 | TwoByteComplex* tbcp=paq.Data1C();
|
|---|
| 462 |
|
|---|
| 463 | // exposant FFT
|
|---|
| 464 | phexp[lc]->Add((r_4)tbcp[idxexpo].realD());
|
|---|
| 465 |
|
|---|
| 466 | for(sa_size_t j=1; j<spectre_.NCols(); j++) {
|
|---|
| 467 | phist[lc]->Add((r_4)tbcp[j].realD());
|
|---|
| 468 | phist[lc]->Add((r_4)tbcp[j].imagD());
|
|---|
| 469 | ph2[lc]->Add((r_4)tbcp[j].realD(), (r_4)tbcp[j].imagD());
|
|---|
| 470 | // comptage saturation
|
|---|
| 471 | int sir=0, sii=0; // saturation partie reelle, partie imaginaire
|
|---|
| 472 | if (tbcp[j].realI()==-128) sir=-1;
|
|---|
| 473 | else if (tbcp[j].realI()==127) sir=1;
|
|---|
| 474 | if (tbcp[j].imagI()==-128) sii=-1;
|
|---|
| 475 | else if (tbcp[j].imagI()==127) sii=1;
|
|---|
| 476 | (*psatur[lc])(sir+1,sii+1)+=1.;
|
|---|
| 477 | if ((sir!=0)||(sii!=0)) (*pvsatfreq[lc])(j)+=1;
|
|---|
| 478 | spectre_(lc,j) += Zmod2(tbcp[j]);
|
|---|
| 479 | }
|
|---|
| 480 | nzm_[lc]++;
|
|---|
| 481 | tbcp=paq.Data2C(); lc++;
|
|---|
| 482 | phexp[lc]->Add((r_4)tbcp[idxexpo].realD());
|
|---|
| 483 | for(sa_size_t j=1; j<spectre_.NCols(); j++) {
|
|---|
| 484 | phist[lc]->Add((r_4)tbcp[j].realD());
|
|---|
| 485 | phist[lc]->Add((r_4)tbcp[j].imagD());
|
|---|
| 486 | ph2[lc]->Add((r_4)tbcp[j].realD(), (r_4)tbcp[j].imagD());
|
|---|
| 487 | // comptage saturation
|
|---|
| 488 | int sir=0, sii=0; // saturation partie reelle, partie imaginaire
|
|---|
| 489 | if (tbcp[j].realI()==-128) sir=-1;
|
|---|
| 490 | else if (tbcp[j].realI()==127) sir=1;
|
|---|
| 491 | if (tbcp[j].imagI()==-128) sii=-1;
|
|---|
| 492 | else if (tbcp[j].imagI()==127) sii=1;
|
|---|
| 493 | (*psatur[lc])(sir+1,sii+1)+=1.;
|
|---|
| 494 | if ((sir!=0)||(sii!=0)) (*pvsatfreq[lc])(j)+=1;
|
|---|
| 495 |
|
|---|
| 496 | spectre_(lc,j) += Zmod2(tbcp[j]);
|
|---|
| 497 | }
|
|---|
| 498 | nzm_[lc]++;
|
|---|
| 499 | }
|
|---|
| 500 | else { // Traitement RawData
|
|---|
| 501 | for(sa_size_t j=0; j<vx.Size(); j++) {
|
|---|
| 502 | phist[lc]->Add((r_8)(*(paq.Data1()+j)));
|
|---|
| 503 | vx(j) = (r_4)(*(paq.Data1()+j))-127.5;
|
|---|
| 504 | }
|
|---|
| 505 | fftwf_execute(plan);
|
|---|
| 506 | // ffts_.FFTForward(vx, cfour_);
|
|---|
| 507 | for(sa_size_t j=0; j<spectre_.NCols(); j++)
|
|---|
| 508 | spectre_(lc,j) += Zmod2(cfour(j+1));
|
|---|
| 509 | nzm_[lc]++; lc++;
|
|---|
| 510 | for(sa_size_t j=0; j<vx.Size(); j++) {
|
|---|
| 511 | phist[lc]->Add((r_8)(*(paq.Data2()+j)));
|
|---|
| 512 | vx(j) = (r_4)(*(paq.Data2()+j))-127.5;
|
|---|
| 513 | }
|
|---|
| 514 | fftwf_execute(plan);
|
|---|
| 515 | // ffts_.FFTForward(vx, cfour_);
|
|---|
| 516 | for(sa_size_t j=0; j<spectre_.NCols(); j++)
|
|---|
| 517 | spectre_(lc,j) += Zmod2(cfour(j+1));
|
|---|
| 518 | nzm_[lc]++;
|
|---|
| 519 | }
|
|---|
| 520 | } // FIN de la boucle sur les paquets
|
|---|
| 521 | } // Boucle sur les fibres
|
|---|
| 522 | memgr.FreeMemZone(mid, mmsta_); // MemZS_Proc);
|
|---|
| 523 | CheckFrameCounters();
|
|---|
| 524 |
|
|---|
| 525 | nblocproc_ ++;
|
|---|
| 526 | totnprocpaq_ += memgr.NbPaquets(); nprocpaq_ += memgr.NbPaquets();
|
|---|
| 527 | bool fgnzm=true;
|
|---|
| 528 | for(int lc=0; lc<2*memgr.NbFibres(); lc++)
|
|---|
| 529 | if (nzm_[lc]<nmean_) fgnzm=false;
|
|---|
| 530 |
|
|---|
| 531 | if (fgnzm) {
|
|---|
| 532 | char buff[32];
|
|---|
| 533 | for(sa_size_t lc=0; lc<2*memgr.NbFibres(); lc++) {
|
|---|
| 534 | spectre_.Row(lc) /= (r_4)nzm_[lc];
|
|---|
| 535 | sprintf(buff,"NPaqMoy%d",(int)lc);
|
|---|
| 536 | spectre_.Info()[buff] = nzm_[lc];
|
|---|
| 537 | }
|
|---|
| 538 | sprintf(fname,"%s/meanspec%d.ppf",path_.c_str(),(int)nfiles_);
|
|---|
| 539 | nfiles_++;
|
|---|
| 540 | POutPersist po(fname);
|
|---|
| 541 | po << PPFNameTag("spectre") << spectre_;
|
|---|
| 542 | spectre_ = (r_4)(0.);
|
|---|
| 543 | char buftag[32];
|
|---|
| 544 | for(int lc=0; lc<2*memgr.NbFibres(); lc++) {
|
|---|
| 545 | sprintf(buftag,"hvalV%d",(int)lc);
|
|---|
| 546 | po << PPFNameTag(buftag) << (*phist[lc]);
|
|---|
| 547 | phist[lc]->Zero();
|
|---|
| 548 | if (par_.fgdatafft) { // data de type FFT
|
|---|
| 549 | sprintf(buftag,"h2dV%d",(int)lc);
|
|---|
| 550 | po << PPFNameTag(buftag) << (*ph2[lc]);
|
|---|
| 551 | ph2[lc]->Zero();
|
|---|
| 552 | sprintf(buftag,"hexpV%d",(int)lc);
|
|---|
| 553 | po << PPFNameTag(buftag) << (*phexp[lc]);
|
|---|
| 554 | phexp[lc]->Zero();
|
|---|
| 555 | sprintf(buftag,"saturV%d",(int)lc);
|
|---|
| 556 | po << PPFNameTag(buftag) << (*psatur[lc]);
|
|---|
| 557 | (*psatur[lc])=0.;
|
|---|
| 558 | sprintf(buftag,"satfreqV%d",(int)lc);
|
|---|
| 559 | po << PPFNameTag(buftag) << (*pvsatfreq[lc]);
|
|---|
| 560 | (*pvsatfreq[lc])=0;
|
|---|
| 561 | }
|
|---|
| 562 | nzm_[lc]=0;
|
|---|
| 563 | }
|
|---|
| 564 | ts.SetNow();
|
|---|
| 565 | // Calcul / impression fraction des paquets avec same-framecounter
|
|---|
| 566 | int fracsame=0;
|
|---|
| 567 | if (nprocpaq_>0) fracsame=100*npaqsamefc_/nprocpaq_;
|
|---|
| 568 | int totfracsame=0;
|
|---|
| 569 | if (totnprocpaq_>0) totfracsame=100*totnpaqsamefc_/totnprocpaq_;
|
|---|
| 570 | filog << ts << " : proc file (meanspectra) " << fname << endl;
|
|---|
| 571 | filog << " NBlocProcessed=" << nblocproc_ << " NSameFC=" << totnpaqsamefc_ << " / " << totnprocpaq_
|
|---|
| 572 | << " -> " << totfracsame << " % (LastPqs: " << npaqsamefc_ << " / " << nprocpaq_
|
|---|
| 573 | << " -> " << fracsame << " % )" << endl;
|
|---|
| 574 | cout << " MonitorProc::procData2C() " << ts << " : created file " << fname << endl;
|
|---|
| 575 | cout << " NBlocProcessed=" << nblocproc_ << " NSameFC=" << totnpaqsamefc_ << " / " << totnprocpaq_
|
|---|
| 576 | << " -> " << totfracsame << " % (LastPqs: " << npaqsamefc_ << " / " << nprocpaq_
|
|---|
| 577 | << " -> " << fracsame << " % )" << endl;
|
|---|
| 578 | nprocpaq_=npaqsamefc_=0;
|
|---|
| 579 | }
|
|---|
| 580 | } // Fin de boucle sur les kmz ( bloc MemZoneMgr a traiter )
|
|---|
| 581 |
|
|---|
| 582 | bool fgnzm=false;
|
|---|
| 583 | for(int lc=0; lc<2*memgr.NbFibres(); lc++)
|
|---|
| 584 | if (nzm_[lc]>0) fgnzm=true;
|
|---|
| 585 |
|
|---|
| 586 | if (fgnzm) {
|
|---|
| 587 | char buff[32];
|
|---|
| 588 | for(sa_size_t lc=0; lc<2*memgr.NbFibres(); lc++) {
|
|---|
| 589 | if (nzm_[lc]>0) spectre_.Row(lc) /= (r_4)nzm_[lc];
|
|---|
| 590 | sprintf(buff,"NPaqMoy%d",(int)lc);
|
|---|
| 591 | spectre_.Info()[buff] = nzm_[lc];
|
|---|
| 592 | }
|
|---|
| 593 | sprintf(fname,"%s/meanspec%d.ppf",path_.c_str(),(int)nfiles_);
|
|---|
| 594 | POutPersist po(fname);
|
|---|
| 595 | po << PPFNameTag("spectre") << spectre_;
|
|---|
| 596 | spectre_ = (r_4)(0.);
|
|---|
| 597 | char buftag[32];
|
|---|
| 598 | for(int lc=0; lc<2*memgr.NbFibres(); lc++) {
|
|---|
| 599 | sprintf(buftag,"hvalV%d",(int)lc);
|
|---|
| 600 | po << PPFNameTag(buftag) << (*phist[lc]);
|
|---|
| 601 | delete phist[lc];
|
|---|
| 602 | if (par_.fgdatafft) { // data de type FFT
|
|---|
| 603 | sprintf(buftag,"h2dV%d",(int)lc);
|
|---|
| 604 | po << PPFNameTag(buftag) << (*ph2[lc]);
|
|---|
| 605 | delete ph2[lc];
|
|---|
| 606 | sprintf(buftag,"hexpV%d",(int)lc);
|
|---|
| 607 | po << PPFNameTag(buftag) << (*phexp[lc]);
|
|---|
| 608 | delete phexp[lc];
|
|---|
| 609 | sprintf(buftag,"saturV%d",(int)lc);
|
|---|
| 610 | po << PPFNameTag(buftag) << (*psatur[lc]);
|
|---|
| 611 | sprintf(buftag,"satfreqV%d",(int)lc);
|
|---|
| 612 | po << PPFNameTag(buftag) << (*pvsatfreq[lc]);
|
|---|
| 613 | delete psatur[lc];
|
|---|
| 614 | delete pvsatfreq[lc];
|
|---|
| 615 | }
|
|---|
| 616 | nzm_[lc]=0;
|
|---|
| 617 | }
|
|---|
| 618 | ts.SetNow();
|
|---|
| 619 | // Calcul / impression fraction des paquets avec same-framecounter
|
|---|
| 620 | int fracsame=0;
|
|---|
| 621 | if (nprocpaq_>0) fracsame=100*npaqsamefc_/nprocpaq_;
|
|---|
| 622 | int totfracsame=0;
|
|---|
| 623 | if (totnprocpaq_>0) totfracsame=100*totnpaqsamefc_/totnprocpaq_;
|
|---|
| 624 | filog << ts << " : proc file (meanspectra) " << fname << endl;
|
|---|
| 625 | filog << " NBlocProcessed=" << nblocproc_ << " NSameFC=" << totnpaqsamefc_ << " / " << totnprocpaq_
|
|---|
| 626 | << " -> " << totfracsame << " % (LastPqs: " << npaqsamefc_ << " / " << nprocpaq_
|
|---|
| 627 | << " -> " << fracsame << " % )" << endl;
|
|---|
| 628 | cout << " MonitorProc::procData2C() " << ts << " : created file " << fname << endl;
|
|---|
| 629 | cout << " NBlocProcessed=" << nblocproc_ << " NSameFC=" << totnpaqsamefc_ << " / " << totnprocpaq_
|
|---|
| 630 | << " -> " << totfracsame << " % (LastPqs: " << npaqsamefc_ << " / " << nprocpaq_
|
|---|
| 631 | << " -> " << fracsame << " % )" << endl;
|
|---|
| 632 | }
|
|---|
| 633 | return 0;
|
|---|
| 634 | }
|
|---|
| 635 |
|
|---|
| 636 | /* --Methode-- */
|
|---|
| 637 | int MonitorProc::CheckFrameCounters()
|
|---|
| 638 | {
|
|---|
| 639 | if (memgr.NbFibres()<2) {
|
|---|
| 640 | npaqsamefc_++; totnpaqsamefc_++;
|
|---|
| 641 | return 99;
|
|---|
| 642 | }
|
|---|
| 643 | sa_size_t pidx[MAXNBFIB];
|
|---|
| 644 | sa_size_t maxidx=curfc_.NCols();
|
|---|
| 645 | uint_8 cfc=0;
|
|---|
| 646 | for(uint_4 fib=0; fib<curfc_.NRows(); fib++) {
|
|---|
| 647 | pidx[fib]=0;
|
|---|
| 648 | while((pidx[fib]<maxidx)&&(cpaqok_(fib,pidx[fib])==0)) pidx[fib]++;
|
|---|
| 649 | }
|
|---|
| 650 |
|
|---|
| 651 | bool fgsuite=true;
|
|---|
| 652 | while (fgsuite) { // Boucle sur l'ensemble des paquets
|
|---|
| 653 | for(uint_4 fib=0; fib<curfc_.NRows(); fib++) {
|
|---|
| 654 | if ((pidx[fib]>=maxidx)||(cpaqok_(fib,pidx[fib])==0)) { fgsuite=false; break; }
|
|---|
| 655 | }
|
|---|
| 656 | if (!fgsuite) break;
|
|---|
| 657 | cfc=curfc_(0,pidx[0]);
|
|---|
| 658 | bool fgsame=true;
|
|---|
| 659 | for(uint_4 fib=1; fib<curfc_.NRows(); fib++) {
|
|---|
| 660 | if (curfc_(fib,pidx[fib])!=cfc) {
|
|---|
| 661 | fgsame=false;
|
|---|
| 662 | if (curfc_(fib,pidx[fib]) > cfc) cfc=curfc_(fib,pidx[fib]);
|
|---|
| 663 | }
|
|---|
| 664 | }
|
|---|
| 665 | if (fgsame) {
|
|---|
| 666 | npaqsamefc_++; totnpaqsamefc_++;
|
|---|
| 667 | for(uint_4 fib=0; fib<curfc_.NRows(); fib++) {
|
|---|
| 668 | pidx[fib]++;
|
|---|
| 669 | while((pidx[fib]<maxidx)&&(cpaqok_(fib,pidx[fib])==0)) pidx[fib]++;
|
|---|
| 670 | }
|
|---|
| 671 | } // fin if (fgsame)
|
|---|
| 672 | else { // else !fgsame
|
|---|
| 673 | for(uint_4 fib=0; fib<memgr.NbFibres(); fib++) {
|
|---|
| 674 | if (curfc_(fib,pidx[fib])<cfc) {
|
|---|
| 675 | pidx[fib]++;
|
|---|
| 676 | while((pidx[fib]<maxidx)&&(cpaqok_(fib,pidx[fib])==0)) pidx[fib]++;
|
|---|
| 677 | }
|
|---|
| 678 | }
|
|---|
| 679 | } // fin de else !fgsame
|
|---|
| 680 | } // Fin de while sur l'ensemble des paquets
|
|---|
| 681 | return 0;
|
|---|
| 682 | }
|
|---|
| 683 |
|
|---|
| 684 |
|
|---|
| 685 | static struct sigaction act;
|
|---|
| 686 | //-------------------------------------------------------
|
|---|
| 687 | // Classe thread de traitement avec 1 voie par frame
|
|---|
| 688 | //-------------------------------------------------------
|
|---|
| 689 |
|
|---|
| 690 | void DataProcSignal(int s)
|
|---|
| 691 | {
|
|---|
| 692 | cout <<"............................................... receive CtrlC" << endl;
|
|---|
| 693 |
|
|---|
| 694 | }
|
|---|
| 695 |
|
|---|
| 696 | DataProc::DataProc(RAcqMemZoneMgr& mem, string& path, uint_4 nmean, uint_4 step, uint_4 nmax)
|
|---|
| 697 | : memgr(mem)
|
|---|
| 698 | {
|
|---|
| 699 | nmax_ = nmax;
|
|---|
| 700 | nmean_ = nmean;
|
|---|
| 701 | step_ = step;
|
|---|
| 702 | stop_ = false;
|
|---|
| 703 | path_ = path;
|
|---|
| 704 | act.sa_handler=DataProcSignal;
|
|---|
| 705 | }
|
|---|
| 706 |
|
|---|
| 707 |
|
|---|
| 708 | void DataProc::Stop()
|
|---|
| 709 | {
|
|---|
| 710 | stop_=true;
|
|---|
| 711 | // cout <<" DataProc::Stop ... > STOP " << endl;
|
|---|
| 712 | }
|
|---|
| 713 |
|
|---|
| 714 | void DataProc::run()
|
|---|
| 715 | {
|
|---|
| 716 |
|
|---|
| 717 | // sigaddset(&act.sa_mask,SIGINT); // pour proteger le transfert DMA
|
|---|
| 718 | // sigaction(SIGINT,&act,NULL);
|
|---|
| 719 | setRC(1);
|
|---|
| 720 | try {
|
|---|
| 721 | TimeStamp ts;
|
|---|
| 722 | cout << " DataProc::run() - Starting " << ts << " NMaxMemZones=" << nmax_
|
|---|
| 723 | << " NMean=" << nmean_ << " Step=" << step_ << endl;
|
|---|
| 724 | cout << " DataProc::run()... - Output Data Path: " << path_ << endl;
|
|---|
| 725 | char fname[512];
|
|---|
| 726 | sprintf(fname,"%s/proc.log",path_.c_str());
|
|---|
| 727 | ofstream filog(fname);
|
|---|
| 728 | filog << " DataProc::run() - starting log file " << ts << endl;
|
|---|
| 729 | filog << " ... NMaxMemZones=" << nmax_ << " NMean=" << nmean_ << " Step=" << step_ << endl;
|
|---|
| 730 |
|
|---|
| 731 | // Initialisation pour clcul FFT
|
|---|
| 732 | TVector< complex<r_4> > cfour; // composant TF
|
|---|
| 733 | uint_4 paqsz = memgr.PaqSize();
|
|---|
| 734 | BRPaquet pq(NULL, NULL, paqsz);
|
|---|
| 735 | TVector<r_4> vx(pq.DataSize());
|
|---|
| 736 | vx = (r_4)(0.);
|
|---|
| 737 | FFTPackServer ffts;
|
|---|
| 738 | ffts.FFTForward(vx, cfour);
|
|---|
| 739 | TVector<r_4> spectre;
|
|---|
| 740 | spectre.ReSize(cfour.Size());
|
|---|
| 741 |
|
|---|
| 742 | fftwf_plan plan = fftwf_plan_dft_r2c_1d(vx.Size(), vx.Data(),
|
|---|
| 743 | (fftwf_complex *)cfour.Data(), FFTW_ESTIMATE);
|
|---|
| 744 |
|
|---|
| 745 | uint_4 ifile = 0;
|
|---|
| 746 | uint_4 nzm = 0;
|
|---|
| 747 | for (uint_4 kmz=0; kmz<nmax_; kmz++) {
|
|---|
| 748 | if (stop_) break;
|
|---|
| 749 | int mid = memgr.FindMemZoneId(MemZA_Proc);
|
|---|
| 750 | Byte* buff = memgr.GetMemZone(mid);
|
|---|
| 751 | if (buff == NULL) {
|
|---|
| 752 | cout << " DataProc::run()/ERROR memgr.GetMemZone(" << mid << ") -> NULL" << endl;
|
|---|
| 753 | setRC(2);
|
|---|
| 754 | return;
|
|---|
| 755 | }
|
|---|
| 756 | BRPaquet paq0(NULL, buff, paqsz);
|
|---|
| 757 | for(uint_4 i=0; i<memgr.NbPaquets(); i+=step_) {
|
|---|
| 758 | BRPaquet paq(NULL, buff+i*paqsz, paqsz);
|
|---|
| 759 | Byte min = 255;
|
|---|
| 760 | Byte max = 0;
|
|---|
| 761 |
|
|---|
| 762 | for(sa_size_t j=0; j<vx.Size(); j++)
|
|---|
| 763 | vx(j) = (r_4)(*(paq.Data1()+j))-127.5;
|
|---|
| 764 | fftwf_execute(plan);
|
|---|
| 765 | // ffts_.FFTForward(vx, cfour_);
|
|---|
| 766 | for(sa_size_t j=0; j<spectre.Size(); j++)
|
|---|
| 767 | spectre(j) += Zmod2(cfour(j));
|
|---|
| 768 | nzm++;
|
|---|
| 769 | }
|
|---|
| 770 | if ((nzm >= nmean_) ||(kmz==(nmax_-1))) {
|
|---|
| 771 | spectre /= (r_4)(nzm);
|
|---|
| 772 | spectre.Info()["NPaqMoy"] = nzm;
|
|---|
| 773 | sprintf(fname,"%s/spectre%d.ppf",path_.c_str(),(int)ifile);
|
|---|
| 774 | POutPersist po(fname);
|
|---|
| 775 | po << spectre;
|
|---|
| 776 | spectre = (r_4)(0.);
|
|---|
| 777 | nzm = 0; ifile++;
|
|---|
| 778 | ts.SetNow();
|
|---|
| 779 | filog << ts << " : proc file " << fname << endl;
|
|---|
| 780 | cout << " DataProc::run() " << ts << " : created file " << fname << endl;
|
|---|
| 781 | }
|
|---|
| 782 |
|
|---|
| 783 | memgr.FreeMemZone(mid, MemZS_Proc);
|
|---|
| 784 | }
|
|---|
| 785 | }
|
|---|
| 786 | catch (std::exception& exc) {
|
|---|
| 787 | cout << " DataProc::run()/catched std::exception " << exc.what() << endl;
|
|---|
| 788 | setRC(3);
|
|---|
| 789 | return;
|
|---|
| 790 | }
|
|---|
| 791 | catch(...) {
|
|---|
| 792 | cout << " DataProc::run()/catched unknown ... exception " << endl;
|
|---|
| 793 | setRC(4);
|
|---|
| 794 | return;
|
|---|
| 795 | }
|
|---|
| 796 | setRC(0);
|
|---|
| 797 | return;
|
|---|
| 798 | }
|
|---|
| 799 |
|
|---|
| 800 | //---------------------------------------------------------------
|
|---|
| 801 | // Classe thread de traitement donnees ADC avec 2 voies par frame
|
|---|
| 802 | //---------------------------------------------------------------
|
|---|
| 803 |
|
|---|
| 804 | DataProc2C::DataProc2C(RAcqMemZoneMgr& mem, string& path, uint_4 nmean, uint_4 step, uint_4 nmax)
|
|---|
| 805 | : memgr(mem)
|
|---|
| 806 | {
|
|---|
| 807 | nmax_ = nmax;
|
|---|
| 808 | nmean_ = nmean;
|
|---|
| 809 | step_ = step;
|
|---|
| 810 | stop_ = false;
|
|---|
| 811 | path_ = path;
|
|---|
| 812 | act.sa_handler=DataProcSignal;
|
|---|
| 813 | }
|
|---|
| 814 | void DataProc2C::Stop()
|
|---|
| 815 | {
|
|---|
| 816 | stop_=true;
|
|---|
| 817 | // cout <<" DataProc2C::Stop ... > STOP " << endl;
|
|---|
| 818 | }
|
|---|
| 819 |
|
|---|
| 820 | void DataProc2C::run()
|
|---|
| 821 | {
|
|---|
| 822 | // sigaction(SIGINT,&act,NULL);
|
|---|
| 823 | setRC(1);
|
|---|
| 824 | try {
|
|---|
| 825 | TimeStamp ts;
|
|---|
| 826 | cout << " DataProc2C::run() - Starting " << ts << " NMaxMemZones=" << nmax_
|
|---|
| 827 | << " NMean=" << nmean_ << " Step=" << step_ << endl;
|
|---|
| 828 | cout << " DataProc::run()... - Output Data Path: " << path_ << endl;
|
|---|
| 829 | char fname[512];
|
|---|
| 830 | sprintf(fname,"%s/proc.log",path_.c_str());
|
|---|
| 831 | ofstream filog(fname);
|
|---|
| 832 | filog << " DataProc2C::run() - starting log file " << ts << endl;
|
|---|
| 833 | filog << " ... NMaxMemZones=" << nmax_ << " NMean=" << nmean_ << " Step=" << step_ << endl;
|
|---|
| 834 |
|
|---|
| 835 | // Initialisation pour clcul FFT
|
|---|
| 836 | TVector< complex<r_4> > cfour; // composant TF
|
|---|
| 837 | uint_4 paqsz = memgr.PaqSize();
|
|---|
| 838 | BRPaquet pq(NULL, NULL, paqsz);
|
|---|
| 839 | TVector<r_4> vx(pq.DataSize()/2);
|
|---|
| 840 | vx = (r_4)(0.);
|
|---|
| 841 | FFTPackServer ffts;
|
|---|
| 842 | ffts.FFTForward(vx, cfour);
|
|---|
| 843 | TVector<r_4> spectreV1, spectreV2;
|
|---|
| 844 | spectreV1.ReSize(cfour.Size());
|
|---|
| 845 | spectreV2.ReSize(cfour.Size());
|
|---|
| 846 |
|
|---|
| 847 | fftwf_plan plan = fftwf_plan_dft_r2c_1d(vx.Size(), vx.Data(),
|
|---|
| 848 | (fftwf_complex *)cfour.Data(), FFTW_ESTIMATE);
|
|---|
| 849 |
|
|---|
| 850 | uint_4 ifile = 0;
|
|---|
| 851 | uint_4 nzm = 0;
|
|---|
| 852 | for (uint_4 kmz=0; kmz<nmax_; kmz++) {
|
|---|
| 853 | if (stop_) break;
|
|---|
| 854 | int mid = memgr.FindMemZoneId(MemZA_Proc);
|
|---|
| 855 | Byte* buff = memgr.GetMemZone(mid);
|
|---|
| 856 | if (buff == NULL) {
|
|---|
| 857 | cout << " DataProc2C::run()/ERROR memgr.GetMemZone(" << mid << ") -> NULL" << endl;
|
|---|
| 858 | setRC(2);
|
|---|
| 859 | return;
|
|---|
| 860 | }
|
|---|
| 861 | BRPaquet paq0(NULL, buff, paqsz);
|
|---|
| 862 | for(uint_4 i=0; i<memgr.NbPaquets(); i+=step_) {
|
|---|
| 863 | BRPaquet paq(NULL, buff+i*paqsz, paqsz);
|
|---|
| 864 | Byte min = 255;
|
|---|
| 865 | Byte max = 0;
|
|---|
| 866 |
|
|---|
| 867 | for(sa_size_t j=0; j<vx.Size(); j++)
|
|---|
| 868 | vx(j) = (r_4)(*(paq.Data1()+j))-127.5;
|
|---|
| 869 | fftwf_execute(plan);
|
|---|
| 870 | // ffts_.FFTForward(vx, cfour_);
|
|---|
| 871 | for(sa_size_t j=0; j<spectreV1.Size(); j++)
|
|---|
| 872 | spectreV1(j) += Zmod2(cfour(j));
|
|---|
| 873 |
|
|---|
| 874 | for(sa_size_t j=0; j<vx.Size(); j++)
|
|---|
| 875 | vx(j) = (r_4)(*(paq.Data2()+j))-127.5;
|
|---|
| 876 | fftwf_execute(plan);
|
|---|
| 877 | // ffts_.FFTForward(vx, cfour_);
|
|---|
| 878 | for(sa_size_t j=0; j<spectreV2.Size(); j++)
|
|---|
| 879 | spectreV2(j) += Zmod2(cfour(j));
|
|---|
| 880 |
|
|---|
| 881 | nzm++;
|
|---|
| 882 | }
|
|---|
| 883 | if ((nzm >= nmean_) ||(kmz==(nmax_-1))) {
|
|---|
| 884 | spectreV1 /= (r_4)(nzm);
|
|---|
| 885 | spectreV2 /= (r_4)(nzm);
|
|---|
| 886 | spectreV1.Info()["NPaqMoy"] = nzm;
|
|---|
| 887 | spectreV2.Info()["NPaqMoy"] = nzm;
|
|---|
| 888 | {
|
|---|
| 889 | sprintf(fname,"%s/spectre2C_%d.ppf",path_.c_str(),(int)ifile);
|
|---|
| 890 | POutPersist po(fname);
|
|---|
| 891 | po << PPFNameTag("specV1") << spectreV1;
|
|---|
| 892 | po << PPFNameTag("specV2") << spectreV2;
|
|---|
| 893 | }
|
|---|
| 894 | spectreV1 = (r_4)(0.);
|
|---|
| 895 | spectreV2 = (r_4)(0.);
|
|---|
| 896 | nzm = 0; ifile++;
|
|---|
| 897 | ts.SetNow();
|
|---|
| 898 | filog << ts << " : proc file " << fname << endl;
|
|---|
| 899 | cout << " DataProc2C::run() " << ts << " : created file " << fname << endl;
|
|---|
| 900 | }
|
|---|
| 901 |
|
|---|
| 902 | memgr.FreeMemZone(mid, MemZS_Proc);
|
|---|
| 903 | }
|
|---|
| 904 | }
|
|---|
| 905 | catch (std::exception& exc) {
|
|---|
| 906 | cout << " DataProc::run()/catched std::exception " << exc.what() << endl;
|
|---|
| 907 | setRC(3);
|
|---|
| 908 | return;
|
|---|
| 909 | }
|
|---|
| 910 | catch(...) {
|
|---|
| 911 | cout << " DataProc2C::run()/catched unknown ... exception " << endl;
|
|---|
| 912 | setRC(4);
|
|---|
| 913 | return;
|
|---|
| 914 | }
|
|---|
| 915 | setRC(0);
|
|---|
| 916 | return;
|
|---|
| 917 | }
|
|---|
| 918 |
|
|---|
| 919 |
|
|---|
| 920 |
|
|---|
| 921 |
|
|---|
| 922 | //---------------------------------------------------------------
|
|---|
| 923 | // Classe thread de traitement donnees FFT avec 2 voies par frame
|
|---|
| 924 | //---------------------------------------------------------------
|
|---|
| 925 |
|
|---|
| 926 | inline r_4 Zmod2TwoByte(TwoByteComplex z)
|
|---|
| 927 | { return (z.realD()*z.realD()+z.imagD()*z.imagD()); }
|
|---|
| 928 |
|
|---|
| 929 | DataProcFFT2C::DataProcFFT2C(RAcqMemZoneMgr& mem, string& path, uint_4 nmean, uint_4 step, uint_4 nmax)
|
|---|
| 930 | : memgr(mem)
|
|---|
| 931 | {
|
|---|
| 932 | nmax_ = nmax;
|
|---|
| 933 | nmean_ = nmean;
|
|---|
| 934 | step_ = step;
|
|---|
| 935 | stop_ = false;
|
|---|
| 936 | path_ = path;
|
|---|
| 937 | act.sa_handler=DataProcSignal;
|
|---|
| 938 | }
|
|---|
| 939 | void DataProcFFT2C::Stop()
|
|---|
| 940 | {
|
|---|
| 941 | stop_=true;
|
|---|
| 942 | // cout <<" DataProcFFT2C::Stop ... > STOP " << endl;
|
|---|
| 943 | }
|
|---|
| 944 |
|
|---|
| 945 | void DataProcFFT2C::run()
|
|---|
| 946 | {
|
|---|
| 947 | // sigaction(SIGINT,&act,NULL);
|
|---|
| 948 | setRC(1);
|
|---|
| 949 | try {
|
|---|
| 950 | TimeStamp ts;
|
|---|
| 951 | cout << " DataProcFFT2C::run() - Starting " << ts << " NMaxMemZones=" << nmax_
|
|---|
| 952 | << " NMean=" << nmean_ << " Step=" << step_ << endl;
|
|---|
| 953 | cout << " DataProc::run()... - Output Data Path: " << path_ << endl;
|
|---|
| 954 | char fname[512];
|
|---|
| 955 | sprintf(fname,"%s/proc.log",path_.c_str());
|
|---|
| 956 | ofstream filog(fname);
|
|---|
| 957 | filog << " DataProcFFT2C::run() - starting log file " << ts << endl;
|
|---|
| 958 | filog << " ... NMaxMemZones=" << nmax_ << " NMean=" << nmean_ << " Step=" << step_ << endl;
|
|---|
| 959 |
|
|---|
| 960 | // Initialisation pour clcul FFT
|
|---|
| 961 | TVector< complex<r_4> > cfour; // composant TF
|
|---|
| 962 | uint_4 paqsz = memgr.PaqSize();
|
|---|
| 963 | BRPaquet pq(NULL, NULL, paqsz);
|
|---|
| 964 |
|
|---|
| 965 | TVector<r_4> spectreV1(pq.DataSize()/4+1), spectreV2(pq.DataSize()/4+1);
|
|---|
| 966 |
|
|---|
| 967 | uint_4 ifile = 0;
|
|---|
| 968 | for (uint_4 kmz=0; kmz<nmax_; kmz++) {
|
|---|
| 969 | if (stop_ ) break;
|
|---|
| 970 | int mid = memgr.FindMemZoneId(MemZA_Proc);
|
|---|
| 971 | Byte* buff = memgr.GetMemZone(mid);
|
|---|
| 972 | if (buff == NULL) {
|
|---|
| 973 | cout << " DataProcFFT2C::run()/ERROR memgr.GetMemZone(" << mid << ") -> NULL" << endl;
|
|---|
| 974 | setRC(2);
|
|---|
| 975 | return;
|
|---|
| 976 | }
|
|---|
| 977 | BRPaquet paq0(NULL, buff, paqsz);
|
|---|
| 978 | uint_4 nzm = 0;
|
|---|
| 979 | for(uint_4 i=0; i<memgr.NbPaquets(); i+=step_) {
|
|---|
| 980 | BRPaquet paq(NULL, buff+i*paqsz, paqsz);
|
|---|
| 981 | Byte min = 255;
|
|---|
| 982 | Byte max = 0;
|
|---|
| 983 |
|
|---|
| 984 | TwoByteComplex* zz;
|
|---|
| 985 | // Traitement Voie 1
|
|---|
| 986 | zz = (TwoByteComplex*)paq.Data1();
|
|---|
| 987 | spectreV1(0) += zz[0].realD()*zz[0].realD(); // Composante continue, partie reelle uniquement
|
|---|
| 988 | for(sa_size_t j=1; j<spectreV1.Size()-1; j++) spectreV1(j) += Zmod2TwoByte(zz[j]);
|
|---|
| 989 |
|
|---|
| 990 | spectreV1(spectreV1.Size()-1) += zz[0].imagD()*zz[0].imagD(); // Freq. Nyquist a N/2
|
|---|
| 991 |
|
|---|
| 992 | // Traitement Voie 2
|
|---|
| 993 | zz = (TwoByteComplex*)paq.Data2();
|
|---|
| 994 | spectreV2(0) += zz[0].realD()*zz[0].realD(); // Composante continue, partie reelle uniquement
|
|---|
| 995 | for(sa_size_t j=1; j<spectreV2.Size()-1; j++) spectreV2(j) += Zmod2TwoByte(zz[j]);
|
|---|
| 996 |
|
|---|
| 997 | spectreV2(spectreV2.Size()-1) += zz[0].imagD()*zz[0].imagD(); // Freq. Nyquist a N/2
|
|---|
| 998 |
|
|---|
| 999 | nzm++;
|
|---|
| 1000 | }
|
|---|
| 1001 | if ((nzm >= nmean_) ||(kmz==(nmax_-1))) {
|
|---|
| 1002 | spectreV1 /= (r_4)(nzm);
|
|---|
| 1003 | spectreV2 /= (r_4)(nzm);
|
|---|
| 1004 | spectreV1.Info()["NPaqMoy"] = nzm;
|
|---|
| 1005 | spectreV2.Info()["NPaqMoy"] = nzm;
|
|---|
| 1006 | {
|
|---|
| 1007 | sprintf(fname,"%s/spectreFFT2C_%d.ppf",path_.c_str(),(int)ifile);
|
|---|
| 1008 | POutPersist po(fname);
|
|---|
| 1009 | po << PPFNameTag("specV1") << spectreV1;
|
|---|
| 1010 | po << PPFNameTag("specV2") << spectreV2;
|
|---|
| 1011 | }
|
|---|
| 1012 | spectreV1 = (r_4)(0.);
|
|---|
| 1013 | spectreV2 = (r_4)(0.);
|
|---|
| 1014 | nzm = 0; ifile++;
|
|---|
| 1015 | ts.SetNow();
|
|---|
| 1016 | filog << ts << " : proc file " << fname << endl;
|
|---|
| 1017 | cout << " DataProcFFT2C::run() " << ts << " : created file " << fname << endl;
|
|---|
| 1018 | }
|
|---|
| 1019 |
|
|---|
| 1020 | memgr.FreeMemZone(mid, MemZS_Proc);
|
|---|
| 1021 | }
|
|---|
| 1022 | }
|
|---|
| 1023 | catch (std::exception& exc) {
|
|---|
| 1024 | cout << " DataProc::run()/catched std::exception " << exc.what() << endl;
|
|---|
| 1025 | setRC(3);
|
|---|
| 1026 | return;
|
|---|
| 1027 | }
|
|---|
| 1028 | catch(...) {
|
|---|
| 1029 | cout << " DataProcFFT2C::run()/catched unknown ... exception " << endl;
|
|---|
| 1030 | setRC(4);
|
|---|
| 1031 | return;
|
|---|
| 1032 | }
|
|---|
| 1033 | setRC(0);
|
|---|
| 1034 | return;
|
|---|
| 1035 | }
|
|---|