--- chewbacca/YodaProfiler/src/GLTables.cpp 2008/09/29 12:41:58 1.3 +++ chewbacca/YodaProfiler/src/GLTables.cpp 2008/12/12 11:07:09 1.6 @@ -218,6 +218,13 @@ NAME = ""; } +GL_RAW::GL_RAW(){ + ID = 0; + PATH = ""; + NAME = ""; + BOOT_NUMBER = 0; +} + GL_PARAM::GL_PARAM(){ ID = 0; PATH = ""; @@ -1309,7 +1316,7 @@ if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; this->GetGLTABLES()->AddQ(); pResult = dbc->Query(myquery.str().c_str()); - // printf(" mysquery is %s\n",myquery.str().c_str()); + // printf(" mysquery is %s\n",myquery.str().c_str()); // if( !pResult->GetRowCount() ) return(-54); Row = pResult->Next(); @@ -1539,10 +1546,10 @@ GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TString type, TSQLServer *dbc){ // MySQL variables TFile *file = 0; - UInt_t idraw = 0; + UInt_t idtsy = 0; // TSQLResult *pResult; - TSQLRow *Row; + TSQLRow *Row = 0; stringstream myquery; stringstream rname; // pcksList packetsNames; @@ -1553,7 +1560,7 @@ myquery.str(""); myquery << "select "; myquery << "PATH"; - myquery << ",NAME,ID_RAW"; + myquery << ",NAME,ID_TIMESYNC"; myquery << " from GL_ROOT where "; myquery << type.Data(); myquery << "=" << id << ";"; @@ -1569,7 +1576,7 @@ fname << gSystem->ExpandPathName(Row->GetField(0)) << "/" << Row->GetField(1); rname << Row->GetField(1); file = new TFile(fname.str().c_str(),"READ"); - idraw = (UInt_t)atoll(Row->GetField(2)); + idtsy = (UInt_t)atoll(Row->GetField(2)); }; }; // @@ -1582,27 +1589,7 @@ T->GetEntry(0); ph = eh->GetPscuHeader(); pktfirst = ph->GetCounter(); - obtfirst = ph->GetOrbitalTime(); - // -// code = eh->GetCounter(); -// UInt_t en = 0; -// for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){ -// en = code->Get(GetPacketType(*Iter)); -// if ( !strcmp("CalibCalPed",*Iter) || !strcmp("CalibTrk1",*Iter) || !strcmp("CalibTrk2",*Iter) || !strcmp("CalibS4",*Iter) ){ -// // -// TTree *TC = 0; -// TC = (TTree*)file->Get("CalibCalPed"); -// if ( !TC || TC->IsZombie() ) return; -// EventHeader *ehc = 0; -// PscuHeader *phc = 0; -// TC->SetBranchAddress("Header", &ehc); -// TC->GetEntry(0); -// phc = ehc->GetPscuHeader(); -// pktfirst = phc->GetCounter(); -// obtfirst = phc->GetOrbitalTime(); -// // -// }; -// }; + // obtfirst = ph->GetOrbitalTime(); // }; // @@ -1610,115 +1597,60 @@ // T0 = 0; // - // stringstream oss; - TString frn = rname.str().c_str(); - frn = frn.ReplaceAll(".root",5,".pam",4); - oss.str(""); - oss << "SELECT YEAR(OFFSET_DATE),MONTH(OFFSET_DATE),DAY(OFFSET_DATE),HOUR(OFFSET_DATE),MINUTE(OFFSET_DATE),SECOND(OFFSET_DATE) FROM GL_RESURS_OFFSET WHERE SPECIAL_FILE='" - << frn.Data() << "';"; - if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; - this->GetGLTABLES()->AddQ(); - pResult = dbc->Query(oss.str().c_str()); - Row = pResult->Next(); // TString name=rname.str().c_str(); UInt_t dworbit = 0; - Int_t nlength = name.Length(); + // Int_t nlength = name.Length(); + delete pResult; // - // Is not a special file + // New code, we have one more column on GL_TIMESYNC so we can trust that one for the Resurs offset // - if ( !Row ){ - delete pResult; - // - // New code, we have one more column on GL_TIMESYNC so we can trust that one for the Resurs offset - // - oss.str(""); - oss << "SELECT ID_RESURS_OFFSET from GL_TIMESYNC where ID_RAW=" << idraw <<";"; - if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; - this->GetGLTABLES()->AddQ(); - pResult = dbc->Query(oss.str().c_str()); - Bool_t fndit = false; - if ( pResult ){ - Row = pResult->Next(); - if ( Row ){ - oss.str(""); - oss << "SELECT YEAR(OFFSET_DATE),MONTH(OFFSET_DATE),DAY(OFFSET_DATE),HOUR(OFFSET_DATE),MINUTE(OFFSET_DATE),SECOND(OFFSET_DATE) FROM GL_RESURS_OFFSET WHERE ID=" - << Row->GetField(0) << ";"; - if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; - this->GetGLTABLES()->AddQ(); - pResult = dbc->Query(oss.str().c_str()); - if ( pResult ){ - Row = pResult->Next(); - if ( Row ){ - // printf(" GREAT! the DB structure is the new one! \n"); - fndit = true; - dworbit = 1; - }; - }; - }; - }; - if ( !fndit ){ - delete pResult; - // - printf(" OK, you got an error because this is the old database\n Using backward compability code, hence you can continue safetly \n"); - // - // Old code, we must trust the filename + oss.str(""); + oss << "SELECT OBT0,TIMESYNC,TYPE,ID_RESURS_OFFSET from GL_TIMESYNC where ID=" << idtsy <<";"; + if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; + this->GetGLTABLES()->AddQ(); + pResult = dbc->Query(oss.str().c_str()); + Bool_t fndit = false; + if ( pResult ){ + Row = pResult->Next(); + if ( Row ){ // - if ( nlength < 5 ) return; - TString dwo = 0; - for (Int_t i = 0; i<5; i++){ - dwo.Append(name[i],1); - }; - if ( dwo.IsDigit() ){ - dworbit = (UInt_t)dwo.Atoi(); - } else { - dwo=""; - for (Int_t i = 8; i<13; i++){ - dwo.Append(name[i],1); - }; - if ( dwo.IsDigit() ){ - dworbit = (UInt_t)dwo.Atoi(); - } else { - dworbit = 1; - }; - }; + OBT0 = (UInt_t)atoll(Row->GetField(0)); + obtfirst = OBT0; + TIMESYNC = (UInt_t)atoll(Row->GetField(1)); + TYPE = (UInt_t)atoll(Row->GetField(2)); // oss.str(""); - oss << "SELECT YEAR(OFFSET_DATE),MONTH(OFFSET_DATE),DAY(OFFSET_DATE),HOUR(OFFSET_DATE),MINUTE(OFFSET_DATE),SECOND(OFFSET_DATE) FROM GL_RESURS_OFFSET WHERE FROM_ORBIT< " - << dworbit << " order by FROM_ORBIT desc limit 1;"; + oss << "SELECT YEAR(OFFSET_DATE),MONTH(OFFSET_DATE),DAY(OFFSET_DATE),HOUR(OFFSET_DATE),MINUTE(OFFSET_DATE),SECOND(OFFSET_DATE) FROM GL_RESURS_OFFSET WHERE ID=" + << Row->GetField(3) << ";"; if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; this->GetGLTABLES()->AddQ(); + delete pResult; pResult = dbc->Query(oss.str().c_str()); - Row = pResult->Next(); - if ( !Row ){ - printf(" ERROR FROM GLTables! cannot determine Resurs offset \n"); - return; + if ( pResult ){ + Row = pResult->Next(); + if ( Row ){ + // printf(" GREAT! the DB structure is the new one! \n"); + fndit = true; + dworbit = 1; + }; }; }; }; + if ( !fndit ){ + // + printf(" ERROR OLD DB! \n"); + printf(" ERROR FROM GLTables! cannot determine Resurs offset \n"); + // + }; // TTimeStamp tu = TTimeStamp((UInt_t)atoi(Row->GetField(0)),(UInt_t)atoi(Row->GetField(1)),(UInt_t)atoi(Row->GetField(2)),(UInt_t)atoi(Row->GetField(3)),(UInt_t)atoi(Row->GetField(4)),(UInt_t)atoi(Row->GetField(5)),0,true,0); T0 = (UInt_t)tu.GetSec(); // - // look for the correct timesync entry + toffset = (UInt_t)TIMESYNC - (UInt_t)(this->DBobt(OBT0)/1000) + T0; // - myquery.str(""); - myquery << " SELECT OBT0,TIMESYNC,TYPE FROM GL_TIMESYNC " - << " WHERE ID_RAW = " << idraw - << ";"; - if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; - this->GetGLTABLES()->AddQ(); - pResult = dbc->Query(myquery.str().c_str()); - if ( pResult ){ - Row = pResult->Next(); - if ( (Row != NULL) && ((UInt_t)atoll(Row->GetField(0)) > 0 ) ){ - OBT0 = (UInt_t)atoll(Row->GetField(0)); - TIMESYNC = (UInt_t)atoll(Row->GetField(1)); - TYPE = (UInt_t)atoll(Row->GetField(2)); - toffset = (UInt_t)atoll(Row->GetField(1)) - (UInt_t)(this->DBobt((UInt_t)atoll(Row->GetField(0)))/1000) + T0; - }; - }; + // printf(" T0 %u toffset is %u \n",T0,toffset); // file->Close(); delete pResult; @@ -1731,6 +1663,7 @@ */ UInt_t GL_TIMESYNC::DBabsTime(UInt_t OBT){ // + // printf(" OBT %u DBobt %llu toffset %u dbabstime %u\n",OBT,this->DBobt(OBT),toffset,((UInt_t)(this->DBobt(OBT)/1000)+toffset)); return(((UInt_t)(this->DBobt(OBT)/1000)+toffset)); // }; @@ -1769,11 +1702,11 @@ */ Long64_t GL_TIMESYNC::DBobt(UInt_t obt){ // - if ( obt < (obtfirst/2) && obtfirst > (numeric_limits::max()/2) ){ + if ( obt < ((Long64_t)obtfirst/2) && obtfirst > (numeric_limits::max()/2) ){ return((Long64_t)obt+(Long64_t)numeric_limits::max()); }; // - if ( obt > (obtfirst*2) && obt > (numeric_limits::max()/2) ){ + if ( obt > ((Long64_t)obtfirst*2) && obt > (numeric_limits::max()/2) ){ return((Long64_t)obt-(Long64_t)numeric_limits::max()); }; //