| [3635] | 1 | //----------------------------------------------------------------
 | 
|---|
| [3683] | 2 | // Projet BAORadio - (C) LAL/IRFU  2008-2010
 | 
|---|
 | 3 | // Classes de threads pour lecture fichiers fits BAORadio
 | 
|---|
| [3635] | 4 | //----------------------------------------------------------------
 | 
|---|
 | 5 | 
 | 
|---|
 | 6 | 
 | 
|---|
 | 7 | #include "brfitsrd.h"
 | 
|---|
 | 8 | 
 | 
|---|
 | 9 | #include <stdlib.h>
 | 
|---|
 | 10 | #include <unistd.h>
 | 
|---|
 | 11 | #include <fstream>
 | 
|---|
| [3683] | 12 | #include <exception>
 | 
|---|
 | 13 | 
 | 
|---|
| [3635] | 14 | #include "pexceptions.h"
 | 
|---|
 | 15 | #include "timestamp.h"
 | 
|---|
 | 16 | #include "ctimer.h"
 | 
|---|
 | 17 | 
 | 
|---|
 | 18 | #include "brpaqu.h"
 | 
|---|
 | 19 | 
 | 
|---|
 | 20 | #include "resusage.h" // Pour mesure temps elapsed/CPU ...
 | 
|---|
 | 21 | #include <sys/time.h>  // pour gettimeofday
 | 
|---|
 | 22 | 
 | 
|---|
| [3683] | 23 | using namespace SOPHYA;
 | 
|---|
 | 24 | 
 | 
|---|
 | 25 | //---------------------------------------------------------------------
 | 
|---|
 | 26 | // Classe thread de lecture de Multi-fibres de fichiers FITS BAORadio  
 | 
|---|
 | 27 | //---------------------------------------------------------------------
 | 
|---|
 | 28 | 
 | 
|---|
 | 29 | /* --Methode-- */
 | 
|---|
 | 30 | BRMultiFitsReader::BRMultiFitsReader(RAcqMemZoneMgr& mem, vector<string>& dirs, bool rdsamefc, 
 | 
|---|
 | 31 |                                      uint_4 imin, uint_4 imax, uint_4 istep)
 | 
|---|
| [3697] | 32 |   :  memgr_(mem), dirs_(dirs), stop_(false), rdsamefc_(rdsamefc), imin_(imin), imax_(imax), istep_(istep) 
 | 
|---|
| [3683] | 33 | {
 | 
|---|
 | 34 |   SetPrintLevel();
 | 
|---|
 | 35 |   totnbytesrd_ = 0;
 | 
|---|
 | 36 |   totsamefc_ = 0;
 | 
|---|
 | 37 |   if (memgr_.NbFibres() > MAXANAFIB) 
 | 
|---|
 | 38 |     throw BAORadioException("BRMultiFitsReader::BRMultiFitsReader/ NbFibres>MAXANAFIB "); 
 | 
|---|
 | 39 |   if (dirs_.size() != memgr_.NbFibres()) 
 | 
|---|
 | 40 |     throw BAORadioException("BRMultiFitsReader::BRMultiFitsReader/ NbFibres != Nb Data Directories"); 
 | 
|---|
 | 41 | 
 | 
|---|
 | 42 |   packsize_=memgr_.PaqSize();
 | 
|---|
 | 43 |   mid_=-2; 
 | 
|---|
 | 44 |   mmbuf_=NULL;
 | 
|---|
 | 45 |   max_targ_npaq = memgr_.NbPaquets();
 | 
|---|
 | 46 |   for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++) mmbufib_[fib]=NULL;
 | 
|---|
 | 47 | 
 | 
|---|
 | 48 |   char flnm[1024];
 | 
