11 using namespace oracle::occi;
38 if (tag != m_monRunTag) {
55 if (iov != m_runIOV) {
69 if (subrun != m_subRunNum) {
86 if (start != m_subRunStart) {
88 m_subRunStart =
start;
103 if (end != m_subRunEnd) {
119 throw(std::runtime_error)
126 this->checkConnection();
129 int monRunTagID, runIOVID;
130 this->fetchParentIDs(&monRunTagID, &runIOVID);
132 if (!monRunTagID || !runIOVID) {
138 if (m_subRunEnd.isNull()) {
143 Statement* stmt = m_conn->createStatement();
144 stmt->setSQL(
"SELECT iov_id FROM mon_run_iov "
145 "WHERE tag_id = :1 AND "
146 "run_iov_id = :2 AND "
147 "subrun_num = :3 AND "
148 "subrun_start = :4 AND "
150 stmt->setInt(1, monRunTagID);
151 stmt->setInt(2, runIOVID);
152 stmt->setInt(3, m_subRunNum);
153 stmt->setDate(4, dh.
tmToDate(m_subRunStart));
154 stmt->setDate(5, dh.
tmToDate(m_subRunEnd));
159 m_ID = rset->getInt(1);
163 m_conn->terminateStatement(stmt);
165 throw(std::runtime_error(
"MonRunIOV::fetchID: "+e.getMessage()));
174 throw(std::runtime_error)
176 this->checkConnection();
181 Statement* stmt = m_conn->createStatement();
183 stmt->setSQL(
"SELECT tag_id, run_iov_id, subrun_num, subrun_start, subrun_end FROM mon_run_iov WHERE iov_id = :1");
188 int monRunTagID = rset->getInt(1);
189 int runIOVID = rset->getInt(2);
190 m_subRunNum = rset->getInt(3);
191 Date startDate = rset->getDate(4);
192 Date endDate = rset->getDate(5);
194 m_subRunStart = dh.
dateToTm( startDate );
195 m_subRunEnd = dh.
dateToTm( endDate );
197 m_monRunTag.setConnection(m_env, m_conn);
198 m_monRunTag.setByID(monRunTagID);
200 m_runIOV.setConnection(m_env, m_conn);
201 m_runIOV.setByID(runIOVID);
205 throw(std::runtime_error(
"MonRunIOV::setByID: Given tag_id is not in the database"));
208 m_conn->terminateStatement(stmt);
210 throw(std::runtime_error(
"MonRunIOV::setByID: "+e.getMessage()));
217 throw(std::runtime_error)
219 this->checkConnection();
222 if (this->fetchID()) {
227 int monRunTagID, runIOVID;
228 this->fetchParentIDs(&monRunTagID, &runIOVID);
231 monRunTagID = m_monRunTag.writeDB();
237 if (m_subRunStart.isNull()) {
238 throw(std::runtime_error(
"MonRunIOV::writeDB: Must setSubRunStart before writing"));
241 if (m_subRunEnd.isNull()) {
246 Statement* stmt = m_conn->createStatement();
248 stmt->setSQL(
"INSERT INTO mon_run_iov (iov_id, tag_id, run_iov_id, subrun_num, subrun_start, subrun_end) "
249 "VALUES (mon_run_iov_sq.NextVal, :1, :2, :3, :4, :5)");
250 stmt->setInt(1, monRunTagID);
251 stmt->setInt(2, runIOVID);
252 stmt->setInt(3, m_subRunNum);
253 stmt->setDate(4, dh.
tmToDate(m_subRunStart));
254 stmt->setDate(5, dh.
tmToDate(m_subRunEnd));
256 stmt->executeUpdate();
258 m_conn->terminateStatement(stmt);
260 throw(std::runtime_error(
"MonRunIOV::writeDB: "+e.getMessage()));
264 if (!this->fetchID()) {
265 throw(std::runtime_error(
"MonRunIOV::writeDB: Failed to write"));
274 throw(std::runtime_error)
277 m_monRunTag.setConnection(m_env, m_conn);
278 *monRunTagID = m_monRunTag.fetchID();
281 m_runIOV.setConnection(m_env, m_conn);
282 *runIOVID = m_runIOV.fetchID();
285 throw(std::runtime_error(
"MonRunIOV: Given RunIOV does not exist in DB"));
293 throw(std::runtime_error)
295 this->checkConnection();
297 runiov->setConnection(m_env, m_conn);
298 int runIOVID = runiov->fetchID();
301 throw(std::runtime_error(
"MonRunIOV::setByRun: Given RunIOV does not exist in DB"));
304 montag->setConnection(m_env, m_conn);
305 int monTagID = montag->fetchID();
308 throw(std::runtime_error(
"MonRunIOV::setByRun: Given MonRunTag does not exist in the DB"));
314 Statement* stmt = m_conn->createStatement();
316 stmt->setSQL(
"SELECT iov_id, subrun_start, subrun_end FROM mon_run_iov "
317 "WHERE tag_id = :1 AND run_iov_id = :2 AND subrun_num = :3");
318 stmt->setInt(1, monTagID);
319 stmt->setInt(2, runIOVID);
320 stmt->setInt(3, subrun);
324 m_monRunTag = *montag;
326 m_subRunNum = subrun;
328 m_ID = rset->getInt(1);
329 Date startDate = rset->getDate(2);
330 Date endDate = rset->getDate(3);
332 m_subRunStart = dh.
dateToTm( startDate );
333 m_subRunEnd = dh.
dateToTm( endDate );
335 throw(std::runtime_error(
"MonRunIOV::setByRun: Given subrun is not in the database"));
338 m_conn->terminateStatement(stmt);
340 throw(std::runtime_error(
"MonRunIOV::setByRun: "+e.getMessage()));
tuple start
Check for commandline option errors.
void setRunIOV(const RunIOV &iov)
run_t getSubRunNumber() const
oracle::occi::SQLException SQLException
Tm getSubRunStart() const
void setByRun(MonRunTag *montag, RunIOV *runiov, subrun_t subrun)
MonRunTag getMonRunTag() const
void setSubRunEnd(const Tm &end)
void setSubRunNumber(subrun_t subrun)
oracle::occi::Date tmToDate(const Tm &inTm) const
void setSubRunStart(const Tm &start)
void fetchParentIDs(int *monRunTagID, int *runIOVID)
void setMonRunTag(const MonRunTag &tag)
oracle::occi::ResultSet ResultSet
Tm dateToTm(oracle::occi::Date &date) const