| [3872] | 1 | //----------------------------------------------------------------
 | 
|---|
 | 2 | // Projet BAORadio - (C) LAL/IRFU  2008-2010
 | 
|---|
 | 3 | // Classes de threads de calcul de visibilites pour BAORadio 
 | 
|---|
 | 4 | //----------------------------------------------------------------
 | 
|---|
 | 5 | 
 | 
|---|
 | 6 | #include <stdlib.h>
 | 
|---|
 | 7 | #include <string.h>
 | 
|---|
 | 8 | #include <unistd.h>
 | 
|---|
 | 9 | #include <fstream>
 | 
|---|
 | 10 | #include <signal.h>
 | 
|---|
 | 11 | 
 | 
|---|
 | 12 | #include "pexceptions.h"
 | 
|---|
 | 13 | #include "fioarr.h"
 | 
|---|
 | 14 | #include "matharr.h"
 | 
|---|
 | 15 | #include "timestamp.h"
 | 
|---|
 | 16 | #include "ctimer.h"
 | 
|---|
 | 17 | 
 | 
|---|
 | 18 | #include "brviscalc.h"
 | 
|---|
 | 19 | 
 | 
|---|
 | 20 | 
 | 
|---|
 | 21 | //---------------------------------------------------------------------
 | 
|---|
 | 22 | // Classe de traitement - calcul de visibilite pour n fibres 
 | 
|---|
 | 23 | //---------------------------------------------------------------------
 | 
|---|
 | 24 | 
 | 
|---|
 | 25 | /* --Methode-- */
 | 
|---|
 | 26 | BRVisibilityCalculator::BRVisibilityCalculator(RAcqMemZoneMgr& memgr, string outpath, uint_4 nmean, size_t nthr)
 | 
|---|
 | 27 |   : BRBaseProcessor(memgr), paralex_(*this, nthr), nparthr_(nthr), 
 | 
|---|
 | 28 |     outpath_(outpath), nmean_(nmean), nbcalc_(1), calcid_(0), vpdata_(2*memgr.NbFibres())
 | 
|---|
 | 29 |     // , dtfos_(outpath+"visdt.fits", Fits_Create), visdt_(dtfos_, 1024, true);
 | 
|---|
 | 30 | {  
 | 
|---|
 | 31 |   DefineRank(1,0);
 | 
|---|
 | 32 | 
 | 
|---|
 | 33 |   uint_4 maxnpairs = (2*memgr_.NbFibres()+1)*memgr_.NbFibres();
 | 
|---|
 | 34 |   chanum_.SetSize(maxnpairs);
 | 
|---|
 | 35 |   sa_size_t k=0;
 | 
|---|
 | 36 |   for(size_t i=0; i<2*memgr_.NbFibres(); i++)  vpdata_[i]=NULL;
 | 
|---|
 | 37 |   for(size_t i=0; i<2*memgr_.NbFibres(); i++) {
 | 
|---|
 | 38 |     for(size_t j=i; j<2*memgr_.NbFibres(); j++) {
 | 
|---|
 | 39 |       chanum_(k) = (i+1)*100+(j+1);  k++;
 | 
|---|
 | 40 |     }
 | 
|---|
 | 41 |   }
 | 
|---|
 | 42 |   SelectPairs();
 | 
|---|
 | 43 | 
 | 
|---|
 | 44 |   //  visdt_.AddFloatColumn("mfc");
 | 
|---|
 | 45 |   visdt_.AddDoubleColumn("mfc");
 | 
|---|
 | 46 |   visdt_.AddDoubleColumn("mtt");
 | 
|---|
 | 47 |   visdt_.AddIntegerColumn("jfreq");
 | 
|---|
 | 48 |   visdt_.AddIntegerColumn("numch");
 | 
|---|
 | 49 |   visdt_.AddFloatColumn("vre");
 | 
|---|
 | 50 |   visdt_.AddFloatColumn("vim");
 | 
|---|
 | 51 | 
 | 
|---|
 | 52 |   if (nmean_ < 1)  nmean_=memgr_.NbPaquets();
 | 
|---|
 | 53 |   if (nmean_ < 1)  nmean_=1;
 | 
|---|
 | 54 | 
 | 
|---|
 | 55 |   cout << " BRVisibilityCalculator::/Info  nmean=" << nmean_ << endl;
 | 
|---|
 | 56 | 
 | 
|---|
 | 57 |   totnbpaq_=0;
 | 
|---|
 | 58 |   numfile_=0;
 | 
|---|
 | 59 |   nb_flop_=0.;
 | 
|---|
 | 60 |   moyfc_=moytt_=0.;
 | 
|---|
 | 61 | 
 | 
|---|
 | 62 |   fgallfibok=NULL;
 | 
|---|
 | 63 |   fgcktt_=false;
 | 
|---|
 | 64 |   setNameId("viscalc", 0); 
 | 
|---|
 | 65 | }
 | 
|---|
 | 66 | 
 | 
|---|
 | 67 | /* --Methode-- */
 | 
|---|
 | 68 | BRVisibilityCalculator::~BRVisibilityCalculator()
 | 
