[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;
|
---|
[3635] | 153 | for (uint_4 kmz=0; kmz<nmax_; kmz++) {
|
---|
| 154 | if (stop_) break;
|
---|
| 155 | int mid = memgr.FindMemZoneId(MemZA_ProcA);
|
---|
| 156 | Byte* buff = memgr.GetMemZone(mid);
|
---|
| 157 | if (buff == NULL) {
|
---|
[3640] | 158 | cout << " BRProcARaw2C::run()/ERROR memgr.GetMemZone(" << mid << ") -> NULL" << endl;
|
---|
| 159 | break;
|
---|
[3635] | 160 | }
|
---|
| 161 | Byte* procbuff = memgr.GetProcMemZone(mid);
|
---|
| 162 | if (procbuff == NULL) {
|
---|
[3640] | 163 | cout << " BRProcARaw2C::run()/ERROR memgr.GetProcMemZone(" << mid << ") -> NULL" << endl;
|
---|
| 164 | break;
|
---|
[3635] | 165 | }
|
---|
[3647] | 166 | //---- DELETE nmnt=0; ms1=ms2=ms12=ms12re=ms12im=ms12phi=0.;
|
---|
[3645] | 167 | for(uint_4 i=0; i<memgr.NbPaquets(); i++) {
|
---|
[3640] | 168 | BRPaquet paq(NULL, buff+i*paqsz, paqsz);
|
---|
| 169 | if (!pcheck.Check(paq)) continue; // on ne traite que les paquets OK
|
---|
[3647] | 170 | if (fgfirst) { firsttt=paq.TimeTag(); fgfirst=false; }
|
---|
| 171 | curfc=paq.FrameCounter();
|
---|
| 172 | curtt=paq.TimeTag()-firsttt;
|
---|
[3635] | 173 | // Traitement voie 1
|
---|
[3652] | 174 | if (fghist_) {
|
---|
| 175 | for(sa_size_t j=0; j<vx.Size(); j++) {
|
---|
| 176 | r_4 vts=(r_4)(*(paq.Data1()+j));
|
---|
| 177 | h1.Add((r_8)vts);
|
---|
| 178 | vx(j) = vts-127.5;
|
---|
| 179 | }
|
---|
| 180 | }
|
---|
| 181 | else {
|
---|
| 182 | for(sa_size_t j=0; j<vx.Size(); j++)
|
---|
| 183 | vx(j) = (r_4)(*(paq.Data1()+j))-127.5;
|
---|
| 184 | }
|
---|
[3640] | 185 | // fftwf_complex* coeff1 = (fftwf_complex*)(procbuff+i*procpaqsz);
|
---|
[3646] | 186 | fftwf_execute(plan1);
|
---|
| 187 | // complex<r_4>* zp1 = (complex<r_4>*)(vx.Data());
|
---|
[3640] | 188 | // ffts.FFTForward(vx, cfour1);
|
---|
[3635] | 189 | for(sa_size_t j=0; j<spectreV1.Size(); j++)
|
---|
[3640] | 190 | spectreV1(j) += Zmod2(cfour1(j));
|
---|
| 191 | memcpy(procbuff+i*procpaqsz, cfour1.Data(), sizeof(complex<r_4>)*cfour1.Size());
|
---|
[3656] | 192 | if (fgtimfreq) { // Remplissage tableau temps-frequence
|
---|
| 193 | for(sa_size_t c=1; c<timfreqV1.NCols(); c++) {
|
---|
| 194 | for(sa_size_t j=c*nfsmap_; j<(c+1)*nfsmap_; j++)
|
---|
| 195 | timfreqV1(nzm, c) += Zmod2(cfour1(j));
|
---|
| 196 | }
|
---|
| 197 | }
|
---|
[3635] | 198 | // Traitement voie 2
|
---|
[3652] | 199 | if (fghist_) {
|
---|
| 200 | for(sa_size_t j=0; j<vx.Size(); j++) {
|
---|
| 201 | r_4 vts=(r_4)(*(paq.Data2()+j));
|
---|
| 202 | h2.Add((r_8)vts);
|
---|
| 203 | vx(j) = vts-127.5;
|
---|
| 204 | }
|
---|
| 205 | }
|
---|
| 206 | else {
|
---|
| 207 | for(sa_size_t j=0; j<vx.Size(); j++)
|
---|
| 208 | vx(j) = (r_4)(*(paq.Data2()+j))-127.5;
|
---|
| 209 | }
|
---|
[3646] | 210 | fftwf_execute(plan2);
|
---|
[3635] | 211 | for(sa_size_t j=0; j<spectreV2.Size(); j++)
|
---|
[3640] | 212 | spectreV2(j) += Zmod2(cfour2(j)); // Zmod2(zp2[j]);
|
---|
| 213 | memcpy(procbuff+i*procpaqsz+procpaqsz/2, cfour2.Data(), sizeof(complex<r_4>)*cfour2.Size());
|
---|
[3656] | 214 | if (fgtimfreq) { // Remplissage tableau temps-frequence
|
---|
| 215 | for(sa_size_t c=1; c<timfreqV2.NCols(); c++) {
|
---|
| 216 | for(sa_size_t j=c*nfsmap_; j<(c+1)*nfsmap_; j++)
|
---|
| 217 | timfreqV2(nzm,c) += Zmod2(cfour2(j));
|
---|
| 218 | }
|
---|
| 219 | }
|
---|
[3635] | 220 |
|
---|
| 221 | // Calcul correlation (visibilite V1 * V2)
|
---|
[3640] | 222 | for(sa_size_t j=0; j<visiV12.Size(); j++)
|
---|
| 223 | visiV12(j)+=cfour1(j)*conj(cfour2(j));
|
---|
| 224 | // for(sa_size_t j=0; j<visiV12.Size(); j++) visiV12(j)+=zp1[j]*zp2[j];
|
---|
[3647] | 225 | if (nzm==0) {
|
---|
| 226 | spectreV1.Info()["StartFC"] = curfc;
|
---|
| 227 | spectreV2.Info()["StartFC"] = curfc;
|
---|
| 228 | visiV12.Info()["StartFC"] = curfc;
|
---|
| 229 | spectreV1.Info()["StartTT"] = curtt;
|
---|
| 230 | spectreV2.Info()["StartTT"] = curtt;
|
---|
| 231 | visiV12.Info()["StartTT"] = curtt;
|
---|
| 232 | }
|
---|
[3640] | 233 | nzm++;
|
---|
[3647] | 234 | /*----DELETE
|
---|
[3646] | 235 | if (nmnt==0) { xnt[0]=paq.FrameCounter(); xnt[1]=paq.TimeTag(); }
|
---|
| 236 | for(sa_size_t j=2700; j<2800; j++) {
|
---|
| 237 | ms1 += Zmod2(cfour1(j)); ms2 += Zmod2(cfour2(j));
|
---|
| 238 | complex<r_4> zvis = cfour1(j)*conj(cfour2(j));
|
---|
| 239 | ms12 += Zmod2(zvis); ms12re += zvis.real(); ms12im += zvis.imag();
|
---|
| 240 | ms12phi+= atan2(zvis.imag(),zvis.real());
|
---|
| 241 | }
|
---|
| 242 | nmnt++;
|
---|
[3647] | 243 | ----*/
|
---|
[3640] | 244 | totnbytesproc += paq.DataSize();
|
---|
| 245 | totnbytesout += (2*sizeof(complex<r_4>)*cfour1.Size());
|
---|
[3635] | 246 |
|
---|
[3640] | 247 | } // Fin de boucle sur les paquets d'une zone
|
---|
[3647] | 248 |
|
---|
| 249 | /*---- DELETE
|
---|
[3646] | 250 | if (nmnt>0) {
|
---|
| 251 | double fnorm = (double)nmnt*(2800-2700);
|
---|
| 252 | xnt[2] = ms1 /= fnorm;
|
---|
| 253 | xnt[3] = ms2 /= fnorm;
|
---|
| 254 | xnt[4] = ms12 /= fnorm;
|
---|
| 255 | xnt[5] = ms12re /= fnorm;
|
---|
| 256 | xnt[6] = ms12im /= fnorm;
|
---|
| 257 | xnt[7] = ms12phi /= fnorm;
|
---|
| 258 | nt.Fill(xnt);
|
---|
| 259 | }
|
---|
[3647] | 260 | ----*/
|
---|
[3640] | 261 | if ((nzm >= nmean_) || ((kmz==(nmax_-1))&&(nzm>1))) {
|
---|
[3635] | 262 | spectreV1 /= (r_4)(nzm);
|
---|
| 263 | spectreV2 /= (r_4)(nzm);
|
---|
| 264 |
|
---|
[3655] | 265 | // pour le calcul des moyennes et sigmas de ces spectres
|
---|
| 266 | moyspecV1 += spectreV1;
|
---|
| 267 | moyspecV2 += spectreV2;
|
---|
| 268 | sigspecV1 += (spectreV1 && spectreV1);
|
---|
| 269 | sigspecV2 += (spectreV2 && spectreV2);
|
---|
| 270 | nmoyspec++;
|
---|
| 271 |
|
---|
[3635] | 272 | visiV12 /= complex<r_4>((r_4)nzm, 0.);
|
---|
| 273 |
|
---|
| 274 | spectreV1.Info()["NPaqMoy"] = nzm;
|
---|
| 275 | spectreV2.Info()["NPaqMoy"] = nzm;
|
---|
| 276 | visiV12.Info()["NPaqMoy"] = nzm;
|
---|
[3647] | 277 | spectreV1.Info()["EndFC"] = curfc;
|
---|
| 278 | spectreV2.Info()["EndFC"] = curfc;
|
---|
| 279 | visiV12.Info()["EndFC"] = curfc;
|
---|
| 280 | spectreV1.Info()["EndTT"] = curtt;
|
---|
| 281 | spectreV2.Info()["EndTT"] = curtt;
|
---|
| 282 | visiV12.Info()["EndTT"] = curtt;
|
---|
[3652] | 283 | {
|
---|
[3635] | 284 | sprintf(fname,"%s_%d.ppf",path_.c_str(),(int)ifile);
|
---|
| 285 | POutPersist po(fname);
|
---|
[3645] | 286 | string tag1="specV1";
|
---|
| 287 | string tag2="specV2";
|
---|
| 288 | string tag12="visiV12";
|
---|
[3652] | 289 | string tagh1="tshV1";
|
---|
| 290 | string tagh2="tshV2";
|
---|
[3656] | 291 | string tagtf1="timfreqV1";
|
---|
| 292 | string tagtf2="timfreqV2";
|
---|
[3645] | 293 | if (card_==2) {
|
---|
| 294 | tag1 = "specV3";
|
---|
| 295 | tag2 = "specV4";
|
---|
[3652] | 296 | tagh1 = "tshV1";
|
---|
| 297 | tagh2 = "tshV2";
|
---|
[3645] | 298 | tag12="visiV34";
|
---|
[3656] | 299 | tagtf1="timfreqV3";
|
---|
| 300 | tagtf2="timfreqV4";
|
---|
[3645] | 301 | }
|
---|
| 302 | po << PPFNameTag(tag1) << spectreV1;
|
---|
| 303 | po << PPFNameTag(tag2) << spectreV2;
|
---|
| 304 | po << PPFNameTag(tag12) << visiV12;
|
---|
[3652] | 305 | if (fghist_) {
|
---|
| 306 | po << PPFNameTag(tagh1) << h1;
|
---|
| 307 | po << PPFNameTag(tagh2) << h2;
|
---|
| 308 | }
|
---|
[3656] | 309 | if (fgtimfreq) {
|
---|
| 310 | timfreqV1 /= (r_4)nzm;
|
---|
| 311 | timfreqV2 /= (r_4)nzm;
|
---|
| 312 | po << PPFNameTag(tagtf1) << timfreqV1;
|
---|
| 313 | po << PPFNameTag(tagtf2) << timfreqV2;
|
---|
| 314 | }
|
---|
[3652] | 315 | }
|
---|
[3635] | 316 | spectreV1 = (r_4)(0.);
|
---|
| 317 | spectreV2 = (r_4)(0.);
|
---|
| 318 | visiV12 = complex<r_4>(0., 0.);
|
---|
[3652] | 319 | if (fghist_) {
|
---|
| 320 | h1.Zero();
|
---|
| 321 | h2.Zero();
|
---|
| 322 | }
|
---|
[3656] | 323 | if (fgtimfreq) {
|
---|
| 324 | timfreqV1 = (r_4)(0.);
|
---|
| 325 | timfreqV2 = (r_4)(0.);
|
---|
| 326 | }
|
---|
[3635] | 327 | nzm = 0; ifile++;
|
---|
| 328 | // ts.SetNow();
|
---|
| 329 | // filog << ts << " : proc file " << fname << endl;
|
---|
[3645] | 330 | cout << " BRProcARaw2C::run() created file " << fname << card2name_(card_) << endl;
|
---|
[3640] | 331 | }
|
---|
[3635] | 332 |
|
---|
| 333 | memgr.FreeMemZone(mid, MemZS_ProcA);
|
---|
[3640] | 334 | } // Fin de boucle sur les zones a traiter
|
---|
[3645] | 335 | cout << " ------------ BRProcARaw2C::run() END " << card2name_(card_)
|
---|
| 336 | << " ------------ " << endl;
|
---|
[3647] | 337 | /*---- DELETE
|
---|
| 338 | {
|
---|
| 339 | nt.Info()["FirstTT"]=firsttt;
|
---|
[3646] | 340 | cout << nt;
|
---|
| 341 | sprintf(fname,"%s_nt.ppf",path_.c_str());
|
---|
| 342 | POutPersist po(fname);
|
---|
| 343 | po << PPFNameTag("ntv12") << nt;
|
---|
| 344 | cout << " BRProcARaw2C::run() created NTuple file " << fname << card2name_(card_) << endl;
|
---|
[3647] | 345 | }
|
---|
| 346 | ---- */
|
---|
[3655] | 347 | if (nmoyspec>0) { // Calcul des moyennes et sigmas des spectres
|
---|
| 348 | r_4 fnms = nmoyspec;
|
---|
| 349 | moyspecV1 /= fnms;
|
---|
| 350 | moyspecV2 /= fnms;
|
---|
| 351 | sigspecV1 /= fnms;
|
---|
| 352 | sigspecV2 /= fnms;
|
---|
| 353 | sigspecV1 -= (moyspecV1 && moyspecV1);
|
---|
| 354 | sigspecV2 -= (moyspecV2 && moyspecV2);
|
---|
| 355 | sigspecV1 = Sqrt(sigspecV1);
|
---|
| 356 | sigspecV2 = Sqrt(sigspecV2);
|
---|
| 357 | TVector<r_4> rsbV1, rsbV2; // Rapport signal/bruit
|
---|
| 358 | moyspecV1.DivElt(sigspecV1, rsbV1, false, true);
|
---|
| 359 | moyspecV2.DivElt(sigspecV2, rsbV2, false, true);
|
---|
| 360 | sprintf(fname,"%s_ms.ppf",path_.c_str());
|
---|
| 361 | POutPersist po(fname);
|
---|
| 362 | po << PPFNameTag("moyspecV1") << moyspecV1;
|
---|
| 363 | po << PPFNameTag("moyspecV2") << moyspecV2;
|
---|
| 364 | po << PPFNameTag("sigspecV1") << sigspecV1;
|
---|
| 365 | po << PPFNameTag("sigspecV2") << sigspecV2;
|
---|
| 366 | po << PPFNameTag("rsbV1") << rsbV1;
|
---|
| 367 | po << PPFNameTag("rsbV2") << rsbV2;
|
---|
| 368 | cout << " BRProcARaw2C::run() created moysigspec file " << fname << card2name_(card_) << endl;
|
---|
| 369 | }
|
---|
| 370 |
|
---|
[3640] | 371 | ts.SetNow();
|
---|
| 372 | tm.SplitQ();
|
---|
| 373 | cout << " TotalProc= " << totnbytesproc/(1024*1024) << " MBytes, rate= "
|
---|
| 374 | << (double)(totnbytesproc)/1024./tm.PartialElapsedTimems() << " MB/s"
|
---|
| 375 | << " ProcDataOut=" << totnbytesout/(1024*1024) << " MB" << endl;
|
---|
| 376 | cout << pcheck;
|
---|
[3645] | 377 | cout << " BRProcARaw2C::run()/Timing: " << card2name_(card_) << endl;
|
---|
[3640] | 378 | tm.Print();
|
---|
| 379 | cout << " ---------------------------------------------------------- " << endl;
|
---|
| 380 |
|
---|
[3635] | 381 | }
|
---|
| 382 | catch (PException& exc) {
|
---|
| 383 | cout << " BRProcARaw2C::run()/catched PException " << exc.Msg() << endl;
|
---|
| 384 | setRC(3);
|
---|
| 385 | return;
|
---|
| 386 | }
|
---|
| 387 | catch(...) {
|
---|
| 388 | cout << " BRProcARaw2C::run()/catched unknown ... exception " << endl;
|
---|
| 389 | setRC(4);
|
---|
| 390 | return;
|
---|
| 391 | }
|
---|
| 392 | setRC(0);
|
---|
| 393 | return;
|
---|
| 394 | }
|
---|
| 395 |
|
---|
[3645] | 396 | //---------------------------------------------------------------------
|
---|
| 397 | // Classe thread de traitement 2 x 2 voies/frames (Apres BRProcARaw2C)
|
---|
| 398 | //---------------------------------------------------------------------
|
---|
[3635] | 399 |
|
---|
[3645] | 400 | /* --Methode-- */
|
---|
| 401 | BRProcBRaw4C::BRProcBRaw4C(RAcqMemZoneMgr& mem1, RAcqMemZoneMgr& mem2,
|
---|
| 402 | string& path, uint_4 nmean, uint_4 nmax, bool fgnotrl)
|
---|
| 403 | : memgr1(mem1), memgr2(mem2)
|
---|
| 404 | {
|
---|
| 405 | nmax_ = nmax;
|
---|
| 406 | nmean_ = nmean;
|
---|
| 407 | stop_ = false;
|
---|
| 408 | path_ = path;
|
---|
| 409 | fgnotrl_ = fgnotrl;
|
---|
| 410 | }
|
---|
[3635] | 411 |
|
---|
[3645] | 412 | /* --Methode-- */
|
---|
| 413 | void BRProcBRaw4C::Stop()
|
---|
| 414 | {
|
---|
| 415 | stop_=true;
|
---|
| 416 | // cout <<" BRProcBRaw4C::Stop ... > STOP " << endl;
|
---|
| 417 | }
|
---|
[3635] | 418 |
|
---|
[3645] | 419 |
|
---|
| 420 | /* --Methode-- */
|
---|
| 421 | void BRProcBRaw4C::run()
|
---|
| 422 | {
|
---|
| 423 | setRC(1);
|
---|
| 424 | try {
|
---|
| 425 | Timer tm("BRProcBRaw4C", false);
|
---|
| 426 | TimeStamp ts;
|
---|
[3646] | 427 | BRPaqChecker pcheck1(!fgnotrl_); // Verification/comptage des paquets
|
---|
| 428 | BRPaqChecker pcheck2(!fgnotrl_); // Verification/comptage des paquets
|
---|
[3645] | 429 |
|
---|
| 430 | size_t totnbytesout = 0;
|
---|
| 431 | size_t totnbytesproc = 0;
|
---|
| 432 |
|
---|
| 433 | cout << " BRProcBRaw4C::run() - Starting " << ts << " NMaxMemZones=" << nmax_
|
---|
| 434 | << " NMean=" << nmean_ << endl;
|
---|
| 435 | cout << " BRProcBRaw4C::run()... - Output Data Path: " << path_ << endl;
|
---|
| 436 |
|
---|
| 437 | uint_4 paqsz = memgr1.PaqSize();
|
---|
| 438 | uint_4 procpaqsz = memgr1.ProcPaqSize();
|
---|
| 439 | if ((paqsz != memgr2.PaqSize())||(procpaqsz!= memgr2.ProcPaqSize())) {
|
---|
| 440 | cout << "BRProcBRaw4C::run()/ERROR : different paquet size -> stop \n ...(PaqSz1="
|
---|
| 441 | << paqsz << " Sz2=" << memgr2.PaqSize() << " ProcPaqSz1="
|
---|
| 442 | << procpaqsz << " Sz2=" << memgr2.ProcPaqSize() << " )" << endl;
|
---|
| 443 | setRC(9);
|
---|
| 444 | return;
|
---|
| 445 | }
|
---|
| 446 |
|
---|
| 447 | TVector< complex<r_4> > cfour; // composant TF
|
---|
[3648] | 448 | BRPaquet pq(NULL, NULL, paqsz);
|
---|
[3646] | 449 | /*
|
---|
[3645] | 450 | TVector<r_4> vx(pq.DataSize()/2);
|
---|
| 451 | vx = (r_4)(0.);
|
---|
| 452 | FFTPackServer ffts;
|
---|
| 453 | ffts.FFTForward(vx, cfour);
|
---|
| 454 |
|
---|
| 455 | TVector< complex<r_4> > visiV13( cfour.Size() );
|
---|
| 456 | TVector< complex<r_4> > visiV14( cfour.Size() );
|
---|
| 457 | TVector< complex<r_4> > visiV23( cfour.Size() );
|
---|
| 458 | TVector< complex<r_4> > visiV24( cfour.Size() );
|
---|
[3646] | 459 | */
|
---|
[3648] | 460 | int szfour = pq.DataSize()/2/2+1;
|
---|
| 461 | // int szfour = (paqsz-40)/2+1;
|
---|
[3646] | 462 | TVector< complex<r_4> > visiV13( szfour );
|
---|
| 463 | TVector< complex<r_4> > visiV14( szfour );
|
---|
| 464 | TVector< complex<r_4> > visiV23( szfour );
|
---|
| 465 | TVector< complex<r_4> > visiV24( szfour );
|
---|
| 466 | // cout << " *DBG*AAAAA ---- Vectors OK" << endl;
|
---|
| 467 | cout << " *DBG*BRProcBRaw4C PaqSz=" << paqsz << " ProcPaqSize=" << procpaqsz
|
---|
| 468 | << " procpaqsz/2=" << procpaqsz/2 << " cfour.Size()=" << szfour
|
---|
| 469 | << " *8=" << szfour*8 << endl;
|
---|
[3645] | 470 |
|
---|
[3647] | 471 | DataTable dt;
|
---|
| 472 | dt.AddLongColumn("fc1");
|
---|
[3651] | 473 | dt.AddLongColumn("tt1");
|
---|
[3647] | 474 | dt.AddLongColumn("fc2");
|
---|
| 475 | dt.AddLongColumn("tt2");
|
---|
| 476 | DataTableRow dtr = dt.EmptyRow();
|
---|
| 477 |
|
---|
[3645] | 478 | uint_4 nzm = 0;
|
---|
| 479 | uint_4 totnoksfc = 0;
|
---|
| 480 | uint_4 totnokpaq = 0;
|
---|
| 481 | uint_4 totnpaq = 0;
|
---|
| 482 | uint_4 ifile = 0;
|
---|
[3647] | 483 |
|
---|
| 484 | uint_4 curfc=0;
|
---|
| 485 | uint_8 curtt=0;
|
---|
| 486 | uint_4 curfc2=0;
|
---|
| 487 | uint_8 curtt2=0;
|
---|
| 488 | uint_8 firsttt=0;
|
---|
| 489 | uint_8 firsttt2=0;
|
---|
| 490 | bool fgfirst=true;
|
---|
[3645] | 491 | for (uint_4 kmz=0; kmz<nmax_; kmz++) {
|
---|
| 492 | uint_4 noksfc = 0;
|
---|
| 493 | uint_4 nokpaq = 0;
|
---|
| 494 | if (stop_) break;
|
---|
[3646] | 495 | // cout << " *DBG*BBBBB" << kmz << endl;
|
---|
| 496 |
|
---|
[3645] | 497 | int mid1 = memgr1.FindMemZoneId(MemZA_ProcB);
|
---|
| 498 | Byte* buff1 = memgr1.GetMemZone(mid1);
|
---|
| 499 | if (buff1 == NULL) {
|
---|
| 500 | cout << " BRProcBRaw4C::run()/ERROR memgr.GetMemZone(" << mid1 << ") -> NULL" << endl;
|
---|
| 501 | break;
|
---|
| 502 | }
|
---|
| 503 | Byte* procbuff1 = memgr1.GetProcMemZone(mid1);
|
---|
| 504 | if (procbuff1 == NULL) {
|
---|
| 505 | cout << " BRProcBRaw4C::run()/ERROR memgr.GetProcMemZone(" << mid1 << ") -> NULL" << endl;
|
---|
| 506 | break;
|
---|
| 507 | }
|
---|
| 508 | int mid2 = memgr2.FindMemZoneId(MemZA_ProcB);
|
---|
| 509 | Byte* buff2 = memgr2.GetMemZone(mid2);
|
---|
| 510 | if (buff1 == NULL) {
|
---|
| 511 | cout << " BRProcBRaw4C::run()/ERROR memgr.GetMemZone(" << mid2 << ") -> NULL" << endl;
|
---|
| 512 | break;
|
---|
| 513 | }
|
---|
| 514 | Byte* procbuff2 = memgr2.GetProcMemZone(mid2);
|
---|
| 515 | if (procbuff2 == NULL) {
|
---|
| 516 | cout << " BRProcBRaw4C::run()/ERROR memgr.GetProcMemZone(" << mid2 << ") -> NULL" << endl;
|
---|
| 517 | break;
|
---|
| 518 | }
|
---|
| 519 | uint_4 i1,i2;
|
---|
| 520 | i1=i2=0;
|
---|
[3646] | 521 | // cout << " *DBG*CCCCCC " << kmz << " memgr1.NbPaquets() =" << memgr1.NbPaquets() << endl;
|
---|
[3645] | 522 | while((i1<memgr1.NbPaquets())&&(i2<memgr2.NbPaquets())) {
|
---|
| 523 | BRPaquet paq1(NULL, buff1+i1*paqsz, paqsz);
|
---|
| 524 | BRPaquet paq2(NULL, buff2+i2*paqsz, paqsz);
|
---|
| 525 | totnpaq++;
|
---|
| 526 | // cout << " DBG["<<kmz<<"] i1,i2=" << i1 <<","<<i2<<" FC1,FC2=" <<paq1.FrameCounter()
|
---|
| 527 | //<<","<<paq2.FrameCounter()<<endl;
|
---|
| 528 | // on ne traite que les paquets OK
|
---|
| 529 | if (!pcheck1.Check(paq1)) { i1++; continue; }
|
---|
| 530 | if (!pcheck2.Check(paq2)) { i2++; continue; }
|
---|
| 531 | nokpaq++;
|
---|
| 532 | if (paq1.FrameCounter()<paq2.FrameCounter()) { i1++; continue; }
|
---|
| 533 | if (paq2.FrameCounter()<paq1.FrameCounter()) { i2++; continue; }
|
---|
| 534 | // cout << " DBG["<<kmz<<"]OKOK i1,i2=" << i1 <<","<<i2<<" FC1,FC2=" <<paq1.FrameCounter()
|
---|
| 535 | // <<","<<paq2.FrameCounter()<<endl;
|
---|
| 536 |
|
---|
[3646] | 537 | if ((i1>=memgr1.NbPaquets())||(i2>=memgr1.NbPaquets())) {
|
---|
| 538 | cout << " *BUG*BUG i1=" << i1 << " i2=" << i2 << endl;
|
---|
| 539 | break;
|
---|
| 540 | }
|
---|
[3645] | 541 | // Les deux framecounters sont identiques ...
|
---|
| 542 | noksfc++;
|
---|
[3647] | 543 | curfc=paq1.FrameCounter();
|
---|
| 544 | curfc2=paq2.FrameCounter();
|
---|
| 545 | if (fgfirst) {
|
---|
[3651] | 546 | firsttt=paq1.TimeTag(); firsttt2=paq2.TimeTag();
|
---|
[3647] | 547 | cout << " BRProcBRaw4C()/Info First FC="<<curfc<<" , "<<curfc2<<" -> TT="
|
---|
| 548 | << firsttt<<" , "<<firsttt2 <<endl;
|
---|
| 549 | fgfirst=false;
|
---|
| 550 | }
|
---|
| 551 | curtt=paq1.TimeTag()-firsttt;
|
---|
| 552 | curtt2=paq2.TimeTag()-firsttt2;
|
---|
| 553 | dtr[0]=curfc; dtr[1]=curtt;
|
---|
| 554 | dtr[2]=curfc2; dtr[3]=curtt2;
|
---|
| 555 | dt.AddRow(dtr);
|
---|
| 556 |
|
---|
[3645] | 557 | complex<r_4>* zp1 = (complex<r_4>*)(procbuff1+i1*procpaqsz);
|
---|
| 558 | complex<r_4>* zp2 = (complex<r_4>*)(procbuff1+i1*procpaqsz+procpaqsz/2);
|
---|
| 559 | complex<r_4>* zp3 = (complex<r_4>*)(procbuff2+i2*procpaqsz);
|
---|
| 560 | complex<r_4>* zp4 = (complex<r_4>*)(procbuff2+i2*procpaqsz+procpaqsz/2);
|
---|
| 561 | for(sa_size_t j=0; j<visiV13.Size(); j++) {
|
---|
| 562 | visiV13(j)+=zp1[j]*conj(zp3[j]);
|
---|
| 563 | visiV14(j)+=zp1[j]*conj(zp4[j]);
|
---|
| 564 | visiV23(j)+=zp2[j]*conj(zp3[j]);
|
---|
| 565 | visiV24(j)+=zp2[j]*conj(zp4[j]);
|
---|
| 566 | }
|
---|
[3647] | 567 | if (nzm==0) {
|
---|
| 568 | visiV13.Info()["StartFC"] = curfc;
|
---|
| 569 | visiV14.Info()["StartFC"] = curfc;
|
---|
| 570 | visiV23.Info()["StartFC"] = curfc;
|
---|
| 571 | visiV24.Info()["StartFC"] = curfc;
|
---|
| 572 | visiV13.Info()["StartTT"] = curtt;
|
---|
| 573 | visiV14.Info()["StartTT"] = curtt;
|
---|
| 574 | visiV23.Info()["StartTT"] = curtt;
|
---|
| 575 | visiV24.Info()["StartTT"] = curtt;
|
---|
| 576 | }
|
---|
[3645] | 577 | nzm++; i1++; i2++;
|
---|
| 578 | totnbytesproc += 2*paq1.DataSize();
|
---|
| 579 | } // Fin de boucle sur les paquets d'une zone
|
---|
[3646] | 580 | memgr1.FreeMemZone(mid1, MemZS_ProcB);
|
---|
| 581 | memgr2.FreeMemZone(mid2, MemZS_ProcB);
|
---|
| 582 |
|
---|
[3645] | 583 | if ((nzm >= nmean_) || ((kmz==(nmax_-1))&&(nzm>1))) {
|
---|
| 584 | visiV13 /= complex<r_4>((r_4)nzm, 0.);
|
---|
| 585 | visiV14 /= complex<r_4>((r_4)nzm, 0.);
|
---|
| 586 | visiV23 /= complex<r_4>((r_4)nzm, 0.);
|
---|
| 587 | visiV24 /= complex<r_4>((r_4)nzm, 0.);
|
---|
| 588 | visiV13.Info()["NPaqMoy"] = nzm;
|
---|
| 589 | visiV14.Info()["NPaqMoy"] = nzm;
|
---|
| 590 | visiV23.Info()["NPaqMoy"] = nzm;
|
---|
| 591 | visiV24.Info()["NPaqMoy"] = nzm;
|
---|
[3647] | 592 | visiV13.Info()["EndFC"] = curfc;
|
---|
| 593 | visiV14.Info()["EndFC"] = curfc;
|
---|
| 594 | visiV23.Info()["EndFC"] = curfc;
|
---|
| 595 | visiV24.Info()["EndFC"] = curfc;
|
---|
| 596 | visiV13.Info()["EndTT"] = curtt;
|
---|
| 597 | visiV14.Info()["EndTT"] = curtt;
|
---|
| 598 | visiV23.Info()["EndTT"] = curtt;
|
---|
| 599 | visiV24.Info()["EndTT"] = curtt;
|
---|
[3645] | 600 | char fname[512];
|
---|
| 601 | {
|
---|
| 602 | sprintf(fname,"%s_%d.ppf",path_.c_str(),(int)ifile);
|
---|
| 603 | POutPersist po(fname);
|
---|
| 604 | po << PPFNameTag("visiV13") << visiV13;
|
---|
| 605 | po << PPFNameTag("visiV14") << visiV14;
|
---|
| 606 | po << PPFNameTag("visiV23") << visiV23;
|
---|
| 607 | po << PPFNameTag("visiV24") << visiV24;
|
---|
| 608 | }
|
---|
| 609 | visiV13 = complex<r_4>(0., 0.);
|
---|
| 610 | visiV14 = complex<r_4>(0., 0.);
|
---|
| 611 | visiV23 = complex<r_4>(0., 0.);
|
---|
| 612 | visiV24 = complex<r_4>(0., 0.);
|
---|
[3646] | 613 | nzm = 0; ifile++;
|
---|
[3645] | 614 | // ts.SetNow();
|
---|
| 615 | // filog << ts << " : proc file " << fname << endl;
|
---|
| 616 | cout << " BRProcBRaw4C::run() created file " << fname << endl;
|
---|
| 617 | }
|
---|
| 618 | double okfrac = (nokpaq>1)?((double)noksfc/(double)nokpaq*100.):0.;
|
---|
[3646] | 619 | cout << "BRProcBRaw4C ["<<kmz<<"] NOKPaq=" << nokpaq << " NSameFC=" << noksfc
|
---|
[3645] | 620 | << " (" << okfrac << " %)" << endl;
|
---|
| 621 | totnokpaq += nokpaq;
|
---|
| 622 | totnoksfc += noksfc;
|
---|
| 623 | } // Fin de boucle sur les zones a traiter
|
---|
| 624 | cout << " ------------------ BRProcBRaw4C::run() END ----------------- " << endl;
|
---|
[3647] | 625 | {
|
---|
| 626 | dt.Info()["FirstTT1"]=firsttt;
|
---|
| 627 | dt.Info()["FirstTT2"]=firsttt2;
|
---|
| 628 | cout << dt;
|
---|
| 629 | char fname[512];
|
---|
| 630 | sprintf(fname,"%s_fctt.ppf",path_.c_str());
|
---|
| 631 | POutPersist po(fname);
|
---|
| 632 | po << PPFNameTag("ttfc") << dt;
|
---|
| 633 | cout << " BRProcBRaw4C::run() created TimeTag/FrameCounter file " << fname << endl;
|
---|
| 634 | }
|
---|
[3645] | 635 | ts.SetNow();
|
---|
| 636 | tm.SplitQ();
|
---|
| 637 | cout << " TotalProc= " << totnbytesproc/(1024*1024) << " MBytes, rate= "
|
---|
| 638 | << (double)(totnbytesproc)/1024./tm.PartialElapsedTimems() << " MB/s" << endl;
|
---|
| 639 | double totokfrac = (totnokpaq>1)?((double)totnoksfc/(double)totnokpaq*100.):0.;
|
---|
| 640 | cout << " NOkPaq1,2=" << totnokpaq << " /TotNPaq=" << totnpaq << " TotNSameFC="
|
---|
| 641 | << totnoksfc << " (" << totokfrac << " %)" << endl;
|
---|
| 642 | // cout << pcheck1;
|
---|
| 643 | // cout << pcheck2;
|
---|
| 644 | cout << " BRProcBRaw4C::run()/Timing: \n";
|
---|
| 645 | tm.Print();
|
---|
| 646 | cout << " ---------------------------------------------------------- " << endl;
|
---|
| 647 | }
|
---|
| 648 | catch (PException& exc) {
|
---|
| 649 | cout << " BRProcBRaw4C::run()/catched PException " << exc.Msg() << endl;
|
---|
| 650 | setRC(3);
|
---|
| 651 | return;
|
---|
| 652 | }
|
---|
| 653 | catch(...) {
|
---|
| 654 | cout << " BRProcBRaw4C::run()/catched unknown ... exception " << endl;
|
---|
| 655 | setRC(4);
|
---|
| 656 | return;
|
---|
| 657 | }
|
---|
| 658 | setRC(0);
|
---|
| 659 | return;
|
---|
| 660 | }
|
---|
| 661 |
|
---|
| 662 |
|
---|