#include <Coverage.h>
Public Member Functions | |
Coverage (calibUtil::Metadata *meta, const std::string &instr, const std::string &flavor, const std::string &level, const facilities::Timestamp &ts) | |
bool | expandTypes (std::string &nickname, std::vector< std::string > &types) |
~Coverage () | |
unsigned | checkType (std::string calibtype) |
void | setOverlap (unsigned seconds) |
Private Attributes | |
rdbModel::Connection * | m_conn |
rdbModel::Rdb * | m_rdb |
std::string | m_instr |
std::string | m_flavor |
std::string | m_level |
std::string | m_calib |
facilities::Timestamp | m_ts |
std::string | m_table |
unsigned | m_overlap |
std::vector< std::string > | m_selects |
std::vector< std::string > | m_orderBy |
Definition at line 26 of file Coverage.h.
Coverage::Coverage | ( | calibUtil::Metadata * | meta, | |
const std::string & | instr, | |||
const std::string & | flavor, | |||
const std::string & | level, | |||
const facilities::Timestamp & | ts | |||
) |
Definition at line 46 of file Coverage.cxx.
References facilities::Timestamp::getClibTime(), m_conn, m_orderBy, m_rdb, m_selects, m_table, m_ts, and meta.
00049 : m_instr(instr), m_flavor(flavor), m_level(level), m_overlap(300) { 00050 m_ts = facilities::Timestamp(ts.getClibTime()); 00051 m_selects.reserve(3); 00052 m_selects.push_back("ser_no"); 00053 m_selects.push_back("vstart"); 00054 m_selects.push_back("vend"); 00055 00056 m_orderBy.reserve(1); 00057 m_orderBy.push_back("vstart asc"); 00058 00059 m_rdb = meta->getRdb(); 00060 m_conn = meta->getReadConnection(); 00061 m_table = meta->getTable(); 00062 }
Coverage::~Coverage | ( | ) | [inline] |
unsigned Coverage::checkType | ( | std::string | calibtype | ) |
Definition at line 88 of file Coverage.cxx.
References rdbModel::FIELDTYPElit, rdbModel::FIELDTYPEold, facilities::Timestamp::getString(), m_conn, m_flavor, m_instr, m_level, m_orderBy, m_overlap, m_selects, m_table, m_ts, rdbModel::OPTYPEand, rdbModel::OPTYPEequal, rdbModel::OPTYPElessThan, and rdbModel::Connection::select().
Referenced by main().
00088 { 00089 using namespace rdbModel; 00090 using facilities::Timestamp; 00091 // Make a query to find all rows matching criteria, ordered ascending 00092 // by vstart 00093 // match calib_type, flavor, instrument, proc_level 00094 // completion = "OK" 00095 // vstart >= ts 00096 // Ask for return of ser_no, vstart, vend 00097 00098 std::vector<Assertion::Operator *> conditions; 00099 conditions.reserve(6); 00100 00101 Assertion::Operator completeOp(OPTYPEequal, "completion", "OK", 00102 FIELDTYPEold, FIELDTYPElit); 00103 // false, true); 00104 Assertion::Operator instOp(OPTYPEequal, "instrument", m_instr, 00105 FIELDTYPEold, FIELDTYPElit); 00106 // false, true); 00107 Assertion::Operator calibTypeOp(OPTYPEequal, "calib_type", calibtype, 00108 FIELDTYPEold, FIELDTYPElit); 00109 // false, true); 00110 Assertion::Operator flavorOp(OPTYPEequal, "flavor", m_flavor, 00111 FIELDTYPEold, FIELDTYPElit); 00112 // false, true); 00113 Assertion::Operator levelOp(OPTYPEequal, "proc_level", m_level, 00114 FIELDTYPEold, FIELDTYPElit); 00115 // false, true); 00116 Assertion::Operator vstartOp(OPTYPElessThan, m_ts.getString(), 00117 "vstart", 00118 FIELDTYPElit, FIELDTYPEold); 00119 // true, false); 00120 conditions.push_back(&calibTypeOp); 00121 conditions.push_back(&instOp); 00122 conditions.push_back(&flavorOp); 00123 conditions.push_back(&levelOp); 00124 conditions.push_back(&vstartOp); 00125 conditions.push_back(&completeOp); 00126 Assertion::Operator* andOp = new Assertion::Operator(OPTYPEand, conditions); 00127 Assertion* whereClause = new Assertion(andOp); 00128 00129 ResultHandle* results = 0; 00130 00131 try { // make the query 00132 results = m_conn->select(m_table, m_selects, m_orderBy, whereClause); 00133 } 00134 catch (RdbException ex) { 00135 std::cerr << ex.getMsg() << std::endl; 00136 std::cerr.flush(); // exit(1); 00137 return false; 00138 } 00139 00140 if (!results) { // Error. Should have ResultHandle even if 0 rows. 00141 std::cerr << "Error making query " << std::endl; 00142 std::cerr.flush(); 00143 exit(1); 00144 } 00145 00146 // Save returned values 00147 std::vector<SelectInfo> info; 00148 unsigned nFound = results->getNRows(); 00149 00150 if (!nFound) { 00151 std::cout << "No calibrations found for calib_type '" << calibtype 00152 << "'" << std::endl; 00153 return true; 00154 } 00155 00156 info.reserve(results->getNRows() ); 00157 00158 unsigned iRow = 0; 00159 std::vector<std::string> fields; 00160 fields.reserve(3); 00161 00162 bool ok = true; 00163 unsigned retCode = 0; 00164 00165 // 1. For each row store columnes; check if vstart < vend 00166 std::cout << std::endl 00167 << "Checking for valid timestamps, vstart < vend .. " 00168 << std::endl; 00169 for (iRow = 0; iRow < nFound; iRow++) { 00170 results->getRow(fields, iRow); 00171 int ser = facilities::Util::stringToInt(fields[0]); 00172 try { 00173 Timestamp vstart = Timestamp(fields[1]); 00174 Timestamp vend = Timestamp(fields[2]); 00175 info.push_back(SelectInfo(ser, vstart, vend)); 00176 00177 if (vend.getClibTime() < vstart.getClibTime() ) { 00178 std::cerr << "vend < vstart for " << info.back(); 00179 ok = false; // or could discard the row and try to continue 00180 retCode = 1; 00181 } 00182 } 00183 catch (facilities::BadTimeInput ex) { 00184 std::cerr << "Bad vstart or vend in row " << ser << std::endl; 00185 ok = false; 00186 retCode = 1; 00187 } 00188 00189 } 00190 if (!ok) return retCode; 00191 00192 // 2. Check if vend's also increase monotonically 00193 std::cout << std::endl << "Checking for vends monotonic.. " << std::endl; 00194 for (iRow = 0; iRow < nFound - 1; iRow++) { 00195 if (info[iRow].m_vend.getClibTime() > info[iRow+1].m_vend.getClibTime()) { 00196 std::cerr << "Validity interval for row with serial #" 00197 << info[iRow+1].m_ser 00198 << " completely contained in interval for row with serial #" 00199 << info[iRow].m_ser << std::endl; 00200 std::cerr << info[iRow]; 00201 std::cerr << info[iRow+1] << std::endl; 00202 ok = false; 00203 retCode = 2; 00204 } 00205 } 00206 if (!ok) return retCode; 00207 00208 // 3. Look for gaps 00209 std::cout << std::endl << "Checking for gaps.. " << std::endl; 00210 for (iRow = 0; iRow < nFound - 1; iRow++) { 00211 if (info[iRow].m_vend < info[iRow+1].m_vstart) { 00212 std::cerr << "Validity interval gap between calibrations with serial #" 00213 << info[iRow].m_ser << " and #" << info[iRow+1].m_ser 00214 << std::endl; 00215 std::cerr << info[iRow]; 00216 std::cerr << info[iRow+1] << std::endl; 00217 ok = false; 00218 retCode = 3; 00219 } 00220 } 00221 // 4. Look for overlaps 00222 std::cout << std::endl << "Checking for overlaps.. " << std::endl; 00223 for (iRow = 0; iRow < nFound - 1; iRow++) { 00224 if ((info[iRow].m_vend).getClibTime() > 00225 (info[iRow+1].m_vstart).getClibTime() + m_overlap) { 00226 std::cerr << "Unacceptable overlap between serial #" << info[iRow].m_ser 00227 << " and #" << info[iRow+1].m_ser << std::endl; 00228 std::cerr << info[iRow]; 00229 std::cerr << info[iRow+1] << std::endl; 00230 ok = false; 00231 if (!retCode) retCode = 4; 00232 } 00233 } 00234 return retCode; 00235 00236 }
bool Coverage::expandTypes | ( | std::string & | nickname, | |
std::vector< std::string > & | types | |||
) |
The argument may be a single legal calib_type or may be one of the special wildcard values "CAL" "TKR" "*", in which case it is expanded to a suitable list of calib types (if we have a schema)
Definition at line 67 of file Coverage.cxx.
References m_rdb.
Referenced by main().
00068 { 00069 if ((nickname == "CAL") || 00070 (nickname == "TKR") || 00071 (nickname == "*") ) { 00072 if (!m_rdb) { 00073 std::cerr << "Unable to expand wildcard argument " << nickname 00074 << " without schema for metadata dbs " << std::endl; 00075 } 00076 else { 00077 std::cerr << 00078 "Wildcard expansion of calib_type argument not yet supported"; 00079 std::cerr << std::endl << "Have a nice day" << std::endl; 00080 } 00081 std::cerr.flush(); 00082 exit(1); 00083 } 00084 types.push_back(nickname); 00085 return true; 00086 }
void Coverage::setOverlap | ( | unsigned | seconds | ) | [inline] |
std::string Coverage::m_calib [private] |
Definition at line 51 of file Coverage.h.
rdbModel::Connection* Coverage::m_conn [private] |
std::string Coverage::m_flavor [private] |
std::string Coverage::m_instr [private] |
std::string Coverage::m_level [private] |
std::vector<std::string> Coverage::m_orderBy [private] |
unsigned Coverage::m_overlap [private] |
rdbModel::Rdb* Coverage::m_rdb [private] |
std::vector<std::string> Coverage::m_selects [private] |
std::string Coverage::m_table [private] |
facilities::Timestamp Coverage::m_ts [private] |