Changeset 3683 in Sophya for trunk/AddOn/TAcq/brfitsrd.cc
- Timestamp:
- Nov 27, 2009, 11:32:46 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/AddOn/TAcq/brfitsrd.cc
r3646 r3683 1 1 //---------------------------------------------------------------- 2 // ---- classes de threads pour lecture fichiers minifits3 // LAL - R. Ansari - Mai 20092 // Projet BAORadio - (C) LAL/IRFU 2008-2010 3 // Classes de threads pour lecture fichiers fits BAORadio 4 4 //---------------------------------------------------------------- 5 5 … … 10 10 #include <unistd.h> 11 11 #include <fstream> 12 #include <signal.h> 12 #include <exception> 13 13 14 #include "pexceptions.h" 14 15 #include "timestamp.h" … … 16 17 17 18 #include "brpaqu.h" 18 #include "minifits.h"19 19 20 20 #include "resusage.h" // Pour mesure temps elapsed/CPU ... 21 #include "datatable.h" // Pour sauver les entetes de paquet22 21 #include <sys/time.h> // pour gettimeofday 23 22 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) 32 : memgr_(mem), dirs_(dirs), rdsamefc_(rdsamefc), imin_(imin), imax_(imax), istep_(istep) 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 } 57 vfilenum_.push_back(imin_); 58 vfpos_.push_back(0); 59 vpaq_.push_back(BRPaquet(NULL,memgr_.PaqSize())); 60 vpchk_.push_back(BRPaqChecker(true,0)); 61 curfc_.push_back(0); 62 totnpqrd_.push_back(0); 63 totnpqok_.push_back(0); 64 } 65 } 66 67 68 /* --Methode-- */ 69 void BRMultiFitsReader::run() 70 { 71 setRC(1); 72 try { 73 TimeStamp ts; 74 Timer tm("BRMultiFitsReader", false); 75 cout << " BRMultiFitsReader::run() - Starting " << ts << " NbFibres()=" << memgr_.NbFibres() 76 << " PaqSize() = " << memgr_.PaqSize() << endl; 77 cout << " ...ReadMode: " << ((rdsamefc_)?"Paquets With SameFrameCounter":"All OK paquets") 78 << " signalII.fits IMin=" << imin_ << " IMax=" << imax_ << " IStep=" << istep_ << endl; 79 80 Byte* nextpaq=NULL; 81 bool fgok=true; 82 while (fgok) { 83 if (stop_) break; 84 if ( MoveToNextTarget() ) { 85 cout << "BRMultiFitsReader::run()/Error-A- MoveToNextTarget() returned true ->STOP 9" << endl; 86 setRC(7); fgok=false; break; 87 } 88 for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++) { 89 nextpaq=GetPaquetTarget(fib); 90 if (nextpaq == NULL) { // Cela ne devrait pas arriver 91 cout << "BRMultiFitsReader::run()/Error-A2- GetPaquetTarget(fib) returned NULL ->STOP 9" << endl; 92 setRC(9); fgok=false; break; 93 } 94 vpaq_[fib].Set(nextpaq); 95 } 96 if (ReadNextAllFibers()) { fgok=false; break; } 97 } 98 99 MoveToNextTarget(); // Pour faire traiter le dernier paquet si plein 100 MZoneManage(true); // Nettoyage final 101 usleep(50000); // Attente de traitement du dernier paquet 102 memgr_.Stop(); // Arret 103 104 cout << " ------------------ BRMultiFitsReader::run() END ----------------- " << endl; 105 ts.SetNow(); 106 tm.SplitQ(); 107 cout << " END reading : " << ts ; 108 if (rdsamefc_) cout << " NSameFC=" << totsamefc_ << endl; 109 else cout << endl; 110 for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++) { 111 int perc=0; 112 if (totnpqrd_[fib]>0) perc=100*totsamefc_/totnpqrd_[fib]; 113 cout << " Fiber" << fib << " TotNPaqRd=" << totnpqrd_[fib] << " TotNPaqOK=" << totnpqok_[fib] 114 << " FracSameFC=" << perc << " %" << endl; 115 } 116 cout << " TotalDiskRead= " << totnbytesrd_/(1024*1024) << " MBytes Disk-Read rate= " 117 << (double)(totnbytesrd_)/1024./tm.PartialElapsedTimems() << " MB/s" << endl; 118 cout << " BRMultiFitsReader::run()/Timing: \n"; 119 tm.Print(); 120 cout << " ---------------------------------------------------------- " << endl; 121 122 } // Fin du bloc try 123 catch (std::exception& exc) { 124 cout << " BRMultiFitsReader::run()/catched execption msg= " << exc.what() << endl; 125 setRC(3); 126 return; 127 } 128 catch(...) { 129 cout << " BRMultiFitsReader::run()/catched unknown ... exception " << endl; 130 setRC(4); 131 return; 132 } 133 setRC(0); 134 return; 135 } 136 137 /* --Methode-- */ 138 bool BRMultiFitsReader::ReadNextAllFibers() 139 { 140 for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++) { 141 if (ReadNext(fib)) return true; // probleme 142 } 143 if (!rdsamefc_ || (memgr_.NbFibres()<2)) { 144 totsamefc_++; return false; // c'est OK 145 } 146 uint_8 cfc=curfc_[0]; 147 bool fgsamefc=true; 148 for(size_t fib=1; fib<memgr_.NbFibres(); fib++) { 149 if (curfc_[fib]!=cfc) { 150 fgsamefc=false; 151 if (curfc_[fib] > cfc) cfc=curfc_[fib]; 152 } 153 } 154 if (fgsamefc) { 155 totsamefc_++; return false; // c'est OK , same framecounter 156 } 157 else { // else !fgsame 158 for(uint_4 fib=0; fib<memgr_.NbFibres(); fib++) { 159 while (curfc_[fib]<cfc) { 160 if (ReadNext(fib)) return true; // probleme 161 } 162 } 163 } // fin de else !fgsame 164 totsamefc_++; 165 return false; // c'est OK 166 } 167 168 /* --Methode-- */ 169 bool BRMultiFitsReader::ReadNext(int fib) 170 { 171 if (!mff_[fib].IsOpen()) return true; 172 bool fggood=false; 173 while(!fggood) { 174 if (vfpos_[fib] >= mff_[fib].NAxis2()) { 175 mff_[fib].Close(); 176 vfilenum_[fib]++; 177 if (vfilenum_[fib]>imax_) return true; 178 char flnm[1024]; 179 sprintf(flnm,"%s/signal%d.fits",dirs_[fib].c_str(),vfilenum_[fib]++); 180 if (prtlev_ > 0) 181 cout << " BRMultiFitsReader::ReadNext() opening" << flnm << endl; 182 mff_[fib].Open(flnm, MF_Read); 183 if (mff_[fib].NAxis1() != packsize_) { 184 cout << " BRMultiFitsReader::ReadNext(fib=" << fib << " File=" << flnm << 185 " NAxis1()= " << mff_[fib].NAxis1() << " <> PaqSize()=" << packsize_ << endl; 186 throw BAORadioException("BRMultiFitsReader::ReadNext()/ mff.NAxis1() != memgr_.PaqSize() "); 187 } 188 vfpos_[fib]=0; 189 } 190 mff_[fib].ReadB(vpaq_[fib].Begin(), packsize_, vfpos_[fib]*packsize_); 191 vfpos_[fib]++; 192 totnbytesrd_+=packsize_; 193 totnpqrd_[fib]++; 194 fggood = vpchk_[fib].Check(vpaq_[fib],curfc_[fib]); 195 } 196 totnpqok_[fib]++; 197 return false; 198 } 199 200 /* --Methode-- */ 201 bool BRMultiFitsReader::MZoneManage(bool fgclean) // Retourne true si probleme 202 { 203 /* Pour debug 204 cout << " BRMultiFitsReader::MZoneManage() mid_=" << mid_ << " arg_npaq_= " << targ_npaq_ 205 << " max_targ_npaq=" << max_targ_npaq << endl; 206 */ 207 if (mid_ >= 0) { 208 if (fgclean) memgr_.FreeMemZone(mid_, MemZS_Free); 209 memgr_.FreeMemZone(mid_, MemZS_Filled); 210 } 211 mmbuf_ = NULL; targ_npaq_ = 0; mid_ = -2; 212 for (int fib=0;fib<(int)memgr_.NbFibres() ;fib++) mmbufib_[fib]=NULL; 213 if (fgclean) return false; 214 mid_ = memgr_.FindMemZoneId(MemZA_Fill); 215 mmbuf_ = memgr_.GetMemZone(mid_); 216 if (mmbuf_==NULL) return true; 217 for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++) 218 mmbufib_[fib]=memgr_.GetMemZone(mid_,fib); 219 return false; 220 } 221 24 222 //------------------------------------------------------- 25 // Classe thread de sauvegarde sur fichiers223 // Classe thread de lecture de fichiers fits BAORadio 26 224 //------------------------------------------------------- 27 225 226 /* --Methode-- */ 28 227 BRFitsReader::BRFitsReader(RAcqMemZoneMgr& mem, vector<string>& infiles, bool fgnotrl) 29 228 : memgr(mem), infiles_(infiles), fgnotrl_(fgnotrl) 30 229 { 31 230 } 32 void BRFitsReader::Stop() 33 { 34 // cout<< " BRFitsReader:Stop ........ " << endl; 35 stop_=true; 36 } 231 232 /* --Methode-- */ 37 233 void BRFitsReader::run() 38 234 {
Note:
See TracChangeset
for help on using the changeset viewer.