--- YodaProfiler/src/GLTables.cpp 2006/09/06 11:04:39 1.5 +++ YodaProfiler/src/GLTables.cpp 2006/09/08 08:48:04 1.8 @@ -759,7 +759,8 @@ }; delete pResult; // - if(TO_TIME < time)return(51); + if ( TO_TIME < time ) return(51); + // if ( (!OBT1 && !PKT1 ) || (!OBT2 && !PKT2) ) return(52); // ONE CALIBRATION PACKET IS MISSING! // return 0; @@ -772,12 +773,13 @@ * \param run starting time * \return struct of type GL_CALO_CALIB_data, which stores the query result */ -Int_t GL_CALO_CALIB::Query_GL_CALO_CALIB(UInt_t time, UInt_t section, TSQLServer *dbc){ +Int_t GL_CALO_CALIB::Query_GL_CALO_CALIB(UInt_t time, UInt_t &uptime, UInt_t section, TSQLServer *dbc){ // MySQL variables TSQLResult *pResult; TSQLRow *Row; int t; stringstream myquery; + uptime = 0; // // select the correct calibration // @@ -785,14 +787,21 @@ myquery << "select ID_ROOT_L0, FROM_TIME, TO_TIME, EV_ROOT,VALIDATION from GL_CALO_CALIB where SECTION=" << section; myquery << " and FROM_TIME <= " << time; myquery << " and TO_TIME > " << time; - myquery << " and VALIDATION=1;"; + myquery << " ;"; + //myquery << " and VALIDATION=1;"; // pResult = dbc->Query(myquery.str().c_str()); + // printf(" mysquery is %s\n",myquery.str().c_str()); + // + if( !pResult->GetRowCount() ) return(-54); + Row = pResult->Next(); + if( Row == NULL ) return (-54); + // + uptime = (UInt_t)atoll(Row->GetField(2)); // // if it is corrupted validation is 0 and we have no results from the query... // - if( !pResult->GetRowCount() ){ - // pResult->Delete(); + if( atoi(Row->GetField(4)) == 0 ){ // if validation = 0 // // in this case take relax the conditions and take the valid calibration that preceed the correct one // @@ -801,15 +810,18 @@ myquery << " and FROM_TIME <= " << time; myquery << " and VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;"; pResult = dbc->Query(myquery.str().c_str()); + // printf(" mysquery is %s\n",myquery.str().c_str()); // // if no results yet quit with error // if( !pResult->GetRowCount() ) return (-54); + // + Row = pResult->Next(); + // }; // // store infos and exit // - Row = pResult->Next(); if( Row == NULL ) return (-54); for( t = 0; t < pResult->GetFieldCount(); t++){ if (t==0) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); @@ -1098,3 +1110,51 @@ // return(rtime); } + +/* + * + * Convert the time in the DB from UInt_t to a string + * + * @param dbt time in the DB + * @param tzone Time Zone, can be UTC,GMT,CET,CEST,MSD default is MSK + * + */ +TString GL_TIMESYNC::UnConvertTime(TString tzone, UInt_t dbt){ + // + TDatime *time = new TDatime(); + TString rtime; + // + time->Set(dbt,false); // MSK = Moscow Winter Time + // + if ( !strcmp(tzone.Data(),"UTC") || !strcmp(tzone.Data(),"GMT") ){ + // + UInt_t timeUTC = time->Convert() + 60*60*3; // UTC (Coordinated Universal Time) +3 hs = Moscow Winter Time + time->Set(timeUTC,false); + // + }; + // + if ( !strcmp(tzone.Data(),"CET") ){ + // + UInt_t timeCET = time->Convert() + 60*60*2; // CET (Central European Time) + 2 hs = Moscow Winter Time + time->Set(timeCET,false); + // + }; + // + if ( !strcmp(tzone.Data(),"CEST") ){ + // + UInt_t timeCEST = time->Convert() + 60*60*1; // CEST (Central European Summer Time) + 1 h = Moscow Winter Time + time->Set(timeCEST,false); + // + }; + // + if ( !strcmp(tzone.Data(),"MSD") ){ + // + UInt_t timeMSD = time->Convert() - 60*60*1; // MSD (Moscow Summer Time) - 1 h = Moscow Winter Time + time->Set(timeMSD,false); + // + }; + // + rtime = time->AsSQLString(); + // + return(rtime); +}