|---|
 | 69 | {
 | 
|---|
| [3876] | 70 |   if (totnbpaq_<1)   return; 
 | 
|---|
| [3872] | 71 |   cout << " BRVisibilityCalculator - Visibility Datatable : " << endl;
 | 
|---|
 | 72 |   cout << visdt_;
 | 
|---|
| [3876] | 73 |   
 | 
|---|
| [3872] | 74 |   string filename;
 | 
|---|
 | 75 |   filename = outpath_+"visdt.ppf";
 | 
|---|
 | 76 |   if (nbcalc_>1) {
 | 
|---|
 | 77 |     char sbuff[32];
 | 
|---|
 | 78 |     sprintf(sbuff,"visdt_%d",(int)calcid_);
 | 
|---|
 | 79 |     filename = outpath_+sbuff;
 | 
|---|
 | 80 |   }
 | 
|---|
 | 81 |   POutPersist po(filename);
 | 
|---|
 | 82 |   po << visdt_;
 | 
|---|
 | 83 |   if (calcid_ == 0) {
 | 
|---|
 | 84 |     POutPersist poc(outpath_+"chanum.ppf");
 | 
|---|
 | 85 |     poc << chanum_;
 | 
|---|
| [3876] | 86 |     
 | 
|---|
| [3872] | 87 |     if (fgcktt_) {
 | 
|---|
 | 88 |       cout << " BRVisibilityCalculator -  Check TimeTag done: TotNPaqProc= " << totnbpaq_ << endl;
 | 
|---|
 | 89 |       for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++)  {
 | 
|---|
 | 90 |         cout << " BRTTCheck-Fiber[" << fib << "] NBadTT=" << vbadtt_[fib] << " NDiffTT>5="
 | 
|---|
 | 91 |              << vndiff5tt_[fib] << "  NotSameTT=" << vnsamett_[fib] << endl; 
 | 
|---|
 | 92 |       }
 | 
|---|
 | 93 |       POutPersist pott(outpath_+"ttfcmtx.ppf");
 | 
|---|
 | 94 |       pott << PPFNameTag("FC") << fcmtx_; 
 | 
|---|
 | 95 |       pott << PPFNameTag("TT") << ttmtx_;     
 | 
|---|
 | 96 |     }
 | 
|---|
 | 97 |   }
 | 
|---|
 | 98 | }
 | 
|---|
 | 99 | 
 | 
|---|
 | 100 | /* --Methode-- */
 | 
|---|
 | 101 | void BRVisibilityCalculator::DefineRank(uint_4 nbc, uint_4 cid)
 | 
|---|
 | 102 | {
 | 
|---|
 | 103 |   if ((nbc>6)||(cid>=nbc)) 
 | 
|---|
 | 104 |     throw ParmError("BRVisibilityCalculator::DefineRank() NbCalc > 6 !");
 | 
|---|
 | 105 |   nbcalc_=nbc;
 | 
|---|
 | 106 |   calcid_=cid;
 | 
|---|
 | 107 |   if (nbcalc_>1) {
 | 
|---|
 | 108 |     uint_4 maxnpairs = (2*memgr_.NbFibres()+1)*memgr_.NbFibres();
 | 
|---|
 | 109 |     uint_4 npairs=maxnpairs/nbcalc_;
 | 
|---|
 | 110 |     if (calcid_==(nbcalc_-1)) 
 | 
|---|
 | 111 |       SelectPairs(calcid_*npairs, maxnpairs-calcid_*npairs);
 | 
|---|
 | 112 |     else 
 | 
|---|
 | 113 |       SelectPairs(calcid_*npairs, npairs);
 | 
|---|
 | 114 |     MemZaction mmzas[6]={MemZA_ProcA,MemZA_ProcB,MemZA_ProcC,MemZA_ProcD,MemZA_ProcE,MemZA_ProcF};
 | 
|---|
 | 115 |     SetMemZAction(mmzas[calcid_]);
 | 
|---|
 | 116 |     setNameId("viscalc_grp", calcid_); 
 | 
|---|
 | 117 |   }
 | 
|---|
 | 118 |   return ;
 | 
|---|
 | 119 | }
 | 
|---|
 | 120 | 
 | 
|---|
 | 121 | /* --Methode-- */
 | 
|---|
 | 122 | uint_4 BRVisibilityCalculator::SelectPairs(uint_4 pair1, uint_4 nbpairs)
 | 
|---|
 | 123 | {
 | 
|---|
 | 124 |   BRPaquet paq(memgr_.PaqSize());
 | 
|---|
 | 125 |   uint_4 maxnpairs = (2*memgr_.NbFibres()+1)*memgr_.NbFibres();
 | 
|---|
 | 126 | 
 | 
|---|
 | 127 |   if (pair1 >= maxnpairs)  pair1=maxnpairs-1;
 | 
|---|
 | 128 |   if (nbpairs > maxnpairs-pair1)  nbpairs=maxnpairs-pair1;
 | 
|---|
 | 129 |   pairst_=pair1;
 | 
|---|
 | 130 |   nbpairs_=nbpairs;
 | 
|---|
 | 131 |   vismtx_.SetSize(nbpairs_, paq.DataSize()/4); 
 | 
|---|
 | 132 |   return nbpairs_;
 | 
|---|
 | 133 | }
 | 
|---|
 | 134 | 
 | 
|---|
 | 135 | /* --Methode-- */
 | 
|---|
 | 136 | int BRVisibilityCalculator::SelectFreqBinning(uint_4 freq1, uint_4 freq2, uint_4 nbfreq)
 | 