|---|
 | 49 |   for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++) {
 | 
|---|
 | 50 |     sprintf(flnm,"%s/signal%d.fits",dirs_[fib].c_str(),imin_);
 | 
|---|
 | 51 |     mff_[fib].Open(flnm, MF_Read);
 | 
|---|
 | 52 |     if (mff_[fib].NAxis1() != memgr_.PaqSize())  {
 | 
|---|
 | 53 |       cout << " BRMultiFitsReader::BRMultiFitsReader/ fib=" << fib << " File=" << flnm <<
 | 
|---|
 | 54 |         " NAxis1()= " << mff_[fib].NAxis1() << " <> PaqSize()=" << memgr_.PaqSize() << endl;
 | 
|---|
 | 55 |       throw BAORadioException("BRMultiFitsReader::BRMultiFitsReader/ mff.NAxis1() != memgr_.PaqSize() "); 
 | 
|---|
 | 56 |     }
 | 
|---|
| [3909] | 57 |     // Extraction de qques parametres utiles depuis les fichiers FITS 
 | 
|---|
 | 58 |     string fkvs;
 | 
|---|
 | 59 |     if (fib==0) {
 | 
|---|
 | 60 |       fkvs=mff_[fib].GetKeyValue("DATEOBS");
 | 
|---|
 | 61 |       if (fkvs.length()>0) { 
 | 
|---|
 | 62 |         cdateobs_.Set(fkvs);
 | 
|---|
 | 63 |         cout << " BRMultiFitsReader/First file (for fiber 0) DATEOBS=" << fkvs << endl;
 | 
|---|
 | 64 |       }
 | 
|---|
 | 65 |     }
 | 
|---|
 | 66 |     fkvs=mff_[fib].GetKeyValue("DATEOBS");
 | 
|---|
 | 67 |     memgr_.FiberId(fib) = atoi( fkvs.c_str() );
 | 
|---|
 | 68 | 
 | 
|---|
| [3683] | 69 |     vfilenum_.push_back(imin_);
 | 
|---|
 | 70 |     vfpos_.push_back(0);
 | 
|---|
 | 71 |     vpaq_.push_back(BRPaquet(NULL,memgr_.PaqSize()));
 | 
|---|
 | 72 |     vpchk_.push_back(BRPaqChecker(true,0)); 
 | 
|---|
 | 73 |     curfc_.push_back(0);
 | 
|---|
 | 74 |     totnpqrd_.push_back(0);
 | 
|---|
 | 75 |     totnpqok_.push_back(0);    
 | 
|---|
 | 76 |   }
 | 
|---|
 | 77 | }
 | 
|---|
 | 78 | 
 | 
|---|
 | 79 | 
 | 
|---|
 | 80 | /* --Methode-- */
 | 
|---|
 | 81 | void BRMultiFitsReader::run()
 | 
