--- YodaProfiler/src/GLTables.cpp 2007/04/17 12:06:55 1.26 +++ YodaProfiler/src/GLTables.cpp 2007/10/19 07:47:52 1.32 @@ -38,6 +38,9 @@ fPsw = new TString(psw.Data()); fSet = true; fNquery = 0; + mh = host.Data(); + mu = user.Data(); + mp = psw.Data(); }; @@ -47,9 +50,12 @@ fPsw = new TString(psw.Data()); fSet = true; fNquery = 0; + mh = host.Data(); + mu = user.Data(); + mp = psw.Data(); }; -Bool_t GL_TABLES::IsConnected(TSQLServer *dbc){ +Bool_t GL_TABLES::IsConnected(TSQLServer *&dbc){ // // // @@ -59,18 +65,28 @@ // // // - // printf(" host is %s \n",fHost->Data()); + // printf(" host is %s \n",fHost->Data()); // stringstream myquery; myquery.str(""); myquery << "show databases;"; - dbc->Query(myquery.str().c_str()); - fNquery++; - // - if ( dbc->GetErrorCode() != 2013 && dbc->GetErrorCode() != 2006 ){ - // is connected - return true; - } else { + if ( dbc ){ + if ( dbc->IsConnected() ){ + dbc->Query(myquery.str().c_str()); + fNquery++; + if ( !(dbc->GetErrorCode()) ){ + // printf("ok\n"); + // + // if ( (dbc->GetErrorCode() != 2013 && dbc->GetErrorCode() != 2006) ){ + // if ( !(dbc->GetErrorCode()) ){ + // is connected + return true; + // }; + }; + }; + }; + // printf("porca di quella \n"); + if ( true ) { // printf(" WARNING: Lost connection to DB! try to recover... \n"); // @@ -84,8 +100,10 @@ myquery << "show databases;"; dbc->Query(myquery.str().c_str()); fNquery++; + // printf(" e riporca di quella \n"); // - if ( dbc->GetErrorCode() != 2013 && dbc->GetErrorCode() != 2006 ){ + // if ( dbc->GetErrorCode() != 2013 && dbc->GetErrorCode() != 2006 ){ + if ( !(dbc->GetErrorCode()) ){ // printf(" ...connection recovered, I can continue! \n"); // @@ -246,9 +264,9 @@ GL_TIMESYNC::GL_TIMESYNC(){ obtfirst = 0; pktfirst = 0; - toffset = 0; - // ID = 0; - // ID_RAW = 0; + ID_RESURS_OFFSET = 0; + ID = 0; + ID_RAW = 0; OBT0 = 0; TIMESYNC = 0; TYPE = 0; @@ -1171,6 +1189,7 @@ myquery.str(""); myquery << "select ID,ID_ROOT_L0,EV_ROOT_CALIBTRK1,EV_ROOT_CALIBTRK2,FROM_TIME,TO_TIME,OBT1,OBT2,PKT1,PKT2,BOOT_NUMBER,VALIDATION from GL_TRK_CALIB where FROM_TIME <= "<< time; // myquery << " AND VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;"; // RIVEDERE LA VALIDAZIONE!!! + myquery << " and EV_ROOT_CALIBTRK1>=0 and EV_ROOT_CALIBTRK2>=0 "; // EM! SE MANCA UN PACCHETTO DEI DUE IL PROCESSAMENTO CRASHA... DA RIVEDERE LA VALIDAZIONE myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; // myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; @@ -1467,9 +1486,11 @@ // // 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='" - << rname.str().c_str() << "';"; + << frn.Data() << "';"; if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; this->GetGLTABLES()->AddQ(); pResult = dbc->Query(oss.str().c_str()); @@ -1478,37 +1499,76 @@ TString name=rname.str().c_str(); UInt_t dworbit = 0; Int_t nlength = name.Length(); - 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; - }; - }; // + // Is not a special file // 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 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 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()); - Row = pResult->Next(); - if ( !Row ){ - printf(" ERROR FROM GLTables! cannot determine Resurs offset \n"); - return; + 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 + // + 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; + }; + }; + // + 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;"; + if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; + this->GetGLTABLES()->AddQ(); + pResult = dbc->Query(oss.str().c_str()); + Row = pResult->Next(); + if ( !Row ){ + printf(" ERROR FROM GLTables! cannot determine Resurs offset \n"); + return; + }; }; }; // @@ -1805,10 +1865,10 @@ TSQLRow *row; // Set the right time_zone (otherwise horrible things will occur! :) + if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; dbc->Query("SET time_zone = '+0:00'"); // Do the query - if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; this->GetGLTABLES()->AddQ(); result = dbc->Query(myquery.Data()); if(! result->GetRowCount() ) {