--- chewbacca/YodaProfiler/src/PamelaDBOperations.cpp 2008/11/04 13:19:36 1.7 +++ chewbacca/YodaProfiler/src/PamelaDBOperations.cpp 2008/11/28 10:57:44 1.12 @@ -660,8 +660,9 @@ UInt_t tjump = 50000; //UInt_t tjump = 100; while ( tjump > 0 ){ - pktlast = numeric_limits::max(); - while ( pktlast > chpktmax && (Int_t)(nevent-1-it) >= 0 ){ + // pktlast = numeric_limits::max(); + pktlast = chpktmax + 1; + while ( PKT(pktlast) > PKT(chpktmax) && (Int_t)(nevent-1-it) >= 0 ){ if ( (Int_t)(nevent-1-it) >= 0 ){ T->GetEntry(nevent-1-it); ph = eh->GetPscuHeader(); @@ -669,7 +670,7 @@ } else { pktlast = chpktmax + 1; }; - if ( (!(it%1000) || abs((int)pktlast - (int)chpktmax)<1000 ) && debug ) printf(" look for up %i %i %i nevent %u (nevent-1-it) %i \n",it,pktlast,chpktmax,nevent,(Int_t)(nevent-1-it)); + if ( (!(it%1000) || abs((int)(PKT(pktlast) - PKT(chpktmax)))<1000 ) && debug ) printf(" look for up %i %i %i nevent %u (nevent-1-it) %i \n",it,pktlast,chpktmax,nevent,(Int_t)(nevent-1-it)); it += tjump; }; if ( tjump > 1 ) it -= 2*tjump; @@ -693,8 +694,10 @@ tjump = 50000; //tjump = 100; while ( tjump > 0 ){ - pktlast = 0; - while ( pktlast < chpktmin && it < (Int_t)nevent ){ + // pktlast = 0; + pktlast = chpktmin - 1; + if ( debug ) printf("LLlook for down %i %i %llu %llu \n",it,pktlast,PKT(pktlast),PKT(chpktmin)); + while ( PKT(pktlast) < PKT(chpktmin) && it < (Int_t)nevent ){ if ( it < (Int_t)nevent ){ T->GetEntry(it); ph = eh->GetPscuHeader(); @@ -1349,7 +1352,7 @@ // // if ( IsDebug() ) printf(" obt conversion: obt is %u obtfirst is %u (numeric_limits::max()/2) is %u \n",obt,pobtfirst,(UInt_t)(numeric_limits::max()/2)); // - if ( obt < (pobtfirst/2) && pobtfirst > (numeric_limits::max()/2) ){ + if ( obt < ((Long64_t)pobtfirst/2) && pobtfirst > (numeric_limits::max()/2) ){ // if ( IsDebug() ) printf(" rise up obt %lld \n",(Long64_t)obt+(Long64_t)numeric_limits::max()); return((Long64_t)obt+(Long64_t)numeric_limits::max()); }; @@ -2314,6 +2317,7 @@ // this->HandleRunFragments(true,true,chminentry,(evbefh)); // + // what about pth=ptht-1 }; }; // @@ -2376,9 +2380,13 @@ // if ( ptt+1 == rtev){ if ( conptt+1 == nrtev ){ // if ( conptt+1 == (nrtev+nrtbef )){ + if ( IsDebug() ) printf(" >>>>>>>>>>> %i %u %i %u \n",ptht,rhev,nrtev,conptt); ptht++; if ( ptht < rhev ){ rh->GetEntry(ptht); + //pth++; + //if ( pth < rhev ){ + //rh->GetEntry(pth); phh = ehh->GetPscuHeader(); pkth = phh->GetCounter(); obth = phh->GetOrbitalTime(); @@ -2403,9 +2411,10 @@ if ( IsDebug() ) printf(" Piece of run at the end of the file with NO RUNHEADER! evbeft %u upperentry-1 %u \n",(UInt_t)evbeft,upperentry-1); // if ( (ptt-1) < 0 ) throw -15; // should never arrive here! - rt->GetEntry(ptt-1); + // rt->GetEntry(ptt-1); + rt->GetEntry(rtev-1); cod = eht->GetCounter(); - tcod = (UInt_t)cod->Get(pctp->Physics); + tcod = (UInt_t)cod->Get(pctp->Physics)+1; evbefh = TMath::Max(chminentry,tcod); // evbefh = cod->Get(pctp->Physics); rt->GetEntry(ptt); @@ -3239,7 +3248,7 @@ // } else { // - if ( IsDebug() ) printf(" There are no-phyics packets inside the run!\n"); + if ( IsDebug() ) printf(" There are no-physics packets inside the run!\n"); // // HERE WE MUST HANDLE THAT RUNS AND GO BACK // @@ -3249,6 +3258,8 @@ UInt_t check = 0; UInt_t lastevtemp = lastev; UInt_t firstevno = firstev; + UInt_t rhchko=0; + UInt_t rhchk=0; // for (UInt_t i=firstev; i<=lastev; i++){ // @@ -3257,9 +3268,15 @@ // check = 0; // + + // if we have a runheader set lastev then exit + // for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){ if ( strcmp(*Iter,"Physics") ) check += code->Get(GetPacketType(*Iter)); }; + // check here if we have a runheader + rhchko = rhchk; + rhchk = code->Get(GetPacketType("RunHeader")); // if ( checkfirst < check || i == lastev ){ // @@ -3676,6 +3693,14 @@ // }; // + if ( i > firstev ){ + if ( rhchko != rhchk ){ + if ( IsDebug() ) printf("oh oh... we have a runheader! stop here and handle later the remaining piece\n"); + lastev = i; + return(false); + }; + }; + // if ( check == checklast && i != lastev ){ lastevtemp = i - 1; i = lastev - 1; @@ -6057,7 +6082,8 @@ // 2) get the OBT of the last validated run // -------------------------------------------------------------- oss.str(""); - oss << " SELECT * FROM GL_RUN WHERE VALIDATION=1 AND RUNHEADER_TIME<="<< t_start + // oss << " SELECT * FROM GL_RUN WHERE VALIDATION=1 AND RUNHEADER_TIME<="<< t_start + oss << " SELECT * FROM GL_RUN WHERE VALIDATION>0 AND RUNHEADER_TIME<="<< t_start <<" ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; if ( IsDebug() ) printf(" Get stop validation-time: query is \n %s \n",oss.str().c_str()); result = conn->Query(oss.str().c_str()); @@ -6200,7 +6226,8 @@ if( interval >= calibtime )CHECK = true; //more than calibtime s => there might be a calibration if( !CHECK && this_run->VALIDATION ){ - for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],true); + // for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],true); + for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],this_run->VALIDATION); nseq=0; } @@ -6221,8 +6248,13 @@ if( CHECK ){ // check if calibration exists if ( IsDebug() )printf("DT %i ===> CHECK Missing calibration\n",interval); - Bool_t MISSING = MissingTRK_CALIB(t1,t2); - for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],!MISSING); + // Bool_t MISSING = MissingTRK_CALIB(t1,t2); + UInt_t MISSING = MissingTRK_CALIB(t1,t2); + UInt_t val = 0; + if ( MISSING == 1 ) val = 0; + if ( MISSING == 0 ) val = 1; + if ( MISSING == 2 ) val = 2; + for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],val); nseq=0; }; //-------------- @@ -6252,14 +6284,17 @@ * @param t2 To absolute time * @return true if there might be a missing calibration */ -Bool_t PamelaDBOperations::MissingTRK_CALIB(UInt_t t1,UInt_t t2){ +//Bool_t PamelaDBOperations::MissingTRK_CALIB(UInt_t t1,UInt_t t2){ +UInt_t PamelaDBOperations::MissingTRK_CALIB(UInt_t t1,UInt_t t2){ GL_TRK_CALIB* trkcalib = new GL_TRK_CALIB(); // get the closest calibration before the run start (t2) - if ( trkcalib->Query_GL_TRK_CALIB(t2, conn) )return(true); //>>> missing + // if ( trkcalib->Query_GL_TRK_CALIB(t2, conn) )return(true); //>>> missing + if ( trkcalib->Query_GL_TRK_CALIB(t2, conn) )return(1); //>>> missing - if ( trkcalib->TO_TIME < t2 ) return(true); //>>> missing + // if ( trkcalib->TO_TIME < t2 ) return(true); //>>> missing + if ( trkcalib->TO_TIME < t2 ) return(1); //>>> missing //============================================================== // Check is done first on the basis of time between calibration, @@ -6276,9 +6311,11 @@ //============================================================== Bool_t DOWNLOAD = false; // check if the calib was skipped becouse of download .... DA FARE!! - if(DOWNLOAD)return(false); + // if(DOWNLOAD)return(false); + if(DOWNLOAD)return(0); - return(true); //>>> missing + // return(true); //>>> missing + return(1); //>>> missing }; @@ -6288,7 +6325,9 @@ //============================================================== // the long time interval bewteen runs might be due to download if ( IsDebug() )printf("Short time between calib and run start %u :-) ==> OK! \n",t2 - trkcalib->FROM_TIME); - return(false); + if ( trkcalib->VALIDATION ) return(0); + if ( IsDebug() )printf("Calibration is not validated... :-/ ==> OK but with VALIDATION=2! \n"); + return(2); }; /** @@ -6297,6 +6336,10 @@ * @param validation true/false */ Int_t PamelaDBOperations::assignVALIDATION(UInt_t idrun, Bool_t validation){ + return(this->assignVALIDATION(idrun,(UInt_t)validation)); +} + +Int_t PamelaDBOperations::assignVALIDATION(UInt_t idrun, UInt_t validation){ TSQLResult *result = 0; stringstream oss; oss.str(""); @@ -6493,7 +6536,7 @@ stringstream myquery; // myquery.str(""); - myquery << " SELECT ID, ID_RAW FROM GL_ROOT where NAME='"<Query(myquery.str().c_str()); // @@ -6509,6 +6552,7 @@ // this->SetID_ROOT((UInt_t)atoll(Row->GetField(0))); this->SetID_RAW((UInt_t)atoll(Row->GetField(1))); + UInt_t idtsy=(UInt_t)atoll(Row->GetField(2)); // this->ValidationOFF(); // @@ -6516,7 +6560,7 @@ // this->RemoveRUNS(); // - this->RemoveFILES(); + this->RemoveFILES(idtsy); // this->SetID_ROOT(0); this->SetID_RAW(0); @@ -6736,7 +6780,7 @@ * Rearrange calibration tables * **/ -void PamelaDBOperations::RemoveFILES(){ +void PamelaDBOperations::RemoveFILES(UInt_t idtsy){ stringstream myquery; // myquery.str(""); @@ -6746,6 +6790,22 @@ // conn->Query(myquery.str().c_str()); // + myquery.str(""); + myquery << " DELETE FROM GL_ROOT WHERE ID=" <GetID_ROOT() <<";"; + // + if ( IsDebug() ) printf(" query is \n %s \n",myquery.str().c_str()); + // + conn->Query(myquery.str().c_str()); // + // + if ( !chewbacca ){ + myquery.str(""); + myquery << " DELETE FROM GL_TIMESYNC WHERE ID=" << idtsy <<";"; + // + if ( IsDebug() ) printf(" query is \n %s \n",myquery.str().c_str()); + // + conn->Query(myquery.str().c_str()); + }; + // }; /**