BOSS 7.1.2
BESIII Offline Software System
Loading...
Searching...
No Matches
Coverage Class Reference

#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)
 

Detailed Description

Check whether calibrations for a particular calibration type (or each in a predefined collection) exist covering full time interval, and whether they overlap.

Definition at line 26 of file Coverage.h.

Constructor & Destructor Documentation

◆ Coverage()

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.

49 : m_instr(instr), m_flavor(flavor), m_level(level), m_overlap(300) {
51 m_selects.reserve(3);
52 m_selects.push_back("ser_no");
53 m_selects.push_back("vstart");
54 m_selects.push_back("vend");
55
56 m_orderBy.reserve(1);
57 m_orderBy.push_back("vstart asc");
58
59 m_rdb = meta->getRdb();
60 m_conn = meta->getReadConnection();
61 m_table = meta->getTable();
62}
double meta
long int getClibTime() const
Definition Timestamp.h:88

◆ ~Coverage()

Coverage::~Coverage ( )
inline

Definition at line 37 of file Coverage.h.

37{};

Member Function Documentation

◆ checkType()

unsigned Coverage::checkType ( std::string calibtype)

Definition at line 88 of file Coverage.cxx.

88 {
89 using namespace rdbModel;
91 // Make a query to find all rows matching criteria, ordered ascending
92 // by vstart
93 // match calib_type, flavor, instrument, proc_level
94 // completion = "OK"
95 // vstart >= ts
96 // Ask for return of ser_no, vstart, vend
97
98 std::vector<Assertion::Operator *> conditions;
99 conditions.reserve(6);
100
101 Assertion::Operator completeOp(OPTYPEequal, "completion", "OK",
102 FIELDTYPEold, FIELDTYPElit);
103 // false, true);
104 Assertion::Operator instOp(OPTYPEequal, "instrument", m_instr,
105 FIELDTYPEold, FIELDTYPElit);
106 // false, true);
107 Assertion::Operator calibTypeOp(OPTYPEequal, "calib_type", calibtype,
108 FIELDTYPEold, FIELDTYPElit);
109 // false, true);
110 Assertion::Operator flavorOp(OPTYPEequal, "flavor", m_flavor,
111 FIELDTYPEold, FIELDTYPElit);
112 // false, true);
113 Assertion::Operator levelOp(OPTYPEequal, "proc_level", m_level,
114 FIELDTYPEold, FIELDTYPElit);
115 // false, true);
116 Assertion::Operator vstartOp(OPTYPElessThan, m_ts.getString(),
117 "vstart",
118 FIELDTYPElit, FIELDTYPEold);
119 // true, false);
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);
126 Assertion::Operator* andOp = new Assertion::Operator(OPTYPEand, conditions);
127 Assertion* whereClause = new Assertion(andOp);
128
129 ResultHandle* results = 0;
130
131 try { // make the query
132 results = m_conn->select(m_table, m_selects, m_orderBy, whereClause);
133 }
134 catch (RdbException ex) {
135 std::cerr << ex.getMsg() << std::endl;
136 std::cerr.flush(); // exit(1);
137 return false;
138 }
139
140 if (!results) { // Error. Should have ResultHandle even if 0 rows.
141 std::cerr << "Error making query " << std::endl;
142 std::cerr.flush();
143 exit(1);
144 }
145
146 // Save returned values
147 std::vector<SelectInfo> info;
148 unsigned nFound = results->getNRows();
149
150 if (!nFound) {
151 std::cout << "No calibrations found for calib_type '" << calibtype
152 << "'" << std::endl;
153 return true;
154 }
155
156 info.reserve(results->getNRows() );
157
158 unsigned iRow = 0;
159 std::vector<std::string> fields;
160 fields.reserve(3);
161
162 bool ok = true;
163 unsigned retCode = 0;
164
165 // 1. For each row store columnes; check if vstart < vend
166 std::cout << std::endl
167 << "Checking for valid timestamps, vstart < vend .. "
168 << std::endl;
169 for (iRow = 0; iRow < nFound; iRow++) {
170 results->getRow(fields, iRow);
171 int ser = facilities::Util::stringToInt(fields[0]);
172 try {
173 Timestamp vstart = Timestamp(fields[1]);
174 Timestamp vend = Timestamp(fields[2]);
175 info.push_back(SelectInfo(ser, vstart, vend));
176
177 if (vend.getClibTime() < vstart.getClibTime() ) {
178 std::cerr << "vend < vstart for " << info.back();
179 ok = false; // or could discard the row and try to continue
180 retCode = 1;
181 }
182 }
183 catch (facilities::BadTimeInput ex) {
184 std::cerr << "Bad vstart or vend in row " << ser << std::endl;
185 ok = false;
186 retCode = 1;
187 }
188
189 }
190 if (!ok) return retCode;
191
192 // 2. Check if vend's also increase monotonically
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;
202 ok = false;
203 retCode = 2;
204 }
205 }
206 if (!ok) return retCode;
207
208 // 3. Look for gaps
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
214 << std::endl;
215 std::cerr << info[iRow];
216 std::cerr << info[iRow+1] << std::endl;
217 ok = false;
218 retCode = 3;
219 }
220 }
221 // 4. Look for overlaps
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;
230 ok = false;
231 if (!retCode) retCode = 4;
232 }
233 }
234 return retCode;
235
236 }
std::string getString() const
Return string representation of time, not including nanoseconds;.
Definition Timestamp.cxx:92
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.

Referenced by main().

◆ expandTypes()

bool Coverage::expandTypes ( std::string & nickname,
std::vector< std::string > & types )

The @nickname 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.

68 {
69 if ((nickname == "CAL") ||
70 (nickname == "TKR") ||
71 (nickname == "*") ) {
72 if (!m_rdb) {
73 std::cerr << "Unable to expand wildcard argument " << nickname
74 << " without schema for metadata dbs " << std::endl;
75 }
76 else {
77 std::cerr <<
78 "Wildcard expansion of calib_type argument not yet supported";
79 std::cerr << std::endl << "Have a nice day" << std::endl;
80 }
81 std::cerr.flush();
82 exit(1);
83 }
84 types.push_back(nickname);
85 return true;
86}

Referenced by main().

◆ setOverlap()

void Coverage::setOverlap ( unsigned seconds)
inline

Definition at line 44 of file Coverage.h.

44{m_overlap = seconds;}

The documentation for this class was generated from the following files: