[3635] | 1 | #include "racquproc.h"
|
---|
| 2 |
|
---|
| 3 | #include <stdlib.h>
|
---|
| 4 | #include <unistd.h>
|
---|
| 5 | #include <fstream>
|
---|
| 6 | #include <signal.h>
|
---|
| 7 |
|
---|
| 8 | #include "pexceptions.h"
|
---|
| 9 | #include "tvector.h"
|
---|
| 10 | #include "fioarr.h"
|
---|
| 11 | #include "timestamp.h"
|
---|
| 12 | #include "ctimer.h"
|
---|
| 13 | #include "fftpserver.h"
|
---|
| 14 | #include "fftwserver.h"
|
---|
| 15 |
|
---|
| 16 | #include "FFTW/fftw3.h"
|
---|
| 17 |
|
---|
| 18 |
|
---|
| 19 | #include "pciewrap.h"
|
---|
| 20 | #include "brpaqu.h"
|
---|
| 21 | #include "brproc.h"
|
---|
| 22 |
|
---|
| 23 |
|
---|
| 24 | //---------------------------------------------------------------
|
---|
| 25 | // Classe thread de traitement donnees ADC avec 2 voies par frame
|
---|
| 26 | //---------------------------------------------------------------
|
---|
| 27 |
|
---|
[3640] | 28 | BRProcARaw2C::BRProcARaw2C(RAcqMemZoneMgr& mem, string& path, uint_4 nmean,
|
---|
| 29 | uint_4 step, uint_4 nmax, bool fgnotrl)
|
---|
[3635] | 30 | : memgr(mem)
|
---|
| 31 | {
|
---|
| 32 | nmax_ = nmax;
|
---|
| 33 | nmean_ = nmean;
|
---|
| 34 | step_ = step;
|
---|
| 35 | stop_ = false;
|
---|
| 36 | path_ = path;
|
---|
[3640] | 37 | fgnotrl_ = fgnotrl;
|
---|
[3635] | 38 | }
|
---|
| 39 |
|
---|
| 40 | void BRProcARaw2C::Stop()
|
---|
| 41 | {
|
---|
| 42 | stop_=true;
|
---|
| 43 | // cout <<" BRProcARaw2C::Stop ... > STOP " << endl;
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 |
|
---|
| 47 | static inline r_4 Zmod2(complex<r_4> z)
|
---|
| 48 | { return (z.real()*z.real()+z.imag()*z.imag()); }
|
---|
| 49 |
|
---|
| 50 | void BRProcARaw2C::run()
|
---|
| 51 | {
|
---|
| 52 | setRC(1);
|
---|
| 53 | try {
|
---|
[3640] | 54 | Timer tm("BRProcARaw2C", false);
|
---|
[3635] | 55 | TimeStamp ts;
|
---|
[3640] | 56 | BRPaqChecker pcheck(~fgnotrl_); // Verification/comptage des paquets
|
---|
| 57 |
|
---|
| 58 | size_t totnbytesout = 0;
|
---|
| 59 | size_t totnbytesproc = 0;
|
---|
| 60 |
|
---|
[3635] | 61 | cout << " BRProcARaw2C::run() - Starting " << ts << " NMaxMemZones=" << nmax_
|
---|
| 62 | << " NMean=" << nmean_ << " Step=" << step_ << endl;
|
---|
| 63 | cout << " BRProcARaw2C::run()... - Output Data Path: " << path_ << endl;
|
---|
| 64 | char fname[512];
|
---|
| 65 | // sprintf(fname,"%s/proc.log",path_.c_str());
|
---|
| 66 | // ofstream filog(fname);
|
---|
| 67 | // filog << " BRProcARaw2C::run() - starting log file " << ts << endl;
|
---|
| 68 | // filog << " ... NMaxMemZones=" << nmax_ << " NMean=" << nmean_ << " Step=" << step_ << endl;
|
---|
| 69 |
|
---|
| 70 | // Initialisation pour calcul FFT
|
---|
[3640] | 71 | TVector< complex<r_4> > cfour1; // composant TF
|
---|
[3635] | 72 | uint_4 paqsz = memgr.PaqSize();
|
---|
| 73 | uint_4 procpaqsz = memgr.ProcPaqSize();
|
---|
| 74 | BRPaquet pq(NULL, NULL, paqsz);
|
---|
| 75 | TVector<r_4> vx(pq.DataSize()/2);
|
---|
| 76 | vx = (r_4)(0.);
|
---|
| 77 | FFTPackServer ffts;
|
---|
[3640] | 78 | ffts.FFTForward(vx, cfour1);
|
---|
| 79 | TVector< complex<r_4> > cfour2(cfour1.Size());
|
---|
[3635] | 80 |
|
---|
[3640] | 81 | TVector<r_4> spectreV1(cfour1.Size());
|
---|
| 82 | TVector<r_4> spectreV2(cfour1.Size());
|
---|
| 83 | TVector< complex<r_4> > visiV12( cfour1.Size() );
|
---|
[3635] | 84 |
|
---|
| 85 |
|
---|
[3640] | 86 | fftwf_plan plan1 = fftwf_plan_dft_r2c_1d(vx.Size(), vx.Data(),
|
---|
| 87 | (fftwf_complex*)cfour1.Data(), FFTW_ESTIMATE);
|
---|
| 88 | fftwf_plan plan2 = fftwf_plan_dft_r2c_1d(vx.Size(), vx.Data(),
|
---|
| 89 | (fftwf_complex*)cfour2.Data(), FFTW_ESTIMATE);
|
---|
| 90 |
|
---|
[3635] | 91 | uint_4 ifile = 0;
|
---|
| 92 | uint_4 nzm = 0;
|
---|
| 93 | for (uint_4 kmz=0; kmz<nmax_; kmz++) {
|
---|
| 94 | if (stop_) break;
|
---|
| 95 | int mid = memgr.FindMemZoneId(MemZA_ProcA);
|
---|
| 96 | Byte* buff = memgr.GetMemZone(mid);
|
---|
| 97 | if (buff == NULL) {
|
---|
[3640] | 98 | cout << " BRProcARaw2C::run()/ERROR memgr.GetMemZone(" << mid << ") -> NULL" << endl;
|
---|
| 99 | break;
|
---|
[3635] | 100 | }
|
---|
| 101 | Byte* procbuff = memgr.GetProcMemZone(mid);
|
---|
| 102 | if (procbuff == NULL) {
|
---|
[3640] | 103 | cout << " BRProcARaw2C::run()/ERROR memgr.GetProcMemZone(" << mid << ") -> NULL" << endl;
|
---|
| 104 | break;
|
---|
[3635] | 105 | }
|
---|
[3640] | 106 |
|
---|
[3635] | 107 | for(uint_4 i=0; i<memgr.NbPaquets(); i+=step_) {
|
---|
[3640] | 108 | BRPaquet paq(NULL, buff+i*paqsz, paqsz);
|
---|
| 109 | if (!pcheck.Check(paq)) continue; // on ne traite que les paquets OK
|
---|
| 110 |
|
---|
[3635] | 111 | // Traitement voie 1
|
---|
[3640] | 112 | for(sa_size_t j=0; j<vx.Size(); j++)
|
---|
| 113 | vx(j) = (r_4)(*(paq.Data1()+j))-127.5;
|
---|
| 114 | // fftwf_complex* coeff1 = (fftwf_complex*)(procbuff+i*procpaqsz);
|
---|
| 115 | fftwf_execute(plan1);
|
---|
| 116 | // complex<r_4>* zp1 = (complex<r_4>*)(coeff1);
|
---|
| 117 | // ffts.FFTForward(vx, cfour1);
|
---|
[3635] | 118 | for(sa_size_t j=0; j<spectreV1.Size(); j++)
|
---|
[3640] | 119 | spectreV1(j) += Zmod2(cfour1(j));
|
---|
| 120 | memcpy(procbuff+i*procpaqsz, cfour1.Data(), sizeof(complex<r_4>)*cfour1.Size());
|
---|
[3635] | 121 | // Traitement voie 2
|
---|
[3640] | 122 | for(sa_size_t j=0; j<vx.Size(); j++)
|
---|
| 123 | vx(j) = (r_4)(*(paq.Data2()+j))-127.5;
|
---|
| 124 |
|
---|
| 125 | fftwf_execute(plan2);
|
---|
| 126 |
|
---|
[3635] | 127 | for(sa_size_t j=0; j<spectreV2.Size(); j++)
|
---|
[3640] | 128 | spectreV2(j) += Zmod2(cfour2(j)); // Zmod2(zp2[j]);
|
---|
| 129 | memcpy(procbuff+i*procpaqsz+procpaqsz/2, cfour2.Data(), sizeof(complex<r_4>)*cfour2.Size());
|
---|
[3635] | 130 |
|
---|
| 131 | // Calcul correlation (visibilite V1 * V2)
|
---|
[3640] | 132 | for(sa_size_t j=0; j<visiV12.Size(); j++)
|
---|
| 133 | visiV12(j)+=cfour1(j)*conj(cfour2(j));
|
---|
| 134 | // for(sa_size_t j=0; j<visiV12.Size(); j++) visiV12(j)+=zp1[j]*zp2[j];
|
---|
| 135 | nzm++;
|
---|
| 136 | totnbytesproc += paq.DataSize();
|
---|
| 137 | totnbytesout += (2*sizeof(complex<r_4>)*cfour1.Size());
|
---|
[3635] | 138 |
|
---|
[3640] | 139 | } // Fin de boucle sur les paquets d'une zone
|
---|
| 140 | if ((nzm >= nmean_) || ((kmz==(nmax_-1))&&(nzm>1))) {
|
---|
[3635] | 141 | spectreV1 /= (r_4)(nzm);
|
---|
| 142 | spectreV2 /= (r_4)(nzm);
|
---|
| 143 |
|
---|
| 144 | visiV12 /= complex<r_4>((r_4)nzm, 0.);
|
---|
| 145 |
|
---|
| 146 | spectreV1.Info()["NPaqMoy"] = nzm;
|
---|
| 147 | spectreV2.Info()["NPaqMoy"] = nzm;
|
---|
| 148 | visiV12.Info()["NPaqMoy"] = nzm;
|
---|
[3640] | 149 | {
|
---|
[3635] | 150 | sprintf(fname,"%s_%d.ppf",path_.c_str(),(int)ifile);
|
---|
| 151 | POutPersist po(fname);
|
---|
| 152 | po << PPFNameTag("specV1") << spectreV1;
|
---|
| 153 | po << PPFNameTag("specV2") << spectreV2;
|
---|
| 154 | po << PPFNameTag("visiV12") << visiV12;
|
---|
[3640] | 155 | }
|
---|
[3635] | 156 | spectreV1 = (r_4)(0.);
|
---|
| 157 | spectreV2 = (r_4)(0.);
|
---|
| 158 | visiV12 = complex<r_4>(0., 0.);
|
---|
| 159 | nzm = 0; ifile++;
|
---|
| 160 | // ts.SetNow();
|
---|
| 161 | // filog << ts << " : proc file " << fname << endl;
|
---|
| 162 | cout << " BRProcARaw2C::run() created file " << fname << endl;
|
---|
[3640] | 163 | }
|
---|
[3635] | 164 |
|
---|
| 165 | memgr.FreeMemZone(mid, MemZS_ProcA);
|
---|
[3640] | 166 | } // Fin de boucle sur les zones a traiter
|
---|
| 167 | cout << " ------------------ BRProcARaw2C::run() END ----------------- " << endl;
|
---|
| 168 | ts.SetNow();
|
---|
| 169 | tm.SplitQ();
|
---|
| 170 | cout << " TotalProc= " << totnbytesproc/(1024*1024) << " MBytes, rate= "
|
---|
| 171 | << (double)(totnbytesproc)/1024./tm.PartialElapsedTimems() << " MB/s"
|
---|
| 172 | << " ProcDataOut=" << totnbytesout/(1024*1024) << " MB" << endl;
|
---|
| 173 | cout << pcheck;
|
---|
| 174 | cout << " BRProcARaw2C::run()/Timing: \n";
|
---|
| 175 | tm.Print();
|
---|
| 176 | cout << " ---------------------------------------------------------- " << endl;
|
---|
| 177 |
|
---|
[3635] | 178 | }
|
---|
| 179 | catch (PException& exc) {
|
---|
| 180 | cout << " BRProcARaw2C::run()/catched PException " << exc.Msg() << endl;
|
---|
| 181 | setRC(3);
|
---|
| 182 | return;
|
---|
| 183 | }
|
---|
| 184 | catch(...) {
|
---|
| 185 | cout << " BRProcARaw2C::run()/catched unknown ... exception " << endl;
|
---|
| 186 | setRC(4);
|
---|
| 187 | return;
|
---|
| 188 | }
|
---|
| 189 | setRC(0);
|
---|
| 190 | return;
|
---|
| 191 | }
|
---|
| 192 |
|
---|
| 193 |
|
---|
| 194 |
|
---|
| 195 |
|
---|