|---|
 | 137 | {
 | 
|---|
 | 138 |   jf1_=freq1; jf2_=freq2;
 | 
|---|
 | 139 |   if ((jf1_<1)||(jf1_>=vismtx_.NCols()))  jf1_=1;
 | 
|---|
 | 140 |   if ((jf2_<1)||(jf2_>=vismtx_.NCols())||(jf2_<jf1_))  jf2_=vismtx_.NCols()-1;
 | 
|---|
| [3876] | 141 |   if (nbfreq<1) nbfreq=(jf2_-jf1_);
 | 
|---|
| [3872] | 142 |   djf_=(jf2_-jf1_)/nbfreq;
 | 
|---|
| [3876] | 143 |   if (djf_<1) djf_=1;
 | 
|---|
| [3872] | 144 |   cout << " BRVisibilityCalculator::SelectFreqBinning/Info  JF1=" << jf1_ 
 | 
|---|
 | 145 |        << " JF2=" << jf2_ << " DJF=" << djf_ << endl;
 | 
|---|
 | 146 | 
 | 
|---|
 | 147 | }
 | 
|---|
 | 148 | 
 | 
|---|
 | 149 | 
 | 
|---|
 | 150 | /* --Methode-- */
 | 
|---|
 | 151 | int BRVisibilityCalculator::ActivateTimeTagCheck(uint_8 maxnpaq)
 | 
|---|
 | 152 | {
 | 
|---|
 | 153 |   mindeltatt_=memgr_.PaqSize()/2;
 | 
|---|
 | 154 |   if (mindeltatt_<1) mindeltatt_=1;
 | 
|---|
 | 155 |   fcmtx_.SetSize(memgr_.NbFibres(), maxnpaq);
 | 
|---|
 | 156 |   ttmtx_.SetSize(memgr_.NbFibres(), maxnpaq);
 | 
|---|
 | 157 |   vlasttt_.resize(memgr_.NbFibres(), 0);
 | 
|---|
 | 158 |   vbadtt_.resize(memgr_.NbFibres(), 0);
 | 
|---|
 | 159 |   vnsamett_.resize(memgr_.NbFibres(), 0);
 | 
|---|
 | 160 |   vndiff5tt_.resize(memgr_.NbFibres(), 0);
 | 
|---|
 | 161 | 
 | 
|---|
 | 162 |   fgcktt_=true;
 | 
|---|
 | 163 |   cout << " BRVisibilityCalculator::ActivateTimeTagCheck() - TT/Fc matrix NCols=" << maxnpaq 
 | 
|---|
 | 164 |        << " MinDeltaTT=" << mindeltatt_ << endl;
 | 
|---|
 | 165 | 
 | 
|---|
 | 166 |   return 0;
 | 
|---|
 | 167 | }
 | 
|---|
 | 168 | 
 | 
|---|
 | 169 | 
 | 
|---|
 | 170 | /* --Methode-- */
 | 
|---|
 | 171 | void BRVisibilityCalculator::run()
 | 
