--- chewbacca/PamOffLineSW/PamOffLineSW_Main.cpp 2009/02/01 16:38:26 1.6 +++ chewbacca/PamOffLineSW/PamOffLineSW_Main.cpp 2010/02/02 15:26:09 1.9 @@ -1,5 +1,5 @@ //============================================================================ -// $Id: PamOffLineSW_Main.cpp,v 1.5 2008/12/18 14:47:02 mocchiut Exp $ +// $Id: PamOffLineSW_Main.cpp,v 1.8 2009/12/24 10:31:13 mocchiut Exp $ // Description : Pamela Off-Line Software //============================================================================ @@ -8,6 +8,7 @@ #include "StateManager.h" #include "PacketUser.h" +#include extern "C" { #include @@ -45,27 +46,34 @@ //bool do_vrl_check = false; //EMI bool do_vrl_check = true; //EMI -char* db_host = ""; + +const char* db_host = ""; int db_port = 0; -char* db_name = ""; +const char* db_name = ""; char conn[100]=""; LogUtil::logLevel loglevel=LogUtil::LOGERROR; -char* logfilename = "chewbacca.log"; +const char* logfilename = "chewbacca.log"; //current route int route = 999; //previous route int old_route = 999; +Long64_t filelength = 0LL; +Long64_t streamposi = 0LL; +Long64_t downcount = 1LL; +TArrayL64 *dwin=new TArrayL64(12); +Long64_t cadcount = 0LL; + bool skip_cadre = false; long int iNumGoodCadres=0; //total number of good cadres // global variables used in all the project namespace PamOffLineSW { - char* db_user = ""; - char* db_pwd = ""; - char* connection = NULL; + const char* db_user = ""; + const char* db_pwd = ""; + char* pelosconnection = NULL; //marco_new_01 bool single_connection=false; long int iNumCadres=0; //cadre's number @@ -75,10 +83,10 @@ char* fni; //path completo short compression = 3; // char *outDir = "."; - char *outDir = ""; + const char *outDir = ""; // char * nome_output="chewbacca"; //EMI - char * nome_output="L0PAM";//EMI + const char * nome_output="L0PAM";//EMI bool multiFile = 0; // unsigned long int step_pkt_number=0; // EMI unsigned long int step_pkt_number=3000; @@ -97,6 +105,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 +195,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 +243,12 @@ tryMerge = false; continue; } + + if (!strcmp(argv[i], "-dontDelete")) // EMI + { + candelete = false; + continue; + } if (!strcmp(argv[i], "-time_Offset")){ if (++i >= argc){ @@ -327,6 +343,7 @@ do_vrl_check = false; nome_output = (char *)gSystem->BaseName(fni); tryMerge = false; + candelete = false; continue; } @@ -612,7 +629,7 @@ char *pamdbhost = getenv("PAM_DBHOST"); if (pamdbhost) { - connection = pamdbhost; + pelosconnection = pamdbhost; } else { @@ -631,12 +648,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 +683,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 +851,61 @@ 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 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); + if (!fin.good()) { //TODO: check here @@ -953,6 +1018,7 @@ if(route!=old_route) { is_new_route=true; + cadcount = 1LL; download++; stringstream oss; oss<<"Found a new download n: "<logAll(msg); return false; } - - route = (int)headVRL[3]; - - if(route!=old_route) - { - stringstream oss; - oss<<"Changing ROUTE at byte: "<logAll(msg); - } + // 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