84 {
85 using namespace rdbModel;
86 using facilities::Timestamp;
87
88
89
90
91
92
93
94 std::vector<Assertion::Operator*> conditions;
95 conditions.reserve( 6 );
96
97 Assertion::Operator completeOp( OPTYPEequal, "completion", "OK", FIELDTYPEold,
98 FIELDTYPElit );
99
100 Assertion::Operator instOp( OPTYPEequal, "instrument", m_instr, FIELDTYPEold, FIELDTYPElit );
101
102 Assertion::Operator calibTypeOp( OPTYPEequal, "calib_type", calibtype, FIELDTYPEold,
103 FIELDTYPElit );
104
105 Assertion::Operator flavorOp( OPTYPEequal, "flavor", m_flavor, FIELDTYPEold, FIELDTYPElit );
106
107 Assertion::Operator levelOp( OPTYPEequal, "proc_level", m_level, FIELDTYPEold,
108 FIELDTYPElit );
109
110 Assertion::Operator vstartOp( OPTYPElessThan, m_ts.getString(), "vstart", FIELDTYPElit,
111 FIELDTYPEold );
112
113 conditions.push_back( &calibTypeOp );
114 conditions.push_back( &instOp );
115 conditions.push_back( &flavorOp );
116 conditions.push_back( &levelOp );
117 conditions.push_back( &vstartOp );
118 conditions.push_back( &completeOp );
119 Assertion::Operator* andOp = new Assertion::Operator( OPTYPEand, conditions );
120 Assertion* whereClause = new Assertion( andOp );
121
122 ResultHandle* results = 0;
123
124 try
125 {
126 results = m_conn->select( m_table, m_selects, m_orderBy, whereClause );
127 } catch ( RdbException ex )
128 {
129 std::cerr << ex.
getMsg() << std::endl;
130 std::cerr.flush();
131 return false;
132 }
133
134 if ( !results )
135 {
136 std::cerr << "Error making query " << std::endl;
137 std::cerr.flush();
138 exit( 1 );
139 }
140
141
142 std::vector<SelectInfo> info;
143 unsigned nFound = results->
getNRows();
144
145 if ( !nFound )
146 {
147 std::cout << "No calibrations found for calib_type '" << calibtype << "'" << std::endl;
148 return true;
149 }
150
151 info.reserve( results->
getNRows() );
152
153 unsigned iRow = 0;
154 std::vector<std::string> fields;
155 fields.reserve( 3 );
156
157 bool ok = true;
158 unsigned retCode = 0;
159
160
161 std::cout << std::endl << "Checking for valid timestamps, vstart < vend .. " << std::endl;
162 for ( iRow = 0; iRow < nFound; iRow++ )
163 {
164 results->
getRow( fields, iRow );
166 try
167 {
168 Timestamp vstart = Timestamp( fields[1] );
169 Timestamp vend = Timestamp( fields[2] );
170 info.push_back( SelectInfo( ser, vstart, vend ) );
171
172 if ( vend.getClibTime() < vstart.getClibTime() )
173 {
174 std::cerr << "vend < vstart for " << info.back();
175 ok = false;
176 retCode = 1;
177 }
178 } catch ( facilities::BadTimeInput ex )
179 {
180 std::cerr << "Bad vstart or vend in row " << ser << std::endl;
181 ok = false;
182 retCode = 1;
183 }
184 }
185 if ( !ok ) return retCode;
186
187
188 std::cout << std::endl << "Checking for vends monotonic.. " << std::endl;
189 for ( iRow = 0; iRow < nFound - 1; iRow++ )
190 {
191 if ( info[iRow].m_vend.getClibTime() > info[iRow + 1].m_vend.getClibTime() )
192 {
193 std::cerr << "Validity interval for row with serial #" << info[iRow + 1].m_ser
194 << " completely contained in interval for row with serial #"
195 << info[iRow].m_ser << std::endl;
196 std::cerr << info[iRow];
197 std::cerr << info[iRow + 1] << std::endl;
198 ok = false;
199 retCode = 2;
200 }
201 }
202 if ( !ok ) return retCode;
203
204
205 std::cout << std::endl << "Checking for gaps.. " << std::endl;
206 for ( iRow = 0; iRow < nFound - 1; iRow++ )
207 {
208 if ( info[iRow].m_vend < info[iRow + 1].m_vstart )
209 {
210 std::cerr << "Validity interval gap between calibrations with serial #"
211 << info[iRow].m_ser << " and #" << info[iRow + 1].m_ser << std::endl;
212 std::cerr << info[iRow];
213 std::cerr << info[iRow + 1] << std::endl;
214 ok = false;
215 retCode = 3;
216 }
217 }
218
219 std::cout << std::endl << "Checking for overlaps.. " << std::endl;
220 for ( iRow = 0; iRow < nFound - 1; iRow++ )
221 {
222 if ( ( info[iRow].m_vend ).getClibTime() >
223 ( info[iRow + 1].m_vstart ).getClibTime() + m_overlap )
224 {
225 std::cerr << "Unacceptable overlap between serial #" << info[iRow].m_ser << " and #"
226 << info[iRow + 1].m_ser << std::endl;
227 std::cerr << info[iRow];
228 std::cerr << info[iRow + 1] << std::endl;
229 ok = false;
230 if ( !retCode ) retCode = 4;
231 }
232 }
233 return retCode;
234}
static int stringToInt(const std::string &InStr)
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.