|---|
 | 172 | {
 | 
|---|
 | 173 |   cout << " BRVisibilityCalculator[" << calcid_ << "/" << nbcalc_ 
 | 
|---|
 | 174 |        << "]::run() - Starting " << " NFibers=" << memgr_.NbFibres() 
 | 
|---|
 | 175 |        << " NChan=" << 2*memgr_.NbFibres() << " NPairs=" << nbpairs_ << " First:" << pairst_ << endl;   
 | 
|---|
 | 176 |   
 | 
|---|
 | 177 |   if (nparthr_ < 2)  return BRBaseProcessor::run();
 | 
|---|
 | 178 |   // Execution multithread parallele
 | 
|---|
 | 179 |   setRC(1);     
 | 
|---|
 | 180 |   int rc=0;
 | 
|---|
 | 181 |   try {
 | 
|---|
 | 182 |     if ((nmean_%memgr_.NbPaquets())!=0) {
 | 
|---|
 | 183 |       uint_4 mnmean = (nmean_/memgr_.NbPaquets()+1)*memgr_.NbPaquets();
 | 
|---|
 | 184 |       cout << " BRVisibilityCalculator::run()/Info changing nmean=" << nmean_  << " to multiple of"
 | 
|---|
 | 185 |            << " memgr_.NbPaquets() -> " << mnmean << endl;
 | 
|---|
 | 186 |       nmean_=mnmean;
 | 
|---|
 | 187 |     }
 | 
|---|
 | 188 |     paralex_.SetParallelTask(*this);
 | 
|---|
 | 189 |     cout << " BRVisibilityCalculator::run()/Info : starting ParallelExecutor with nThreads=" 
 | 
|---|
 | 190 |          << paralex_.nThreads() << " ... " << endl;
 | 
|---|
 | 191 |     paralex_.start();
 | 
|---|
 | 192 | 
 | 
|---|
 | 193 |     fgallfibok = new bool[memgr_.NbPaquets()];
 | 
|---|
 | 194 | 
 | 
|---|
 | 195 |     size_t paqsz=memgr_.PaqSize();
 | 
|---|
 | 196 |     bool fgrun=true;
 | 
|---|
 | 197 |     while (fgrun) {
 | 
|---|
 | 198 |       if (stop_) break;
 | 
|---|
 | 199 |       if (memgr_.GetRunState() == MemZR_Stopped) break;
 | 
|---|
 | 200 |       int mid = memgr_.FindMemZoneId(mmact_);  // (MemZA_ProcA);
 | 
|---|
 | 201 |       //      Byte* buffg = memgr_.GetMemZone(mid);
 | 
|---|
 | 202 |       //      if (buffg == NULL) {
 | 
|---|
 | 203 |       if (mid < 0) {
 | 
|---|
 | 204 |         cout << "BRVisibilityCalculator[" << calcid_ << "]::run()/ERROR FindMemZoneId(" 
 | 
|---|
 | 205 |              << (int)mmact_ << ") ->" << mid << ") -> NULL" << endl;
 | 
|---|
 | 206 |         setRC(7);      fgrun=false;             
 | 
|---|
 | 207 |         break;  
 | 
|---|
 | 208 |       }
 | 
|---|
 | 209 |       for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++) {
 | 
|---|
 | 210 |         fbuff_[fib] = memgr_.GetMemZone(mid,fib);
 | 
|---|
 | 211 |         if (fbuff_[fib] == NULL) { // cela ne devrait pas arriver 
 | 
|---|
 | 212 |           cout << "BRVisibilityCalculator[" << calcid_ << "]::run()/ERROR memgr.GetMemZone(" << mid << "," << fib << ") -> NULL" << endl;
 | 
|---|
 | 213 |           setRC(9);       fgrun=false;          
 | 
|---|
 | 214 |           break;
 | 
|---|
 | 215 |         }
 | 
|---|
 | 216 |       }
 | 
|---|
 | 217 | 
 | 
|---|
 | 218 |       if (totnbpaq_%nmean_ == 0) {
 | 
|---|
 | 219 |         if (totnbpaq_ > 0) {
 | 
|---|
 | 220 |           moyfc_/=nmean_;
 | 
|---|
 | 221 |           moytt_/=nmean_;
 | 
|---|
| [3878] | 222 |           UpdateVisMtxInfo();    // add/update keywords in the Info DVList 
 | 
|---|
| [3872] | 223 |           // ATTENTION : Matrice visibilites non moyennee 
 | 
|---|
 | 224 |           char nfile[48];
 | 
|---|
 | 225 |           if (nbcalc_==1) 
 | 
|---|
 | 226 |             sprintf(nfile,"vismtx%d.ppf",numfile_);
 | 
|---|
 | 227 |           else 
 | 
|---|
 | 228 |             sprintf(nfile,"vismtx_%d_%d.ppf",(int)calcid_,numfile_);
 | 
|---|
 | 229 |           string flnm=outpath_+nfile;
 | 
|---|
 | 230 |           POutPersist po(flnm);
 | 
|---|
 | 231 |           po << vismtx_;
 | 
|---|
 | 232 |           cout << numfile_ << "-BRVisibilityCalculator[" << calcid_ << "]::run() NPaqProc="
 | 
|---|
 | 233 |                << totnbpaq_ << "  -> Visibility Matrix in " << flnm << endl;
 | 
|---|
 | 234 |           FillVisibTable(moyfc_, moytt_);
 | 
|---|
 | 235 |           numfile_++;
 | 
|---|
 | 236 |         }
 | 
|---|
 | 237 |         vismtx_ = complex<r_4>((r_4)0.,(r_4)0.);
 | 
|---|
 | 238 |         moyfc_=moytt_=0.;
 | 
|---|
| [3878] | 239 |         first_fc_=curfc_[0];
 | 
|---|
 | 240 |         first_tt_= (vpaq_[0].TimeTag()-ttfirst_[0]);
 | 
|---|
 | 241 |         first_tmstamp_.SetNow();  // Current date and time 
 | 
|---|
| [3872] | 242 |       }
 | 
|---|
 | 243 | 
 | 
|---|
 | 244 |       for(size_t jp=0; jp<memgr_.NbPaquets(); jp++) {   // boucle sur les paquets d'une zone  
 | 
|---|
 | 245 |         fgallfibok[jp]=fgokallfibers_=true;
 | 
|---|
 | 246 |         for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++) {
 | 
|---|
 | 247 |           vpaq_[fib].Set(fbuff_[fib]+jp*paqsz);
 | 
|---|
 | 248 |           vfgok_[fib] = vpchk_[fib].Check(vpaq_[fib],curfc_[fib]);
 | 
|---|
 | 249 |           if (!vfgok_[fib])  fgallfibok[jp]=fgokallfibers_=false;
 | 
|---|
 | 250 |         }
 | 
|---|
 | 251 |         if (fgokallfibers_)  {
 | 
|---|
 | 252 |           if (totprocnpaq_==0) {
 | 
|---|
 | 253 |             for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++)  {
 | 
|---|
 | 254 |               fcfirst_[fib]=curfc_[fib];
 | 
|---|
 | 255 |               ttfirst_[fib]=vpaq_[fib].TimeTag();
 | 
|---|
 | 256 |             }
 | 
|---|
 | 257 |           }
 | 
|---|
 | 258 |           totprocnpaq_++;
 | 
|---|
 | 259 |           moyfc_ += curfc_[0];
 | 
|---|
 | 260 |           moytt_ += (vpaq_[0].TimeTag()-ttfirst_[0]);
 | 
|---|
 | 261 |           if ((fgcktt_)&&(calcid_==0))  CheckTimeTag();
 | 
|---|
 | 262 |           totnbpaq_++;
 | 
|---|
 | 263 |         }
 | 
|---|
 | 264 |       }  // Fin de boucle sur les paquets 
 | 
|---|
 | 265 |       
 | 
|---|
 | 266 |       // Execution parallele  pour calcul des visibilites par bandes de frequence
 | 
|---|
 | 267 |       int rcpex=paralex_.execute();
 | 
|---|
 | 268 |       if (rcpex!=0)  cout << " BRVisibilityCalculator[" << calcid_ << "]::run() / Error Rc[paralex_.execute()]=" << rcpex << endl;
 | 
|---|
 | 269 | 
 | 
|---|
 | 270 |       memgr_.FreeMemZone(mid, mmsta_);  // (MemZS_ProcA);
 | 
|---|
 | 271 |     } // Fin de boucle sur les zones a traiter 
 | 
|---|
 | 272 |     //------------------------------------
 | 
