--- chewbacca/YodaProfiler/src/PamelaDBOperations.cpp 2008/11/04 09:44:49 1.5 +++ chewbacca/YodaProfiler/src/PamelaDBOperations.cpp 2008/11/07 08:56:13 1.10 @@ -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(); @@ -1938,7 +1941,7 @@ glroot.PATH = "$PAM_L0"; }; }; - // glroot.NAME = GetRootFile(); + glroot.NAME = GetRootFile(); if ( insertPamelaRootFile(&glroot) )return 1; @@ -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; @@ -4892,20 +4917,22 @@ // }; // + + if( !(MISSING_pkt1&MISSING_pkt2) ){ + this->HandleTRK_CALIB(!MISSING_pkt1,!MISSING_pkt2); + ncalib++; + if( MISSING_pkt1||MISSING_pkt2||!valid )try_to_recover=true; + } + + } else { - // + // if ( IsDebug() ) printf(" Trk calibration1 at time %u obt %u pkt %u OUTSIDE the considered time interval \n",fromtime,obt1,pkt1); // if ( PEDANTIC ) throw -79; // }; // - if( !(MISSING_pkt1&MISSING_pkt2) ){ - this->HandleTRK_CALIB(!MISSING_pkt1,!MISSING_pkt2); - ncalib++; - if( MISSING_pkt1||MISSING_pkt2||!valid )try_to_recover=true; - } - }; //end loop on pkt1 @@ -5130,7 +5157,8 @@ // ------------------------------------------------------ // ... retrieve the calibration packets. // ------------------------------------------------------ - TFile *file = new TFile((TString)gSystem->ExpandPathName(path)+"/"+name); // EM, path could be symbolic and we must expand it + if ( IsDebug() ) printf(" file is %s/%s \n",((TString)gSystem->ExpandPathName(path.Data())).Data(),name.Data()); + TFile *file = new TFile(((TString)gSystem->ExpandPathName(path.Data()))+"/"+name); // EM, path could be symbolic and we must expand it if(!file)throw -100; if(file->IsZombie())throw -100; // @@ -6490,7 +6518,7 @@ stringstream myquery; // myquery.str(""); - myquery << " SELECT ID, ID_RAW FROM GL_ROOT where NAME='"<Query(myquery.str().c_str()); // @@ -6506,6 +6534,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(); // @@ -6513,7 +6542,7 @@ // this->RemoveRUNS(); // - this->RemoveFILES(); + this->RemoveFILES(idtsy); // this->SetID_ROOT(0); this->SetID_RAW(0); @@ -6733,7 +6762,7 @@ * Rearrange calibration tables * **/ -void PamelaDBOperations::RemoveFILES(){ +void PamelaDBOperations::RemoveFILES(UInt_t idtsy){ stringstream myquery; // myquery.str(""); @@ -6743,6 +6772,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()); + }; + // }; /** @@ -7092,120 +7137,6 @@ } -// UInt_t PamelaDBOperations::ValidateTrkCalib( CalibTrk1Event* caltrk, EventHeader *eh ){ - -// if(!caltrk || !eh) return 0; - -// Int_t vorder[]={5,5,3,3,4,4,2,2,1,1,0,0}; -// UInt_t timeaftercalib=120000; //2000; -// // ---------- -// // Check CRCs -// // ---------- -// for(Int_t ipkt=0; ipkt<6; ipkt++){ -// if( caltrk->crc_hcal[ipkt] )return 0; // :-( -// for(Int_t ilad=0; ilad<3; ilad++)if( caltrk->crc_cal[ipkt][ilad] )return 0; // :-( -// } -// // ----------------------- -// // Check missing packets: -// // ----------------------- -// // Readout order: -// // ------------------ -// // DSP packet board -// // ------------------ -// // 12 0 1 -// // 10 1 1 -// // 8 2 1 -// // 4 3 1 -// // 6 4 1 -// // 2 5 1 -// // ------------------ -// // 11 0 2 -// // 9 1 2 -// // 7 2 2 -// // 3 3 2 -// // 5 4 2 -// // 1 5 2 -// // ------------------ -// // ------------------------------------------------- -// // Check if it is first or second calibration packet -// // ------------------------------------------------- -// UInt_t build=0; -// TString classname = caltrk->GetName(); -// UInt_t base=0; -// UInt_t mask=0; -// if(classname.Contains("CalibTrk1Event")){ -// base=12; -// mask=0x03F000; -// } -// if(classname.Contains("CalibTrk2Event")){ -// base=18; -// mask=0xFC0000; -// } -// // ------------------------------------------------- -// // Count number of packets and set build variable -// // ------------------------------------------------- -// Int_t npkts=0; -// for(Int_t ipkt=0; ipkt<6; ipkt++){ -// if(caltrk->DSPnumber[ipkt]>0 && caltrk->DSPnumber[ipkt]<=12){ -// npkts++; -// build = build | ( 1<<(base+vorder[caltrk->DSPnumber[ipkt]-1]) ); -// } -// } -// // if( npkts==6 )return 1; // :-) - -// // cout << classname << " "<GetPscuHeader()->GetOrbitalTime()<GetCounter(); -// Int_t irun = cod->Get(pctp->RunHeader); -// TTree *rh=(TTree*)file->Get("RunHeader"); -// if ( !rh || rh->IsZombie() ) throw -17; -// if( rh->GetEntries() == irun ){ -// if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (1) -- cannot validate :-( "<SetBranchAddress("RunHeader", &run); -// rh->SetBranchAddress("Header", &hrun); -// rh->GetEntry(irun); -// // cout << classname << " "<GetPscuHeader()->GetOrbitalTime() << " Run " << hrun->GetPscuHeader()->GetOrbitalTime() <GetPscuHeader()->GetOrbitalTime()) < OBT(eh->GetPscuHeader()->GetOrbitalTime())){ -// if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (2) -- cannot validate :-( "<RM_ACQ_AFTER_CALIB ){ -// if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) RM_ACQ_AFTER_CALIB=0 -- cannot validate :-( "<GetPscuHeader()->GetOrbitalTime()) - OBT(eh->GetPscuHeader()->GetOrbitalTime()); -// if( dtime > timeaftercalib ){ -// if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) run after calib too far ( "<ACQ_BUILD_INFO & mask) != build ){ -// if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) ACQ_BUILD_INFO= >>> "<ACQ_BUILD_INFO&mask) << " != "<< build << dec<