--- chewbacca/PamOffLineSW/PamOffLineSW_Main.cpp 2009/08/05 18:48:43 1.7 +++ chewbacca/PamOffLineSW/PamOffLineSW_Main.cpp 2010/02/12 04:46:53 1.11 @@ -1,5 +1,5 @@ //============================================================================ -// $Id: PamOffLineSW_Main.cpp,v 1.6 2009-02-01 16:38:26 mocchiut Exp $ +// $Id: PamOffLineSW_Main.cpp,v 1.10 2010/02/11 09:02:10 mocchiut Exp $ // Description : Pamela Off-Line Software //============================================================================ @@ -8,6 +8,7 @@ #include "StateManager.h" #include "PacketUser.h" +#include extern "C" { #include @@ -45,6 +46,7 @@ //bool do_vrl_check = false; //EMI bool do_vrl_check = true; //EMI + const char* db_host = ""; int db_port = 0; const char* db_name = ""; @@ -57,6 +59,16 @@ //previous route int old_route = 999; +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; +Int_t hc = 0; + bool skip_cadre = false; long int iNumGoodCadres=0; //total number of good cadres @@ -65,7 +77,7 @@ { const char* db_user = ""; const char* db_pwd = ""; - char* connection = NULL; + char* pelosconnection = NULL; //marco_new_01 bool single_connection=false; long int iNumCadres=0; //cadre's number @@ -97,6 +109,7 @@ unsigned long int time_Offset=0; // bool tryMerge = false; bool tryMerge = true; + bool candelete = true; //EM bool do_cont_check=true;//if do_cont_check is false do not use a DB ... @@ -186,7 +199,8 @@ cout << "\t -session_number Value of the session number. If 0 this is retrieved from the input file name. [default = 0]\n"; cout << "\t -time_Offset Value of the timeOffset. If 0 this is retrieved using the orbital number. [default = 0]\n"; cout << "\t -tryMerge if you want to try to Merge ROOT files\n"; - cout << "\t -dontMerge if you don not want to try to Merge ROOT files\n"; + cout << "\t -dontMerge if you do not want to try to Merge ROOT files\n"; + cout << "\t -dontDelete if you do not want to delete bad ROOT files from disks\n"; //marco_new_01 cout << "\t -single_connection if you want to open only one connection to DB.\n"; cout << "\t -tag if you want add the 'The owner of the file' - the tag lenght is 4 char\n"; @@ -233,6 +247,12 @@ tryMerge = false; continue; } + + if (!strcmp(argv[i], "-dontDelete")) // EMI + { + candelete = false; + continue; + } if (!strcmp(argv[i], "-time_Offset")){ if (++i >= argc){ @@ -327,6 +347,7 @@ do_vrl_check = false; nome_output = (char *)gSystem->BaseName(fni); tryMerge = false; + candelete = false; continue; } @@ -612,7 +633,7 @@ char *pamdbhost = getenv("PAM_DBHOST"); if (pamdbhost) { - connection = pamdbhost; + pelosconnection = pamdbhost; } else { @@ -631,12 +652,12 @@ db_name="chewbacca_db"; } sprintf(conn,"mysql://%s:%d/%s",db_host,db_port,db_name); - connection=conn; + pelosconnection=conn; } } else{ sprintf(conn,"mysql://%s:%d/%s",db_host,db_port,db_name); - connection=conn; + pelosconnection=conn; } if (!strcmp(db_user,"")) @@ -666,7 +687,7 @@ } } - string msg = "Using DB: " + string(connection);// +" "+ string(db_user) +" "+ string(db_pwd); + string msg = "Using DB: " + string(pelosconnection);// +" "+ string(db_user) +" "+ string(db_pwd); mainLogUtil->logAlways(msg); } @@ -834,13 +855,72 @@ ifstream fin; fin.open(fni, ifstream::binary); if (!fin) {cout<<"Can not open input file "< 5LL ) dwin->Set(2LL+2LL*downcount); + dwin->Reset(); + dwin->AddAt(0LL,0); + // + Int_t dco = 1; + // + for (Int_t ee=1; ee<(-1+2+2*downcount); ee+=2){ + dwin->AddAt(((downsize*(dco-1))+hwint),ee); + dwin->AddAt(((downsize*dco)-hwint),ee+1); + dco++; + }; + // + fin.seekg(0,std::ios::beg); + // + dwin->AddAt(filelength,(-1LL+2LL+2LL*downcount)); + // + // printf(" file lenght is %L downcount is %L downsize is %L hwint is %L \n",filelength,downcount,downsize,hwint); + stringstream ess; + ess.str() = ""; + ess << " (EM) " << " file lenght is "<< filelength<< " downcount is "<< downcount <<" downsize is "<< downsize <<" hwint is " << hwint; + string emsg = ess.str(); + mainLogUtil->logInfo(emsg); + // + // cout << " file lenght is "<< filelength<< " downcount is "<< downcount <<" downsize is "<< downsize <<" hwint is " << hwint << endl; + // for (Int_t ee=0; ee "<< dwin->At(ee) << endl; + // //a printf(" %i ==> %L \n",ee,dwin->At(ee)); + // }; + //main read loop while(fin.eof()==0) { 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); + // 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 @@ -868,8 +948,38 @@ " This error occurred after byte: "<logWarning(msg); + // printf(" streamposi %llu \n",streamposi); } + // + // we completely missed more than 10 VRL packets + // + if ( horrorcount > 10 && hc < 500 ){ + hc++; + //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(); @@ -953,6 +1063,7 @@ if(route!=old_route) { is_new_route=true; + cadcount = 1LL; download++; stringstream oss; oss<<"Found a new download n: "<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; } - - route = (int)headVRL[3]; - - if(route!=old_route) - { - stringstream oss; - oss<<"Changing ROUTE at byte: "<logAll(msg); - } + + horrorcount = 0; + + // EM qui condizione su posizione file + Bool_t downchangeallowed = false; + for (Int_t ee=0; ee<(-1+2+2*downcount); ee+=2){ + if ( streamposi >= dwin->At(ee) && streamposi < dwin->At(ee+1) ) downchangeallowed = true; + // printf(" %i ==> %i \n",ee,dwin->At(ee)); + }; + if ( cadcount < 10000LL && cadcount > 0LL) downchangeallowed = false; + cadcount++; + // cout << " cadcount " << cadcount << endl; + // printf("cadcount %L \n",cadcount); + if ( downchangeallowed ){ + // printf(" change allowed! \n"); + + route = (int)headVRL[3]; + + if(route!=old_route) + { + stringstream oss; + oss<<"Changing ROUTE at byte: "<logAll(msg); + } + + }; //TODO: check the cadre number and save this info? //TODO check that the lenght is 8