|---|
 | 273 |     cout << " --------- END BRVisibilityCalculator[" << calcid_ << "]::run() , TotNbProcPaq=" << totprocnpaq_ << endl;
 | 
|---|
 | 274 |     /*
 | 
|---|
 | 275 |     for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++)  vpchk_[fib].Print();
 | 
|---|
 | 276 |     cout << " ------------------------------------ " << endl;
 | 
|---|
 | 277 |     */
 | 
|---|
 | 278 |     delete[] fgallfibok;
 | 
|---|
 | 279 |   }
 | 
|---|
 | 280 |   catch (std::exception& exc) {
 | 
|---|
 | 281 |     cout << " BRVisibilityCalculator[" << calcid_ << "]::run()/catched std::exception " << exc.what() << endl;
 | 
|---|
 | 282 |     setRC(98);  
 | 
|---|
 | 283 |     return; 
 | 
|---|
 | 284 |   }
 | 
|---|
 | 285 |   catch(...) {
 | 
|---|
 | 286 |     cout << " BRVisibilityCalculator[" << calcid_ << "]::run()/catched unknown ... exception " << endl;
 | 
|---|
 | 287 |     setRC(99);  
 | 
|---|
 | 288 |     return; 
 | 
|---|
 | 289 |   }
 | 
|---|
 | 290 |   
 | 
|---|
 | 291 | }
 | 
|---|
 | 292 | 
 | 
|---|
 | 293 | /* --Methode-- */
 | 
|---|
 | 294 | int BRVisibilityCalculator::Process()
 | 
|---|
 | 295 | {
 | 
|---|
 | 296 |     
 | 
|---|
 | 297 |   for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++) {
 | 
|---|
 | 298 |     vpdata_[2*fib] = vpaq_[fib].Data1C();
 | 
|---|
 | 299 |     vpdata_[2*fib+1] = vpaq_[fib].Data2C();
 | 
|---|
 | 300 |   }
 | 
|---|
 | 301 |   
 | 
|---|
 | 302 |   if (totnbpaq_%nmean_ == 0) {
 | 
|---|
 | 303 |     if (totnbpaq_ > 0) {
 | 
|---|
 | 304 |       moyfc_/=nmean_;
 | 
|---|
 | 305 |       moytt_/=nmean_;
 | 
|---|
| [3878] | 306 |       UpdateVisMtxInfo();    // add/update keywords in the Info DVList 
 | 
|---|
| [3872] | 307 |       // ATTENTION : Matrice visibilites non moyennee 
 | 
|---|
 | 308 |       char nfile[48];
 | 
|---|
 | 309 |       if (nbcalc_==1) 
 | 
|---|
 | 310 |         sprintf(nfile,"vismtx%d.ppf",numfile_);
 | 
|---|
 | 311 |       else 
 | 
|---|
 | 312 |         sprintf(nfile,"vismtx_%d_%d.ppf",(int)calcid_,numfile_);
 | 
|---|
 | 313 |       string flnm=outpath_+nfile;
 | 
|---|
 | 314 |       POutPersist po(flnm);
 | 
|---|
 | 315 |       po << vismtx_;
 | 
|---|
 | 316 |       cout << numfile_ << "-BRVisibilityCalculator::Process() NPaqProc="
 | 
|---|
 | 317 |            << totnbpaq_ << "  -> Visibility Matrix in " << flnm << endl;
 | 
|---|
 | 318 |       FillVisibTable(moyfc_, moytt_);
 | 
|---|
 | 319 |       numfile_++;
 | 
|---|
 | 320 |     }
 | 
|---|
 | 321 |     vismtx_ = complex<r_4>((r_4)0.,(r_4)0.);
 | 
|---|
 | 322 |     moyfc_=moytt_=0.;
 | 
|---|
| [3878] | 323 |     first_fc_=curfc_[0];
 | 
|---|
 | 324 |     first_tt_= (vpaq_[0].TimeTag()-ttfirst_[0]);
 | 
|---|
 | 325 |     first_tmstamp_.SetNow();  // Current date and time 
 | 
|---|
| [3872] | 326 |   }
 | 
|---|
 | 327 | 
 | 
|---|
 | 328 |   sa_size_t k=0;
 | 
|---|
 | 329 |   for(size_t i=0; i<vpdata_.size(); i++) {
 | 
|---|
 | 330 |     for(size_t j=i; j<vpdata_.size(); j++) {
 | 
|---|
 | 331 |       size_t kpair=i*vpdata_.size()+j;
 | 
|---|
 | 332 |       if (kpair<pairst_)  continue;
 | 
|---|
 | 333 |       if (kpair>=(pairst_+nbpairs_))  break;
 | 
|---|
 | 334 |       TVector< complex<r_4> > vis = vismtx_.Row(k);   k++;
 | 
|---|
 | 335 |       for(sa_size_t f=1; f<vis.Size(); f++) {
 | 
|---|
 | 336 |         vis(f) += complex<r_4>((r_4)vpdata_[i][f].realB(), (r_4)vpdata_[i][f].imagB()) * 
 | 
|---|
 | 337 |           complex<r_4>((r_4)vpdata_[j][f].realB(), -(r_4)vpdata_[j][f].imagB());
 | 
|---|
 | 338 |       }
 | 
|---|
 | 339 |       nb_flop_ += (7.*(r_8)vis.Size());
 | 
|---|
 | 340 |     }
 | 
|---|
 | 341 |   }
 | 
|---|
 | 342 | 
 | 
|---|
 | 343 |   moyfc_ += curfc_[0];
 | 
|---|
 | 344 |   moytt_ += (vpaq_[0].TimeTag()-ttfirst_[0]);
 | 
