11 using namespace oracle::occi;
28 if (tag != m_monRunTag) {
37 if (iov != m_runIOV) {
46 if (subrun != m_subRunNum) {
55 if (start != m_subRunStart) {
57 m_subRunStart =
start;
64 if (end != m_subRunEnd) {
78 this->checkConnection();
81 int monRunTagID, runIOVID;
82 this->fetchParentIDs(&monRunTagID, &runIOVID);
84 if (!monRunTagID || !runIOVID) {
90 if (m_subRunEnd.isNull()) {
95 Statement* stmt = m_conn->createStatement();
97 "SELECT iov_id FROM mon_run_iov "
98 "WHERE tag_id = :1 AND "
99 "run_iov_id = :2 AND "
100 "subrun_num = :3 AND "
101 "subrun_start = :4 AND "
103 stmt->setInt(1, monRunTagID);
104 stmt->setInt(2, runIOVID);
105 stmt->setInt(3, m_subRunNum);
106 stmt->setDate(4, dh.
tmToDate(m_subRunStart));
107 stmt->setDate(5, dh.
tmToDate(m_subRunEnd));
109 ResultSet* rset = stmt->executeQuery();
112 m_ID = rset->getInt(1);
116 m_conn->terminateStatement(stmt);
117 }
catch (SQLException&
e) {
118 throw(std::runtime_error(
"MonRunIOV::fetchID: " + e.getMessage()));
125 this->checkConnection();
130 Statement* stmt = m_conn->createStatement();
132 stmt->setSQL(
"SELECT tag_id, run_iov_id, subrun_num, subrun_start, subrun_end FROM mon_run_iov WHERE iov_id = :1");
135 ResultSet* rset = stmt->executeQuery();
137 int monRunTagID = rset->getInt(1);
138 int runIOVID = rset->getInt(2);
139 m_subRunNum = rset->getInt(3);
140 Date startDate = rset->getDate(4);
141 Date endDate = rset->getDate(5);
143 m_subRunStart = dh.
dateToTm(startDate);
146 m_monRunTag.setConnection(m_env, m_conn);
147 m_monRunTag.setByID(monRunTagID);
149 m_runIOV.setConnection(m_env, m_conn);
150 m_runIOV.setByID(runIOVID);
154 throw(std::runtime_error(
"MonRunIOV::setByID: Given tag_id is not in the database"));
157 m_conn->terminateStatement(stmt);
158 }
catch (SQLException&
e) {
159 throw(std::runtime_error(
"MonRunIOV::setByID: " + e.getMessage()));
164 this->checkConnection();
167 if (this->fetchID()) {
172 int monRunTagID, runIOVID;
173 this->fetchParentIDs(&monRunTagID, &runIOVID);
176 monRunTagID = m_monRunTag.writeDB();
182 if (m_subRunStart.isNull()) {
183 throw(std::runtime_error(
"MonRunIOV::writeDB: Must setSubRunStart before writing"));
186 if (m_subRunEnd.isNull()) {
191 Statement* stmt = m_conn->createStatement();
194 "INSERT INTO mon_run_iov (iov_id, tag_id, run_iov_id, subrun_num, subrun_start, subrun_end) "
195 "VALUES (mon_run_iov_sq.NextVal, :1, :2, :3, :4, :5)");
196 stmt->setInt(1, monRunTagID);
197 stmt->setInt(2, runIOVID);
198 stmt->setInt(3, m_subRunNum);
199 stmt->setDate(4, dh.
tmToDate(m_subRunStart));
200 stmt->setDate(5, dh.
tmToDate(m_subRunEnd));
202 stmt->executeUpdate();
204 m_conn->terminateStatement(stmt);
205 }
catch (SQLException&
e) {
206 throw(std::runtime_error(
"MonRunIOV::writeDB: " + e.getMessage()));
210 if (!this->fetchID()) {
211 throw(std::runtime_error(
"MonRunIOV::writeDB: Failed to write"));
219 m_monRunTag.setConnection(m_env, m_conn);
220 *monRunTagID = m_monRunTag.fetchID();
223 m_runIOV.setConnection(m_env, m_conn);
224 *runIOVID = m_runIOV.fetchID();
227 throw(std::runtime_error(
"MonRunIOV: Given RunIOV does not exist in DB"));
232 this->checkConnection();
234 runiov->setConnection(m_env, m_conn);
235 int runIOVID = runiov->fetchID();
238 throw(std::runtime_error(
"MonRunIOV::setByRun: Given RunIOV does not exist in DB"));
241 montag->setConnection(m_env, m_conn);
242 int monTagID = montag->fetchID();
245 throw(std::runtime_error(
"MonRunIOV::setByRun: Given MonRunTag does not exist in the DB"));
251 Statement* stmt = m_conn->createStatement();
254 "SELECT iov_id, subrun_start, subrun_end FROM mon_run_iov "
255 "WHERE tag_id = :1 AND run_iov_id = :2 AND subrun_num = :3");
256 stmt->setInt(1, monTagID);
257 stmt->setInt(2, runIOVID);
258 stmt->setInt(3, subrun);
260 ResultSet* rset = stmt->executeQuery();
262 m_monRunTag = *montag;
264 m_subRunNum = subrun;
266 m_ID = rset->getInt(1);
267 Date startDate = rset->getDate(2);
268 Date endDate = rset->getDate(3);
270 m_subRunStart = dh.
dateToTm(startDate);
273 throw(std::runtime_error(
"MonRunIOV::setByRun: Given subrun is not in the database"));
276 m_conn->terminateStatement(stmt);
277 }
catch (SQLException&
e) {
278 throw(std::runtime_error(
"MonRunIOV::setByRun: " + e.getMessage()));
void setByID(int id) noexcept(false) override
void fetchParentIDs(int *monRunTagID, int *runIOVID) noexcept(false)
uint16_t *__restrict__ id
int writeDB() noexcept(false)
void setRunIOV(const RunIOV &iov)
run_t getSubRunNumber() const
int fetchID() noexcept(false) override
Tm getSubRunStart() const
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 setMonRunTag(const MonRunTag &tag)
void setByRun(MonRunTag *montag, RunIOV *runiov, subrun_t subrun) noexcept(false)
Tm dateToTm(oracle::occi::Date &date) const