38 if (iov != m_runIOV) {
52 if (subrun != m_subRunNum) {
69 if (start != m_subRunStart) {
71 m_subRunStart =
start;
86 if (end != m_subRunEnd) {
109 this->checkConnection();
113 this->fetchParentIDs(&runIOVID);
121 if (m_subRunEnd.isNull()) {
126 Statement* stmt = m_conn->createStatement();
127 stmt->setSQL(
"SELECT iov_id FROM OD_run_iov " 129 "run_iov_id = :1 AND " 130 "subrun_num = :2 AND " 131 "subrun_start = :3 AND " 134 stmt->setInt(1, runIOVID);
135 stmt->setInt(2, m_subRunNum);
136 stmt->setDate(3, dh.
tmToDate(m_subRunStart));
137 stmt->setDate(4, dh.
tmToDate(m_subRunEnd));
139 ResultSet* rset = stmt->executeQuery();
142 m_ID = rset->getInt(1);
146 m_conn->terminateStatement(stmt);
147 }
catch (SQLException &
e) {
148 throw(std::runtime_error(
"MODRunIOV::fetchID: "+e.getMessage()));
159 this->checkConnection();
164 Statement* stmt = m_conn->createStatement();
166 stmt->setSQL(
"SELECT run_iov_id, subrun_num, subrun_start, subrun_end FROM OD_run_iov WHERE iov_id = :1");
169 ResultSet* rset = stmt->executeQuery();
171 int runIOVID = rset->getInt(1);
172 m_subRunNum = rset->getInt(2);
173 Date startDate = rset->getDate(3);
174 Date endDate = rset->getDate(4);
176 m_subRunStart = dh.
dateToTm( startDate );
177 m_subRunEnd = dh.
dateToTm( endDate );
179 m_runIOV.setConnection(m_env, m_conn);
180 m_runIOV.setByID(runIOVID);
184 throw(std::runtime_error(
"MODRunIOV::setByID: Given id is not in the database"));
187 m_conn->terminateStatement(stmt);
188 }
catch (SQLException &
e) {
189 throw(std::runtime_error(
"MODRunIOV::setByID: "+e.getMessage()));
198 this->checkConnection();
201 if (this->fetchID()) {
207 this->fetchParentIDs(&runIOVID);
212 if (m_subRunStart.isNull()) {
213 throw(std::runtime_error(
"MODRunIOV::writeDB: Must setSubRunStart before writing"));
216 if (m_subRunEnd.isNull()) {
221 Statement* stmt = m_conn->createStatement();
223 stmt->setSQL(
"INSERT INTO od_run_iov (iov_id, run_iov_id, subrun_num, subrun_start, subrun_end) " 224 "VALUES (OD_run_iov_sq.NextVal, :1, :2, :3, :4)");
225 stmt->setInt(1, runIOVID);
226 stmt->setInt(2, m_subRunNum);
227 stmt->setDate(3, dh.
tmToDate(m_subRunStart));
228 stmt->setDate(4, dh.
tmToDate(m_subRunEnd));
230 stmt->executeUpdate();
232 m_conn->terminateStatement(stmt);
233 }
catch (SQLException &
e) {
234 throw(std::runtime_error(
"MODRunIOV::writeDB: "+e.getMessage()));
238 if (!this->fetchID()) {
239 throw(std::runtime_error(
"MODRunIOV::writeDB: Failed to write"));
251 m_runIOV.setConnection(m_env, m_conn);
252 *runIOVID = m_runIOV.fetchID();
255 throw(std::runtime_error(
"MODRunIOV: Given RunIOV does not exist in DB"));
265 this->checkConnection();
267 runiov->setConnection(m_env, m_conn);
268 int runIOVID = runiov->fetchID();
271 throw(std::runtime_error(
"MODRunIOV::setByRun: Given RunIOV does not exist in DB"));
277 Statement* stmt = m_conn->createStatement();
279 stmt->setSQL(
"SELECT iov_id, subrun_start, subrun_end FROM OD_run_iov " 280 "WHERE run_iov_id = :1 AND subrun_num = :2");
281 stmt->setInt(1, runIOVID);
282 stmt->setInt(2, subrun);
284 ResultSet* rset = stmt->executeQuery();
287 m_subRunNum = subrun;
289 m_ID = rset->getInt(1);
290 Date startDate = rset->getDate(2);
291 Date endDate = rset->getDate(3);
293 m_subRunStart = dh.
dateToTm( startDate );
294 m_subRunEnd = dh.
dateToTm( endDate );
296 throw(std::runtime_error(
"MODRunIOV::setByRun: Given subrun is not in the database"));
299 m_conn->terminateStatement(stmt);
300 }
catch (SQLException &
e) {
301 throw(std::runtime_error(
"MODRunIOV::setByRun: "+e.getMessage()));
void setRunIOV(const RunIOV &iov)
int writeDB() noexcept(false)
Tm getSubRunStart() const
void setSubRunEnd(const Tm &end)
int fetchID() noexcept(false)
run_t getSubRunNumber() const
void setByID(int id) noexcept(false)
oracle::occi::Date tmToDate(const Tm &inTm) const
void setSubRunStart(const Tm &start)
void fetchParentIDs(int *runIOVID) noexcept(false)
void setSubRunNumber(subrun_t subrun)
void setByRun(RunIOV *runiov, subrun_t subrun) noexcept(false)
Tm dateToTm(oracle::occi::Date &date) const