|---|
 | 345 |   if ((fgcktt_)&&(calcid_==0))  CheckTimeTag();
 | 
|---|
 | 346 |   totnbpaq_++;
 | 
|---|
 | 347 |   return 0;
 | 
|---|
 | 348 | }
 | 
|---|
 | 349 | 
 | 
|---|
 | 350 | /* --Methode-- */
 | 
|---|
| [3878] | 351 | void BRVisibilityCalculator::UpdateVisMtxInfo()
 | 
|---|
 | 352 | {
 | 
|---|
 | 353 |   string ikey,ikdesc;
 | 
|---|
 | 354 |   ikey="DATEOBS";  ikdesc=" Date/Time corresponding to TimeTagFirst";
 | 
|---|
 | 355 |   vismtx_.Info().SetS(ikey,first_tmstamp_.ToString());
 | 
|---|
 | 356 |   vismtx_.Info().SetComment(ikey,ikdesc);
 | 
|---|
 | 357 |   ikey="FirstFC";  ikdesc="First FrameCounter";
 | 
|---|
 | 358 |   vismtx_.Info().SetI(ikey,first_fc_);
 | 
|---|
 | 359 |   vismtx_.Info().SetComment(ikey,ikdesc);
 | 
|---|
 | 360 |   ikey="FirstTT";  ikdesc="First TimeTag";
 | 
|---|
 | 361 |   vismtx_.Info().SetI(ikey,first_tt_);
 | 
|---|
 | 362 |   vismtx_.Info().SetComment(ikey,ikdesc);
 | 
|---|
 | 363 |   ikey="LastFC";  ikdesc="Last FrameCounter";
 | 
|---|
 | 364 |   vismtx_.Info().SetI(ikey,curfc_[0]);
 | 
|---|
 | 365 |   vismtx_.Info().SetComment(ikey,ikdesc);
 | 
|---|
 | 366 |   ikey="LastTT";  ikdesc="Last TimeTag";
 | 
|---|
 | 367 |   vismtx_.Info().SetI(ikey,vpaq_[0].TimeTag()-ttfirst_[0]);
 | 
|---|
 | 368 |   vismtx_.Info().SetComment(ikey,ikdesc);
 | 
|---|
 | 369 |   ikey="MeanFC";  ikdesc="Mean FrameCounter";
 | 
|---|
 | 370 |   vismtx_.Info().SetD(ikey,moyfc_); 
 | 
|---|
 | 371 |   vismtx_.Info().SetComment(ikey,ikdesc);
 | 
|---|
 | 372 |   ikey="MeanTT";  ikdesc="Mean TimeTag";
 | 
|---|
 | 373 |   vismtx_.Info().SetD(ikey,moytt_);
 | 
|---|
 | 374 |   vismtx_.Info().SetComment(ikey,ikdesc);
 | 
|---|
 | 375 |   ikey="NPAQSUM";  ikdesc="Number of paquets summed";
 | 
|---|
 | 376 |   vismtx_.Info().SetI(ikey,nmean_);
 | 
|---|
 | 377 | }
 | 
|---|
 | 378 | 
 | 
|---|
 | 379 | 
 | 
|---|
 | 380 | /* --Methode-- */
 | 
|---|
| [3872] | 381 | int BRVisibilityCalculator::execute(int tid)
 | 
|---|
 | 382 | {
 | 
|---|
 | 383 |   vector<TwoByteComplex*>  pvpdata(2*memgr_.NbFibres());
 | 
|---|
 | 384 |   size_t paqsz=memgr_.PaqSize();
 | 
|---|
 | 385 |   BRPaquet ppaq(paqsz);
 | 
|---|
 | 386 | 
 | 
|---|
 | 387 |   sa_size_t fdelt = vismtx_.NCols()/nparthr_;
 | 
|---|
 | 388 |   sa_size_t fdeb = tid*fdelt;
 | 
|---|
 | 389 |   sa_size_t ffin = (tid+1)*fdelt;
 | 
|---|
 | 390 | 
 | 
|---|
 | 391 |   if (fdeb<1) fdeb=1;
 | 
|---|
 | 392 |   if ((ffin>vismtx_.NCols())||(tid==(nparthr_-1))) ffin=vismtx_.NCols();
 | 
|---|
 | 393 | 
 | 
|---|
 | 394 |   for(size_t jp=0; jp<memgr_.NbPaquets(); jp++) {   // boucle sur les paquets d'une zone  
 | 
|---|
 | 395 |     if (!fgallfibok[jp])  continue;
 | 
|---|
 | 396 |     for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++) {
 | 
|---|
 | 397 |       ppaq.Set(fbuff_[fib]+jp*paqsz);
 | 
|---|
 | 398 |       pvpdata[2*fib] = ppaq.Data1C();
 | 
|---|
 | 399 |       pvpdata[2*fib+1] = ppaq.Data2C();
 | 
|---|
 | 400 |     }
 | 
|---|
 | 401 |     sa_size_t k=0;
 | 
|---|
 | 402 |     for(size_t i=0; i<vpdata_.size(); i++) {
 | 
|---|
 | 403 |       for(size_t j=i; j<vpdata_.size(); j++) {
 | 
|---|
 | 404 |         size_t kpair=i*vpdata_.size()+j;
 | 
|---|
 | 405 |         if (kpair<pairst_)  continue;
 | 
|---|
 | 406 |         if (kpair>=(pairst_+nbpairs_))  break;
 | 
|---|
 | 407 |         TVector< complex<r_4> > vis = vismtx_.Row(k);   k++;
 | 
|---|
 | 408 |         for(sa_size_t f=fdeb; f<ffin; f++) {
 | 
|---|
 | 409 |           vis(f) += complex<r_4>((r_4)pvpdata[i][f].realB(), (r_4)pvpdata[i][f].imagB()) * 
 | 
|---|
 | 410 |             complex<r_4>((r_4)pvpdata[j][f].realB(), -(r_4)pvpdata[j][f].imagB());
 | 
|---|
 | 411 |         }
 | 
|---|
 | 412 |         nb_flop_ += (7.*(r_8)(ffin-fdeb));
 | 
|---|
 | 413 |       }
 | 
|---|
 | 414 |     }
 | 
|---|
 | 415 | 
 | 
|---|
 | 416 |   }  // Fin de boucle sur les paquets 
 | 
