[3872] | 1 | //----------------------------------------------------------------
|
---|
[3939] | 2 | // Projet BAORadio - (C) LAL/IRFU 2008-2011
|
---|
[3872] | 3 | // Classes de threads de traitement pour BAORadio
|
---|
| 4 | //----------------------------------------------------------------
|
---|
[3635] | 5 |
|
---|
| 6 | #include <stdlib.h>
|
---|
[3642] | 7 | #include <string.h>
|
---|
[3635] | 8 | #include <unistd.h>
|
---|
| 9 | #include <fstream>
|
---|
| 10 | #include <signal.h>
|
---|
| 11 |
|
---|
| 12 | #include "pexceptions.h"
|
---|
| 13 | #include "tvector.h"
|
---|
[3646] | 14 | #include "ntuple.h"
|
---|
[3647] | 15 | #include "datatable.h"
|
---|
[3652] | 16 | #include "histos.h"
|
---|
[3635] | 17 | #include "fioarr.h"
|
---|
[3655] | 18 | #include "matharr.h"
|
---|
[3635] | 19 | #include "timestamp.h"
|
---|
| 20 | #include "ctimer.h"
|
---|
| 21 | #include "fftpserver.h"
|
---|
[3886] | 22 | #include "fitsarrhand.h"
|
---|
[3635] | 23 |
|
---|
| 24 | #include "FFTW/fftw3.h"
|
---|
| 25 |
|
---|
| 26 |
|
---|
| 27 | #include "pciewrap.h"
|
---|
| 28 | #include "brpaqu.h"
|
---|
| 29 | #include "brproc.h"
|
---|
| 30 |
|
---|
[3872] | 31 |
|
---|
| 32 |
|
---|
[3683] | 33 | //---------------------------------------------------------------------
|
---|
[3939] | 34 | // Classe BRMeanSpecCalculator de traitement de spectres -
|
---|
[3905] | 35 | // Calcul de spectres moyennes,variance / voie + nettoyage
|
---|
[3939] | 36 | // Implementation de traitement par fenetres temps-frequence
|
---|
| 37 | // Le temps correspond au numero de paquet
|
---|
[3683] | 38 | //---------------------------------------------------------------------
|
---|
| 39 | /* --Methode-- */
|
---|
[3872] | 40 | BRMeanSpecCalculator::BRMeanSpecCalculator(RAcqMemZoneMgr& memgr, string outpath, uint_4 nmean,
|
---|
| 41 | bool fgdatafft, bool fgsinglechan)
|
---|
| 42 | : BRBaseProcessor(memgr), outpath_(outpath), nmean_(nmean),
|
---|
[3886] | 43 | fgdatafft_(fgdatafft), fgsinglechannel_(fgsinglechan),
|
---|
[3905] | 44 | nbpaq4mean_(fgsinglechan?memgr_.NbFibres():2*memgr_.NbFibres()),
|
---|
[3943] | 45 | nbadpaq_(fgsinglechan?memgr_.NbFibres():2*memgr_.NbFibres())
|
---|
[3683] | 46 | {
|
---|
[3872] | 47 | setNameId("meanSpecCalc",1);
|
---|
[3943] | 48 |
|
---|
| 49 | uint_4 nb_octets_entrop = 0; //this value is valid for Dec. 2010 data at Nancay
|
---|
| 50 | const char* venvp = NULL;
|
---|
| 51 | venvp=getenv("BRANA_NBYTECUT");
|
---|
| 52 | if (venvp!=NULL){
|
---|
| 53 | nb_octets_entrop = atoi(venvp);
|
---|
| 54 | cout << "BRMeanSpecCalculator : BRANA_NBYTECUT : " << nb_octets_entrop << endl;
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | BRPaquet paq(memgr_.PaqSize()-nb_octets_entrop);
|
---|
| 58 |
|
---|
[3881] | 59 | if (fgsinglechannel_) {
|
---|
[3872] | 60 | mspecmtx_.SetSize(memgr_.NbFibres(), paq.DataSize()/2);
|
---|
[3881] | 61 | sigspecmtx_.SetSize(memgr_.NbFibres(), paq.DataSize()/2);
|
---|
[3888] | 62 | sgain_.SetSize(memgr_.NbFibres(), paq.DataSize()/2);
|
---|
[3881] | 63 | }
|
---|
| 64 | else {
|
---|
[3872] | 65 | mspecmtx_.SetSize(2*memgr_.NbFibres(), paq.DataSize()/4);
|
---|
[3881] | 66 | sigspecmtx_.SetSize(2*memgr_.NbFibres(), paq.DataSize()/4);
|
---|
[3888] | 67 | sgain_.SetSize(2*memgr_.NbFibres(), paq.DataSize()/4);
|
---|
[3881] | 68 | }
|
---|
| 69 | mspecmtx_=(r_4)(0.);
|
---|
| 70 | sigspecmtx_=(r_4)(0.);
|
---|
[3888] | 71 | sgain_=(r_4)(1.); // Gain en fonction de la frequence, à 1 par defaut
|
---|
| 72 |
|
---|
[3872] | 73 | numfile_=0;
|
---|
| 74 | totnbpaq_=0;
|
---|
[3886] | 75 |
|
---|
[3905] | 76 | size_t nchan=(fgsinglechannel_?memgr_.NbFibres():2*memgr_.NbFibres());
|
---|
| 77 |
|
---|
| 78 | for(size_t i=0; i<nchan; i++) {
|
---|
| 79 | nbpaq4mean_[i]=nbadpaq_[i]=0;
|
---|
| 80 | }
|
---|
| 81 |
|
---|
[3943] | 82 | //
|
---|
| 83 |
|
---|
| 84 |
|
---|
[3905] | 85 | // Definition des tailles de fenetres de spectres, etc ...
|
---|
| 86 | SetSpectraWindowSize();
|
---|
[3943] | 87 | SetMaxNbSpecWinFiles();
|
---|
[3905] | 88 | nbtot_specwin_=0;
|
---|
[3886] | 89 | SetVarianceLimits();
|
---|
[3943] | 90 | SetNumberOfBands();
|
---|
[3886] | 91 |
|
---|
| 92 | ofsdtp_=NULL;
|
---|
| 93 | dtp_=NULL;
|
---|
[3943] | 94 |
|
---|
| 95 | // cout << "(JEC) creation tuple de " << nchan*(1+numberOfBands_) << " doubles " << endl;
|
---|
[3944] | 96 | // CHECK : ATTENTION , on alloue une taille minimum pour le tableau xnt, reallocation si DefineDataTable() appele
|
---|
| 97 | xnt_=new double[nchan*2];
|
---|
[3776] | 98 | }
|
---|
| 99 |
|
---|
| 100 | /* --Methode-- */
|
---|
[3872] | 101 | BRMeanSpecCalculator::~BRMeanSpecCalculator()
|
---|
[3776] | 102 | {
|
---|
[3943] | 103 | cout << " ---------------- BRMeanSpecCalculator()_Finalizing -------------------- " << endl;
|
---|
[3905] | 104 | uint_8 npqm=0;
|
---|
| 105 | for(size_t i=0; i<nbpaq4mean_.size(); i++) npqm+=nbpaq4mean_[i];
|
---|
| 106 | if (npqm>nmean_*nbpaq4mean_.size()/10) SaveMeanSpectra();
|
---|
[3886] | 107 | for(size_t i=0; i<nbadpaq_.size(); i++) {
|
---|
| 108 | cout << " Channel " << i << " NBadPaq=" << nbadpaq_[i] << " / TotNbPaq=" << totnbpaq_ << endl;
|
---|
| 109 | }
|
---|
| 110 | if (dtp_) {
|
---|
| 111 | cout << *dtp_;
|
---|
| 112 | delete dtp_;
|
---|
| 113 | delete ofsdtp_;
|
---|
| 114 | }
|
---|
[3938] | 115 | if (xnt_) delete xnt_;
|
---|
[3886] | 116 | cout << " ------------------------------------------------------------------------ " << endl;
|
---|
[3776] | 117 | }
|
---|
| 118 |
|
---|
[3888] | 119 | /* --Methode-- */
|
---|
[3905] | 120 | void BRMeanSpecCalculator::SetSpectraWindowSize(uint_4 winsz, uint_4 wszext)
|
---|
[3888] | 121 | {
|
---|
[3905] | 122 | if (winsz < 3) {
|
---|
| 123 | winsz=1; wszext=0;
|
---|
| 124 | }
|
---|
| 125 | if (wszext>=winsz/2) wszext=winsz/2;
|
---|
| 126 | sa_size_t sz[5]={0,0,0,0,0};
|
---|
| 127 | sz[0]=mspecmtx_.NCols();
|
---|
| 128 | sz[1]=mspecmtx_.NRows();
|
---|
| 129 | sz[2]=winsz+2*wszext;
|
---|
| 130 | spec_window_.SetSize(3,sz);
|
---|
| 131 | spwin_ext_sz_=wszext;
|
---|
| 132 | sz[0]=mspecmtx_.NRows();
|
---|
| 133 | sz[1]=winsz+2*wszext;
|
---|
| 134 | clnflg_.SetSize(2,sz);
|
---|
| 135 | cout << "BRMeanSpecCalculator::SetSpectraWindowSize()/Info: SpectraWindowSize()=" << GetSpectraWindowSize()
|
---|
| 136 | << " ExtensionSize=" << GetSpecWinExtensionSize() << " Overlap=" << GetSpecWinOverlapSize()
|
---|
| 137 | << " ArraySize=" << spec_window_.SizeZ() << endl;
|
---|
| 138 |
|
---|
| 139 | paqnum_w_start=spwin_ext_sz_; // premiere initialisation du numero de paquet
|
---|
| 140 | return;
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 | /* --Methode-- */
|
---|
[3938] | 144 | void BRMeanSpecCalculator::DefineDataTable()
|
---|
| 145 | {
|
---|
[3943] | 146 | cout << "(JEC) BRMeanSpecCalculator::DefineDataTable START" << endl;
|
---|
[3938] | 147 | string dtfile="!"+outpath_+"/dtspec.fits";
|
---|
| 148 | ofsdtp_ = new FitsInOutFile(dtfile,FitsInOutFile::Fits_Create);
|
---|
| 149 | dtp_ = new SwFitsDataTable(*ofsdtp_,1024,true);
|
---|
| 150 | char cnom[32];
|
---|
| 151 | size_t nchan=(fgsinglechannel_?memgr_.NbFibres():2*memgr_.NbFibres());
|
---|
| 152 | for(int i=0; i<nchan; i++) {
|
---|
| 153 | sprintf(cnom,"variance%d",i);
|
---|
| 154 | dtp_->AddFloatColumn(cnom);
|
---|
| 155 | }
|
---|
[3943] | 156 | for(int i=0; i<nchan; i++) {
|
---|
| 157 | for(int j=0;j<numberOfBands_;j++){
|
---|
| 158 | sprintf(cnom,"varnormb%d%d",i,j);
|
---|
| 159 | dtp_->AddFloatColumn(cnom);
|
---|
| 160 | }
|
---|
| 161 | }
|
---|
[3938] | 162 | /*
|
---|
| 163 | for(int i=0; i<nchan; i++) {
|
---|
| 164 | sprintf(cnom,"sigma%d",i);
|
---|
| 165 | dtp_->AddFloatColumn(cnom);
|
---|
| 166 | }
|
---|
| 167 | */
|
---|
| 168 | // xnt_=new double[nchan*2]; CHECK : faut-il reallouer ?
|
---|
[3943] | 169 | cout << "(JEC) creation tuple de " << nchan*(1+numberOfBands_) << " doubles " << endl;
|
---|
[3944] | 170 | if (xnt_) delete[] xnt_;
|
---|
[3943] | 171 | xnt_=new double[nchan*(1+numberOfBands_)];
|
---|
| 172 | cout << "(JEC) BRMeanSpecCalculator::DefineDataTable END" << endl;
|
---|
[3938] | 173 | }
|
---|
[3943] | 174 |
|
---|
| 175 | /* --Methode-- */
|
---|
| 176 | void BRMeanSpecCalculator::SetNumberOfBands(int numberOfBands, int ibandfirst, int ibandlast)
|
---|
| 177 | {
|
---|
| 178 | if (numberOfBands < 1) numberOfBands = 1;
|
---|
| 179 | numberOfBands_ = numberOfBands;
|
---|
| 180 | if (ibandfirst < 0 )ibandfirst = 0;
|
---|
| 181 | if (ibandlast >= numberOfBands_ ) ibandlast = numberOfBands_-1;
|
---|
| 182 | ibandfirst_=ibandfirst; ibandlast_=ibandlast;
|
---|
[3938] | 183 |
|
---|
[3943] | 184 | cout << "(JEC): SetNumberOfBands (END) : "
|
---|
| 185 | << numberOfBands_ << " "
|
---|
| 186 | << ibandfirst_ << " "
|
---|
| 187 | << ibandlast_ << endl;
|
---|
| 188 |
|
---|
| 189 | }
|
---|
| 190 |
|
---|
[3938] | 191 | /* --Methode-- */
|
---|
[3905] | 192 | void BRMeanSpecCalculator::ReadGainFitsFile(string filename, bool fgapp)
|
---|
| 193 | {
|
---|
[3888] | 194 | cout << " BRMeanSpecCalculator::ReadGainFitsFile() - reading file " << filename;
|
---|
| 195 | FitsInOutFile fis(filename, FitsInOutFile::Fits_RO);
|
---|
| 196 | fis >> sgain_;
|
---|
[3905] | 197 | fg_apply_gains_=fgapp;
|
---|
| 198 | cout << " MeanGain=" << sgain_.Sum()/sgain_.Size() << " ApplyGains="
|
---|
| 199 | << ((fg_apply_gains_)?"true":"false") << endl;
|
---|
[3943] | 200 | if( (spec_window_.SizeX()!= sgain_.NCols()) || (spec_window_.SizeY()!= sgain_.NRows()) ){
|
---|
| 201 | cout << " ReadGainFitsFile: BAD Gain Matrix sizes " << endl;
|
---|
| 202 | sgain_.Show();
|
---|
| 203 | spec_window_.Show();
|
---|
| 204 | throw ParmError("ReadGainFitsFile: BAD Gain Matrix sizes");
|
---|
| 205 | }
|
---|
[3888] | 206 | }
|
---|
[3776] | 207 |
|
---|
[3943] | 208 | //JEC
|
---|
| 209 | //static inline r_4 Zmod2(complex<r_4> z)
|
---|
| 210 | //{ return (z.real()*z.real()+z.imag()*z.imag()); }
|
---|
[3776] | 211 |
|
---|
[3905] | 212 |
|
---|
| 213 |
|
---|
| 214 |
|
---|
[3776] | 215 | /* --Methode-- */
|
---|
[3872] | 216 | int BRMeanSpecCalculator::Process()
|
---|
[3724] | 217 | {
|
---|
[3905] | 218 | // Cette methode remplit le tableau spec_window_ avec les spectres (renormalise avec
|
---|
| 219 | // les gains si demande) et appelle la methode du traitement de la fenetre temporelle
|
---|
| 220 | // des spectres le cas echeant ProcSpecWin()
|
---|
| 221 |
|
---|
[3943] | 222 |
|
---|
[3905] | 223 | int_8 nbpaqdec = (int_8)totnbpaq_-(int_8)GetSpecWinOverlapSize();
|
---|
| 224 | if ((nbpaqdec>0)&&(nbpaqdec%GetSpectraWindowSize()==0)) {
|
---|
| 225 | paqnum_w_end=totnbpaq_-GetSpecWinExtensionSize();
|
---|
| 226 | ProcSpecWin(paqnum_w_start, paqnum_w_end);
|
---|
| 227 | paqnum_w_start=totnbpaq_-GetSpecWinExtensionSize();
|
---|
| 228 | }
|
---|
| 229 |
|
---|
[3872] | 230 | if (fgdatafft_) { // Donnees firmware FFT
|
---|
[3905] | 231 | for(sa_size_t i=0; i<spec_window_.SizeY(); i++) {
|
---|
[3872] | 232 | TwoByteComplex* zp=NULL;
|
---|
| 233 | if (fgsinglechannel_) {
|
---|
| 234 | zp=vpaq_[i].Data1C();
|
---|
| 235 | }
|
---|
| 236 | else {
|
---|
| 237 | zp=vpaq_[i/2].Data1C();
|
---|
| 238 | if (i%2==1) zp=vpaq_[i/2].Data2C();
|
---|
| 239 | }
|
---|
[3905] | 240 | sa_size_t kz=PaqNumToArrayIndex(totnbpaq_);
|
---|
| 241 | for(sa_size_t f=0; f<spec_window_.SizeX(); f++)
|
---|
| 242 | spec_window_(f,i,kz) = zp[f].module2F();
|
---|
[3726] | 243 | }
|
---|
[3872] | 244 | }
|
---|
| 245 | else { // Donnees RAW qui ont du etre processe par BRFFTCalculator
|
---|
[3905] | 246 | for(sa_size_t i=0; i<spec_window_.SizeY(); i++) {
|
---|
[3872] | 247 | complex<ODT>* zp=NULL;
|
---|
| 248 | if (fgsinglechannel_) {
|
---|
| 249 | zp=reinterpret_cast< complex<ODT>* > (vprocpaq_[i]);
|
---|
[3726] | 250 | }
|
---|
[3872] | 251 | else {
|
---|
| 252 | zp=reinterpret_cast< complex<ODT>* > (vprocpaq_[i/2]);
|
---|
| 253 | if (i%2==1) zp= reinterpret_cast< complex<ODT>* >(vprocpaq_[i/2]+memgr_.ProcPaqSize()/2) ;
|
---|
[3726] | 254 | }
|
---|
[3905] | 255 | sa_size_t kz=PaqNumToArrayIndex(totnbpaq_);
|
---|
| 256 | for(sa_size_t f=0; f<spec_window_.SizeX(); f++)
|
---|
| 257 | spec_window_(f,i,kz) = Zmod2(zp[f]);
|
---|
[3872] | 258 | }
|
---|
[3724] | 259 | }
|
---|
[3905] | 260 | if (fg_apply_gains_) { // Application des gains, si demande
|
---|
| 261 | sa_size_t kz=PaqNumToArrayIndex(totnbpaq_);
|
---|
[3943] | 262 | for(sa_size_t i=0; i<spec_window_.SizeY(); i++) {
|
---|
| 263 | (spec_window_(Range::all(), Range(i), Range(kz)).CompactAllDimensions()).Div(sgain_.Row(i).CompactAllDimensions());
|
---|
| 264 | }
|
---|
[3905] | 265 | }
|
---|
| 266 |
|
---|
| 267 | totnbpaq_++;
|
---|
[3872] | 268 | return 0;
|
---|
[3724] | 269 | }
|
---|
| 270 |
|
---|
[3905] | 271 |
|
---|
[3724] | 272 | /* --Methode-- */
|
---|
[3905] | 273 | void BRMeanSpecCalculator::ProcSpecWin(uint_8 numpaqstart, uint_8 numpaqend)
|
---|
[3886] | 274 | {
|
---|
[3905] | 275 |
|
---|
[3938] | 276 | if (prtlev_>0) {
|
---|
| 277 | uint_8 modulo = prtmodulo_/GetSpectraWindowSize();
|
---|
| 278 | if (modulo<1) modulo=1;
|
---|
| 279 | if (nbtot_specwin_%modulo==0) {
|
---|
| 280 | cout << " BRMeanSpecCalculator::ProcSpecWin() num_win=" << nbtot_specwin_ << " numpaqstart=" << numpaqstart
|
---|
| 281 | << " numpaqend=" << numpaqend << endl;
|
---|
| 282 | cout << " ... ObsTime=" << getObsTime() << " TimeTag=" << getCurTimeTagSeconds() << " s. FrameCounter="
|
---|
| 283 | << getCurFrameCounter() << endl;
|
---|
| 284 | }
|
---|
| 285 | }
|
---|
[3905] | 286 | // On appelle la routine de nettoyage qui doit flagger les mauvais paquets
|
---|
| 287 | FlagBadPackets(numpaqstart, numpaqend);
|
---|
| 288 |
|
---|
| 289 | // Boucle sur les numeros de paquets de la fenetre en temps
|
---|
| 290 | for (uint_8 jp=numpaqstart; jp<numpaqend; jp++) {
|
---|
| 291 | // On sauvegarde les spectres moyennes si necessaire
|
---|
| 292 | if ((nbpaq4mean_[0]>0)&&(nbpaq4mean_[0]%nmean_ == 0)) SaveMeanSpectra();
|
---|
| 293 | // On peut aussi acceder aux spectres et flags pour (jpmin -),(jpmax+) GetSpecWinExtensionSize()
|
---|
| 294 | sa_size_t kz=PaqNumToArrayIndex(jp);
|
---|
| 295 | // Boucle sur les numeros de voie (canaux)
|
---|
| 296 | for(sa_size_t i=0; i<spec_window_.SizeY(); i++) {
|
---|
| 297 | if ( clnflg_(i,kz) != 0) continue;
|
---|
| 298 | TVector< r_4 > spec = mspecmtx_.Row(i);
|
---|
| 299 | TVector< r_4 > sspec = sigspecmtx_.Row(i);
|
---|
| 300 | // Calcul de spectres moyennes et variance
|
---|
| 301 | for(sa_size_t f=1; f<spec.Size(); f++) { // boucle sur les frequences
|
---|
[3943] | 302 | spec(f) += spec_window_(f,i,kz);
|
---|
[3905] | 303 | sspec(f) += spec_window_(f,i,kz)*spec_window_(f,i,kz);
|
---|
[3886] | 304 | }
|
---|
[3905] | 305 | nbpaq4mean_[i]++; // compteur de paquets OK pour la moyenne
|
---|
[3886] | 306 | }
|
---|
| 307 | }
|
---|
[3905] | 308 | if (nbtot_specwin_<nmaxfiles_specw_) SaveSpectraWindow();
|
---|
| 309 | nbtot_specwin_++;
|
---|
| 310 | return;
|
---|
| 311 | }
|
---|
| 312 |
|
---|
| 313 | /* --Methode-- */
|
---|
| 314 | void BRMeanSpecCalculator::FlagBadPackets(uint_8 numpaqstart, uint_8 numpaqend)
|
---|
| 315 | {
|
---|
| 316 | // Boucle sur les numeros de paquets de la fenetre en temps
|
---|
| 317 | for (uint_8 jp=numpaqstart; jp<numpaqend; jp++) {
|
---|
| 318 | // On peut aussi acceder aux spectres et flags pour (jpmin -),(jpmax+) GetSpecWinExtensionSize()
|
---|
| 319 | sa_size_t kz=PaqNumToArrayIndex(jp);
|
---|
| 320 | // Boucle sur les numeros de voie (canaux)
|
---|
| 321 | for(sa_size_t i=0; i<spec_window_.SizeY(); i++) {
|
---|
| 322 | double mean, sigma;
|
---|
[3943] | 323 | ////////BUG sa_size_t kz=PaqNumToArrayIndex(totnbpaq_);
|
---|
[3886] | 324 | double variance=0.;
|
---|
[3905] | 325 | variance=spec_window_(Range(1,Range::lastIndex()), Range(i), Range(kz)).Sum();
|
---|
[3943] | 326 | xnt_[i]=variance;
|
---|
| 327 | //Compute nomalized variance in bands freq.
|
---|
| 328 | sa_size_t fMin;
|
---|
| 329 | sa_size_t fMax;
|
---|
| 330 | int bandW = spec_window_.SizeX()/numberOfBands_;
|
---|
| 331 | vector<double> varNomBinned(numberOfBands_);
|
---|
| 332 | for (sa_size_t j=0; j<numberOfBands_; j++){
|
---|
| 333 | fMin = j*bandW;
|
---|
| 334 | fMax =fMin+bandW-1;
|
---|
| 335 | varNomBinned[j]=spec_window_(Range(fMin,fMax), Range(i), Range(kz)).Sum();
|
---|
| 336 | varNomBinned[j]/=(r_4)bandW;
|
---|
| 337 | xnt_[spec_window_.SizeY()+i*numberOfBands_+j] = varNomBinned[j];
|
---|
| 338 | }//eof
|
---|
| 339 |
|
---|
[3905] | 340 | clnflg_(i,kz)=0;
|
---|
[3943] | 341 | for (sa_size_t j=ibandfirst_; j<=ibandlast_; j++){
|
---|
| 342 | // cout << "(jec) var["<<j<<"] =" << varNomBinned[j]
|
---|
| 343 | // << " min " << varmin_
|
---|
| 344 | // << " max " << varmax_ << endl;
|
---|
| 345 | if(varNomBinned[j]<varmin_) { clnflg_(i,kz)=10+j; nbadpaq_[i]++; break;}
|
---|
| 346 | else if(varNomBinned[j]>varmax_) { clnflg_(i,kz)=100+j; nbadpaq_[i]++; break;}
|
---|
| 347 | }
|
---|
| 348 | //cout << "clnflg_("<<i<<","<<kz<<"): " << clnflg_(i,kz) << endl;
|
---|
[3886] | 349 | }
|
---|
[3938] | 350 | if (dtp_) dtp_->AddRow(xnt_);
|
---|
[3886] | 351 | }
|
---|
| 352 | return;
|
---|
| 353 | }
|
---|
| 354 |
|
---|
| 355 | /* --Methode-- */
|
---|
[3905] | 356 | void BRMeanSpecCalculator::SaveMeanSpectra()
|
---|
[3683] | 357 | {
|
---|
[3905] | 358 | for(sa_size_t ir=0; ir<mspecmtx_.NRows(); ir++) {
|
---|
| 359 | char buff[32];
|
---|
| 360 | sprintf(buff,"NPAQSUM_%d",(int)ir);
|
---|
| 361 | mspecmtx_.Info()["NPAQSUM"] = nbpaq4mean_[0];
|
---|
| 362 | mspecmtx_.Info()[buff] = nbpaq4mean_[ir];
|
---|
| 363 | sigspecmtx_.Info()["NPAQSUM"] = nbpaq4mean_[0];
|
---|
| 364 | sigspecmtx_.Info()[buff] = nbpaq4mean_[ir];
|
---|
| 365 | if (nbpaq4mean_[ir] > 0) {
|
---|
| 366 | mspecmtx_.Row(ir) /= (r_4)nbpaq4mean_[ir];
|
---|
| 367 | sigspecmtx_.Row(ir) /= (r_4)nbpaq4mean_[ir];
|
---|
| 368 | sigspecmtx_.Row(ir) -= (mspecmtx_.Row(ir) && mspecmtx_.Row(ir)); // Mean(X^2) - [ Mean(X) ]^2
|
---|
| 369 | }
|
---|
| 370 | }
|
---|
[3881] | 371 | char nfile[64];
|
---|
| 372 | string flnm;
|
---|
| 373 | {
|
---|
[3886] | 374 | sprintf(nfile,"mspecmtx%d.fits",numfile_);
|
---|
| 375 | flnm="!"+outpath_+nfile;
|
---|
| 376 | FitsInOutFile fos(flnm,FitsInOutFile::Fits_Create);
|
---|
| 377 | fos << mspecmtx_;
|
---|
| 378 | }
|
---|
| 379 | {
|
---|
| 380 | sprintf(nfile,"sigspecmtx%d.fits",numfile_);
|
---|
| 381 | flnm="!"+outpath_+nfile;
|
---|
| 382 | FitsInOutFile fos(flnm,FitsInOutFile::Fits_Create);
|
---|
| 383 | fos << sigspecmtx_;
|
---|
| 384 | }
|
---|
| 385 |
|
---|
[3905] | 386 | cout << numfile_ << "-BRMeanSpecCalculator::SaveMeanSpectra() NPaqProc="
|
---|
[3881] | 387 | << totnbpaq_ << " -> Mean/Sig spectra Matrix in " << flnm << " /sigspec...ppf" << endl;
|
---|
[3905] | 388 | numfile_++;
|
---|
| 389 |
|
---|
| 390 | for(size_t i=0; i<nbpaq4mean_.size(); i++) nbpaq4mean_[i]=0;
|
---|
[3881] | 391 | mspecmtx_ = (r_4)(0.);
|
---|
| 392 | sigspecmtx_ = (r_4)(0.);
|
---|
[3872] | 393 | return;
|
---|
[3724] | 394 | }
|
---|
| 395 |
|
---|
[3905] | 396 | /* --Methode-- */
|
---|
| 397 | void BRMeanSpecCalculator::SaveSpectraWindow()
|
---|
| 398 | {
|
---|
| 399 | char nfile[64];
|
---|
| 400 | string flnm;
|
---|
| 401 | sprintf(nfile,"specwin%d.fits",nbtot_specwin_);
|
---|
| 402 | flnm="!"+outpath_+nfile;
|
---|
| 403 | FitsInOutFile fos(flnm,FitsInOutFile::Fits_Create);
|
---|
| 404 | fos << spec_window_;
|
---|
| 405 | cout << " SaveSpectraWindow() " << nbtot_specwin_ << "- file " << nfile << " created " << endl;
|
---|
| 406 | }
|
---|
| 407 |
|
---|
[3872] | 408 | //---------------------------------------------------------------------
|
---|
| 409 | // Classe de thread de calcul de FFT sur donnees RAW
|
---|
| 410 | //---------------------------------------------------------------------
|
---|
[3724] | 411 | /* --Methode-- */
|
---|
[3872] | 412 | BRFFTCalculator::BRFFTCalculator(RAcqMemZoneMgr& memgr, bool fgsinglechannel)
|
---|
| 413 | : BRBaseProcessor(memgr), fgsinglechannel_(fgsinglechannel), totnbfftpaq_(0)
|
---|
[3724] | 414 | {
|
---|
[3943] | 415 | uint_4 nb_octets_entrop = 0; //this value is valid for Dec. 2010 data at Nancay
|
---|
| 416 | const char* venvp = NULL;
|
---|
| 417 | venvp=getenv("BRANA_NBYTECUT");
|
---|
| 418 | if (venvp!=NULL){
|
---|
| 419 | nb_octets_entrop = atoi(venvp);
|
---|
| 420 | cout << "BRFFTCalculator : BRANA_NBYTECUT : " << nb_octets_entrop << endl;
|
---|
| 421 | }
|
---|
| 422 |
|
---|
| 423 | BRPaquet paq(memgr_.PaqSize()-nb_octets_entrop);
|
---|
| 424 | //JEC END
|
---|
| 425 | // BRPaquet paq(memgr_.PaqSize());
|
---|
[3872] | 426 | setNameId("FFTCalc",2);
|
---|
| 427 | ffts_.SetInDataSize((fgsinglechannel_)?paq.DataSize():paq.DataSize()/2);
|
---|
[3683] | 428 | }
|
---|
| 429 |
|
---|
[3692] | 430 | /* --Methode-- */
|
---|
[3872] | 431 | BRFFTCalculator::~BRFFTCalculator()
|
---|
[3692] | 432 | {
|
---|
| 433 | }
|
---|
| 434 |
|
---|
[3872] | 435 |
|
---|
[3705] | 436 | /* --Methode-- */
|
---|
[3872] | 437 | int BRFFTCalculator::Process()
|
---|
[3705] | 438 | {
|
---|
| 439 | for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++) {
|
---|
[3872] | 440 | ffts_.DoFFT( reinterpret_cast<IDT *>(vpaq_[fib].Data1() ),
|
---|
| 441 | reinterpret_cast< complex<ODT>* > (vprocpaq_[fib]) );
|
---|
| 442 | totnbfftpaq_++;
|
---|
| 443 | if ( fgsinglechannel_ ) continue;
|
---|
| 444 | ffts_.DoFFT( reinterpret_cast<IDT *>(vpaq_[fib].Data2() ),
|
---|
| 445 | reinterpret_cast< complex<ODT>* > (vprocpaq_[fib]+memgr_.ProcPaqSize()/2) );
|
---|
| 446 | totnbfftpaq_++;
|
---|
| 447 | }
|
---|
[3705] | 448 | return 0;
|
---|
| 449 | }
|
---|
| 450 |
|
---|
[3774] | 451 |
|
---|
[3872] | 452 | //-------------------------------------------------------------------------
|
---|
| 453 | // Classe WBRFFT : Calcul de TF sur donnees brutes (firmware RAW)
|
---|
| 454 | //-------------------------------------------------------------------------
|
---|
| 455 | ZMutex* WBRFFT::mtx_fftwp_ = NULL;
|
---|
| 456 |
|
---|
[3776] | 457 | /* --Methode-- */
|
---|
[3872] | 458 | WBRFFT::WBRFFT(uint_4 sz)
|
---|
| 459 | : sz_(sz)
|
---|
[3776] | 460 | {
|
---|
[3872] | 461 | if (mtx_fftwp_ == NULL) mtx_fftwp_ = new ZMutex;
|
---|
| 462 | if (sz>0) SetInDataSize(sz);
|
---|
[3776] | 463 | }
|
---|
[3872] | 464 |
|
---|
[3776] | 465 | /* --Methode-- */
|
---|
[3872] | 466 | WBRFFT::~WBRFFT()
|
---|
[3776] | 467 | {
|
---|
| 468 | }
|
---|
| 469 |
|
---|
[3774] | 470 | /* --Methode-- */
|
---|
[3872] | 471 | void WBRFFT::SetInDataSize(uint_4 sz)
|
---|
[3774] | 472 | {
|
---|
[3872] | 473 | sz_ = sz;
|
---|
| 474 | if (sz_<1) return;
|
---|
| 475 | inp.SetSize(sz);
|
---|
| 476 | outfc.SetSize(sz/2+1);
|
---|
| 477 | mtx_fftwp_->lock();
|
---|
| 478 | myplan_ = fftwf_plan_dft_r2c_1d(inp.Size(), inp.Data(),
|
---|
| 479 | (fftwf_complex*)outfc.Data(), FFTW_ESTIMATE);
|
---|
| 480 | mtx_fftwp_->unlock();
|
---|
[3774] | 481 | }
|
---|
| 482 |
|
---|
| 483 | /* --Methode-- */
|
---|
[3872] | 484 | void WBRFFT::DoFFT( IDT *indata, complex<ODT> * ofc)
|
---|
[3774] | 485 | {
|
---|
[3872] | 486 | if (sz_<1) return;
|
---|
| 487 | for(uint_4 k=0; k<inp.Size(); k++) inp(k)=(ODT)indata[k];
|
---|
| 488 | fftwf_execute(myplan_);
|
---|
[3905] | 489 | for(uint_4 k=0; k<outfc.Size(); k++) ofc[k]=outfc(k)/(ODT)sz_; // on renormalise les coeff FFT ( / sz )
|
---|
[3872] | 490 | return;
|
---|
[3774] | 491 | }
|
---|
| 492 |
|
---|
| 493 | /* --Methode-- */
|
---|
[3872] | 494 | void WBRFFT::PrintData(IDT *indata, complex<ODT> * ofc, uint_4 sz)
|
---|
[3774] | 495 | {
|
---|
[3872] | 496 | cout << " --- WBRFFT::PrintData() size=" << sz << endl;
|
---|
| 497 | for(uint_4 k=0; k<sz; k+=8) {
|
---|
| 498 | IDT* in = indata+k;
|
---|
| 499 | cout << " Indata[" << k << "..." << k+8 << "]= ";
|
---|
| 500 | for(uint_4 i=0; i<8; i++) cout << (IIDT)in[i] << " ";
|
---|
| 501 | cout << endl;
|
---|
[3774] | 502 | }
|
---|
[3872] | 503 | cout << endl;
|
---|
| 504 | for(uint_4 k=0; k<sz/2; k+=4) {
|
---|
| 505 | complex< ODT>* out = ofc+k;
|
---|
| 506 | cout << " OutFC[" << k << "..." << k+4 << "]= ";
|
---|
| 507 | for(uint_4 i=0; i<4; i++) cout << out[i] << " ";
|
---|
| 508 | cout << endl;
|
---|
| 509 | }
|
---|
| 510 | return;
|
---|
[3774] | 511 |
|
---|
| 512 | }
|
---|
| 513 |
|
---|
| 514 |
|
---|
[3635] | 515 | //---------------------------------------------------------------
|
---|
| 516 | // Classe thread de traitement donnees ADC avec 2 voies par frame
|
---|
[3872] | 517 | // !!!! OBSOLETE !!!!
|
---|
[3635] | 518 | //---------------------------------------------------------------
|
---|
| 519 |
|
---|
[3649] | 520 | // Mutex pour eviter le plantage du a FFTW qui ne semble pas thread-safe
|
---|
| 521 | static ZMutex* pmutfftw=NULL;
|
---|
| 522 |
|
---|
[3645] | 523 | /* --Methode-- */
|
---|
[3683] | 524 | BRProcA2C::BRProcA2C(RAcqMemZoneMgr& mem, string& path, bool fgraw, uint_4 nmean,
|
---|
[3656] | 525 | uint_4 nmax, bool fghist, uint_4 nfsmap, bool fgnotrl, int card)
|
---|
[3635] | 526 | : memgr(mem)
|
---|
| 527 | {
|
---|
[3683] | 528 | fgraw_ = fgraw;
|
---|
[3635] | 529 | nmax_ = nmax;
|
---|
| 530 | nmean_ = nmean;
|
---|
[3683] | 531 | if (fgraw_) cout << " BRProcA2C::BRProcA2C() - constructeur RAW data - NMean=" << nmean_ << endl;
|
---|
| 532 | else cout << " BRProcA2C::BRProcA2C() - constructeur FFT data - NMean=" << nmean_ << endl;
|
---|
[3656] | 533 | nfsmap_ = nfsmap;
|
---|
[3635] | 534 | stop_ = false;
|
---|
| 535 | path_ = path;
|
---|
[3640] | 536 | fgnotrl_ = fgnotrl;
|
---|
[3652] | 537 | fghist_ = fghist;
|
---|
[3645] | 538 | card_ = card;
|
---|
[3649] | 539 | if (pmutfftw==NULL) pmutfftw=new ZMutex;
|
---|
[3635] | 540 | }
|
---|
| 541 |
|
---|
[3645] | 542 | /* --Methode-- */
|
---|
[3683] | 543 | void BRProcA2C::Stop()
|
---|
[3635] | 544 | {
|
---|
| 545 | stop_=true;
|
---|
[3683] | 546 | // cout <<" BRProcA2C::Stop ... > STOP " << endl;
|
---|
[3635] | 547 | }
|
---|
| 548 |
|
---|
| 549 |
|
---|
| 550 |
|
---|
[3872] | 551 |
|
---|
[3645] | 552 | static inline string card2name_(int card)
|
---|
| 553 | {
|
---|
| 554 | if (card==2) return " (Chan3,4) ";
|
---|
| 555 | else return " (Chan1,2) ";
|
---|
| 556 | }
|
---|
| 557 | /* --Methode-- */
|
---|
[3683] | 558 | void BRProcA2C::run()
|
---|
[3635] | 559 | {
|
---|
| 560 | setRC(1);
|
---|
| 561 | try {
|
---|
[3683] | 562 | Timer tm("BRProcA2C", false);
|
---|
[3635] | 563 | TimeStamp ts;
|
---|
[3646] | 564 | BRPaqChecker pcheck(!fgnotrl_); // Verification/comptage des paquets
|
---|
[3640] | 565 |
|
---|
| 566 | size_t totnbytesout = 0;
|
---|
| 567 | size_t totnbytesproc = 0;
|
---|
| 568 |
|
---|
[3683] | 569 | cout << " BRProcA2C::run() - Starting " << ts << " NMaxMemZones=" << nmax_
|
---|
[3645] | 570 | << " NMean=" << nmean_ << card2name_(card_) << endl;
|
---|
[3683] | 571 | cout << " BRProcA2C::run()... - Output Data Path: " << path_ << endl;
|
---|
[3635] | 572 | char fname[512];
|
---|
| 573 | // sprintf(fname,"%s/proc.log",path_.c_str());
|
---|
| 574 | // ofstream filog(fname);
|
---|
[3683] | 575 | // filog << " BRProcA2C::run() - starting log file " << ts << endl;
|
---|
[3635] | 576 | // filog << " ... NMaxMemZones=" << nmax_ << " NMean=" << nmean_ << " Step=" << step_ << endl;
|
---|
| 577 |
|
---|
[3647] | 578 | /*----DELETE NTuple
|
---|
[3646] | 579 | const char* nnames[8] = {"fcs","tts","s1","s2","s12","s12re","s12im","s12phi"};
|
---|
| 580 | NTuple nt(8, nnames);
|
---|
| 581 | double xnt[10];
|
---|
| 582 | uint_4 nmnt = 0;
|
---|
| 583 | double ms1,ms2,ms12,ms12re,ms12im,ms12phi;
|
---|
[3647] | 584 | ----*/
|
---|
[3683] | 585 | // Time sample (raw data) /FFT coeff histograms
|
---|
| 586 | Histo* ph1=NULL;
|
---|
| 587 | Histo* ph2=NULL;
|
---|
| 588 | if (fghist_) {
|
---|
| 589 | if (fgraw_) {
|
---|
| 590 | ph1 = new Histo(-0.5, 255.5, 256);
|
---|
| 591 | ph2 = new Histo(-0.5, 255.5, 256);
|
---|
| 592 | }
|
---|
| 593 | else {
|
---|
| 594 | ph1 = new Histo(-128.5, 128.5, 257);
|
---|
| 595 | ph2 = new Histo(-128.5, 128.5, 257);
|
---|
| 596 | }
|
---|
| 597 | }
|
---|
| 598 |
|
---|
[3635] | 599 | // Initialisation pour calcul FFT
|
---|
[3640] | 600 | TVector< complex<r_4> > cfour1; // composant TF
|
---|
[3635] | 601 | uint_4 paqsz = memgr.PaqSize();
|
---|
| 602 | uint_4 procpaqsz = memgr.ProcPaqSize();
|
---|
[3646] | 603 |
|
---|
| 604 |
|
---|
[3635] | 605 | BRPaquet pq(NULL, NULL, paqsz);
|
---|
| 606 | TVector<r_4> vx(pq.DataSize()/2);
|
---|
[3648] | 607 | int szfour = pq.DataSize()/2/2+1;
|
---|
| 608 | cfour1.SetSize(szfour);
|
---|
| 609 | /*
|
---|
[3635] | 610 | vx = (r_4)(0.);
|
---|
| 611 | FFTPackServer ffts;
|
---|
[3640] | 612 | ffts.FFTForward(vx, cfour1);
|
---|
[3648] | 613 | szfour = cfour1.Size();
|
---|
| 614 | */
|
---|
| 615 |
|
---|
[3656] | 616 | bool fgtimfreq = false; // true->cartes temps<>frequences
|
---|
| 617 | if (nfsmap_>0) fgtimfreq=true;
|
---|
| 618 |
|
---|
[3640] | 619 | TVector< complex<r_4> > cfour2(cfour1.Size());
|
---|
[3635] | 620 |
|
---|
[3640] | 621 | TVector<r_4> spectreV1(cfour1.Size());
|
---|
| 622 | TVector<r_4> spectreV2(cfour1.Size());
|
---|
[3655] | 623 | TVector<r_4> moyspecV1(cfour1.Size()); // Moyenne des Spectres
|
---|
| 624 | TVector<r_4> moyspecV2(cfour1.Size());
|
---|
| 625 | TVector<r_4> sigspecV1(cfour1.Size()); // Sigma des Spectres
|
---|
| 626 | TVector<r_4> sigspecV2(cfour1.Size());
|
---|
[3640] | 627 | TVector< complex<r_4> > visiV12( cfour1.Size() );
|
---|
[3635] | 628 |
|
---|
[3656] | 629 | TMatrix<r_4> timfreqV1, timfreqV2; // Cartes temps<>frequences
|
---|
| 630 | if (fgtimfreq) {
|
---|
| 631 | timfreqV1.SetSize(nmean_, spectreV1.Size()/nfsmap_);
|
---|
| 632 | timfreqV2.SetSize(nmean_, spectreV2.Size()/nfsmap_);
|
---|
| 633 | }
|
---|
[3683] | 634 | cout << " *DBG*BRProcA2C PaqSz=" << paqsz << " ProcPaqSize=" << procpaqsz
|
---|
[3646] | 635 | << " procpaqsz/2=" << procpaqsz/2 << " cfour1.Size()=" << cfour1.Size()
|
---|
| 636 | << " *8=" << cfour1.Size()*8 << endl;
|
---|
[3635] | 637 |
|
---|
[3649] | 638 | pmutfftw->lock();
|
---|
[3640] | 639 | fftwf_plan plan1 = fftwf_plan_dft_r2c_1d(vx.Size(), vx.Data(),
|
---|
| 640 | (fftwf_complex*)cfour1.Data(), FFTW_ESTIMATE);
|
---|
| 641 | fftwf_plan plan2 = fftwf_plan_dft_r2c_1d(vx.Size(), vx.Data(),
|
---|
| 642 | (fftwf_complex*)cfour2.Data(), FFTW_ESTIMATE);
|
---|
[3649] | 643 | pmutfftw->unlock();
|
---|
[3640] | 644 |
|
---|
[3635] | 645 | uint_4 ifile = 0;
|
---|
[3655] | 646 | uint_4 nzm = 0; // Nb de paquets moyennes pour le calcul de chaque spectre
|
---|
| 647 | uint_4 nmoyspec = 0; // Nb de spectres moyennes
|
---|
[3647] | 648 |
|
---|
| 649 | uint_4 curfc=0;
|
---|
| 650 | uint_8 curtt=0;
|
---|
| 651 | uint_8 firsttt=0;
|
---|
| 652 | bool fgfirst=true;
|
---|
[3658] | 653 | double moysig[2]={0.,0.};
|
---|
| 654 | double sigsig[2]={0.,0.};
|
---|
| 655 | uint_8 nbsig[2]={0,0};
|
---|
| 656 |
|
---|
[3635] | 657 | for (uint_4 kmz=0; kmz<nmax_; kmz++) {
|
---|
| 658 | if (stop_) break;
|
---|
| 659 | int mid = memgr.FindMemZoneId(MemZA_ProcA);
|
---|
| 660 | Byte* buff = memgr.GetMemZone(mid);
|
---|
| 661 | if (buff == NULL) {
|
---|
[3683] | 662 | cout << " BRProcA2C::run()/ERROR memgr.GetMemZone(" << mid << ") -> NULL" << endl;
|
---|
[3640] | 663 | break;
|
---|
[3635] | 664 | }
|
---|
| 665 | Byte* procbuff = memgr.GetProcMemZone(mid);
|
---|
| 666 | if (procbuff == NULL) {
|
---|
[3683] | 667 | cout << " BRProcA2C::run()/ERROR memgr.GetProcMemZone(" << mid << ") -> NULL" << endl;
|
---|
[3640] | 668 | break;
|
---|
[3635] | 669 | }
|
---|
[3647] | 670 | //---- DELETE nmnt=0; ms1=ms2=ms12=ms12re=ms12im=ms12phi=0.;
|
---|
[3645] | 671 | for(uint_4 i=0; i<memgr.NbPaquets(); i++) {
|
---|
[3640] | 672 | BRPaquet paq(NULL, buff+i*paqsz, paqsz);
|
---|
| 673 | if (!pcheck.Check(paq)) continue; // on ne traite que les paquets OK
|
---|
[3647] | 674 | if (fgfirst) { firsttt=paq.TimeTag(); fgfirst=false; }
|
---|
| 675 | curfc=paq.FrameCounter();
|
---|
| 676 | curtt=paq.TimeTag()-firsttt;
|
---|
[3635] | 677 | // Traitement voie 1
|
---|
[3652] | 678 | if (fghist_) {
|
---|
| 679 | for(sa_size_t j=0; j<vx.Size(); j++) {
|
---|
[3683] | 680 | r_4 vts=(fgraw_)?((r_4)(*(paq.Data1()+j))):((r_4)(*(paq.Data1S()+j)));
|
---|
| 681 | ph1->Add((r_8)vts);
|
---|
[3658] | 682 | moysig[0] += (double)vts;
|
---|
| 683 | sigsig[0] += ((double)vts)*((double)vts);
|
---|
| 684 | nbsig[0]++;
|
---|
[3652] | 685 | }
|
---|
[3683] | 686 | for(sa_size_t j=0; j<vx.Size(); j++) {
|
---|
| 687 | r_4 vts=(fgraw_)?((r_4)(*(paq.Data2()+j))):((r_4)(*(paq.Data2S()+j)));
|
---|
| 688 | ph2->Add((r_8)vts);
|
---|
[3658] | 689 | moysig[1] += (double)vts;
|
---|
| 690 | sigsig[1] += ((double)vts)*((double)vts);
|
---|
| 691 | nbsig[1]++;
|
---|
[3652] | 692 | }
|
---|
| 693 | }
|
---|
[3683] | 694 | if (fgraw_) {
|
---|
| 695 | for(sa_size_t j=0; j<vx.Size(); j++)
|
---|
| 696 | vx(j) = (r_4)(*(paq.Data1()+j))-127.5;
|
---|
| 697 | // fftwf_complex* coeff1 = (fftwf_complex*)(procbuff+i*procpaqsz);
|
---|
| 698 | fftwf_execute(plan1);
|
---|
| 699 | // Traitement voie 2
|
---|
| 700 | for(sa_size_t j=0; j<vx.Size(); j++)
|
---|
| 701 | vx(j) = (r_4)(*(paq.Data2()+j))-127.5;
|
---|
| 702 | fftwf_execute(plan2);
|
---|
| 703 | }
|
---|
| 704 | else {
|
---|
| 705 | for(sa_size_t j=1; j<cfour1.Size()-1; j++) {
|
---|
| 706 | cfour1(j) = complex<r_4>((r_4)paq.Data1C()[j].realB(), (r_4)paq.Data1C()[j].imagB());
|
---|
| 707 | cfour2(j) = complex<r_4>((r_4)paq.Data2C()[j].realB(), (r_4)paq.Data2C()[j].imagB());
|
---|
| 708 | }
|
---|
| 709 | cfour1(0) = complex<r_4>((r_4)paq.Data1C()[0].realB(), (r_4)0.);
|
---|
| 710 | cfour1(cfour1.Size()-1) = complex<r_4>((r_4)paq.Data1C()[0].imagB(), (r_4)0.);
|
---|
| 711 | cfour2(0) = complex<r_4>((r_4)paq.Data2C()[0].realB(), (r_4)0.);
|
---|
| 712 | cfour2(cfour2.Size()-1) = complex<r_4>((r_4)paq.Data2C()[0].imagB(), (r_4)0.);
|
---|
| 713 | }
|
---|
| 714 | for(sa_size_t j=0; j<spectreV1.Size(); j++)
|
---|
[3943] | 715 | spectreV1(j) += BRMeanSpecCalculator::Zmod2(cfour1(j));
|
---|
[3683] | 716 | memcpy(procbuff+i*procpaqsz, cfour1.Data(), sizeof(complex<r_4>)*cfour1.Size());
|
---|
| 717 | if (fgtimfreq) { // Remplissage tableau temps-frequence
|
---|
| 718 | for(sa_size_t c=1; c<timfreqV1.NCols(); c++) {
|
---|
| 719 | for(sa_size_t j=c*nfsmap_; j<(c+1)*nfsmap_; j++)
|
---|
[3943] | 720 | timfreqV1(nzm, c) += BRMeanSpecCalculator::Zmod2(cfour1(j));
|
---|
[3683] | 721 | }
|
---|
| 722 | }
|
---|
[3635] | 723 | for(sa_size_t j=0; j<spectreV2.Size(); j++)
|
---|
[3943] | 724 | spectreV2(j) += BRMeanSpecCalculator::Zmod2(cfour2(j)); // BRMeanSpecCalculator::Zmod2(zp2[j]);
|
---|
[3640] | 725 | memcpy(procbuff+i*procpaqsz+procpaqsz/2, cfour2.Data(), sizeof(complex<r_4>)*cfour2.Size());
|
---|
[3656] | 726 | if (fgtimfreq) { // Remplissage tableau temps-frequence
|
---|
| 727 | for(sa_size_t c=1; c<timfreqV2.NCols(); c++) {
|
---|
| 728 | for(sa_size_t j=c*nfsmap_; j<(c+1)*nfsmap_; j++)
|
---|
[3943] | 729 | timfreqV2(nzm,c) += BRMeanSpecCalculator::Zmod2(cfour2(j));
|
---|
[3656] | 730 | }
|
---|
| 731 | }
|
---|
[3635] | 732 |
|
---|
| 733 | // Calcul correlation (visibilite V1 * V2)
|
---|
[3640] | 734 | for(sa_size_t j=0; j<visiV12.Size(); j++)
|
---|
| 735 | visiV12(j)+=cfour1(j)*conj(cfour2(j));
|
---|
| 736 | // for(sa_size_t j=0; j<visiV12.Size(); j++) visiV12(j)+=zp1[j]*zp2[j];
|
---|
[3647] | 737 | if (nzm==0) {
|
---|
| 738 | spectreV1.Info()["StartFC"] = curfc;
|
---|
| 739 | spectreV2.Info()["StartFC"] = curfc;
|
---|
| 740 | visiV12.Info()["StartFC"] = curfc;
|
---|
| 741 | spectreV1.Info()["StartTT"] = curtt;
|
---|
| 742 | spectreV2.Info()["StartTT"] = curtt;
|
---|
| 743 | visiV12.Info()["StartTT"] = curtt;
|
---|
| 744 | }
|
---|
[3640] | 745 | nzm++;
|
---|
[3647] | 746 | /*----DELETE
|
---|
[3646] | 747 | if (nmnt==0) { xnt[0]=paq.FrameCounter(); xnt[1]=paq.TimeTag(); }
|
---|
| 748 | for(sa_size_t j=2700; j<2800; j++) {
|
---|
[3943] | 749 | ms1 += BRMeanSpecCalculator::Zmod2(cfour1(j)); ms2 += BRMeanSpecCalculator::Zmod2(cfour2(j));
|
---|
[3646] | 750 | complex<r_4> zvis = cfour1(j)*conj(cfour2(j));
|
---|
[3943] | 751 | ms12 += BRMeanSpecCalculator::Zmod2(zvis); ms12re += zvis.real(); ms12im += zvis.imag();
|
---|
[3646] | 752 | ms12phi+= atan2(zvis.imag(),zvis.real());
|
---|
| 753 | }
|
---|
| 754 | nmnt++;
|
---|
[3647] | 755 | ----*/
|
---|
[3640] | 756 | totnbytesproc += paq.DataSize();
|
---|
| 757 | totnbytesout += (2*sizeof(complex<r_4>)*cfour1.Size());
|
---|
[3635] | 758 |
|
---|
[3640] | 759 | } // Fin de boucle sur les paquets d'une zone
|
---|
[3647] | 760 |
|
---|
| 761 | /*---- DELETE
|
---|
[3646] | 762 | if (nmnt>0) {
|
---|
| 763 | double fnorm = (double)nmnt*(2800-2700);
|
---|
| 764 | xnt[2] = ms1 /= fnorm;
|
---|
| 765 | xnt[3] = ms2 /= fnorm;
|
---|
| 766 | xnt[4] = ms12 /= fnorm;
|
---|
| 767 | xnt[5] = ms12re /= fnorm;
|
---|
| 768 | xnt[6] = ms12im /= fnorm;
|
---|
| 769 | xnt[7] = ms12phi /= fnorm;
|
---|
| 770 | nt.Fill(xnt);
|
---|
| 771 | }
|
---|
[3647] | 772 | ----*/
|
---|
[3640] | 773 | if ((nzm >= nmean_) || ((kmz==(nmax_-1))&&(nzm>1))) {
|
---|
[3635] | 774 | spectreV1 /= (r_4)(nzm);
|
---|
| 775 | spectreV2 /= (r_4)(nzm);
|
---|
| 776 |
|
---|
[3655] | 777 | // pour le calcul des moyennes et sigmas de ces spectres
|
---|
| 778 | moyspecV1 += spectreV1;
|
---|
| 779 | moyspecV2 += spectreV2;
|
---|
| 780 | sigspecV1 += (spectreV1 && spectreV1);
|
---|
| 781 | sigspecV2 += (spectreV2 && spectreV2);
|
---|
| 782 | nmoyspec++;
|
---|
| 783 |
|
---|
[3635] | 784 | visiV12 /= complex<r_4>((r_4)nzm, 0.);
|
---|
| 785 |
|
---|
| 786 | spectreV1.Info()["NPaqMoy"] = nzm;
|
---|
| 787 | spectreV2.Info()["NPaqMoy"] = nzm;
|
---|
| 788 | visiV12.Info()["NPaqMoy"] = nzm;
|
---|
[3647] | 789 | spectreV1.Info()["EndFC"] = curfc;
|
---|
| 790 | spectreV2.Info()["EndFC"] = curfc;
|
---|
| 791 | visiV12.Info()["EndFC"] = curfc;
|
---|
| 792 | spectreV1.Info()["EndTT"] = curtt;
|
---|
| 793 | spectreV2.Info()["EndTT"] = curtt;
|
---|
| 794 | visiV12.Info()["EndTT"] = curtt;
|
---|
[3652] | 795 | {
|
---|
[3635] | 796 | sprintf(fname,"%s_%d.ppf",path_.c_str(),(int)ifile);
|
---|
| 797 | POutPersist po(fname);
|
---|
[3645] | 798 | string tag1="specV1";
|
---|
| 799 | string tag2="specV2";
|
---|
| 800 | string tag12="visiV12";
|
---|
[3652] | 801 | string tagh1="tshV1";
|
---|
| 802 | string tagh2="tshV2";
|
---|
[3656] | 803 | string tagtf1="timfreqV1";
|
---|
| 804 | string tagtf2="timfreqV2";
|
---|
[3645] | 805 | if (card_==2) {
|
---|
| 806 | tag1 = "specV3";
|
---|
| 807 | tag2 = "specV4";
|
---|
[3652] | 808 | tagh1 = "tshV1";
|
---|
| 809 | tagh2 = "tshV2";
|
---|
[3645] | 810 | tag12="visiV34";
|
---|
[3656] | 811 | tagtf1="timfreqV3";
|
---|
| 812 | tagtf2="timfreqV4";
|
---|
[3645] | 813 | }
|
---|
| 814 | po << PPFNameTag(tag1) << spectreV1;
|
---|
| 815 | po << PPFNameTag(tag2) << spectreV2;
|
---|
| 816 | po << PPFNameTag(tag12) << visiV12;
|
---|
[3652] | 817 | if (fghist_) {
|
---|
[3683] | 818 | po << PPFNameTag(tagh1) << (*ph1);
|
---|
| 819 | po << PPFNameTag(tagh2) << (*ph2);
|
---|
[3658] | 820 |
|
---|
| 821 | double sspvmax[3] = {0.,0.,0.};
|
---|
| 822 | int_4 sspvmaxidx[3] = {-1,-1,-1};
|
---|
| 823 | for(int jji=1;jji<visiV12.Size()-1;jji++) {
|
---|
[3943] | 824 | r_4 zmv2 = BRMeanSpecCalculator::Zmod2(visiV12(jji));
|
---|
[3658] | 825 | if (zmv2>sspvmax[2]) { sspvmax[2]=zmv2; sspvmaxidx[2]=jji; }
|
---|
| 826 | }
|
---|
| 827 | TVector<r_4>& sspv = spectreV1;
|
---|
| 828 | for(int ic=0; ic<2; ic++) {
|
---|
| 829 | if (ic==1) sspv = spectreV2;
|
---|
| 830 | for(int jji=1;jji<sspv.Size()-1;jji++)
|
---|
| 831 | if (sspv(jji)>sspvmax[ic]) { sspvmax[ic]=sspv(jji); sspvmaxidx[ic]=jji; }
|
---|
| 832 | if (nbsig[ic] < 1) { moysig[ic]=sigsig[ic]=-1.; }
|
---|
| 833 | else {
|
---|
| 834 | moysig[ic] /= (double)nbsig[ic];
|
---|
| 835 | sigsig[ic] /= (double)nbsig[ic];
|
---|
| 836 | sigsig[ic] -= (moysig[ic]*moysig[ic]);
|
---|
| 837 | sigsig[ic] = sqrt(sigsig[ic]);
|
---|
| 838 | cout << "===Voie " << ic << " Moy=" << moysig[ic] << " Sig=" << sigsig[ic]
|
---|
| 839 | << " MaxSpec Amp= " << sqrt(sspvmax[ic])/double(pq.DataSize()/2/2)
|
---|
| 840 | << " Pos=" << sspvmaxidx[ic] << " (NPts=" << nbsig[ic] << ")" << endl;
|
---|
| 841 | }
|
---|
| 842 | }
|
---|
| 843 | cout << "=== Voie1x2 MaxSpec Amp= " << sqrt(sqrt(sspvmax[2])/double(pq.DataSize()/2/2))
|
---|
| 844 | << " Pos=" << sspvmaxidx[2] << endl;
|
---|
| 845 | } // fin if (fghist_)
|
---|
| 846 |
|
---|
[3656] | 847 | if (fgtimfreq) {
|
---|
| 848 | timfreqV1 /= (r_4)nzm;
|
---|
| 849 | timfreqV2 /= (r_4)nzm;
|
---|
| 850 | po << PPFNameTag(tagtf1) << timfreqV1;
|
---|
| 851 | po << PPFNameTag(tagtf2) << timfreqV2;
|
---|
| 852 | }
|
---|
[3652] | 853 | }
|
---|
[3635] | 854 | spectreV1 = (r_4)(0.);
|
---|
| 855 | spectreV2 = (r_4)(0.);
|
---|
| 856 | visiV12 = complex<r_4>(0., 0.);
|
---|
[3652] | 857 | if (fghist_) {
|
---|
[3683] | 858 | ph1->Zero();
|
---|
| 859 | ph2->Zero();
|
---|
[3658] | 860 | moysig[0]=moysig[1]=0.;
|
---|
| 861 | sigsig[0]=sigsig[1]=0.;
|
---|
| 862 | nbsig[0]=nbsig[1]=0;
|
---|
[3652] | 863 | }
|
---|
[3656] | 864 | if (fgtimfreq) {
|
---|
| 865 | timfreqV1 = (r_4)(0.);
|
---|
| 866 | timfreqV2 = (r_4)(0.);
|
---|
| 867 | }
|
---|
[3635] | 868 | nzm = 0; ifile++;
|
---|
| 869 | // ts.SetNow();
|
---|
| 870 | // filog << ts << " : proc file " << fname << endl;
|
---|
[3683] | 871 | cout << " BRProcA2C::run() created file " << fname << card2name_(card_) << endl;
|
---|
[3640] | 872 | }
|
---|
[3635] | 873 |
|
---|
| 874 | memgr.FreeMemZone(mid, MemZS_ProcA);
|
---|
[3640] | 875 | } // Fin de boucle sur les zones a traiter
|
---|
[3683] | 876 | cout << " ------------ BRProcA2C::run() END " << card2name_(card_)
|
---|
[3645] | 877 | << " ------------ " << endl;
|
---|
[3647] | 878 | /*---- DELETE
|
---|
| 879 | {
|
---|
| 880 | nt.Info()["FirstTT"]=firsttt;
|
---|
[3646] | 881 | cout << nt;
|
---|
| 882 | sprintf(fname,"%s_nt.ppf",path_.c_str());
|
---|
| 883 | POutPersist po(fname);
|
---|
| 884 | po << PPFNameTag("ntv12") << nt;
|
---|
[3683] | 885 | cout << " BRProcA2C::run() created NTuple file " << fname << card2name_(card_) << endl;
|
---|
[3647] | 886 | }
|
---|
| 887 | ---- */
|
---|
[3655] | 888 | if (nmoyspec>0) { // Calcul des moyennes et sigmas des spectres
|
---|
| 889 | r_4 fnms = nmoyspec;
|
---|
| 890 | moyspecV1 /= fnms;
|
---|
| 891 | moyspecV2 /= fnms;
|
---|
| 892 | sigspecV1 /= fnms;
|
---|
| 893 | sigspecV2 /= fnms;
|
---|
| 894 | sigspecV1 -= (moyspecV1 && moyspecV1);
|
---|
| 895 | sigspecV2 -= (moyspecV2 && moyspecV2);
|
---|
| 896 | sigspecV1 = Sqrt(sigspecV1);
|
---|
| 897 | sigspecV2 = Sqrt(sigspecV2);
|
---|
| 898 | TVector<r_4> rsbV1, rsbV2; // Rapport signal/bruit
|
---|
| 899 | moyspecV1.DivElt(sigspecV1, rsbV1, false, true);
|
---|
| 900 | moyspecV2.DivElt(sigspecV2, rsbV2, false, true);
|
---|
| 901 | sprintf(fname,"%s_ms.ppf",path_.c_str());
|
---|
| 902 | POutPersist po(fname);
|
---|
| 903 | po << PPFNameTag("moyspecV1") << moyspecV1;
|
---|
| 904 | po << PPFNameTag("moyspecV2") << moyspecV2;
|
---|
| 905 | po << PPFNameTag("sigspecV1") << sigspecV1;
|
---|
| 906 | po << PPFNameTag("sigspecV2") << sigspecV2;
|
---|
| 907 | po << PPFNameTag("rsbV1") << rsbV1;
|
---|
| 908 | po << PPFNameTag("rsbV2") << rsbV2;
|
---|
[3683] | 909 | cout << " BRProcA2C::run() created moysigspec file " << fname << card2name_(card_) << endl;
|
---|
[3655] | 910 | }
|
---|
| 911 |
|
---|
[3683] | 912 | if (fghist_) {
|
---|
| 913 | delete ph1;
|
---|
| 914 | delete ph2;
|
---|
| 915 | }
|
---|
[3640] | 916 | ts.SetNow();
|
---|
| 917 | tm.SplitQ();
|
---|
| 918 | cout << " TotalProc= " << totnbytesproc/(1024*1024) << " MBytes, rate= "
|
---|
| 919 | << (double)(totnbytesproc)/1024./tm.PartialElapsedTimems() << " MB/s"
|
---|
| 920 | << " ProcDataOut=" << totnbytesout/(1024*1024) << " MB" << endl;
|
---|
| 921 | cout << pcheck;
|
---|
[3683] | 922 | cout << " BRProcA2C::run()/Timing: " << card2name_(card_) << endl;
|
---|
[3640] | 923 | tm.Print();
|
---|
| 924 | cout << " ---------------------------------------------------------- " << endl;
|
---|
| 925 |
|
---|
[3635] | 926 | }
|
---|
| 927 | catch (PException& exc) {
|
---|
[3683] | 928 | cout << " BRProcA2C::run()/catched PException " << exc.Msg() << endl;
|
---|
[3635] | 929 | setRC(3);
|
---|
| 930 | return;
|
---|
| 931 | }
|
---|
| 932 | catch(...) {
|
---|
[3683] | 933 | cout << " BRProcA2C::run()/catched unknown ... exception " << endl;
|
---|
[3635] | 934 | setRC(4);
|
---|
| 935 | return;
|
---|
| 936 | }
|
---|
| 937 | setRC(0);
|
---|
| 938 | return;
|
---|
| 939 | }
|
---|
| 940 |
|
---|
[3872] | 941 |
|
---|
[3645] | 942 | //---------------------------------------------------------------------
|
---|
[3683] | 943 | // Classe thread de traitement 2 x 2 voies/frames (Apres BRProcA2C)
|
---|
[3872] | 944 | // !!!! OBSOLETE !!!!
|
---|
[3645] | 945 | //---------------------------------------------------------------------
|
---|
[3635] | 946 |
|
---|
[3645] | 947 | /* --Methode-- */
|
---|
[3683] | 948 | BRProcB4C::BRProcB4C(RAcqMemZoneMgr& mem1, RAcqMemZoneMgr& mem2, string& path,
|
---|
| 949 | bool fgraw, uint_4 nmean, uint_4 nmax, bool fgnotrl)
|
---|
[3645] | 950 | : memgr1(mem1), memgr2(mem2)
|
---|
| 951 | {
|
---|
[3683] | 952 | fgraw_ = fgraw;
|
---|
[3645] | 953 | nmax_ = nmax;
|
---|
| 954 | nmean_ = nmean;
|
---|
[3683] | 955 | if (fgraw_) cout << " BRProcB4C::BRProcB4C() - constructeur RAW data - NMean= " << nmean_ << endl;
|
---|
| 956 | else cout << " BRProcB4C::BRProcB4C() - constructeur FFT data - NMean= " << nmean_ << endl;
|
---|
[3645] | 957 | stop_ = false;
|
---|
| 958 | path_ = path;
|
---|
| 959 | fgnotrl_ = fgnotrl;
|
---|
| 960 | }
|
---|
[3635] | 961 |
|
---|
[3645] | 962 | /* --Methode-- */
|
---|
[3683] | 963 | void BRProcB4C::Stop()
|
---|
[3645] | 964 | {
|
---|
| 965 | stop_=true;
|
---|
[3683] | 966 | // cout <<" BRProcB4C::Stop ... > STOP " << endl;
|
---|
[3645] | 967 | }
|
---|
[3635] | 968 |
|
---|
[3645] | 969 |
|
---|
| 970 | /* --Methode-- */
|
---|
[3683] | 971 | void BRProcB4C::run()
|
---|
[3645] | 972 | {
|
---|
| 973 | setRC(1);
|
---|
| 974 | try {
|
---|
[3683] | 975 | Timer tm("BRProcB4C", false);
|
---|
[3645] | 976 | TimeStamp ts;
|
---|
[3646] | 977 | BRPaqChecker pcheck1(!fgnotrl_); // Verification/comptage des paquets
|
---|
| 978 | BRPaqChecker pcheck2(!fgnotrl_); // Verification/comptage des paquets
|
---|
[3645] | 979 |
|
---|
| 980 | size_t totnbytesout = 0;
|
---|
| 981 | size_t totnbytesproc = 0;
|
---|
| 982 |
|
---|
[3683] | 983 | cout << " BRProcB4C::run() - Starting " << ts << " NMaxMemZones=" << nmax_
|
---|
[3645] | 984 | << " NMean=" << nmean_ << endl;
|
---|
[3683] | 985 | cout << " BRProcB4C::run()... - Output Data Path: " << path_ << endl;
|
---|
[3645] | 986 |
|
---|
| 987 | uint_4 paqsz = memgr1.PaqSize();
|
---|
| 988 | uint_4 procpaqsz = memgr1.ProcPaqSize();
|
---|
| 989 | if ((paqsz != memgr2.PaqSize())||(procpaqsz!= memgr2.ProcPaqSize())) {
|
---|
[3683] | 990 | cout << "BRProcB4C::run()/ERROR : different paquet size -> stop \n ...(PaqSz1="
|
---|
[3645] | 991 | << paqsz << " Sz2=" << memgr2.PaqSize() << " ProcPaqSz1="
|
---|
| 992 | << procpaqsz << " Sz2=" << memgr2.ProcPaqSize() << " )" << endl;
|
---|
| 993 | setRC(9);
|
---|
| 994 | return;
|
---|
| 995 | }
|
---|
| 996 |
|
---|
| 997 | TVector< complex<r_4> > cfour; // composant TF
|
---|
[3648] | 998 | BRPaquet pq(NULL, NULL, paqsz);
|
---|
[3646] | 999 | /*
|
---|
[3645] | 1000 | TVector<r_4> vx(pq.DataSize()/2);
|
---|
| 1001 | vx = (r_4)(0.);
|
---|
| 1002 | FFTPackServer ffts;
|
---|
| 1003 | ffts.FFTForward(vx, cfour);
|
---|
| 1004 |
|
---|
| 1005 | TVector< complex<r_4> > visiV13( cfour.Size() );
|
---|
| 1006 | TVector< complex<r_4> > visiV14( cfour.Size() );
|
---|
| 1007 | TVector< complex<r_4> > visiV23( cfour.Size() );
|
---|
| 1008 | TVector< complex<r_4> > visiV24( cfour.Size() );
|
---|
[3646] | 1009 | */
|
---|
[3648] | 1010 | int szfour = pq.DataSize()/2/2+1;
|
---|
| 1011 | // int szfour = (paqsz-40)/2+1;
|
---|
[3646] | 1012 | TVector< complex<r_4> > visiV13( szfour );
|
---|
| 1013 | TVector< complex<r_4> > visiV14( szfour );
|
---|
| 1014 | TVector< complex<r_4> > visiV23( szfour );
|
---|
| 1015 | TVector< complex<r_4> > visiV24( szfour );
|
---|
| 1016 | // cout << " *DBG*AAAAA ---- Vectors OK" << endl;
|
---|
[3683] | 1017 | cout << " *DBG*BRProcB4C PaqSz=" << paqsz << " ProcPaqSize=" << procpaqsz
|
---|
[3646] | 1018 | << " procpaqsz/2=" << procpaqsz/2 << " cfour.Size()=" << szfour
|
---|
| 1019 | << " *8=" << szfour*8 << endl;
|
---|
[3645] | 1020 |
|
---|
[3647] | 1021 | DataTable dt;
|
---|
| 1022 | dt.AddLongColumn("fc1");
|
---|
[3651] | 1023 | dt.AddLongColumn("tt1");
|
---|
[3647] | 1024 | dt.AddLongColumn("fc2");
|
---|
| 1025 | dt.AddLongColumn("tt2");
|
---|
| 1026 | DataTableRow dtr = dt.EmptyRow();
|
---|
| 1027 |
|
---|
[3645] | 1028 | uint_4 nzm = 0;
|
---|
| 1029 | uint_4 totnoksfc = 0;
|
---|
| 1030 | uint_4 totnokpaq = 0;
|
---|
| 1031 | uint_4 totnpaq = 0;
|
---|
| 1032 | uint_4 ifile = 0;
|
---|
[3647] | 1033 |
|
---|
| 1034 | uint_4 curfc=0;
|
---|
| 1035 | uint_8 curtt=0;
|
---|
| 1036 | uint_4 curfc2=0;
|
---|
| 1037 | uint_8 curtt2=0;
|
---|
| 1038 | uint_8 firsttt=0;
|
---|
| 1039 | uint_8 firsttt2=0;
|
---|
| 1040 | bool fgfirst=true;
|
---|
[3645] | 1041 | for (uint_4 kmz=0; kmz<nmax_; kmz++) {
|
---|
| 1042 | uint_4 noksfc = 0;
|
---|
| 1043 | uint_4 nokpaq = 0;
|
---|
| 1044 | if (stop_) break;
|
---|
[3646] | 1045 | // cout << " *DBG*BBBBB" << kmz << endl;
|
---|
| 1046 |
|
---|
[3645] | 1047 | int mid1 = memgr1.FindMemZoneId(MemZA_ProcB);
|
---|
| 1048 | Byte* buff1 = memgr1.GetMemZone(mid1);
|
---|
| 1049 | if (buff1 == NULL) {
|
---|
[3683] | 1050 | cout << " BRProcB4C::run()/ERROR memgr.GetMemZone(" << mid1 << ") -> NULL" << endl;
|
---|
[3645] | 1051 | break;
|
---|
| 1052 | }
|
---|
| 1053 | Byte* procbuff1 = memgr1.GetProcMemZone(mid1);
|
---|
| 1054 | if (procbuff1 == NULL) {
|
---|
[3683] | 1055 | cout << " BRProcB4C::run()/ERROR memgr.GetProcMemZone(" << mid1 << ") -> NULL" << endl;
|
---|
[3645] | 1056 | break;
|
---|
| 1057 | }
|
---|
| 1058 | int mid2 = memgr2.FindMemZoneId(MemZA_ProcB);
|
---|
| 1059 | Byte* buff2 = memgr2.GetMemZone(mid2);
|
---|
| 1060 | if (buff1 == NULL) {
|
---|
[3683] | 1061 | cout << " BRProcB4C::run()/ERROR memgr.GetMemZone(" << mid2 << ") -> NULL" << endl;
|
---|
[3645] | 1062 | break;
|
---|
| 1063 | }
|
---|
| 1064 | Byte* procbuff2 = memgr2.GetProcMemZone(mid2);
|
---|
| 1065 | if (procbuff2 == NULL) {
|
---|
[3683] | 1066 | cout << " BRProcB4C::run()/ERROR memgr.GetProcMemZone(" << mid2 << ") -> NULL" << endl;
|
---|
[3645] | 1067 | break;
|
---|
| 1068 | }
|
---|
| 1069 | uint_4 i1,i2;
|
---|
| 1070 | i1=i2=0;
|
---|
[3646] | 1071 | // cout << " *DBG*CCCCCC " << kmz << " memgr1.NbPaquets() =" << memgr1.NbPaquets() << endl;
|
---|
[3645] | 1072 | while((i1<memgr1.NbPaquets())&&(i2<memgr2.NbPaquets())) {
|
---|
| 1073 | BRPaquet paq1(NULL, buff1+i1*paqsz, paqsz);
|
---|
| 1074 | BRPaquet paq2(NULL, buff2+i2*paqsz, paqsz);
|
---|
| 1075 | totnpaq++;
|
---|
| 1076 | // cout << " DBG["<<kmz<<"] i1,i2=" << i1 <<","<<i2<<" FC1,FC2=" <<paq1.FrameCounter()
|
---|
| 1077 | //<<","<<paq2.FrameCounter()<<endl;
|
---|
| 1078 | // on ne traite que les paquets OK
|
---|
| 1079 | if (!pcheck1.Check(paq1)) { i1++; continue; }
|
---|
| 1080 | if (!pcheck2.Check(paq2)) { i2++; continue; }
|
---|
| 1081 | nokpaq++;
|
---|
| 1082 | if (paq1.FrameCounter()<paq2.FrameCounter()) { i1++; continue; }
|
---|
| 1083 | if (paq2.FrameCounter()<paq1.FrameCounter()) { i2++; continue; }
|
---|
| 1084 | // cout << " DBG["<<kmz<<"]OKOK i1,i2=" << i1 <<","<<i2<<" FC1,FC2=" <<paq1.FrameCounter()
|
---|
| 1085 | // <<","<<paq2.FrameCounter()<<endl;
|
---|
| 1086 |
|
---|
[3646] | 1087 | if ((i1>=memgr1.NbPaquets())||(i2>=memgr1.NbPaquets())) {
|
---|
| 1088 | cout << " *BUG*BUG i1=" << i1 << " i2=" << i2 << endl;
|
---|
| 1089 | break;
|
---|
| 1090 | }
|
---|
[3645] | 1091 | // Les deux framecounters sont identiques ...
|
---|
| 1092 | noksfc++;
|
---|
[3647] | 1093 | curfc=paq1.FrameCounter();
|
---|
| 1094 | curfc2=paq2.FrameCounter();
|
---|
| 1095 | if (fgfirst) {
|
---|
[3651] | 1096 | firsttt=paq1.TimeTag(); firsttt2=paq2.TimeTag();
|
---|
[3683] | 1097 | cout << " BRProcB4C()/Info First FC="<<curfc<<" , "<<curfc2<<" -> TT="
|
---|
[3647] | 1098 | << firsttt<<" , "<<firsttt2 <<endl;
|
---|
| 1099 | fgfirst=false;
|
---|
| 1100 | }
|
---|
| 1101 | curtt=paq1.TimeTag()-firsttt;
|
---|
| 1102 | curtt2=paq2.TimeTag()-firsttt2;
|
---|
| 1103 | dtr[0]=curfc; dtr[1]=curtt;
|
---|
| 1104 | dtr[2]=curfc2; dtr[3]=curtt2;
|
---|
| 1105 | dt.AddRow(dtr);
|
---|
| 1106 |
|
---|
[3645] | 1107 | complex<r_4>* zp1 = (complex<r_4>*)(procbuff1+i1*procpaqsz);
|
---|
| 1108 | complex<r_4>* zp2 = (complex<r_4>*)(procbuff1+i1*procpaqsz+procpaqsz/2);
|
---|
| 1109 | complex<r_4>* zp3 = (complex<r_4>*)(procbuff2+i2*procpaqsz);
|
---|
| 1110 | complex<r_4>* zp4 = (complex<r_4>*)(procbuff2+i2*procpaqsz+procpaqsz/2);
|
---|
| 1111 | for(sa_size_t j=0; j<visiV13.Size(); j++) {
|
---|
| 1112 | visiV13(j)+=zp1[j]*conj(zp3[j]);
|
---|
| 1113 | visiV14(j)+=zp1[j]*conj(zp4[j]);
|
---|
| 1114 | visiV23(j)+=zp2[j]*conj(zp3[j]);
|
---|
| 1115 | visiV24(j)+=zp2[j]*conj(zp4[j]);
|
---|
| 1116 | }
|
---|
[3647] | 1117 | if (nzm==0) {
|
---|
| 1118 | visiV13.Info()["StartFC"] = curfc;
|
---|
| 1119 | visiV14.Info()["StartFC"] = curfc;
|
---|
| 1120 | visiV23.Info()["StartFC"] = curfc;
|
---|
| 1121 | visiV24.Info()["StartFC"] = curfc;
|
---|
| 1122 | visiV13.Info()["StartTT"] = curtt;
|
---|
| 1123 | visiV14.Info()["StartTT"] = curtt;
|
---|
| 1124 | visiV23.Info()["StartTT"] = curtt;
|
---|
| 1125 | visiV24.Info()["StartTT"] = curtt;
|
---|
| 1126 | }
|
---|
[3645] | 1127 | nzm++; i1++; i2++;
|
---|
| 1128 | totnbytesproc += 2*paq1.DataSize();
|
---|
| 1129 | } // Fin de boucle sur les paquets d'une zone
|
---|
[3646] | 1130 | memgr1.FreeMemZone(mid1, MemZS_ProcB);
|
---|
| 1131 | memgr2.FreeMemZone(mid2, MemZS_ProcB);
|
---|
| 1132 |
|
---|
[3645] | 1133 | if ((nzm >= nmean_) || ((kmz==(nmax_-1))&&(nzm>1))) {
|
---|
| 1134 | visiV13 /= complex<r_4>((r_4)nzm, 0.);
|
---|
| 1135 | visiV14 /= complex<r_4>((r_4)nzm, 0.);
|
---|
| 1136 | visiV23 /= complex<r_4>((r_4)nzm, 0.);
|
---|
| 1137 | visiV24 /= complex<r_4>((r_4)nzm, 0.);
|
---|
| 1138 | visiV13.Info()["NPaqMoy"] = nzm;
|
---|
| 1139 | visiV14.Info()["NPaqMoy"] = nzm;
|
---|
| 1140 | visiV23.Info()["NPaqMoy"] = nzm;
|
---|
| 1141 | visiV24.Info()["NPaqMoy"] = nzm;
|
---|
[3647] | 1142 | visiV13.Info()["EndFC"] = curfc;
|
---|
| 1143 | visiV14.Info()["EndFC"] = curfc;
|
---|
| 1144 | visiV23.Info()["EndFC"] = curfc;
|
---|
| 1145 | visiV24.Info()["EndFC"] = curfc;
|
---|
| 1146 | visiV13.Info()["EndTT"] = curtt;
|
---|
| 1147 | visiV14.Info()["EndTT"] = curtt;
|
---|
| 1148 | visiV23.Info()["EndTT"] = curtt;
|
---|
| 1149 | visiV24.Info()["EndTT"] = curtt;
|
---|
[3645] | 1150 | char fname[512];
|
---|
| 1151 | {
|
---|
| 1152 | sprintf(fname,"%s_%d.ppf",path_.c_str(),(int)ifile);
|
---|
| 1153 | POutPersist po(fname);
|
---|
| 1154 | po << PPFNameTag("visiV13") << visiV13;
|
---|
| 1155 | po << PPFNameTag("visiV14") << visiV14;
|
---|
| 1156 | po << PPFNameTag("visiV23") << visiV23;
|
---|
| 1157 | po << PPFNameTag("visiV24") << visiV24;
|
---|
| 1158 | }
|
---|
| 1159 | visiV13 = complex<r_4>(0., 0.);
|
---|
| 1160 | visiV14 = complex<r_4>(0., 0.);
|
---|
| 1161 | visiV23 = complex<r_4>(0., 0.);
|
---|
| 1162 | visiV24 = complex<r_4>(0., 0.);
|
---|
[3646] | 1163 | nzm = 0; ifile++;
|
---|
[3645] | 1164 | // ts.SetNow();
|
---|
| 1165 | // filog << ts << " : proc file " << fname << endl;
|
---|
[3683] | 1166 | cout << " BRProcB4C::run() created file " << fname << endl;
|
---|
[3645] | 1167 | }
|
---|
| 1168 | double okfrac = (nokpaq>1)?((double)noksfc/(double)nokpaq*100.):0.;
|
---|
[3683] | 1169 | cout << "BRProcB4C ["<<kmz<<"] NOKPaq=" << nokpaq << " NSameFC=" << noksfc
|
---|
[3645] | 1170 | << " (" << okfrac << " %)" << endl;
|
---|
| 1171 | totnokpaq += nokpaq;
|
---|
| 1172 | totnoksfc += noksfc;
|
---|
| 1173 | } // Fin de boucle sur les zones a traiter
|
---|
[3683] | 1174 | cout << " ------------------ BRProcB4C::run() END ----------------- " << endl;
|
---|
[3647] | 1175 | {
|
---|
| 1176 | dt.Info()["FirstTT1"]=firsttt;
|
---|
| 1177 | dt.Info()["FirstTT2"]=firsttt2;
|
---|
| 1178 | cout << dt;
|
---|
| 1179 | char fname[512];
|
---|
| 1180 | sprintf(fname,"%s_fctt.ppf",path_.c_str());
|
---|
| 1181 | POutPersist po(fname);
|
---|
| 1182 | po << PPFNameTag("ttfc") << dt;
|
---|
[3683] | 1183 | cout << " BRProcB4C::run() created TimeTag/FrameCounter file " << fname << endl;
|
---|
[3647] | 1184 | }
|
---|
[3645] | 1185 | ts.SetNow();
|
---|
| 1186 | tm.SplitQ();
|
---|
| 1187 | cout << " TotalProc= " << totnbytesproc/(1024*1024) << " MBytes, rate= "
|
---|
| 1188 | << (double)(totnbytesproc)/1024./tm.PartialElapsedTimems() << " MB/s" << endl;
|
---|
| 1189 | double totokfrac = (totnokpaq>1)?((double)totnoksfc/(double)totnokpaq*100.):0.;
|
---|
| 1190 | cout << " NOkPaq1,2=" << totnokpaq << " /TotNPaq=" << totnpaq << " TotNSameFC="
|
---|
| 1191 | << totnoksfc << " (" << totokfrac << " %)" << endl;
|
---|
| 1192 | // cout << pcheck1;
|
---|
| 1193 | // cout << pcheck2;
|
---|
[3683] | 1194 | cout << " BRProcB4C::run()/Timing: \n";
|
---|
[3645] | 1195 | tm.Print();
|
---|
| 1196 | cout << " ---------------------------------------------------------- " << endl;
|
---|
| 1197 | }
|
---|
| 1198 | catch (PException& exc) {
|
---|
[3683] | 1199 | cout << " BRProcB4C::run()/catched PException " << exc.Msg() << endl;
|
---|
[3645] | 1200 | setRC(3);
|
---|
| 1201 | return;
|
---|
| 1202 | }
|
---|
| 1203 | catch(...) {
|
---|
[3683] | 1204 | cout << " BRProcB4C::run()/catched unknown ... exception " << endl;
|
---|
[3645] | 1205 | setRC(4);
|
---|
| 1206 | return;
|
---|
| 1207 | }
|
---|
| 1208 | setRC(0);
|
---|
| 1209 | return;
|
---|
| 1210 | }
|
---|
| 1211 |
|
---|
| 1212 |
|
---|