#include "ISlowControlMySQLRow.hxx" #include // ROOT includes #include "TUrl.h" #include "TSQLResult.h" #include "TSQLRow.h" #define GSC_ROW_ERROR_CODE -9999; ISlowControlMySQLRow::ISlowControlMySQLRow(TSQLResult *result, TSQLRow *row, std::string itable_name){ fEndTime = 0x7fffffff; table_name = itable_name; fSQLResult = result; fSQLRow = row; if(result->GetFieldCount() >= 2){ fStartTime = GetValueInteger("_i_time"); } } bool ISlowControlMySQLRow::HasField(std::string field){ for(int i = 0; i < fSQLResult->GetFieldCount(); i++){ std::string tmp(fSQLResult->GetFieldName(i)); if(tmp == field) return true; } return false; } void ISlowControlMySQLRow::SetEndTime(int interval_end_time){ fEndTime = interval_end_time; if(fEndTime <= fStartTime) COMETError("ISlowControlMySQLRow::SetEndTime: wrong start/end time: " << fStartTime << " " << fEndTime); }; bool ISlowControlMySQLRow::IsLastRow(){ if(fEndTime == 0x7fffffff) return true; return false; } float ISlowControlMySQLRow::GetValueFloat(std::string field){ // Find the column that matchs our field. for(int i = 0; i < fSQLResult->GetFieldCount(); i++){ std::string tmp(fSQLResult->GetFieldName(i)); if(tmp == field){ // Check if field is NULL. if(fSQLRow->GetField(i)) return atof(fSQLRow->GetField(i)); else return GSC_ROW_ERROR_CODE; } } return GSC_ROW_ERROR_CODE; } int ISlowControlMySQLRow::GetValueInteger(std::string field){ // Find the column that matchs our field. for(int i = 0; i < fSQLResult->GetFieldCount(); i++){ std::string tmp(fSQLResult->GetFieldName(i)); if(tmp == field){ // Check if field is NULL. if(fSQLRow->GetField(i)) return atoi(fSQLRow->GetField(i)); else return GSC_ROW_ERROR_CODE; } } return GSC_ROW_ERROR_CODE; } std::string ISlowControlMySQLRow::GetValueString(std::string field){ // Find the column that matchs our field. for(int i = 0; i < fSQLResult->GetFieldCount(); i++){ std::string tmp(fSQLResult->GetFieldName(i)); if(tmp == field){ // Check if field is NULL. if(fSQLRow->GetField(i)) return std::string(fSQLRow->GetField(i)); else return std::string("NULL"); } } return std::string("COULD_NOT_FIND_GSC_FIELD"); } void ISlowControlMySQLRow::Print(){ COMETLog("These are contents of table " << table_name.c_str()); // Don't print last row (it is cruft, associated with MYSQL command). for(int i = 0; i < fSQLResult->GetFieldCount()-1; i++){ if(fSQLRow->GetField(i)) COMETLog("Variable " << fSQLResult->GetFieldName(i) << " has value = " << fSQLRow->GetField(i)); else COMETLog("Variable " << fSQLResult->GetFieldName(i) << " has value = **** UNDEFINED ****"); } }