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