26 if (iov != m_runIOV) {
35 if (subrun != m_subRunNum) {
44 if (
start != m_subRunStart) {
46 m_subRunStart =
start;
53 if (
end != m_subRunEnd) {
67 this->checkConnection();
71 this->fetchParentIDs(&runIOVID);
79 if (m_subRunEnd.isNull()) {
80 m_subRunEnd =
dh.getPlusInfTm();
84 Statement* stmt = m_conn->createStatement();
86 "SELECT iov_id FROM OD_run_iov " 88 "run_iov_id = :1 AND " 89 "subrun_num = :2 AND " 90 "subrun_start = :3 AND " 93 stmt->setInt(1, runIOVID);
94 stmt->setInt(2, m_subRunNum);
95 stmt->setDate(3,
dh.tmToDate(m_subRunStart));
96 stmt->setDate(4,
dh.tmToDate(m_subRunEnd));
98 ResultSet* rset = stmt->executeQuery();
101 m_ID = rset->getInt(1);
105 m_conn->terminateStatement(stmt);
106 }
catch (SQLException&
e) {
107 throw(std::runtime_error(
"MODRunIOV::fetchID: " +
e.getMessage()));
114 this->checkConnection();
119 Statement* stmt = m_conn->createStatement();
121 stmt->setSQL(
"SELECT run_iov_id, subrun_num, subrun_start, subrun_end FROM OD_run_iov WHERE iov_id = :1");
124 ResultSet* rset = stmt->executeQuery();
126 int runIOVID = rset->getInt(1);
127 m_subRunNum = rset->getInt(2);
128 Date startDate = rset->getDate(3);
129 Date endDate = rset->getDate(4);
131 m_subRunStart =
dh.dateToTm(startDate);
132 m_subRunEnd =
dh.dateToTm(endDate);
134 m_runIOV.setConnection(m_env, m_conn);
135 m_runIOV.setByID(runIOVID);
139 throw(std::runtime_error(
"MODRunIOV::setByID: Given id is not in the database"));
142 m_conn->terminateStatement(stmt);
143 }
catch (SQLException&
e) {
144 throw(std::runtime_error(
"MODRunIOV::setByID: " +
e.getMessage()));
149 this->checkConnection();
152 if (this->fetchID()) {
158 this->fetchParentIDs(&runIOVID);
163 if (m_subRunStart.isNull()) {
164 throw(std::runtime_error(
"MODRunIOV::writeDB: Must setSubRunStart before writing"));
167 if (m_subRunEnd.isNull()) {
168 m_subRunEnd =
dh.getPlusInfTm();
172 Statement* stmt = m_conn->createStatement();
175 "INSERT INTO od_run_iov (iov_id, run_iov_id, subrun_num, subrun_start, subrun_end) " 176 "VALUES (OD_run_iov_sq.NextVal, :1, :2, :3, :4)");
177 stmt->setInt(1, runIOVID);
178 stmt->setInt(2, m_subRunNum);
179 stmt->setDate(3,
dh.tmToDate(m_subRunStart));
180 stmt->setDate(4,
dh.tmToDate(m_subRunEnd));
182 stmt->executeUpdate();
184 m_conn->terminateStatement(stmt);
185 }
catch (SQLException&
e) {
186 throw(std::runtime_error(
"MODRunIOV::writeDB: " +
e.getMessage()));
190 if (!this->fetchID()) {
191 throw(std::runtime_error(
"MODRunIOV::writeDB: Failed to write"));
199 m_runIOV.setConnection(m_env, m_conn);
200 *runIOVID = m_runIOV.fetchID();
203 throw(std::runtime_error(
"MODRunIOV: Given RunIOV does not exist in DB"));
208 this->checkConnection();
210 runiov->setConnection(m_env, m_conn);
211 int runIOVID = runiov->fetchID();
214 throw(std::runtime_error(
"MODRunIOV::setByRun: Given RunIOV does not exist in DB"));
220 Statement* stmt = m_conn->createStatement();
223 "SELECT iov_id, subrun_start, subrun_end FROM OD_run_iov " 224 "WHERE run_iov_id = :1 AND subrun_num = :2");
225 stmt->setInt(1, runIOVID);
226 stmt->setInt(2, subrun);
228 ResultSet* rset = stmt->executeQuery();
231 m_subRunNum = subrun;
233 m_ID = rset->getInt(1);
234 Date startDate = rset->getDate(2);
235 Date endDate = rset->getDate(3);
237 m_subRunStart =
dh.dateToTm(startDate);
238 m_subRunEnd =
dh.dateToTm(endDate);
240 throw(std::runtime_error(
"MODRunIOV::setByRun: Given subrun is not in the database"));
243 m_conn->terminateStatement(stmt);
244 }
catch (SQLException&
e) {
245 throw(std::runtime_error(
"MODRunIOV::setByRun: " +
e.getMessage()));
void setRunIOV(const RunIOV &iov)
int writeDB() noexcept(false)
void setSubRunEnd(const Tm &end)
Tm getSubRunStart() const
int fetchID() noexcept(false) override
void setSubRunStart(const Tm &start)
void fetchParentIDs(int *runIOVID) noexcept(false)
void setByID(int id) noexcept(false) override
void setSubRunNumber(subrun_t subrun)
void setByRun(RunIOV *runiov, subrun_t subrun) noexcept(false)
run_t getSubRunNumber() const