[3635] | 1 | #include "racquproc.h"
|
---|
| 2 |
|
---|
| 3 | #include <stdlib.h>
|
---|
[3642] | 4 | #include <string.h>
|
---|
[3635] | 5 | #include <unistd.h>
|
---|
| 6 | #include <fstream>
|
---|
| 7 | #include <signal.h>
|
---|
| 8 |
|
---|
| 9 | #include "pexceptions.h"
|
---|
| 10 | #include "tvector.h"
|
---|
[3646] | 11 | #include "ntuple.h"
|
---|
[3647] | 12 | #include "datatable.h"
|
---|
[3652] | 13 | #include "histos.h"
|
---|
[3635] | 14 | #include "fioarr.h"
|
---|
[3655] | 15 | #include "matharr.h"
|
---|
[3635] | 16 | #include "timestamp.h"
|
---|
| 17 | #include "ctimer.h"
|
---|
| 18 | #include "fftpserver.h"
|
---|
| 19 | #include "fftwserver.h"
|
---|
| 20 |
|
---|
| 21 | #include "FFTW/fftw3.h"
|
---|
| 22 |
|
---|
| 23 |
|
---|
| 24 | #include "pciewrap.h"
|
---|
| 25 | #include "brpaqu.h"
|
---|
| 26 | #include "brproc.h"
|
---|
| 27 |
|
---|
| 28 |
|
---|
| 29 | //---------------------------------------------------------------
|
---|
| 30 | // Classe thread de traitement donnees ADC avec 2 voies par frame
|
---|
| 31 | //---------------------------------------------------------------
|
---|
| 32 |
|
---|
[3649] | 33 | // Mutex pour eviter le plantage du a FFTW qui ne semble pas thread-safe
|
---|
| 34 | static ZMutex* pmutfftw=NULL;
|
---|
| 35 |
|
---|
[3645] | 36 | /* --Methode-- */
|
---|
[3640] | 37 | BRProcARaw2C::BRProcARaw2C(RAcqMemZoneMgr& mem, string& path, uint_4 nmean,
|
---|
[3656] | 38 | uint_4 nmax, bool fghist, uint_4 nfsmap, bool fgnotrl, int card)
|
---|
[3635] | 39 | : memgr(mem)
|
---|
| 40 | {
|
---|
| 41 | nmax_ = nmax;
|
---|
| 42 | nmean_ = nmean;
|
---|
[3656] | 43 | nfsmap_ = nfsmap;
|
---|
[3635] | 44 | stop_ = false;
|
---|
| 45 | path_ = path;
|
---|
[3640] | 46 | fgnotrl_ = fgnotrl;
|
---|
[3652] | 47 | fghist_ = fghist;
|
---|
[3645] | 48 | card_ = card;
|
---|
[3649] | 49 | if (pmutfftw==NULL) pmutfftw=new ZMutex;
|
---|
[3635] | 50 | }
|
---|
| 51 |
|
---|
[3645] | 52 | /* --Methode-- */
|
---|
[3635] | 53 | void BRProcARaw2C::Stop()
|
---|
| 54 | {
|
---|
| 55 | stop_=true;
|
---|
| 56 | // cout <<" BRProcARaw2C::Stop ... > STOP " << endl;
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 |
|
---|
| 60 | static inline r_4 Zmod2(complex<r_4> z)
|
---|
| 61 | { return (z.real()*z.real()+z.imag()*z.imag()); }
|
---|
| 62 |
|
---|
[3645] | 63 | static inline string card2name_(int card)
|
---|
| 64 | {
|
---|
| 65 | if (card==2) return " (Chan3,4) ";
|
---|
| 66 | else return " (Chan1,2) ";
|
---|
| 67 | }
|
---|
| 68 | /* --Methode-- */
|
---|
[3635] | 69 | void BRProcARaw2C::run()
|
---|
| 70 | {
|
---|
| 71 | setRC(1);
|
---|
| 72 | try {
|
---|
[3640] | 73 | Timer tm("BRProcARaw2C", false);
|
---|
[3635] | 74 | TimeStamp ts;
|
---|
[3646] | 75 | BRPaqChecker pcheck(!fgnotrl_); // Verification/comptage des paquets
|
---|
[3640] | 76 |
|
---|
| 77 | size_t totnbytesout = 0;
|
---|
| 78 | size_t totnbytesproc = 0;
|
---|
| 79 |
|
---|
[3635] | 80 | cout << " BRProcARaw2C::run() - Starting " << ts << " NMaxMemZones=" << nmax_
|
---|
[3645] | 81 | << " NMean=" << nmean_ << card2name_(card_) << endl;
|
---|
[3635] | 82 | cout << " BRProcARaw2C::run()... - Output Data Path: " << path_ << endl;
|
---|
| 83 | char fname[512];
|
---|
| 84 | // sprintf(fname,"%s/proc.log",path_.c_str());
|
---|
| 85 | // ofstream filog(fname);
|
---|
| 86 | // filog << " BRProcARaw2C::run() - starting log file " << ts << endl;
|
---|
| 87 | // filog << " ... NMaxMemZones=" << nmax_ << " NMean=" << nmean_ << " Step=" << step_ << endl;
|
---|
| 88 |
|
---|
[3647] | 89 | /*----DELETE NTuple
|
---|
[3646] | 90 | const char* nnames[8] = {"fcs","tts","s1","s2","s12","s12re","s12im","s12phi"};
|
---|
| 91 | NTuple nt(8, nnames);
|
---|
| 92 | double xnt[10];
|
---|
| 93 | uint_4 nmnt = 0;
|
---|
| 94 | double ms1,ms2,ms12,ms12re,ms12im,ms12phi;
|
---|
[3647] | 95 | ----*/
|
---|
[3652] | 96 | // Time sample histograms
|
---|
| 97 | Histo h1(-0.5, 255.5, 256);
|
---|
| 98 | Histo h2(-0.5, 255.5, 256);
|
---|
[3635] | 99 | // Initialisation pour calcul FFT
|
---|
[3640] | 100 | TVector< complex<r_4> > cfour1; // composant TF
|
---|
[3635] | 101 | uint_4 paqsz = memgr.PaqSize();
|
---|
| 102 | uint_4 procpaqsz = memgr.ProcPaqSize();
|
---|
[3646] | 103 |
|
---|
| 104 |
|
---|
[3635] | 105 | BRPaquet pq(NULL, NULL, paqsz);
|
---|
| 106 | TVector<r_4> vx(pq.DataSize()/2);
|
---|
[3648] | 107 | int szfour = pq.DataSize()/2/2+1;
|
---|
| 108 | cfour1.SetSize(szfour);
|
---|
| 109 | /*
|
---|
[3635] | 110 | vx = (r_4)(0.);
|
---|
| 111 | FFTPackServer ffts;
|
---|
[3640] | 112 | ffts.FFTForward(vx, cfour1);
|
---|
[3648] | 113 | szfour = cfour1.Size();
|
---|
| 114 | */
|
---|
| 115 |
|
---|
[3656] | 116 | bool fgtimfreq = false; // true->cartes temps<>frequences
|
---|
| 117 | if (nfsmap_>0) fgtimfreq=true;
|
---|
| 118 |
|
---|
[3640] | 119 | TVector< complex<r_4> > cfour2(cfour1.Size());
|
---|
[3635] | 120 |
|
---|
[3640] | 121 | TVector<r_4> spectreV1(cfour1.Size());
|
---|
| 122 | TVector<r_4> spectreV2(cfour1.Size());
|
---|
[3655] | 123 | TVector<r_4> moyspecV1(cfour1.Size()); // Moyenne des Spectres
|
---|
| 124 | TVector<r_4> moyspecV2(cfour1.Size());
|
---|
| 125 | TVector<r_4> sigspecV1(cfour1.Size()); // Sigma des Spectres
|
---|
| 126 | TVector<r_4> sigspecV2(cfour1.Size());
|
---|
[3640] | 127 | TVector< complex<r_4> > visiV12( cfour1.Size() );
|
---|
[3635] | 128 |
|
---|
[3656] | 129 | TMatrix<r_4> timfreqV1, timfreqV2; // Cartes temps<>frequences
|
---|
| 130 | if (fgtimfreq) {
|
---|
| 131 | timfreqV1.SetSize(nmean_, spectreV1.Size()/nfsmap_);
|
---|
| 132 | timfreqV2.SetSize(nmean_, spectreV2.Size()/nfsmap_);
|
---|
| 133 | }
|
---|
[3646] | 134 | cout << " *DBG*BRProcARaw2C PaqSz=" << paqsz << " ProcPaqSize=" << procpaqsz
|
---|
| 135 | << " procpaqsz/2=" << procpaqsz/2 << " cfour1.Size()=" << cfour1.Size()
|
---|
| 136 | << " *8=" << cfour1.Size()*8 << endl;
|
---|
[3635] | 137 |
|
---|
[3649] | 138 | pmutfftw->lock();
|
---|
[3640] | 139 | fftwf_plan plan1 = fftwf_plan_dft_r2c_1d(vx.Size(), vx.Data(),
|
---|
| 140 | (fftwf_complex*)cfour1.Data(), FFTW_ESTIMATE);
|
---|
| 141 | fftwf_plan plan2 = fftwf_plan_dft_r2c_1d(vx.Size(), vx.Data(),
|
---|
| 142 | (fftwf_complex*)cfour2.Data(), FFTW_ESTIMATE);
|
---|
[3649] | 143 | pmutfftw->unlock();
|
---|
[3640] | 144 |
|
---|
[3635] | 145 | uint_4 ifile = 0;
|
---|
[3655] | 146 | uint_4 nzm = 0; // Nb de paquets moyennes pour le calcul de chaque spectre
|
---|
| 147 | uint_4 nmoyspec = 0; // Nb de spectres moyennes
|
---|
[3647] | 148 |
|
---|
| 149 | uint_4 curfc=0;
|
---|
| 150 | uint_8 curtt=0;
|
---|
| 151 | uint_8 firsttt=0;
|
---|
| 152 | bool fgfirst=true;
|
---|
[3658] | 153 | double moysig[2]={0.,0.};
|
---|
| 154 | double sigsig[2]={0.,0.};
|
---|
| 155 | uint_8 nbsig[2]={0,0};
|
---|
| 156 |
|
---|
[3635] | 157 | for (uint_4 kmz=0; kmz<nmax_; kmz++) {
|
---|
| 158 | if (stop_) break;
|
---|
| 159 | int mid = memgr.FindMemZoneId(MemZA_ProcA);
|
---|
| 160 | Byte* buff = memgr.GetMemZone(mid);
|
---|
| 161 | if (buff == NULL) {
|
---|
[3640] | 162 | cout << " BRProcARaw2C::run()/ERROR memgr.GetMemZone(" << mid << ") -> NULL" << endl;
|
---|
| 163 | break;
|
---|
[3635] | 164 | }
|
---|
| 165 | Byte* procbuff = memgr.GetProcMemZone(mid);
|
---|
| 166 | if (procbuff == NULL) {
|
---|
[3640] | 167 | cout << " BRProcARaw2C::run()/ERROR memgr.GetProcMemZone(" << mid << ") -> NULL" << endl;
|
---|
| 168 | break;
|
---|
[3635] | 169 | }
|
---|
[3647] | 170 | //---- DELETE nmnt=0; ms1=ms2=ms12=ms12re=ms12im=ms12phi=0.;
|
---|
[3645] | 171 | for(uint_4 i=0; i<memgr.NbPaquets(); i++) {
|
---|
[3640] | 172 | BRPaquet paq(NULL, buff+i*paqsz, paqsz);
|
---|
| 173 | if (!pcheck.Check(paq)) continue; // on ne traite que les paquets OK
|
---|
[3647] | 174 | if (fgfirst) { firsttt=paq.TimeTag(); fgfirst=false; }
|
---|
| 175 | curfc=paq.FrameCounter();
|
---|
| 176 | curtt=paq.TimeTag()-firsttt;
|
---|
[3635] | 177 | // Traitement voie 1
|
---|
[3652] | 178 | if (fghist_) {
|
---|
| 179 | for(sa_size_t j=0; j<vx.Size(); j++) {
|
---|
| 180 | r_4 vts=(r_4)(*(paq.Data1()+j));
|
---|
| 181 | h1.Add((r_8)vts);
|
---|
[3658] | 182 | moysig[0] += (double)vts;
|
---|
| 183 | sigsig[0] += ((double)vts)*((double)vts);
|
---|
| 184 | nbsig[0]++;
|
---|
[3652] | 185 | vx(j) = vts-127.5;
|
---|
| 186 | }
|
---|
| 187 | }
|
---|
| 188 | else {
|
---|
| 189 | for(sa_size_t j=0; j<vx.Size(); j++)
|
---|
| 190 | vx(j) = (r_4)(*(paq.Data1()+j))-127.5;
|
---|
| 191 | }
|
---|
[3640] | 192 | // fftwf_complex* coeff1 = (fftwf_complex*)(procbuff+i*procpaqsz);
|
---|
[3646] | 193 | fftwf_execute(plan1);
|
---|
| 194 | // complex<r_4>* zp1 = (complex<r_4>*)(vx.Data());
|
---|
[3640] | 195 | // ffts.FFTForward(vx, cfour1);
|
---|
[3635] | 196 | for(sa_size_t j=0; j<spectreV1.Size(); j++)
|
---|
[3640] | 197 | spectreV1(j) += Zmod2(cfour1(j));
|
---|
| 198 | memcpy(procbuff+i*procpaqsz, cfour1.Data(), sizeof(complex<r_4>)*cfour1.Size());
|
---|
[3656] | 199 | if (fgtimfreq) { // Remplissage tableau temps-frequence
|
---|
| 200 | for(sa_size_t c=1; c<timfreqV1.NCols(); c++) {
|
---|
| 201 | for(sa_size_t j=c*nfsmap_; j<(c+1)*nfsmap_; j++)
|
---|
| 202 | timfreqV1(nzm, c) += Zmod2(cfour1(j));
|
---|
| 203 | }
|
---|
| 204 | }
|
---|
[3635] | 205 | // Traitement voie 2
|
---|
[3652] | 206 | if (fghist_) {
|
---|
| 207 | for(sa_size_t j=0; j<vx.Size(); j++) {
|
---|
| 208 | r_4 vts=(r_4)(*(paq.Data2()+j));
|
---|
| 209 | h2.Add((r_8)vts);
|
---|
[3658] | 210 | moysig[1] += (double)vts;
|
---|
| 211 | sigsig[1] += ((double)vts)*((double)vts);
|
---|
| 212 | nbsig[1]++;
|
---|
[3652] | 213 | vx(j) = vts-127.5;
|
---|
| 214 | }
|
---|
| 215 | }
|
---|
| 216 | else {
|
---|
| 217 | for(sa_size_t j=0; j<vx.Size(); j++)
|
---|
| 218 | vx(j) = (r_4)(*(paq.Data2()+j))-127.5;
|
---|
| 219 | }
|
---|
[3646] | 220 | fftwf_execute(plan2);
|
---|
[3635] | 221 | for(sa_size_t j=0; j<spectreV2.Size(); j++)
|
---|
[3640] | 222 | spectreV2(j) += Zmod2(cfour2(j)); // Zmod2(zp2[j]);
|
---|
| 223 | memcpy(procbuff+i*procpaqsz+procpaqsz/2, cfour2.Data(), sizeof(complex<r_4>)*cfour2.Size());
|
---|
[3656] | 224 | if (fgtimfreq) { // Remplissage tableau temps-frequence
|
---|
| 225 | for(sa_size_t c=1; c<timfreqV2.NCols(); c++) {
|
---|
| 226 | for(sa_size_t j=c*nfsmap_; j<(c+1)*nfsmap_; j++)
|
---|
| 227 | timfreqV2(nzm,c) += Zmod2(cfour2(j));
|
---|
| 228 | }
|
---|
| 229 | }
|
---|
[3635] | 230 |
|
---|
| 231 | // Calcul correlation (visibilite V1 * V2)
|
---|
[3640] | 232 | for(sa_size_t j=0; j<visiV12.Size(); j++)
|
---|
| 233 | visiV12(j)+=cfour1(j)*conj(cfour2(j));
|
---|
| 234 | // for(sa_size_t j=0; j<visiV12.Size(); j++) visiV12(j)+=zp1[j]*zp2[j];
|
---|
[3647] | 235 | if (nzm==0) {
|
---|
| 236 | spectreV1.Info()["StartFC"] = curfc;
|
---|
| 237 | spectreV2.Info()["StartFC"] = curfc;
|
---|
| 238 | visiV12.Info()["StartFC"] = curfc;
|
---|
| 239 | spectreV1.Info()["StartTT"] = curtt;
|
---|
| 240 | spectreV2.Info()["StartTT"] = curtt;
|
---|
| 241 | visiV12.Info()["StartTT"] = curtt;
|
---|
| 242 | }
|
---|
[3640] | 243 | nzm++;
|
---|
[3647] | 244 | /*----DELETE
|
---|
[3646] | 245 | if (nmnt==0) { xnt[0]=paq.FrameCounter(); xnt[1]=paq.TimeTag(); }
|
---|
| 246 | for(sa_size_t j=2700; j<2800; j++) {
|
---|
| 247 | ms1 += Zmod2(cfour1(j)); ms2 += Zmod2(cfour2(j));
|
---|
| 248 | complex<r_4> zvis = cfour1(j)*conj(cfour2(j));
|
---|
| 249 | ms12 += Zmod2(zvis); ms12re += zvis.real(); ms12im += zvis.imag();
|
---|
| 250 | ms12phi+= atan2(zvis.imag(),zvis.real());
|
---|
| 251 | }
|
---|
| 252 | nmnt++;
|
---|
[3647] | 253 | ----*/
|
---|
[3640] | 254 | totnbytesproc += paq.DataSize();
|
---|
| 255 | totnbytesout += (2*sizeof(complex<r_4>)*cfour1.Size());
|
---|
[3635] | 256 |
|
---|
[3640] | 257 | } // Fin de boucle sur les paquets d'une zone
|
---|
[3647] | 258 |
|
---|
| 259 | /*---- DELETE
|
---|
[3646] | 260 | if (nmnt>0) {
|
---|
| 261 | double fnorm = (double)nmnt*(2800-2700);
|
---|
| 262 | xnt[2] = ms1 /= fnorm;
|
---|
| 263 | xnt[3] = ms2 /= fnorm;
|
---|
| 264 | xnt[4] = ms12 /= fnorm;
|
---|
| 265 | xnt[5] = ms12re /= fnorm;
|
---|
| 266 | xnt[6] = ms12im /= fnorm;
|
---|
| 267 | xnt[7] = ms12phi /= fnorm;
|
---|
| 268 | nt.Fill(xnt);
|
---|
| 269 | }
|
---|
[3647] | 270 | ----*/
|
---|
[3640] | 271 | if ((nzm >= nmean_) || ((kmz==(nmax_-1))&&(nzm>1))) {
|
---|
[3635] | 272 | spectreV1 /= (r_4)(nzm);
|
---|
| 273 | spectreV2 /= (r_4)(nzm);
|
---|
| 274 |
|
---|
[3655] | 275 | // pour le calcul des moyennes et sigmas de ces spectres
|
---|
| 276 | moyspecV1 += spectreV1;
|
---|
| 277 | moyspecV2 += spectreV2;
|
---|
| 278 | sigspecV1 += (spectreV1 && spectreV1);
|
---|
| 279 | sigspecV2 += (spectreV2 && spectreV2);
|
---|
| 280 | nmoyspec++;
|
---|
| 281 |
|
---|
[3635] | 282 | visiV12 /= complex<r_4>((r_4)nzm, 0.);
|
---|
| 283 |
|
---|
| 284 | spectreV1.Info()["NPaqMoy"] = nzm;
|
---|
| 285 | spectreV2.Info()["NPaqMoy"] = nzm;
|
---|
| 286 | visiV12.Info()["NPaqMoy"] = nzm;
|
---|
[3647] | 287 | spectreV1.Info()["EndFC"] = curfc;
|
---|
| 288 | spectreV2.Info()["EndFC"] = curfc;
|
---|
| 289 | visiV12.Info()["EndFC"] = curfc;
|
---|
| 290 | spectreV1.Info()["EndTT"] = curtt;
|
---|
| 291 | spectreV2.Info()["EndTT"] = curtt;
|
---|
| 292 | visiV12.Info()["EndTT"] = curtt;
|
---|
[3652] | 293 | {
|
---|
[3635] | 294 | sprintf(fname,"%s_%d.ppf",path_.c_str(),(int)ifile);
|
---|
| 295 | POutPersist po(fname);
|
---|
[3645] | 296 | string tag1="specV1";
|
---|
| 297 | string tag2="specV2";
|
---|
| 298 | string tag12="visiV12";
|
---|
[3652] | 299 | string tagh1="tshV1";
|
---|
| 300 | string tagh2="tshV2";
|
---|
[3656] | 301 | string tagtf1="timfreqV1";
|
---|
| 302 | string tagtf2="timfreqV2";
|
---|
[3645] | 303 | if (card_==2) {
|
---|
| 304 | tag1 = "specV3";
|
---|
| 305 | tag2 = "specV4";
|
---|
[3652] | 306 | tagh1 = "tshV1";
|
---|
| 307 | tagh2 = "tshV2";
|
---|
[3645] | 308 | tag12="visiV34";
|
---|
[3656] | 309 | tagtf1="timfreqV3";
|
---|
| 310 | tagtf2="timfreqV4";
|
---|
[3645] | 311 | }
|
---|
| 312 | po << PPFNameTag(tag1) << spectreV1;
|
---|
| 313 | po << PPFNameTag(tag2) << spectreV2;
|
---|
| 314 | po << PPFNameTag(tag12) << visiV12;
|
---|
[3652] | 315 | if (fghist_) {
|
---|
| 316 | po << PPFNameTag(tagh1) << h1;
|
---|
| 317 | po << PPFNameTag(tagh2) << h2;
|
---|
[3658] | 318 |
|
---|
| 319 | double sspvmax[3] = {0.,0.,0.};
|
---|
| 320 | int_4 sspvmaxidx[3] = {-1,-1,-1};
|
---|
| 321 | for(int jji=1;jji<visiV12.Size()-1;jji++) {
|
---|
| 322 | r_4 zmv2 = Zmod2(visiV12(jji));
|
---|
| 323 | if (zmv2>sspvmax[2]) { sspvmax[2]=zmv2; sspvmaxidx[2]=jji; }
|
---|
| 324 | }
|
---|
| 325 | TVector<r_4>& sspv = spectreV1;
|
---|
| 326 | for(int ic=0; ic<2; ic++) {
|
---|
| 327 | if (ic==1) sspv = spectreV2;
|
---|
| 328 | for(int jji=1;jji<sspv.Size()-1;jji++)
|
---|
| 329 | if (sspv(jji)>sspvmax[ic]) { sspvmax[ic]=sspv(jji); sspvmaxidx[ic]=jji; }
|
---|
| 330 | if (nbsig[ic] < 1) { moysig[ic]=sigsig[ic]=-1.; }
|
---|
| 331 | else {
|
---|
| 332 | moysig[ic] /= (double)nbsig[ic];
|
---|
| 333 | sigsig[ic] /= (double)nbsig[ic];
|
---|
| 334 | sigsig[ic] -= (moysig[ic]*moysig[ic]);
|
---|
| 335 | sigsig[ic] = sqrt(sigsig[ic]);
|
---|
| 336 | cout << "===Voie " << ic << " Moy=" << moysig[ic] << " Sig=" << sigsig[ic]
|
---|
| 337 | << " MaxSpec Amp= " << sqrt(sspvmax[ic])/double(pq.DataSize()/2/2)
|
---|
| 338 | << " Pos=" << sspvmaxidx[ic] << " (NPts=" << nbsig[ic] << ")" << endl;
|
---|
| 339 | }
|
---|
| 340 | }
|
---|
| 341 | cout << "=== Voie1x2 MaxSpec Amp= " << sqrt(sqrt(sspvmax[2])/double(pq.DataSize()/2/2))
|
---|
| 342 | << " Pos=" << sspvmaxidx[2] << endl;
|
---|
| 343 | } // fin if (fghist_)
|
---|
| 344 |
|
---|
[3656] | 345 | if (fgtimfreq) {
|
---|
| 346 | timfreqV1 /= (r_4)nzm;
|
---|
| 347 | timfreqV2 /= (r_4)nzm;
|
---|
| 348 | po << PPFNameTag(tagtf1) << timfreqV1;
|
---|
| 349 | po << PPFNameTag(tagtf2) << timfreqV2;
|
---|
| 350 | }
|
---|
[3652] | 351 | }
|
---|
[3635] | 352 | spectreV1 = (r_4)(0.);
|
---|
| 353 | spectreV2 = (r_4)(0.);
|
---|
| 354 | visiV12 = complex<r_4>(0., 0.);
|
---|
[3652] | 355 | if (fghist_) {
|
---|
| 356 | h1.Zero();
|
---|
| 357 | h2.Zero();
|
---|
[3658] | 358 | moysig[0]=moysig[1]=0.;
|
---|
| 359 | sigsig[0]=sigsig[1]=0.;
|
---|
| 360 | nbsig[0]=nbsig[1]=0;
|
---|
[3652] | 361 | }
|
---|
[3656] | 362 | if (fgtimfreq) {
|
---|
| 363 | timfreqV1 = (r_4)(0.);
|
---|
| 364 | timfreqV2 = (r_4)(0.);
|
---|
| 365 | }
|
---|
[3635] | 366 | nzm = 0; ifile++;
|
---|
| 367 | // ts.SetNow();
|
---|
| 368 | // filog << ts << " : proc file " << fname << endl;
|
---|
[3645] | 369 | cout << " BRProcARaw2C::run() created file " << fname << card2name_(card_) << endl;
|
---|
[3640] | 370 | }
|
---|
[3635] | 371 |
|
---|
| 372 | memgr.FreeMemZone(mid, MemZS_ProcA);
|
---|
[3640] | 373 | } // Fin de boucle sur les zones a traiter
|
---|
[3645] | 374 | cout << " ------------ BRProcARaw2C::run() END " << card2name_(card_)
|
---|
| 375 | << " ------------ " << endl;
|
---|
[3647] | 376 | /*---- DELETE
|
---|
| 377 | {
|
---|
| 378 | nt.Info()["FirstTT"]=firsttt;
|
---|
[3646] | 379 | cout << nt;
|
---|
| 380 | sprintf(fname,"%s_nt.ppf",path_.c_str());
|
---|
| 381 | POutPersist po(fname);
|
---|
| 382 | po << PPFNameTag("ntv12") << nt;
|
---|
| 383 | cout << " BRProcARaw2C::run() created NTuple file " << fname << card2name_(card_) << endl;
|
---|
[3647] | 384 | }
|
---|
| 385 | ---- */
|
---|
[3655] | 386 | if (nmoyspec>0) { // Calcul des moyennes et sigmas des spectres
|
---|
| 387 | r_4 fnms = nmoyspec;
|
---|
| 388 | moyspecV1 /= fnms;
|
---|
| 389 | moyspecV2 /= fnms;
|
---|
| 390 | sigspecV1 /= fnms;
|
---|
| 391 | sigspecV2 /= fnms;
|
---|
| 392 | sigspecV1 -= (moyspecV1 && moyspecV1);
|
---|
| 393 | sigspecV2 -= (moyspecV2 && moyspecV2);
|
---|
| 394 | sigspecV1 = Sqrt(sigspecV1);
|
---|
| 395 | sigspecV2 = Sqrt(sigspecV2);
|
---|
| 396 | TVector<r_4> rsbV1, rsbV2; // Rapport signal/bruit
|
---|
| 397 | moyspecV1.DivElt(sigspecV1, rsbV1, false, true);
|
---|
| 398 | moyspecV2.DivElt(sigspecV2, rsbV2, false, true);
|
---|
| 399 | sprintf(fname,"%s_ms.ppf",path_.c_str());
|
---|
| 400 | POutPersist po(fname);
|
---|
| 401 | po << PPFNameTag("moyspecV1") << moyspecV1;
|
---|
| 402 | po << PPFNameTag("moyspecV2") << moyspecV2;
|
---|
| 403 | po << PPFNameTag("sigspecV1") << sigspecV1;
|
---|
| 404 | po << PPFNameTag("sigspecV2") << sigspecV2;
|
---|
| 405 | po << PPFNameTag("rsbV1") << rsbV1;
|
---|
| 406 | po << PPFNameTag("rsbV2") << rsbV2;
|
---|
| 407 | cout << " BRProcARaw2C::run() created moysigspec file " << fname << card2name_(card_) << endl;
|
---|
| 408 | }
|
---|
| 409 |
|
---|
[3640] | 410 | ts.SetNow();
|
---|
| 411 | tm.SplitQ();
|
---|
| 412 | cout << " TotalProc= " << totnbytesproc/(1024*1024) << " MBytes, rate= "
|
---|
| 413 | << (double)(totnbytesproc)/1024./tm.PartialElapsedTimems() << " MB/s"
|
---|
| 414 | << " ProcDataOut=" << totnbytesout/(1024*1024) << " MB" << endl;
|
---|
| 415 | cout << pcheck;
|
---|
[3645] | 416 | cout << " BRProcARaw2C::run()/Timing: " << card2name_(card_) << endl;
|
---|
[3640] | 417 | tm.Print();
|
---|
| 418 | cout << " ---------------------------------------------------------- " << endl;
|
---|
| 419 |
|
---|
[3635] | 420 | }
|
---|
| 421 | catch (PException& exc) {
|
---|
| 422 | cout << " BRProcARaw2C::run()/catched PException " << exc.Msg() << endl;
|
---|
| 423 | setRC(3);
|
---|
| 424 | return;
|
---|
| 425 | }
|
---|
| 426 | catch(...) {
|
---|
| 427 | cout << " BRProcARaw2C::run()/catched unknown ... exception " << endl;
|
---|
| 428 | setRC(4);
|
---|
| 429 | return;
|
---|
| 430 | }
|
---|
| 431 | setRC(0);
|
---|
| 432 | return;
|
---|
| 433 | }
|
---|
| 434 |
|
---|
[3645] | 435 | //---------------------------------------------------------------------
|
---|
| 436 | // Classe thread de traitement 2 x 2 voies/frames (Apres BRProcARaw2C)
|
---|
| 437 | //---------------------------------------------------------------------
|
---|
[3635] | 438 |
|
---|
[3645] | 439 | /* --Methode-- */
|
---|
| 440 | BRProcBRaw4C::BRProcBRaw4C(RAcqMemZoneMgr& mem1, RAcqMemZoneMgr& mem2,
|
---|
| 441 | string& path, uint_4 nmean, uint_4 nmax, bool fgnotrl)
|
---|
| 442 | : memgr1(mem1), memgr2(mem2)
|
---|
| 443 | {
|
---|
| 444 | nmax_ = nmax;
|
---|
| 445 | nmean_ = nmean;
|
---|
| 446 | stop_ = false;
|
---|
| 447 | path_ = path;
|
---|
| 448 | fgnotrl_ = fgnotrl;
|
---|
| 449 | }
|
---|
[3635] | 450 |
|
---|
[3645] | 451 | /* --Methode-- */
|
---|
| 452 | void BRProcBRaw4C::Stop()
|
---|
| 453 | {
|
---|
| 454 | stop_=true;
|
---|
| 455 | // cout <<" BRProcBRaw4C::Stop ... > STOP " << endl;
|
---|
| 456 | }
|
---|
[3635] | 457 |
|
---|
[3645] | 458 |
|
---|
| 459 | /* --Methode-- */
|
---|
| 460 | void BRProcBRaw4C::run()
|
---|
| 461 | {
|
---|
| 462 | setRC(1);
|
---|
| 463 | try {
|
---|
| 464 | Timer tm("BRProcBRaw4C", false);
|
---|
| 465 | TimeStamp ts;
|
---|
[3646] | 466 | BRPaqChecker pcheck1(!fgnotrl_); // Verification/comptage des paquets
|
---|
| 467 | BRPaqChecker pcheck2(!fgnotrl_); // Verification/comptage des paquets
|
---|
[3645] | 468 |
|
---|
| 469 | size_t totnbytesout = 0;
|
---|
| 470 | size_t totnbytesproc = 0;
|
---|
| 471 |
|
---|
| 472 | cout << " BRProcBRaw4C::run() - Starting " << ts << " NMaxMemZones=" << nmax_
|
---|
| 473 | << " NMean=" << nmean_ << endl;
|
---|
| 474 | cout << " BRProcBRaw4C::run()... - Output Data Path: " << path_ << endl;
|
---|
| 475 |
|
---|
| 476 | uint_4 paqsz = memgr1.PaqSize();
|
---|
| 477 | uint_4 procpaqsz = memgr1.ProcPaqSize();
|
---|
| 478 | if ((paqsz != memgr2.PaqSize())||(procpaqsz!= memgr2.ProcPaqSize())) {
|
---|
| 479 | cout << "BRProcBRaw4C::run()/ERROR : different paquet size -> stop \n ...(PaqSz1="
|
---|
| 480 | << paqsz << " Sz2=" << memgr2.PaqSize() << " ProcPaqSz1="
|
---|
| 481 | << procpaqsz << " Sz2=" << memgr2.ProcPaqSize() << " )" << endl;
|
---|
| 482 | setRC(9);
|
---|
| 483 | return;
|
---|
| 484 | }
|
---|
| 485 |
|
---|
| 486 | TVector< complex<r_4> > cfour; // composant TF
|
---|
[3648] | 487 | BRPaquet pq(NULL, NULL, paqsz);
|
---|
[3646] | 488 | /*
|
---|
[3645] | 489 | TVector<r_4> vx(pq.DataSize()/2);
|
---|
| 490 | vx = (r_4)(0.);
|
---|
| 491 | FFTPackServer ffts;
|
---|
| 492 | ffts.FFTForward(vx, cfour);
|
---|
| 493 |
|
---|
| 494 | TVector< complex<r_4> > visiV13( cfour.Size() );
|
---|
| 495 | TVector< complex<r_4> > visiV14( cfour.Size() );
|
---|
| 496 | TVector< complex<r_4> > visiV23( cfour.Size() );
|
---|
| 497 | TVector< complex<r_4> > visiV24( cfour.Size() );
|
---|
[3646] | 498 | */
|
---|
[3648] | 499 | int szfour = pq.DataSize()/2/2+1;
|
---|
| 500 | // int szfour = (paqsz-40)/2+1;
|
---|
[3646] | 501 | TVector< complex<r_4> > visiV13( szfour );
|
---|
| 502 | TVector< complex<r_4> > visiV14( szfour );
|
---|
| 503 | TVector< complex<r_4> > visiV23( szfour );
|
---|
| 504 | TVector< complex<r_4> > visiV24( szfour );
|
---|
| 505 | // cout << " *DBG*AAAAA ---- Vectors OK" << endl;
|
---|
| 506 | cout << " *DBG*BRProcBRaw4C PaqSz=" << paqsz << " ProcPaqSize=" << procpaqsz
|
---|
| 507 | << " procpaqsz/2=" << procpaqsz/2 << " cfour.Size()=" << szfour
|
---|
| 508 | << " *8=" << szfour*8 << endl;
|
---|
[3645] | 509 |
|
---|
[3647] | 510 | DataTable dt;
|
---|
| 511 | dt.AddLongColumn("fc1");
|
---|
[3651] | 512 | dt.AddLongColumn("tt1");
|
---|
[3647] | 513 | dt.AddLongColumn("fc2");
|
---|
| 514 | dt.AddLongColumn("tt2");
|
---|
| 515 | DataTableRow dtr = dt.EmptyRow();
|
---|
| 516 |
|
---|
[3645] | 517 | uint_4 nzm = 0;
|
---|
| 518 | uint_4 totnoksfc = 0;
|
---|
| 519 | uint_4 totnokpaq = 0;
|
---|
| 520 | uint_4 totnpaq = 0;
|
---|
| 521 | uint_4 ifile = 0;
|
---|
[3647] | 522 |
|
---|
| 523 | uint_4 curfc=0;
|
---|
| 524 | uint_8 curtt=0;
|
---|
| 525 | uint_4 curfc2=0;
|
---|
| 526 | uint_8 curtt2=0;
|
---|
| 527 | uint_8 firsttt=0;
|
---|
| 528 | uint_8 firsttt2=0;
|
---|
| 529 | bool fgfirst=true;
|
---|
[3645] | 530 | for (uint_4 kmz=0; kmz<nmax_; kmz++) {
|
---|
| 531 | uint_4 noksfc = 0;
|
---|
| 532 | uint_4 nokpaq = 0;
|
---|
| 533 | if (stop_) break;
|
---|
[3646] | 534 | // cout << " *DBG*BBBBB" << kmz << endl;
|
---|
| 535 |
|
---|
[3645] | 536 | int mid1 = memgr1.FindMemZoneId(MemZA_ProcB);
|
---|
| 537 | Byte* buff1 = memgr1.GetMemZone(mid1);
|
---|
| 538 | if (buff1 == NULL) {
|
---|
| 539 | cout << " BRProcBRaw4C::run()/ERROR memgr.GetMemZone(" << mid1 << ") -> NULL" << endl;
|
---|
| 540 | break;
|
---|
| 541 | }
|
---|
| 542 | Byte* procbuff1 = memgr1.GetProcMemZone(mid1);
|
---|
| 543 | if (procbuff1 == NULL) {
|
---|
| 544 | cout << " BRProcBRaw4C::run()/ERROR memgr.GetProcMemZone(" << mid1 << ") -> NULL" << endl;
|
---|
| 545 | break;
|
---|
| 546 | }
|
---|
| 547 | int mid2 = memgr2.FindMemZoneId(MemZA_ProcB);
|
---|
| 548 | Byte* buff2 = memgr2.GetMemZone(mid2);
|
---|
| 549 | if (buff1 == NULL) {
|
---|
| 550 | cout << " BRProcBRaw4C::run()/ERROR memgr.GetMemZone(" << mid2 << ") -> NULL" << endl;
|
---|
| 551 | break;
|
---|
| 552 | }
|
---|
| 553 | Byte* procbuff2 = memgr2.GetProcMemZone(mid2);
|
---|
| 554 | if (procbuff2 == NULL) {
|
---|
| 555 | cout << " BRProcBRaw4C::run()/ERROR memgr.GetProcMemZone(" << mid2 << ") -> NULL" << endl;
|
---|
| 556 | break;
|
---|
| 557 | }
|
---|
| 558 | uint_4 i1,i2;
|
---|
| 559 | i1=i2=0;
|
---|
[3646] | 560 | // cout << " *DBG*CCCCCC " << kmz << " memgr1.NbPaquets() =" << memgr1.NbPaquets() << endl;
|
---|
[3645] | 561 | while((i1<memgr1.NbPaquets())&&(i2<memgr2.NbPaquets())) {
|
---|
| 562 | BRPaquet paq1(NULL, buff1+i1*paqsz, paqsz);
|
---|
| 563 | BRPaquet paq2(NULL, buff2+i2*paqsz, paqsz);
|
---|
| 564 | totnpaq++;
|
---|
| 565 | // cout << " DBG["<<kmz<<"] i1,i2=" << i1 <<","<<i2<<" FC1,FC2=" <<paq1.FrameCounter()
|
---|
| 566 | //<<","<<paq2.FrameCounter()<<endl;
|
---|
| 567 | // on ne traite que les paquets OK
|
---|
| 568 | if (!pcheck1.Check(paq1)) { i1++; continue; }
|
---|
| 569 | if (!pcheck2.Check(paq2)) { i2++; continue; }
|
---|
| 570 | nokpaq++;
|
---|
| 571 | if (paq1.FrameCounter()<paq2.FrameCounter()) { i1++; continue; }
|
---|
| 572 | if (paq2.FrameCounter()<paq1.FrameCounter()) { i2++; continue; }
|
---|
| 573 | // cout << " DBG["<<kmz<<"]OKOK i1,i2=" << i1 <<","<<i2<<" FC1,FC2=" <<paq1.FrameCounter()
|
---|
| 574 | // <<","<<paq2.FrameCounter()<<endl;
|
---|
| 575 |
|
---|
[3646] | 576 | if ((i1>=memgr1.NbPaquets())||(i2>=memgr1.NbPaquets())) {
|
---|
| 577 | cout << " *BUG*BUG i1=" << i1 << " i2=" << i2 << endl;
|
---|
| 578 | break;
|
---|
| 579 | }
|
---|
[3645] | 580 | // Les deux framecounters sont identiques ...
|
---|
| 581 | noksfc++;
|
---|
[3647] | 582 | curfc=paq1.FrameCounter();
|
---|
| 583 | curfc2=paq2.FrameCounter();
|
---|
| 584 | if (fgfirst) {
|
---|
[3651] | 585 | firsttt=paq1.TimeTag(); firsttt2=paq2.TimeTag();
|
---|
[3647] | 586 | cout << " BRProcBRaw4C()/Info First FC="<<curfc<<" , "<<curfc2<<" -> TT="
|
---|
| 587 | << firsttt<<" , "<<firsttt2 <<endl;
|
---|
| 588 | fgfirst=false;
|
---|
| 589 | }
|
---|
| 590 | curtt=paq1.TimeTag()-firsttt;
|
---|
| 591 | curtt2=paq2.TimeTag()-firsttt2;
|
---|
| 592 | dtr[0]=curfc; dtr[1]=curtt;
|
---|
| 593 | dtr[2]=curfc2; dtr[3]=curtt2;
|
---|
| 594 | dt.AddRow(dtr);
|
---|
| 595 |
|
---|
[3645] | 596 | complex<r_4>* zp1 = (complex<r_4>*)(procbuff1+i1*procpaqsz);
|
---|
| 597 | complex<r_4>* zp2 = (complex<r_4>*)(procbuff1+i1*procpaqsz+procpaqsz/2);
|
---|
| 598 | complex<r_4>* zp3 = (complex<r_4>*)(procbuff2+i2*procpaqsz);
|
---|
| 599 | complex<r_4>* zp4 = (complex<r_4>*)(procbuff2+i2*procpaqsz+procpaqsz/2);
|
---|
| 600 | for(sa_size_t j=0; j<visiV13.Size(); j++) {
|
---|
| 601 | visiV13(j)+=zp1[j]*conj(zp3[j]);
|
---|
| 602 | visiV14(j)+=zp1[j]*conj(zp4[j]);
|
---|
| 603 | visiV23(j)+=zp2[j]*conj(zp3[j]);
|
---|
| 604 | visiV24(j)+=zp2[j]*conj(zp4[j]);
|
---|
| 605 | }
|
---|
[3647] | 606 | if (nzm==0) {
|
---|
| 607 | visiV13.Info()["StartFC"] = curfc;
|
---|
| 608 | visiV14.Info()["StartFC"] = curfc;
|
---|
| 609 | visiV23.Info()["StartFC"] = curfc;
|
---|
| 610 | visiV24.Info()["StartFC"] = curfc;
|
---|
| 611 | visiV13.Info()["StartTT"] = curtt;
|
---|
| 612 | visiV14.Info()["StartTT"] = curtt;
|
---|
| 613 | visiV23.Info()["StartTT"] = curtt;
|
---|
| 614 | visiV24.Info()["StartTT"] = curtt;
|
---|
| 615 | }
|
---|
[3645] | 616 | nzm++; i1++; i2++;
|
---|
| 617 | totnbytesproc += 2*paq1.DataSize();
|
---|
| 618 | } // Fin de boucle sur les paquets d'une zone
|
---|
[3646] | 619 | memgr1.FreeMemZone(mid1, MemZS_ProcB);
|
---|
| 620 | memgr2.FreeMemZone(mid2, MemZS_ProcB);
|
---|
| 621 |
|
---|
[3645] | 622 | if ((nzm >= nmean_) || ((kmz==(nmax_-1))&&(nzm>1))) {
|
---|
| 623 | visiV13 /= complex<r_4>((r_4)nzm, 0.);
|
---|
| 624 | visiV14 /= complex<r_4>((r_4)nzm, 0.);
|
---|
| 625 | visiV23 /= complex<r_4>((r_4)nzm, 0.);
|
---|
| 626 | visiV24 /= complex<r_4>((r_4)nzm, 0.);
|
---|
| 627 | visiV13.Info()["NPaqMoy"] = nzm;
|
---|
| 628 | visiV14.Info()["NPaqMoy"] = nzm;
|
---|
| 629 | visiV23.Info()["NPaqMoy"] = nzm;
|
---|
| 630 | visiV24.Info()["NPaqMoy"] = nzm;
|
---|
[3647] | 631 | visiV13.Info()["EndFC"] = curfc;
|
---|
| 632 | visiV14.Info()["EndFC"] = curfc;
|
---|
| 633 | visiV23.Info()["EndFC"] = curfc;
|
---|
| 634 | visiV24.Info()["EndFC"] = curfc;
|
---|
| 635 | visiV13.Info()["EndTT"] = curtt;
|
---|
| 636 | visiV14.Info()["EndTT"] = curtt;
|
---|
| 637 | visiV23.Info()["EndTT"] = curtt;
|
---|
| 638 | visiV24.Info()["EndTT"] = curtt;
|
---|
[3645] | 639 | char fname[512];
|
---|
| 640 | {
|
---|
| 641 | sprintf(fname,"%s_%d.ppf",path_.c_str(),(int)ifile);
|
---|
| 642 | POutPersist po(fname);
|
---|
| 643 | po << PPFNameTag("visiV13") << visiV13;
|
---|
| 644 | po << PPFNameTag("visiV14") << visiV14;
|
---|
| 645 | po << PPFNameTag("visiV23") << visiV23;
|
---|
| 646 | po << PPFNameTag("visiV24") << visiV24;
|
---|
| 647 | }
|
---|
| 648 | visiV13 = complex<r_4>(0., 0.);
|
---|
| 649 | visiV14 = complex<r_4>(0., 0.);
|
---|
| 650 | visiV23 = complex<r_4>(0., 0.);
|
---|
| 651 | visiV24 = complex<r_4>(0., 0.);
|
---|
[3646] | 652 | nzm = 0; ifile++;
|
---|
[3645] | 653 | // ts.SetNow();
|
---|
| 654 | // filog << ts << " : proc file " << fname << endl;
|
---|
| 655 | cout << " BRProcBRaw4C::run() created file " << fname << endl;
|
---|
| 656 | }
|
---|
| 657 | double okfrac = (nokpaq>1)?((double)noksfc/(double)nokpaq*100.):0.;
|
---|
[3646] | 658 | cout << "BRProcBRaw4C ["<<kmz<<"] NOKPaq=" << nokpaq << " NSameFC=" << noksfc
|
---|
[3645] | 659 | << " (" << okfrac << " %)" << endl;
|
---|
| 660 | totnokpaq += nokpaq;
|
---|
| 661 | totnoksfc += noksfc;
|
---|
| 662 | } // Fin de boucle sur les zones a traiter
|
---|
| 663 | cout << " ------------------ BRProcBRaw4C::run() END ----------------- " << endl;
|
---|
[3647] | 664 | {
|
---|
| 665 | dt.Info()["FirstTT1"]=firsttt;
|
---|
| 666 | dt.Info()["FirstTT2"]=firsttt2;
|
---|
| 667 | cout << dt;
|
---|
| 668 | char fname[512];
|
---|
| 669 | sprintf(fname,"%s_fctt.ppf",path_.c_str());
|
---|
| 670 | POutPersist po(fname);
|
---|
| 671 | po << PPFNameTag("ttfc") << dt;
|
---|
| 672 | cout << " BRProcBRaw4C::run() created TimeTag/FrameCounter file " << fname << endl;
|
---|
| 673 | }
|
---|
[3645] | 674 | ts.SetNow();
|
---|
| 675 | tm.SplitQ();
|
---|
| 676 | cout << " TotalProc= " << totnbytesproc/(1024*1024) << " MBytes, rate= "
|
---|
| 677 | << (double)(totnbytesproc)/1024./tm.PartialElapsedTimems() << " MB/s" << endl;
|
---|
| 678 | double totokfrac = (totnokpaq>1)?((double)totnoksfc/(double)totnokpaq*100.):0.;
|
---|
| 679 | cout << " NOkPaq1,2=" << totnokpaq << " /TotNPaq=" << totnpaq << " TotNSameFC="
|
---|
| 680 | << totnoksfc << " (" << totokfrac << " %)" << endl;
|
---|
| 681 | // cout << pcheck1;
|
---|
| 682 | // cout << pcheck2;
|
---|
| 683 | cout << " BRProcBRaw4C::run()/Timing: \n";
|
---|
| 684 | tm.Print();
|
---|
| 685 | cout << " ---------------------------------------------------------- " << endl;
|
---|
| 686 | }
|
---|
| 687 | catch (PException& exc) {
|
---|
| 688 | cout << " BRProcBRaw4C::run()/catched PException " << exc.Msg() << endl;
|
---|
| 689 | setRC(3);
|
---|
| 690 | return;
|
---|
| 691 | }
|
---|
| 692 | catch(...) {
|
---|
| 693 | cout << " BRProcBRaw4C::run()/catched unknown ... exception " << endl;
|
---|
| 694 | setRC(4);
|
---|
| 695 | return;
|
---|
| 696 | }
|
---|
| 697 | setRC(0);
|
---|
| 698 | return;
|
---|
| 699 | }
|
---|
| 700 |
|
---|
| 701 |
|
---|