#include "odbGscUtils.hxx" #include #include bool odbGscUtils::IsODBContextValid(COMET::ICOMETContext context){ // Add 5 seconds to time, just to be sure we don't have problems with // timestamp. int time = context.GetTimeStamp() + 5; // Get partition code int partition = context.GetPartition(); // Check for invalid partitions, or blank partitions or MC partitions; // if so, return false; if(partition & COMET::ICOMETContext::kMCData || partition == 0xdeadbeef || partition == 0){ return false; } // Do different checks for global or FGD or TPC partition data. if(partition & COMET::ICOMETContext::kGlobalPartition){ // Now do some checks using the global run number stored in FGD and TPC cascade ODB } else if(partition & COMET::ICOMETContext::kFGDClockPresent){ // Do check using the local FGD run number; should be same as run number in context. ISlowControlMySQLRow* rowRunInfo = ISlowControlDatabase::ODB().GetTable(time,"FGD_Runinfo"); if(!rowRunInfo) return false; int run = rowRunInfo->GetValueInteger("Runnumber"); if(run != context.GetRun()) return false; } else if(partition & COMET::ICOMETContext::kTPCClockPresent){ std::cout << "TPC clock" << std::endl; // Do check using the local TPC run number; should be same as run number in context. ISlowControlMySQLRow* rowRunInfo = ISlowControlDatabase::ODB().GetTable(time,"TPC_Runinfo"); if(!rowRunInfo) return false; int run = rowRunInfo->GetValueInteger("Runnumber"); if(run != context.GetRun()) return false; } return true; } double odbGscUtils::GetODBVarDouble(COMET::ICOMETContext context,const char *table, const char *fieldname){ if(!IsODBContextValid(context)) return odbGscUtils::odb_gsc_error; // Add 5 seconds to time, just to be sure we don't have problems with // timestamp. int time = context.GetTimeStamp() + 5; return ISlowControlDatabase::ODB().QueryShowFieldDouble(time,table,fieldname); } int odbGscUtils::GetODBVarInteger(COMET::ICOMETContext context,const char *table, const char *fieldname){ if(!IsODBContextValid(context)) return odbGscUtils::odb_gsc_error; // Add 5 seconds to time, just to be sure we don't have problems with // timestamp. int time = context.GetTimeStamp() + 5; return ISlowControlDatabase::ODB().QueryShowFieldInteger(time,table,fieldname); } std::string odbGscUtils::GetODBVarString(COMET::ICOMETContext context,const char *table, const char *fieldname){ if(!IsODBContextValid(context)) return std::string("odbGscUtils::odb_gsc_error"); // Add 5 seconds to time, just to be sure we don't have problems with // timestamp. int time = context.GetTimeStamp() + 5; return ISlowControlDatabase::ODB().QueryShowFieldString(time,table,fieldname); }