|---|
 | 82 | {
 | 
|---|
 | 83 |   setRC(1); 
 | 
|---|
 | 84 |   try {
 | 
|---|
 | 85 |     TimeStamp ts; 
 | 
|---|
 | 86 |     Timer tm("BRMultiFitsReader", false);
 | 
|---|
 | 87 |     cout << " BRMultiFitsReader::run() - Starting " << ts << " NbFibres()=" << memgr_.NbFibres()
 | 
|---|
 | 88 |          << "  PaqSize() = " << memgr_.PaqSize() << endl;
 | 
|---|
 | 89 |     cout << " ...ReadMode: " << ((rdsamefc_)?"Paquets With SameFrameCounter":"All OK paquets") 
 | 
|---|
 | 90 |          << " signalII.fits IMin=" << imin_ << " IMax=" << imax_ << " IStep=" << istep_ << endl;
 | 
|---|
 | 91 | 
 | 
|---|
| [3883] | 92 |     uint_8  prtcnt=0;
 | 
|---|
| [3683] | 93 |     Byte* nextpaq=NULL;
 | 
|---|
 | 94 |     bool fgok=true;
 | 
|---|
 | 95 |     while (fgok) {
 | 
|---|
 | 96 |       if (stop_) break;
 | 
|---|
 | 97 |       if ( MoveToNextTarget() ) {
 | 
|---|
 | 98 |         cout << "BRMultiFitsReader::run()/Error-A- MoveToNextTarget() returned true ->STOP 9" << endl;
 | 
|---|
 | 99 |         setRC(7);  fgok=false;  break;
 | 
|---|
 | 100 |       }
 | 
|---|
 | 101 |       for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++) {
 | 
|---|
 | 102 |         nextpaq=GetPaquetTarget(fib);
 | 
|---|
 | 103 |         if (nextpaq == NULL) { // Cela ne devrait pas arriver 
 | 
|---|
 | 104 |           cout << "BRMultiFitsReader::run()/Error-A2- GetPaquetTarget(fib)  returned NULL ->STOP 9" << endl;
 | 
|---|
 | 105 |           setRC(9);  fgok=false;  break;
 | 
|---|
 | 106 |         }
 | 
|---|
 | 107 |         vpaq_[fib].Set(nextpaq);
 | 
|---|
 | 108 |       }
 | 
|---|
 | 109 |       if (ReadNextAllFibers()) { fgok=false;  break; }
 | 
|---|
| [3883] | 110 |       prtcnt++;
 | 
|---|
 | 111 |       if ((prtlev_>0)&&(prtcnt%prtmodulo_==0))  {
 | 
|---|
 | 112 |           cout << "BRMultiFitsReader: NbPaqMFRead=" << prtcnt << " NSameFC=" 
 | 
|---|
 | 113 |                << totsamefc_ << " / NPaqFib0Read=" << totnpqrd_[0] 
 | 
|---|
 | 114 |                << " FracSameFC=" << 100*totsamefc_/totnpqrd_[0] << " %" <<  endl;
 | 
|---|
 | 115 |       }
 | 
|---|
| [3683] | 116 |     }
 | 
|---|
 | 117 | 
 | 
|---|
 | 118 |     MoveToNextTarget();  // Pour faire traiter le dernier paquet si plein 
 | 
|---|
 | 119 |     MZoneManage(true);   // Nettoyage final 
 | 
|---|
 | 120 | 
 | 
|---|
 | 121 |     cout << " ------------------  BRMultiFitsReader::run() END ----------------- " << endl;
 | 
|---|
 | 122 |     ts.SetNow();
 | 
|---|
 | 123 |     tm.SplitQ();
 | 
|---|
| [3883] | 124 |     cout << "BRMultiFitsReader::run():  END reading : " << ts << endl;
 | 
|---|
 | 125 |     cout << "... NbPaqMFRead=" << prtcnt << " NSameFC=" 
 | 
|---|
 | 126 |          << totsamefc_ << " / NPaqFib0Read=" << totnpqrd_[0] 
 | 
|---|
 | 127 |          << " FracSameFC=" << 100*totsamefc_/totnpqrd_[0] << " %" << endl;
 | 
|---|
 | 128 | 
 | 
|---|
| [3683] | 129 |     for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++)  {
 | 
|---|
 | 130 |       int perc=0;
 | 
|---|
 | 131 |       if (totnpqrd_[fib]>0) perc=100*totsamefc_/totnpqrd_[fib];
 | 
|---|
 | 132 |       cout << " Fiber" << fib << " TotNPaqRd=" << totnpqrd_[fib] << " TotNPaqOK=" << totnpqok_[fib] 
 | 
|---|
 | 133 |            << " FracSameFC=" << perc << " %" << endl;
 | 
|---|
| [3699] | 134 |       if (prtlev_ > 0)  vpchk_[fib].Print(cout);
 | 
|---|
| [3683] | 135 |     }
 | 
|---|
 | 136 |     cout << "  TotalDiskRead= " << totnbytesrd_/(1024*1024) << " MBytes Disk-Read rate= " 
 | 
|---|
 | 137 |          << (double)(totnbytesrd_)/1024./tm.PartialElapsedTimems() << " MB/s" << endl;    
 | 
|---|
 | 138 |     cout << " BRMultiFitsReader::run()/Timing: \n"; 
 | 
|---|
 | 139 |     tm.Print();
 | 
|---|
 | 140 |     cout << " ---------------------------------------------------------- " << endl;
 | 
|---|
 | 141 | 
 | 
|---|
| [3883] | 142 |     usleep(50000);       // Attente de traitement du dernier paquet
 | 
|---|
 | 143 |     memgr_.Stop();        // Arret 
 | 
|---|
 | 144 | 
 | 
|---|
| [3683] | 145 |   }  // Fin du bloc try 
 | 
