| [3683] | 1 | //---------------------------------------------------------------- | 
|---|
|  | 2 | // Projet BAORadio - (C) LAL/IRFU  2008-2010 | 
|---|
|  | 3 | // Classes de base pour les threads de traitememt donnees BAORadio | 
|---|
|  | 4 | //---------------------------------------------------------------- | 
|---|
|  | 5 |  | 
|---|
|  | 6 | #include <stdlib.h> | 
|---|
|  | 7 | #include <string.h> | 
|---|
|  | 8 | #include <unistd.h> | 
|---|
|  | 9 | #include <fstream> | 
|---|
|  | 10 | #include "brbaseproc.h" | 
|---|
|  | 11 |  | 
|---|
|  | 12 |  | 
|---|
|  | 13 | using namespace SOPHYA; | 
|---|
|  | 14 | //--------------------------------------------------------------------- | 
|---|
| [3939] | 15 | // Classe BRBaseProcessor : classe de base pour l'analyse des donnees | 
|---|
|  | 16 | // BAORadio - Les classes de traitement heritent de cette classe et | 
|---|
|  | 17 | // redefinissent la mathode Process() qui est appele paquet par paquet | 
|---|
| [3683] | 18 | //--------------------------------------------------------------------- | 
|---|
| [4016] | 19 | /*! | 
|---|
|  | 20 | \class BRBaseProcessor | 
|---|
|  | 21 | \ingroup TAcq | 
|---|
| [3683] | 22 |  | 
|---|
| [4016] | 23 | \brief Base class for BAORadio processing thread classes. | 
|---|
|  | 24 |  | 
|---|
|  | 25 | Thread classes for BAORadio data processing and analysis can inherit from | 
|---|
|  | 26 | this class and redefine/implement the Process() method which is called | 
|---|
|  | 27 | for each BRpaquet. | 
|---|
|  | 28 | */ | 
|---|
|  | 29 |  | 
|---|
| [3683] | 30 | /* --Methode-- */ | 
|---|
| [3774] | 31 | BRBaseProcessor::BRBaseProcessor(RAcqMemZoneMgr& memgr, MemZaction mmact) | 
|---|
| [3872] | 32 | : memgr_(memgr), fbuff_(memgr.NbFibres()), fprocbuff_(memgr.NbFibres()), | 
|---|
|  | 33 | vpaq_(memgr.NbFibres()), vprocpaq_(memgr.NbFibres()), | 
|---|
|  | 34 | vpchk_(memgr.NbFibres()), vfgok_(memgr.NbFibres()), | 
|---|
| [3696] | 35 | curfc_(memgr.NbFibres()), fcfirst_(memgr.NbFibres()), ttfirst_(memgr.NbFibres()) | 
|---|
| [3683] | 36 | { | 
|---|
| [3774] | 37 | SetMemZAction(mmact); | 
|---|
| [3686] | 38 | stop_ = false; | 
|---|
| [3683] | 39 | for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++)  { | 
|---|
| [3872] | 40 | fbuff_[fib]=NULL; | 
|---|
|  | 41 | fprocbuff_[fib]=NULL; | 
|---|
| [3694] | 42 | vpaq_[fib]=BRPaquet(NULL,memgr_.PaqSize()); | 
|---|
| [3872] | 43 | vprocpaq_[fib]=NULL; | 
|---|
| [3694] | 44 | vpchk_[fib]=BRPaqChecker(true,0); | 
|---|
|  | 45 | vfgok_[fib]=true; | 
|---|
|  | 46 | curfc_[fib]=0; | 
|---|
| [3696] | 47 | fcfirst_[fib]=0; | 
|---|
|  | 48 | ttfirst_[fib]=0; | 
|---|
| [3683] | 49 | } | 
|---|
| [3696] | 50 | fgokallfibers_=true; | 
|---|
| [3683] | 51 | totprocnpaq_=0; | 
|---|
| [3993] | 52 | startdate_=0; | 
|---|
| [3778] | 53 | setNameId("baseproc",0); | 
|---|
| [3981] | 54 | ClearProcTimeWindow(); | 
|---|
| [3938] | 55 | SetPrintLevel(); | 
|---|
| [3683] | 56 | } | 
|---|
|  | 57 |  | 
|---|
|  | 58 | /* --Methode-- */ | 
|---|
| [3774] | 59 | MemZStatus BRBaseProcessor::SetMemZAction(MemZaction mmact) | 
|---|
|  | 60 | { | 
|---|
|  | 61 | mmact_=mmact; | 
|---|
|  | 62 | mmsta_=MemZS_ProcA; | 
|---|
|  | 63 | switch (mmact) { | 
|---|
|  | 64 | case MemZA_ProcA: | 
|---|
|  | 65 | mmsta_=MemZS_ProcA; | 
|---|
|  | 66 | break; | 
|---|
|  | 67 | case MemZA_ProcB: | 
|---|
|  | 68 | mmsta_=MemZS_ProcB; | 
|---|
|  | 69 | break; | 
|---|
|  | 70 | case MemZA_ProcC: | 
|---|
|  | 71 | mmsta_=MemZS_ProcC; | 
|---|
|  | 72 | break; | 
|---|
|  | 73 | case MemZA_ProcD: | 
|---|
|  | 74 | mmsta_=MemZS_ProcD; | 
|---|
|  | 75 | break; | 
|---|
|  | 76 | case MemZA_ProcE: | 
|---|
|  | 77 | mmsta_=MemZS_ProcE; | 
|---|
|  | 78 | break; | 
|---|
|  | 79 | case MemZA_ProcF: | 
|---|
|  | 80 | mmsta_=MemZS_ProcF; | 
|---|
|  | 81 | break; | 
|---|
| [3955] | 82 | case MemZA_ProcG: | 
|---|
|  | 83 | mmsta_=MemZS_ProcG; | 
|---|
|  | 84 | break; | 
|---|
|  | 85 | case MemZA_ProcH: | 
|---|
|  | 86 | mmsta_=MemZS_ProcH; | 
|---|
|  | 87 | break; | 
|---|
|  | 88 | case MemZA_ProcI: | 
|---|
|  | 89 | mmsta_=MemZS_ProcI; | 
|---|
|  | 90 | break; | 
|---|
|  | 91 | case MemZA_ProcJ: | 
|---|
|  | 92 | mmsta_=MemZS_ProcI; | 
|---|
|  | 93 | break; | 
|---|
| [3774] | 94 | default: | 
|---|
|  | 95 | mmact_=MemZA_ProcA; | 
|---|
|  | 96 | mmsta_=MemZS_ProcA; | 
|---|
|  | 97 | break; | 
|---|
|  | 98 | } | 
|---|
|  | 99 | return mmsta_; | 
|---|
|  | 100 | } | 
|---|
|  | 101 |  | 
|---|
|  | 102 | /* --Methode-- */ | 
|---|
| [3683] | 103 | void BRBaseProcessor::run() | 
|---|
|  | 104 | { | 
|---|
|  | 105 | setRC(1); | 
|---|
|  | 106 | int rc=0; | 
|---|
|  | 107 | try { | 
|---|
| [3872] | 108 | cout << "BRBaseProcessor[" << bpnom_ << "," << bpid_ << "]::run() - Starting " << " NFibers=" | 
|---|
| [3882] | 109 | << memgr_.NbFibres() << endl; | 
|---|
| [3979] | 110 | if (fgproctimewin_) cout << " BRBaseProcessor...TimeWindow Start=" << tmstart_ << " End=" << tmend_ << endl; | 
|---|
| [3683] | 111 |  | 
|---|
|  | 112 | size_t paqsz=memgr_.PaqSize(); | 
|---|
| [3872] | 113 | size_t procpaqsz=memgr_.ProcPaqSize(); | 
|---|
| [3979] | 114 |  | 
|---|
|  | 115 | double tstartdays = tmstart_.ToDays(); | 
|---|
|  | 116 | double tenddays = tmend_.ToDays(); | 
|---|
|  | 117 |  | 
|---|
| [3683] | 118 | bool fgrun=true; | 
|---|
|  | 119 | while (fgrun) { | 
|---|
|  | 120 | if (stop_) break; | 
|---|
|  | 121 | if (memgr_.GetRunState() == MemZR_Stopped) break; | 
|---|
| [3979] | 122 | mid_ = memgr_.FindMemZoneId(mmact_);  // (MemZA_ProcA); | 
|---|
|  | 123 | //      Byte* buffg = memgr_.GetMemZone(mid_); | 
|---|
| [3779] | 124 | //      if (buffg == NULL) { | 
|---|
| [3979] | 125 | if (mid_ < 0) { | 
|---|
| [3872] | 126 | cout << "BRBaseProcessor[" << bpnom_ << "," << bpid_ << "]::run()/ERROR FindMemZoneId(" | 
|---|
| [3979] | 127 | << (int)mmact_ << ") ->" << mid_ << ") -> NULL" << endl; | 
|---|
| [3683] | 128 | setRC(7);      fgrun=false; | 
|---|
|  | 129 | break; | 
|---|
|  | 130 | } | 
|---|
| [3979] | 131 | cts_=memgr_.GetAuxData(mid_)->FillTime();   // get associated date/time (DATEOBS) | 
|---|
| [3993] | 132 | if (startdate_==0)  startdate_=cts_.DaysPart(); | 
|---|
|  | 133 |  | 
|---|
| [3696] | 134 | for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++) { | 
|---|
| [3979] | 135 | fbuff_[fib] = memgr_.GetMemZone(mid_,fib); | 
|---|
| [3696] | 136 | if (fbuff_[fib] == NULL) { // cela ne devrait pas arriver | 
|---|
| [3872] | 137 | cout << "BRBaseProcessor[" << bpnom_ << "," << bpid_ << "]::run()/ERROR memgr.GetMemZone(" | 
|---|
| [3979] | 138 | << mid_ << "," << fib << ") -> NULL" << endl; | 
|---|
| [3696] | 139 | setRC(9);       fgrun=false; | 
|---|
|  | 140 | break; | 
|---|
|  | 141 | } | 
|---|
| [3979] | 142 | if ((procpaqsz>0)&&((fprocbuff_[fib]=memgr_.GetProcMemZone(mid_,fib))==NULL)) {   // cela ne devrait pas arriver non plus | 
|---|
| [3872] | 143 | cout << "BRBaseProcessor[" << bpnom_ << "," << bpid_ << "]::run()/ERROR memgr.GetProcMemZone(" | 
|---|
| [3979] | 144 | << mid_ << "," << fib << ") -> NULL" << endl; | 
|---|
| [3872] | 145 | setRC(9);       fgrun=false; | 
|---|
|  | 146 | break; | 
|---|
|  | 147 | } | 
|---|
| [3696] | 148 | } | 
|---|
| [3979] | 149 |  | 
|---|
|  | 150 | // On ne traite les paquets que si pas de fenetre en temps ou tmstart_ <= FillTime() <= tmend_ | 
|---|
|  | 151 | double ftmdays = memgr_.GetAuxData(mid_)->FillTime().ToDays(); | 
|---|
|  | 152 | if ((!fgproctimewin_) || ( (ftmdays<=tenddays)&&(ftmdays>=tstartdays) ) ) { | 
|---|
|  | 153 |  | 
|---|
|  | 154 | for(size_t jp=0; jp<memgr_.NbPaquets(); jp++) {   // boucle sur les paquets d'une zone | 
|---|
|  | 155 | fgokallfibers_=true; | 
|---|
|  | 156 | for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++) { | 
|---|
|  | 157 | vpaq_[fib].Set(fbuff_[fib]+jp*paqsz); | 
|---|
|  | 158 | vfgok_[fib]=vpchk_[fib].Check(vpaq_[fib],curfc_[fib]); | 
|---|
|  | 159 | if (!vfgok_[fib])  fgokallfibers_=false; | 
|---|
|  | 160 | if (procpaqsz>0)    vprocpaq_[fib] = fprocbuff_[fib]+jp*procpaqsz; | 
|---|
|  | 161 | } | 
|---|
|  | 162 | //--- Traitement | 
|---|
|  | 163 | int rcp=0; | 
|---|
|  | 164 | if (fgokallfibers_)  { | 
|---|
|  | 165 | if (totprocnpaq_==0) { | 
|---|
|  | 166 | for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++)  { | 
|---|
|  | 167 | fcfirst_[fib]=curfc_[fib]; | 
|---|
|  | 168 | ttfirst_[fib]=vpaq_[fib].TimeTag(); | 
|---|
|  | 169 | } | 
|---|
| [3696] | 170 | } | 
|---|
| [3979] | 171 | rcp=Process(); | 
|---|
|  | 172 | totprocnpaq_++; | 
|---|
| [3696] | 173 | } | 
|---|
| [3979] | 174 | //    if (rcp != 0)   { fgrun=false; break; } | 
|---|
|  | 175 | }  // Fin de boucle sur les paquets | 
|---|
|  | 176 | }  // Fin de test pour fenetre en temps de traitement des paquets | 
|---|
|  | 177 |  | 
|---|
|  | 178 | memgr_.FreeMemZone(mid_, mmsta_);   // (MemZS_ProcA); | 
|---|
| [3683] | 179 | } // Fin de boucle sur les zones a traiter | 
|---|
|  | 180 | //------------------------------------ | 
|---|
| [3872] | 181 | cout << " ---- END BRBaseProcessor[" << bpnom_ << "," << bpid_ << "]::run() , TotNbProcPaq=" | 
|---|
|  | 182 | << totprocnpaq_ << endl; | 
|---|
| [3686] | 183 | /* | 
|---|
|  | 184 | for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++)  vpchk_[fib].Print(); | 
|---|
|  | 185 | cout << " ------------------------------------ " << endl; | 
|---|
|  | 186 | */ | 
|---|
| [3683] | 187 | } | 
|---|
|  | 188 | catch (std::exception& exc) { | 
|---|
| [3872] | 189 | cout << "BRBaseProcessor[" << bpnom_ << "," << bpid_ << "]::run()/catched std::exception " << exc.what() << endl; | 
|---|
| [3683] | 190 | setRC(98); | 
|---|
|  | 191 | return; | 
|---|
|  | 192 | } | 
|---|
|  | 193 | catch(...) { | 
|---|
| [3872] | 194 | cout << "BRBaseProcessor[" << bpnom_ << "," << bpid_ << "]::run()/catched unknown ... exception " << endl; | 
|---|
| [3683] | 195 | setRC(99); | 
|---|
|  | 196 | return; | 
|---|
|  | 197 | } | 
|---|
|  | 198 |  | 
|---|
|  | 199 | } | 
|---|
|  | 200 |  | 
|---|
|  | 201 |  | 
|---|
|  | 202 | /* --Methode-- */ | 
|---|
|  | 203 | int BRBaseProcessor::Process() | 
|---|
|  | 204 | { | 
|---|
| [3876] | 205 | // Cette methode est appele pour chaque "trigger', cad la serie de paquets pour toutes les fibres | 
|---|
| [3683] | 206 | // la methode par defaut ne fait rien | 
|---|
|  | 207 | // if (fgokallfibers_) { faire le traitement } | 
|---|
| [3696] | 208 | //  return 0; | 
|---|
|  | 209 | /*    Exemple de code test  */ | 
|---|
| [3938] | 210 | if ((prtlev_>0)&&(totprocnpaq_ %prtmodulo_==0))  { | 
|---|
|  | 211 | cout << " BRBaseProcessor::Process(totnpaq=" << totprocnpaq_ << ")  ObsTime=" << getObsTime() | 
|---|
|  | 212 | << " TimeTag=" << getCurTimeTagSeconds() << " s. FrameCounter="  << getCurFrameCounter() << endl; | 
|---|
|  | 213 | if (prtlev_<2) return 0; | 
|---|
|  | 214 | cout << " ... FrameCnt[0..." << memgr_.NbFibres()-1 << "]=" ; | 
|---|
| [3686] | 215 | for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++) | 
|---|
| [3938] | 216 | cout << getCurFrameCounter(fib) << "," ; | 
|---|
| [3686] | 217 | cout << endl; | 
|---|
| [3938] | 218 | cout << " ... TimeTag[0..." << memgr_.NbFibres()-1 << "]=" ; | 
|---|
| [3686] | 219 | for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++) | 
|---|
| [3938] | 220 | cout << getCurTimeTag(fib) << "," ; | 
|---|
|  | 221 | cout << endl; | 
|---|
|  | 222 | if (prtlev_<3) return 0; | 
|---|
|  | 223 | cout << " ... TimeTagSeconds[0..." << memgr_.NbFibres()-1 << "]=" ; | 
|---|
|  | 224 | for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++) | 
|---|
|  | 225 | cout << getCurTimeTagSeconds(fib) << "," ; | 
|---|
| [3982] | 226 | cout << endl; | 
|---|
| [3979] | 227 | if (prtlev_<4) return 0; | 
|---|
|  | 228 | cout << " ... FileSequenceNumber[0..." << memgr_.NbFibres()-1 << "]=" ; | 
|---|
|  | 229 | for(size_t fib=0; fib<(size_t)memgr_.NbFibres(); fib++) | 
|---|
|  | 230 | cout << memgr_.GetAuxData(mid_)->FileSequenceNumber(fib) << ","; | 
|---|
| [3938] | 231 | cout << endl; | 
|---|
| [3686] | 232 | } | 
|---|
| [3696] | 233 | return 0; | 
|---|
| [3683] | 234 | } | 
|---|
|  | 235 |  | 
|---|