12#include "facilities/Util.h"
13#include "calibUtil/Metadata.h"
14#include "rdbModel/Management/Manager.h"
15#include "rdbModel/Management/XercesBuilder.h"
17#include "rdbModel/Db/MysqlConnection.h"
18#include "rdbModel/Db/MysqlResults.h"
19#include "rdbModel/Rdb.h"
20#include "rdbModel/RdbException.h"
21#include "rdbModel/Tables/Assertion.h"
22#include "rdbModel/Tables/Table.h"
23#include "rdbModel/Tables/Column.h"
40 out <<
"Serial #" << info.
m_ser <<
" validitiy interval ["
47 const std::string& instr,
const std::string& flavor,
49 : m_instr(instr), m_flavor(flavor), m_level(level), m_overlap(300) {
52 m_selects.push_back(
"ser_no");
53 m_selects.push_back(
"vstart");
54 m_selects.push_back(
"vend");
57 m_orderBy.push_back(
"vstart asc");
59 m_rdb =
meta->getRdb();
60 m_conn =
meta->getReadConnection();
61 m_table =
meta->getTable();
68 std::vector<std::string>& types) {
69 if ((nickname ==
"CAL") ||
70 (nickname ==
"TKR") ||
73 std::cerr <<
"Unable to expand wildcard argument " << nickname
74 <<
" without schema for metadata dbs " << std::endl;
78 "Wildcard expansion of calib_type argument not yet supported";
79 std::cerr << std::endl <<
"Have a nice day" << std::endl;
84 types.push_back(nickname);
98 std::vector<Assertion::Operator *> conditions;
99 conditions.reserve(6);
102 FIELDTYPEold, FIELDTYPElit);
105 FIELDTYPEold, FIELDTYPElit);
108 FIELDTYPEold, FIELDTYPElit);
111 FIELDTYPEold, FIELDTYPElit);
114 FIELDTYPEold, FIELDTYPElit);
118 FIELDTYPElit, FIELDTYPEold);
120 conditions.push_back(&calibTypeOp);
121 conditions.push_back(&instOp);
122 conditions.push_back(&flavorOp);
123 conditions.push_back(&levelOp);
124 conditions.push_back(&vstartOp);
125 conditions.push_back(&completeOp);
132 results = m_conn->
select(m_table, m_selects, m_orderBy, whereClause);
135 std::cerr << ex.
getMsg() << std::endl;
141 std::cerr <<
"Error making query " << std::endl;
147 std::vector<SelectInfo> info;
148 unsigned nFound = results->
getNRows();
151 std::cout <<
"No calibrations found for calib_type '" << calibtype
159 std::vector<std::string> fields;
163 unsigned retCode = 0;
166 std::cout << std::endl
167 <<
"Checking for valid timestamps, vstart < vend .. "
169 for (iRow = 0; iRow < nFound; iRow++) {
170 results->
getRow(fields, iRow);
173 Timestamp vstart = Timestamp(fields[1]);
174 Timestamp vend = Timestamp(fields[2]);
175 info.push_back(
SelectInfo(ser, vstart, vend));
177 if (vend.getClibTime() < vstart.getClibTime() ) {
178 std::cerr <<
"vend < vstart for " << info.back();
184 std::cerr <<
"Bad vstart or vend in row " << ser << std::endl;
190 if (!ok)
return retCode;
193 std::cout << std::endl <<
"Checking for vends monotonic.. " << std::endl;
194 for (iRow = 0; iRow < nFound - 1; iRow++) {
195 if (info[iRow].m_vend.getClibTime() > info[iRow+1].m_vend.getClibTime()) {
196 std::cerr <<
"Validity interval for row with serial #"
197 << info[iRow+1].m_ser
198 <<
" completely contained in interval for row with serial #"
199 << info[iRow].m_ser << std::endl;
200 std::cerr << info[iRow];
201 std::cerr << info[iRow+1] << std::endl;
206 if (!ok)
return retCode;
209 std::cout << std::endl <<
"Checking for gaps.. " << std::endl;
210 for (iRow = 0; iRow < nFound - 1; iRow++) {
211 if (info[iRow].m_vend < info[iRow+1].m_vstart) {
212 std::cerr <<
"Validity interval gap between calibrations with serial #"
213 << info[iRow].m_ser <<
" and #" << info[iRow+1].m_ser
215 std::cerr << info[iRow];
216 std::cerr << info[iRow+1] << std::endl;
222 std::cout << std::endl <<
"Checking for overlaps.. " << std::endl;
223 for (iRow = 0; iRow < nFound - 1; iRow++) {
224 if ((info[iRow].m_vend).getClibTime() >
225 (info[iRow+1].m_vstart).getClibTime() + m_overlap) {
226 std::cerr <<
"Unacceptable overlap between serial #" << info[iRow].m_ser
227 <<
" and #" << info[iRow+1].m_ser << std::endl;
228 std::cerr << info[iRow];
229 std::cerr << info[iRow+1] << std::endl;
231 if (!retCode) retCode = 4;
std::ostream & operator<<(std::ostream &out, const SelectInfo &info)
unsigned checkType(std::string calibtype)
bool expandTypes(std::string &nickname, std::vector< std::string > &types)
Coverage(calibUtil::Metadata *meta, const std::string &instr, const std::string &flavor, const std::string &level, const facilities::Timestamp &ts)
facilities::Timestamp m_vstart
SelectInfo(int ser, const facilities::Timestamp &start, const facilities::Timestamp &end)
facilities::Timestamp m_vend
std::string getString() const
Return string representation of time, not including nanoseconds;.
long int getClibTime() const
static int stringToInt(const std::string &InStr)
virtual ResultHandle * select(const std::string &tableName, const StringVector &getCols, const StringVector &orderCols, const Assertion *where=0, int rowLimit=0, int rowOffset=0)=0
virtual std::string getMsg()
virtual bool getRow(std::vector< std::string > &fields, unsigned int i=0, bool clear=true)=0
virtual unsigned int getNRows() const =0
Return number of rows in results.