|---|
 | 146 |   catch (std::exception& exc) {
 | 
|---|
 | 147 |     cout << " BRMultiFitsReader::run()/catched execption msg=  " << exc.what() << endl;
 | 
|---|
 | 148 |     setRC(3);   
 | 
|---|
 | 149 |     return; 
 | 
|---|
 | 150 |   }
 | 
|---|
 | 151 |   catch(...) {
 | 
|---|
 | 152 |     cout << " BRMultiFitsReader::run()/catched unknown ... exception " << endl;
 | 
|---|
 | 153 |     setRC(4);   
 | 
|---|
 | 154 |     return; 
 | 
|---|
 | 155 |   }
 | 
|---|
 | 156 |   setRC(0);
 | 
|---|
 | 157 |   return;
 | 
|---|
 | 158 | }
 | 
|---|
 | 159 | 
 | 
|---|
 | 160 | /* --Methode-- */
 | 
|---|
 | 161 | bool BRMultiFitsReader::ReadNextAllFibers()
 | 
|---|
 | 162 | {
 | 
|---|
 | 163 |   for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++)  {
 | 
|---|
 | 164 |     if (ReadNext(fib)) return true;  // probleme 
 | 
|---|
 | 165 |   }
 | 
|---|
| [3883] | 166 |   if (!rdsamefc_ || (memgr_.NbFibres()<2))  {
 | 
|---|
 | 167 |     uint_8 cfc=curfc_[0];
 | 
|---|
 | 168 |     bool fgsamefc=true;
 | 
|---|
 | 169 |     for(size_t fib=1; fib<memgr_.NbFibres(); fib++) {
 | 
|---|
 | 170 |       if (curfc_[fib]!=cfc)   fgsamefc=false;
 | 
|---|
| [3683] | 171 |     }
 | 
|---|
| [3883] | 172 |     if (fgsamefc)  totsamefc_++;  
 | 
|---|
 | 173 |     return false;  // c'est OK 
 | 
|---|
| [3683] | 174 |   }
 | 
|---|
| [3883] | 175 |   //  On va essayer de lire jusqu'a avoir same_frame_counter 
 | 
|---|
 | 176 |   bool echec=true;
 | 
|---|
 | 177 |   while (echec) {
 | 
|---|
 | 178 |     uint_8 cfc=curfc_[0];
 | 
|---|
 | 179 |     bool fgsamefc=true;
 | 
|---|
 | 180 |     for(size_t fib=1; fib<memgr_.NbFibres(); fib++) {
 | 
|---|
 | 181 |       if (curfc_[fib]!=cfc) {
 | 
|---|
 | 182 |         fgsamefc=false;
 | 
|---|
 | 183 |         if (curfc_[fib] > cfc)  cfc=curfc_[fib]; 
 | 
|---|
| [3683] | 184 |       }
 | 
|---|
 | 185 |     }
 | 
|---|
| [3883] | 186 |     if (fgsamefc) { 
 | 
|---|
 | 187 |       totsamefc_++;  echec=false; return false;  // c'est OK  , same framecounter
 | 
|---|
 | 188 |     }
 | 
|---|
 | 189 |     else {  // else !fgsame
 | 
|---|
 | 190 |       for(uint_4 fib=0; fib<memgr_.NbFibres(); fib++) {
 | 
|---|
 | 191 |         while (curfc_[fib]<cfc) {
 | 
|---|
 | 192 |           if (ReadNext(fib)) return true;  // probleme 
 | 
|---|
 | 193 |         }
 | 
|---|
 | 194 |       }
 | 
|---|
 | 195 |     }   // fin de  else !fgsame 
 | 
|---|
 | 196 |   }  // fin de while(echec): lecture jusqu'a same_frame_counter 
 | 
|---|
 | 197 | 
 | 
|---|
 | 198 |   return true; // probleme 
 | 
|---|
| [3683] | 199 | }
 | 
|---|
 | 200 | 
 | 
|---|
 | 201 | /* --Methode-- */
 | 
|---|
 | 202 | bool BRMultiFitsReader::ReadNext(int fib)
 | 