|---|
 | 417 |   
 | 
|---|
 | 418 |   return 0;
 | 
|---|
 | 419 | }
 | 
|---|
 | 420 | 
 | 
|---|
 | 421 | /* --Methode-- */
 | 
|---|
 | 422 | int BRVisibilityCalculator::FillVisibTable(double fcm, double ttm)
 | 
|---|
 | 423 | {
 | 
|---|
 | 424 |   double xnt[10];
 | 
|---|
 | 425 |   xnt[0]=fcm;  xnt[1]=ttm/1.25e8;
 | 
|---|
 | 426 | 
 | 
|---|
 | 427 |   if (djf_<2) {
 | 
|---|
 | 428 |     for(sa_size_t rv=0; rv<vismtx_.NRows(); rv++) {
 | 
|---|
 | 429 |       for(sa_size_t jf=jf1_; jf<jf2_; jf++) {
 | 
|---|
 | 430 |         xnt[2]=jf;
 | 
|---|
 | 431 |         xnt[3]=chanum_(rv+pairst_);
 | 
|---|
 | 432 |         xnt[4]=vismtx_(rv,jf).real()/(r_4)(nmean_);
 | 
|---|
 | 433 |         xnt[5]=vismtx_(rv,jf).imag()/(r_4)(nmean_);
 | 
|---|
 | 434 |         visdt_.AddRow(xnt);
 | 
|---|
 | 435 |       }
 | 
|---|
 | 436 |     }
 | 
|---|
 | 437 |   }
 | 
|---|
 | 438 |   else {
 | 
|---|
 | 439 |     for(sa_size_t rv=0; rv<vismtx_.NRows(); rv++) {
 | 
|---|
 | 440 |       for(sa_size_t jf=jf1_; jf<jf2_; jf+=djf_) {
 | 
|---|
 | 441 |         r_4 moyreal=0.;
 | 
|---|
 | 442 |         r_4 moyimag=0.;
 | 
|---|
 | 443 |         sa_size_t jjfmx=jf+djf_;
 | 
|---|
 | 444 |         if (jjfmx > vismtx_.NCols()) jjfmx=vismtx_.NCols();
 | 
|---|
 | 445 |         for(sa_size_t jjf=jf; jjf<jjfmx; jjf++) {
 | 
|---|
 | 446 |           moyreal+=vismtx_(rv,jjf).real();
 | 
|---|
 | 447 |           moyimag+=vismtx_(rv,jjf).imag();
 | 
|---|
 | 448 |         }
 | 
|---|
 | 449 |         xnt[2]=jf+djf_/2;
 | 
|---|
 | 450 |         xnt[3]=chanum_(rv+pairst_);
 | 
|---|
 | 451 |         xnt[4]=moyreal/(r_4)(nmean_*djf_);
 | 
|---|
 | 452 |         xnt[5]=moyimag/(r_4)(nmean_*djf_);
 | 
|---|
 | 453 |         visdt_.AddRow(xnt);
 | 
|---|
 | 454 |       }
 | 
|---|
 | 455 |     }
 | 
|---|
 | 456 |   }
 | 
|---|
 | 457 |   return 0;
 | 
|---|
 | 458 | }
 | 
|---|
 | 459 | 
 | 
|---|
 | 460 | /* --Methode-- */
 | 
|---|
 | 461 | int BRVisibilityCalculator::CheckTimeTag()
 | 
|---|
 | 462 | {
 | 
|---|
 | 463 |   if (totnbpaq_==0) {
 | 
|---|
 | 464 |     for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++)  {
 | 
|---|
 | 465 |       vlasttt_[fib]=ttfirst_[fib];
 | 
|---|
 | 466 |       if (ttmtx_.NCols()>0) {
 | 
|---|
 | 467 |         fcmtx_(fib,totnbpaq_) = curfc_[fib]; 
 | 
|---|
 | 468 |         ttmtx_(fib,totnbpaq_) = vlasttt_[fib]; 
 | 
|---|
 | 469 |       }
 | 
|---|
 | 470 |     }
 | 
|---|
 | 471 |     return 0;
 | 
|---|
 | 472 |   }
 | 
