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