|---|
 | 203 | {
 | 
|---|
 | 204 |   if (!mff_[fib].IsOpen())  return true;
 | 
|---|
 | 205 |   bool fggood=false;
 | 
|---|
 | 206 |   while(!fggood) { 
 | 
|---|
 | 207 |     if (vfpos_[fib] >= mff_[fib].NAxis2()) {
 | 
|---|
 | 208 |       mff_[fib].Close();
 | 
|---|
 | 209 |       vfilenum_[fib]++;
 | 
|---|
 | 210 |       if (vfilenum_[fib]>imax_)  return true;
 | 
|---|
 | 211 |       char flnm[1024];
 | 
|---|
| [3700] | 212 |       sprintf(flnm,"%s/signal%d.fits",dirs_[fib].c_str(),vfilenum_[fib]);
 | 
|---|
| [3699] | 213 |       if (prtlev_ > 1)
 | 
|---|
| [3683] | 214 |         cout << " BRMultiFitsReader::ReadNext() opening" << flnm << endl;
 | 
|---|
 | 215 |       mff_[fib].Open(flnm, MF_Read);
 | 
|---|
 | 216 |       if (mff_[fib].NAxis1() != packsize_)  {
 | 
|---|
 | 217 |         cout << " BRMultiFitsReader::ReadNext(fib=" << fib << " File=" << flnm <<
 | 
|---|
 | 218 |           " NAxis1()= " << mff_[fib].NAxis1() << " <> PaqSize()=" << packsize_ << endl;
 | 
|---|
 | 219 |         throw BAORadioException("BRMultiFitsReader::ReadNext()/ mff.NAxis1() != memgr_.PaqSize() "); 
 | 
|---|
 | 220 |       }
 | 
|---|
| [3909] | 221 |       if (fib==0) {  // updating current date from file (fiber 0) 
 | 
|---|
 | 222 |         string fkvs=mff_[fib].GetKeyValue("DATEOBS");
 | 
|---|
 | 223 |         if (fkvs.length()>0)  cdateobs_.Set(fkvs);
 | 
|---|
 | 224 |       } 
 | 
|---|
| [3683] | 225 |       vfpos_[fib]=0;
 | 
|---|
 | 226 |     }
 | 
|---|
 | 227 |     mff_[fib].ReadB(vpaq_[fib].Begin(), packsize_, vfpos_[fib]*packsize_);
 | 
|---|
 | 228 |     vfpos_[fib]++;
 | 
|---|
 | 229 |     totnbytesrd_+=packsize_;
 | 
|---|
 | 230 |     totnpqrd_[fib]++;
 | 
|---|
 | 231 |     fggood = vpchk_[fib].Check(vpaq_[fib],curfc_[fib]);
 | 
|---|
 | 232 |   }
 | 
|---|
 | 233 |   totnpqok_[fib]++;
 | 
|---|
 | 234 |   return false;
 | 
|---|
 | 235 | }
 | 
|---|
 | 236 | 
 | 
|---|
 | 237 | /* --Methode-- */
 | 
|---|
 | 238 | bool BRMultiFitsReader::MZoneManage(bool fgclean)    // Retourne true si probleme 
 | 
|---|
 | 239 | {
 | 
|---|
 | 240 |   /* Pour debug 
 | 
|---|
 | 241 |   cout << " BRMultiFitsReader::MZoneManage() mid_=" << mid_ << " arg_npaq_= " << targ_npaq_  
 | 
|---|
 | 242 |        << " max_targ_npaq=" << max_targ_npaq << endl;
 | 
|---|
 | 243 |   */
 | 
|---|
 | 244 |   if (mid_ >= 0)  { 
 | 
|---|
 | 245 |     if (fgclean) memgr_.FreeMemZone(mid_, MemZS_Free);    
 | 
|---|
| [3686] | 246 |     else memgr_.FreeMemZone(mid_, MemZS_Filled);
 | 
|---|
| [3683] | 247 |   }
 | 
|---|
 | 248 |   mmbuf_ = NULL;  targ_npaq_ = 0;  mid_ = -2;
 | 
|---|
 | 249 |   for (int fib=0;fib<(int)memgr_.NbFibres() ;fib++) mmbufib_[fib]=NULL;
 | 
|---|
 | 250 |   if (fgclean)  return false;
 | 
|---|
 | 251 |   mid_ = memgr_.FindMemZoneId(MemZA_Fill);
 | 
|---|
 | 252 |   mmbuf_ = memgr_.GetMemZone(mid_);
 | 
|---|
 | 253 |   if (mmbuf_==NULL)   return true;
 | 
|---|
 | 254 |   for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++)
 | 
