--- chewbacca/PamOffLineSW/PamOffLineSW_Main.cpp 2010/02/02 15:26:09 1.9 +++ chewbacca/PamOffLineSW/PamOffLineSW_Main.cpp 2010/02/11 09:02:10 1.10 @@ -1,5 +1,5 @@ //============================================================================ -// $Id: PamOffLineSW_Main.cpp,v 1.8 2009/12/24 10:31:13 mocchiut Exp $ +// $Id: PamOffLineSW_Main.cpp,v 1.9 2010/02/02 15:26:09 mocchiut Exp $ // Description : Pamela Off-Line Software //============================================================================ @@ -61,9 +61,12 @@ Long64_t filelength = 0LL; Long64_t streamposi = 0LL; +Long64_t streamposisaved = 0LL; +Int_t numposi = 10; Long64_t downcount = 1LL; TArrayL64 *dwin=new TArrayL64(12); Long64_t cadcount = 0LL; +Int_t horrorcount = 0; bool skip_cadre = false; long int iNumGoodCadres=0; //total number of good cadres @@ -902,10 +905,21 @@ { isCadreGood = true; //start reading the file + streamposi = (Long64_t)fin.tellg(); // stream position in the file before reading the vrl header + if ( iNumCadres > 9 && numposi > 9 ){ + streamposisaved = streamposi; + numposi = 0; + }; + numposi++; + // fin.read(ccHeader_VRL, LENGTH_HEADER_VRL); - streamposi = (Long64_t)fin.tellg(); // stream position in the file - // printf(" position in file is %i \n",streamposi); - + // printf(" position in file is %llu \n",streamposi); + stringstream ss; + ss.str() = ""; + ss << " position in file is "<logError(sms); + // if (!fin.good()) { //TODO: check here @@ -933,8 +947,37 @@ " This error occurred after byte: "<logWarning(msg); + // printf(" streamposi %llu \n",streamposi); } + // + // we completely missed more than 10 VRL packets + // + // if ( horrorcount > 10 ){ + if ( horrorcount > 1 ){ + stringstream os; + os<<" NEW (EM) THIS IS TOO MUCH, LOST SYNC WITH VRL HEADERS! try to recover horrorcount = "<logAll(ms); + // printf(" fin.(streamposi-10*1025-7) %llu \n",streamposi-(10LL*1025LL)-7LL); + if ( (streamposi-(10LL*1024LL)+1LL) < streamposisaved ){ + fin.seekg(streamposisaved+1LL); + stringstream oss; + oss<<" Problems repositioning stream reader... streamposisaved "<logWarning(msg); + + } else { + fin.seekg(streamposi-(10LL*1024LL)+1LL); + }; + // fin.seekg(streamposi-(1LL*1024LL)+1LL); + horrorcount = 0; + continue; + }; + + //we have read and analysed the header VRL of this cadre iByte_tot+=fin.gcount(); @@ -1106,8 +1149,21 @@ " This error occurred after byte: "<logAll(msg); + + if ( ((int)(unsigned char)headVRL[0]!=CODE_FF)&&((int)(unsigned char)headVRL[1]!=CODE_46)&& ((int)(unsigned char)headVRL[2]!=CODE_D5) ){ + stringstream os; + os<<" Horror movie, the cadre does not start with FF 46 D5 at all! "<< + " This error occurred after byte: "<logAll(ms); + horrorcount++; + }; + return false; } + + horrorcount = 0; + // EM qui condizione su posizione file Bool_t downchangeallowed = false; for (Int_t ee=0; ee<(-1+2+2*downcount); ee+=2){