|---|
 | 473 |   for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++) {
 | 
|---|
 | 474 |     int_8 ld = (int_8)vpaq_[fib].TimeTag()-(int_8)vlasttt_[fib];
 | 
|---|
 | 475 |     int_8 fd = (int_8)vpaq_[fib].TimeTag()-(int_8)ttfirst_[fib]-(int_8)vpaq_[0].TimeTag()+(int_8)ttfirst_[0];
 | 
|---|
 | 476 |     /*    if ( (ld < mindeltatt_) || (fd<-5) || (fd>5)) { vbadtt_[fib]++; vnsamett_[fib]++; }
 | 
|---|
 | 477 |     else {
 | 
|---|
 | 478 |       if (fd!=0)  vnsamett_[fib]++;
 | 
|---|
 | 479 |     }
 | 
|---|
 | 480 |     */
 | 
|---|
 | 481 |     if  (ld < mindeltatt_) vbadtt_[fib]++;
 | 
|---|
 | 482 |     else {
 | 
|---|
 | 483 |       if (fd != 0)  vnsamett_[fib]++;
 | 
|---|
 | 484 |       if ((fd<-5)||(fd>5))  vndiff5tt_[fib]++;
 | 
|---|
 | 485 |     }
 | 
|---|
 | 486 |     vlasttt_[fib]=vpaq_[fib].TimeTag();
 | 
|---|
 | 487 |     if (totnbpaq_<ttmtx_.NCols()) {
 | 
|---|
 | 488 |       fcmtx_(fib,totnbpaq_) = curfc_[fib]; 
 | 
|---|
 | 489 |       ttmtx_(fib,totnbpaq_) = vlasttt_[fib]; 
 | 
|---|
 | 490 |     }
 | 
|---|
 | 491 |   }
 | 
|---|
 | 492 |   return 0;
 | 
|---|
 | 493 | }
 | 
|---|
 | 494 | 
 | 
|---|
 | 495 | //-------------------------------------------------------------------------------
 | 
|---|
 | 496 | // Classe Groupe (ensemble) de Calculateur de Visibilites, tournant en parallele
 | 
|---|
 | 497 | //-------------------------------------------------------------------------------
 | 
|---|
 | 498 | 
 | 
|---|
 | 499 | /* --Methode-- */
 | 
|---|
 | 500 | BRVisCalcGroup::BRVisCalcGroup(size_t nbcalc, RAcqMemZoneMgr& memgr, string outpath, uint_4 nmean, size_t nthr)
 | 
|---|
 | 501 |   : tm_(false)
 | 
|---|
 | 502 | {
 | 
|---|
 | 503 |   if ((nbcalc<1)||(nbcalc>6)) 
 | 
|---|
 | 504 |     throw ParmError("BRVisCalcGroup::BRVisCalcGroup NbCalc > 6 !");
 | 
|---|
 | 505 |   for(size_t i=0; i<nbcalc; i++) {
 | 
|---|
 | 506 |     BRVisibilityCalculator * viscp=new BRVisibilityCalculator(memgr, outpath, nmean, nthr);
 | 
|---|
 | 507 |     viscp->DefineRank(nbcalc, i);
 | 
|---|
 | 508 |     viscalcp_.push_back(viscp); 
 | 
|---|
 | 509 |   }
 | 
|---|
 | 510 | }
 | 
|---|
 | 511 | /* --Methode-- */
 | 
|---|
 | 512 | BRVisCalcGroup::~BRVisCalcGroup()
 | 
|---|
 | 513 | {
 | 
|---|
 | 514 |   for(size_t i=0; i<viscalcp_.size(); i++) 
 | 
|---|
 | 515 |     delete viscalcp_[i];
 | 
|---|
 | 516 | }
 | 
|---|
 | 517 | /* --Methode-- */
 | 
|---|
 | 518 | int BRVisCalcGroup::SelectFreqBinning(uint_4 freq1, uint_4 freq2, uint_4 nbfreq)
 | 
|---|
 | 519 | {
 | 
|---|
 | 520 |   int rc=0;
 | 
|---|
 | 521 |   for(size_t i=0; i<viscalcp_.size(); i++) 
 | 
|---|
 | 522 |     rc=viscalcp_[i]->SelectFreqBinning(freq1, freq2, nbfreq);
 | 
|---|
 | 523 |   return rc;
 | 
|---|
 | 524 | }
 | 
|---|
 | 525 | /* --Methode-- */
 | 
|---|
 | 526 | void BRVisCalcGroup::start()
 | 
|---|
 | 527 | {
 | 
|---|
 | 528 |   for(size_t i=0; i<viscalcp_.size(); i++) 
 | 
|---|
 | 529 |     viscalcp_[i]->start();
 | 
|---|
 | 530 |   tm_.SplitQ();
 | 
|---|
 | 531 | }
 | 
|---|
 | 532 | /* --Methode-- */
 | 
|---|
 | 533 | void BRVisCalcGroup::join()
 | 
|---|
 | 534 | {
 | 
|---|
 | 535 |   r_8 totflop=0.;
 | 
|---|
 | 536 |   for(size_t i=0; i<viscalcp_.size(); i++) {
 | 
|---|
 | 537 |     viscalcp_[i]->join();
 | 
|---|
 | 538 |     totflop += viscalcp_[i]->TotNbFLOP();
 | 
|---|
 | 539 |   }
 | 
|---|
 | 540 |   tm_.SplitQ();
 | 
|---|
 | 541 |   cout << "      ----------------------------------------------------------" << endl;
 | 
|---|
 | 542 |   cout << " BRVisCalcGroup::join() : Finished , Elaspsed time: " << tm_.PartialElapsedTimems() 
 | 
|---|
 | 543 |        << " ms (total:" << tm_.TotalElapsedTimems() << ")" << endl;
 | 
|---|
 | 544 |   cout << " ... TotalMegaFLOP= " << totflop/(1024.e3) << " @ " 
 | 
|---|
 | 545 |        << totflop/(r_8)tm_.PartialElapsedTimems()/(1024) << " MFLOP/s" << endl; 
 | 
|---|
 | 546 |   cout << "      ----------------------------------------------------------" << endl;
 | 
|---|
 | 547 |   return;
 | 
|---|
 | 548 | }
 | 
|---|