|---|
 | 255 |     mmbufib_[fib]=memgr_.GetMemZone(mid_,fib);
 | 
|---|
 | 256 |   return false;
 | 
|---|
 | 257 | }
 | 
|---|
 | 258 | 
 | 
|---|
| [3635] | 259 | //-------------------------------------------------------
 | 
|---|
| [3683] | 260 | // Classe thread de lecture de fichiers fits BAORadio 
 | 
|---|
| [3635] | 261 | //-------------------------------------------------------
 | 
|---|
 | 262 | 
 | 
|---|
| [3683] | 263 | /* --Methode-- */
 | 
|---|
| [3635] | 264 | BRFitsReader::BRFitsReader(RAcqMemZoneMgr& mem, vector<string>& infiles, bool fgnotrl)
 | 
|---|
 | 265 |   :  memgr(mem), infiles_(infiles), fgnotrl_(fgnotrl)
 | 
|---|
 | 266 | {
 | 
|---|
 | 267 | }
 | 
|---|
| [3683] | 268 | 
 | 
|---|
 | 269 | /* --Methode-- */
 | 
|---|
| [3635] | 270 | void BRFitsReader::run()
 | 
|---|
 | 271 | {
 | 
|---|
 | 272 |   setRC(1);     
 | 
|---|
 | 273 | 
 | 
|---|
 | 274 |   try {
 | 
|---|
 | 275 |     TimeStamp ts; 
 | 
|---|
| [3640] | 276 |     Timer tm("BRFitsReader", false);
 | 
|---|
| [3646] | 277 |     BRPaqChecker pcheck(!fgnotrl_);  // Verification/comptage des paquets 
 | 
|---|
| [3640] | 278 |     
 | 
|---|
| [3635] | 279 |     size_t totnbytesrd = 0;
 | 
|---|
 | 280 |     cout << " BRFitsReader::run() - Starting " << ts << " NbFiles=" << infiles_.size() 
 | 
|---|
 | 281 |          << "  memgr.PaqSize() = " << memgr.PaqSize() << endl;
 | 
|---|
 | 282 | 
 | 
|---|
 | 283 |     uint_4  nfileok = 0; 
 | 
|---|
 | 284 |     uint_8 nbytesrd = 0;  
 | 
|---|
| [3640] | 285 |     /*  Variables pour la logique des zones memoire et numeros de paquets dans la zone memoire */
 | 
|---|
 | 286 |     int mid = -2;
 | 
|---|
 | 287 |     Byte* buff = NULL;  
 | 
|---|
 | 288 |     int kmp = 0;   
 | 
|---|
 | 289 |     int kmpmax=memgr.NbPaquets(); 
 | 
|---|
 | 290 | 
 | 
|---|
 | 291 |     int paqsz = 0;
 | 
|---|
| [3635] | 292 |     for(int ifile=0; ifile<infiles_.size(); ifile++) {
 | 
|---|
 | 293 |       string ffname = infiles_[ifile];
 | 
|---|
 | 294 | // -------------- Lecture de bytes      
 | 
|---|
 | 295 |       cout << "BRFitsReader::run() [" << ifile <<"]Ouverture/lecture fichier " << ffname << endl;
 | 
|---|
 | 296 |       MiniFITSFile mff(ffname, MF_Read);
 | 
|---|
 | 297 |       cout << "... Type=" << mff.DataTypeToString() << " NAxis1=" << mff.NAxis1() 
 | 
|---|
 | 298 |            << " NAxis2=" << mff.NAxis2() << endl;
 | 
|---|
 | 299 |       if (mff.DataType() != MF_Byte) {
 | 
|---|
 | 300 |         cout << "BRFitsReader::run() PB : DataType!=MF_Byte --> skipping " << endl;
 | 
|---|
 | 301 |         continue;
 | 
|---|
 | 302 |       }
 | 
|---|
 | 303 | // Les fichier FITS contiennent l'entet (24 bytes), mais pas le trailer (16 bytes) si fgnotrl=true
 | 
|---|
 | 304 |       int incpaqsz=0;
 | 
|---|
 | 305 |       if (fgnotrl_) {
 | 
|---|
 | 306 |         incpaqsz=16;
 | 
|---|
| [3646] | 307 |         if (ifile==0) cout << " Warning : FITS files without frame trailers ..." << endl;
 | 
|---|
| [3635] | 308 |       }
 | 
|---|
| [3640] | 309 |       if (paqsz == 0)  {  // premier passage, on fixe la taille de paquet et on verifie compatibilite avec memgr
 | 
|---|
| [3635] | 310 |         paqsz = mff.NAxis1()+incpaqsz;
 | 
|---|
 | 311 |         if (paqsz != memgr.PaqSize()) {
 | 
|---|
 | 312 |          cout << "BRFitsReader::run() mff.NAxis1() incompatible with memgr.PaqSize() -> exception " << endl;
 | 
|---|
 | 313 |          throw SzMismatchError(" fits file size incompatible with memgr.PaqSize()"); 
 | 
|---|
 | 314 |         }
 | 
|---|
 | 315 |       }
 | 
|---|
 | 316 |       else {
 | 
|---|
 | 317 |         if (paqsz != mff.NAxis1()+incpaqsz) {
 | 
|---|
 | 318 |         cout << " PB : paqsz=" << paqsz << " != mff.NAxis1()+" << incpaqsz << " --> skipping " << endl;
 | 
|---|
 | 319 |         continue;
 | 
|---|
 | 320 |         }
 | 
|---|
| [3640] | 321 |       }   
 | 
|---|
 | 322 |       if (mid < 0) {
 | 
|---|
 | 323 |         mid = memgr.FindMemZoneId(MemZA_Fill);  
 | 
|---|
 | 324 |         buff = memgr.GetMemZone(mid);
 | 
|---|
 | 325 |         if (buff == NULL) {
 | 
|---|
 | 326 |               cout << " BRFitsReader::run()/ERROR memgr.GetMemZone(" << mid << ") -> NULL" << endl;
 | 
|---|
 | 327 |               setRC(2); 
 | 
|---|
 | 328 |                return;  
 | 
|---|
 | 329 |          }
 | 
|---|
 | 330 |          kmp=0;
 | 
|---|
| [3635] | 331 |       }
 | 
|---|
 | 332 |       size_t sx = mff.NAxis1(); 
 | 
|---|
| [3640] | 333 |       size_t sy = mff.NAxis2();      
 | 
|---|
 | 334 |       int nprt=0;
 | 
|---|
 | 335 |       for(int j=0; j<sy; j++) {
 | 
|---|
 | 336 |         mff.ReadB(buff+kmp*paqsz, sx, j*sx);
 | 
|---|
 | 337 |         BRPaquet paq(NULL, buff+kmp*paqsz, paqsz);
 | 
|---|
 | 338 |         bool pqok = pcheck.Check(paq);   // Verification du paquet / FrameCounter
 | 
|---|
 | 339 |         if (!pqok && (nprt < 10)) {
 | 
|---|
 | 340 |           cout << "--BUG-- i=" << ifile << " mid=" << mid << " j=" << j << " kmp=" << kmp 
 | 
|---|
 | 341 |                << " paqsz=" << paqsz << endl;
 | 
|---|
 | 342 |           nprt++; 
 | 
|---|
 | 343 |           paq.Print();  
 | 
|---|
 | 344 |         }
 | 
|---|
 | 345 |         kmp++;
 | 
|---|
 | 346 |         if (kmp >= kmpmax)  {   // Zone memoire rempli !
 | 
|---|
 | 347 |           memgr.FreeMemZone(mid, MemZS_Filled);
 | 
|---|
 | 348 |               mid = -2;
 | 
|---|
 | 349 |           if (j<sy) { 
 | 
|---|
 | 350 |             mid = memgr.FindMemZoneId(MemZA_Fill);  
 | 
|---|
 | 351 |             buff = memgr.GetMemZone(mid);
 | 
|---|
 | 352 |             if (buff == NULL) {
 | 
|---|
 | 353 |                   cout << " BRFitsReader::run()/ERROR memgr.GetMemZone(" << mid << ") -> NULL" << endl;
 | 
|---|
 | 354 |                   setRC(2);     
 | 
|---|
 | 355 |                    return;      
 | 
|---|
 | 356 |              }
 | 
|---|
 | 357 |              kmp=0;
 | 
|---|
 | 358 |           }
 | 
|---|
 | 359 |         } 
 | 
|---|
| [3635] | 360 |       }
 | 
|---|
 | 361 |       nfileok++;   
 | 
|---|
 | 362 |       size_t nbytesrd = sx*sy;
 | 
|---|
 | 363 |       totnbytesrd += nbytesrd;
 | 
|---|
| [3640] | 364 |     }   // Fin de la boucle sur les fichiers
 | 
|---|
 | 365 | // Gestion d'une zone partiellement remplie
 | 
|---|
 | 366 |     if (mid>=0) {
 | 
|---|
 | 367 |       for(int k=kmp;k<kmpmax;k++) {
 | 
|---|
 | 368 |         Byte* bp=buff+k*paqsz;
 | 
|---|
 | 369 |         for(int l=0;l<paqsz;l++) bp[l]=0;
 | 
|---|
 | 370 |       }
 | 
|---|
| [3635] | 371 |       memgr.FreeMemZone(mid, MemZS_Filled);
 | 
|---|
| [3640] | 372 |     }
 | 
|---|
| [3635] | 373 | 
 | 
|---|
 | 374 | //    sprintf(fname,"%s/.log",path_.c_str());
 | 
|---|
 | 375 | //    ofstream filog(fname);
 | 
|---|
 | 376 | //    filog << " DataProc::run() - starting log file " << ts << endl;                  
 | 
|---|
 | 377 | //    filog << " NbFiles=" << nfiles_ << " NBloc/File="  << nblocperfile_ << " NMaxMemZones=" << nmax_ << endl;
 | 
|---|
 | 378 |         
 | 
|---|
 | 379 | 
 | 
|---|
 | 380 | 
 | 
|---|
 | 381 |     cout << " ------------------  BRFitsReader::run() END ----------------- " << endl;
 | 
|---|
 | 382 |     ts.SetNow();
 | 
|---|
| [3640] | 383 |     tm.SplitQ();
 | 
|---|
| [3635] | 384 |     cout << "  END reading " << ts << " NFileOK=" << nfileok << endl; 
 | 
|---|
 | 385 |     cout << "  TotalDiskRead= " << totnbytesrd/(1024*1024) << " MBytes Disk-Read rate= " 
 | 
|---|
 | 386 |          << (double)(totnbytesrd)/1024./tm.PartialElapsedTimems() << " MB/s" << endl;    
 | 
|---|
 | 387 |     pcheck.Print(cout);
 | 
|---|
| [3640] | 388 |     cout << " BRFitsReader::run()/Timing: \n"; 
 | 
|---|
 | 389 |     tm.Print();
 | 
|---|
| [3635] | 390 |     cout << " ---------------------------------------------------------- " << endl;
 | 
|---|
 | 391 | 
 | 
|---|
 | 392 |   }  // Fin du bloc try 
 | 
|---|
 | 393 |   catch (MiniFITSException& exc) {
 | 
|---|
 | 394 |     cout << " BRFitsReader::run()/catched MiniFITSException " << exc.Msg() << endl;
 | 
|---|
 | 395 |     setRC(3);   
 | 
|---|
 | 396 |     return; 
 | 
|---|
 | 397 |   }
 | 
|---|
 | 398 |   catch(...) {
 | 
|---|
 | 399 |     cout << " BRFitsReader::run()/catched unknown ... exception " << endl;
 | 
|---|
 | 400 |     setRC(4);   
 | 
|---|
 | 401 |     return; 
 | 
|---|
 | 402 |   }
 | 
|---|
 | 403 |   setRC(0);
 | 
|---|
 | 404 |   return;
 | 
|---|
 | 405 | }   
 | 
|---|