File indexing completed on 2024-04-06 12:23:08
0001 #include <stdexcept>
0002 #include "OnlineDB/Oracle/interface/Oracle.h"
0003
0004 #include "OnlineDB/EcalCondDB/interface/MonRunList.h"
0005 #include "OnlineDB/EcalCondDB/interface/RunIOV.h"
0006 #include "OnlineDB/EcalCondDB/interface/RunTag.h"
0007 #include "OnlineDB/EcalCondDB/interface/MonRunIOV.h"
0008 #include "OnlineDB/EcalCondDB/interface/Tm.h"
0009 #include "OnlineDB/EcalCondDB/interface/DateHandler.h"
0010
0011 using namespace std;
0012 using namespace oracle::occi;
0013
0014 MonRunList::MonRunList() { m_conn = nullptr; }
0015
0016 MonRunList::~MonRunList() {}
0017
0018 void MonRunList::setRunTag(const RunTag& tag) {
0019 if (tag != m_runTag) {
0020 m_runTag = tag;
0021 }
0022 }
0023 void MonRunList::setMonRunTag(const MonRunTag& tag) {
0024 if (tag != m_monrunTag) {
0025 m_monrunTag = tag;
0026 }
0027 }
0028
0029 RunTag MonRunList::getRunTag() const { return m_runTag; }
0030 MonRunTag MonRunList::getMonRunTag() const { return m_monrunTag; }
0031
0032 std::vector<MonRunIOV> MonRunList::getRuns() { return m_vec_monruniov; }
0033
0034 void MonRunList::fetchRuns() noexcept(false) {
0035 this->checkConnection();
0036 int nruns = 0;
0037
0038 m_runTag.setConnection(m_env, m_conn);
0039 int tagID = m_runTag.fetchID();
0040 cout << "tag id=" << tagID << endl;
0041 if (!tagID) {
0042 return;
0043 }
0044 m_monrunTag.setConnection(m_env, m_conn);
0045 int montagID = m_monrunTag.fetchID();
0046 cout << "mon tag id=" << montagID << endl;
0047 if (!montagID) {
0048 return;
0049 }
0050
0051 try {
0052 Statement* stmt0 = m_conn->createStatement();
0053 stmt0->setSQL(
0054 "SELECT count(mon_run_iov.iov_id) FROM mon_run_iov, run_iov "
0055 "WHERE mon_run_iov.run_iov_id= run_iov.iov_id and run_iov.tag_id = :tag_id and mon_run_iov.tag_id=:montag_id ");
0056 stmt0->setInt(1, tagID);
0057 stmt0->setInt(2, montagID);
0058
0059 ResultSet* rset0 = stmt0->executeQuery();
0060 if (rset0->next()) {
0061 nruns = rset0->getInt(1);
0062 }
0063 m_conn->terminateStatement(stmt0);
0064
0065 cout << "nruns=" << nruns << endl;
0066
0067 m_vec_monruniov.reserve(nruns);
0068
0069 Statement* stmt = m_conn->createStatement();
0070 stmt->setSQL(
0071 "SELECT run_iov.run_num, run_iov.run_start, run_iov.run_end, mon_run_iov.tag_id, mon_run_iov.run_iov_id, "
0072 "mon_run_iov.subrun_num, mon_run_iov.subrun_start, mon_run_iov.subrun_end, mon_run_iov.iov_id FROM run_iov, "
0073 "mon_run_iov "
0074 "WHERE mon_run_iov.run_iov_id=run_iov.iov_id and run_iov.tag_id = :tag_id order by run_iov.run_num, "
0075 "mon_run_iov.subrun_num ASC ");
0076 stmt->setInt(1, tagID);
0077
0078 DateHandler dh(m_env, m_conn);
0079 Tm runStart;
0080 Tm runEnd;
0081 Tm lrunStart;
0082 Tm lrunEnd;
0083
0084 ResultSet* rset = stmt->executeQuery();
0085 int i = 0;
0086 while (i < nruns) {
0087 rset->next();
0088 int runNum = rset->getInt(1);
0089 Date startDate = rset->getDate(2);
0090 Date endDate = rset->getDate(3);
0091
0092 int lid = rset->getInt(5);
0093 int subrun = rset->getInt(6);
0094 Date monstartDate = rset->getDate(7);
0095 Date monendDate = rset->getDate(8);
0096 int liov_id = rset->getInt(9);
0097
0098 runStart = dh.dateToTm(startDate);
0099 runEnd = dh.dateToTm(endDate);
0100 lrunStart = dh.dateToTm(monstartDate);
0101 lrunEnd = dh.dateToTm(monendDate);
0102
0103 RunIOV r;
0104 r.setRunNumber(runNum);
0105 r.setRunStart(runStart);
0106 r.setRunEnd(runEnd);
0107 r.setRunTag(m_runTag);
0108 r.setID(lid);
0109
0110 MonRunIOV lr;
0111
0112 lr.setRunIOV(r);
0113 lr.setSubRunNumber(subrun);
0114 lr.setSubRunStart(lrunStart);
0115 lr.setSubRunEnd(lrunEnd);
0116 lr.setMonRunTag(m_monrunTag);
0117 lr.setID(liov_id);
0118 m_vec_monruniov.push_back(lr);
0119
0120 i++;
0121 }
0122
0123 m_conn->terminateStatement(stmt);
0124 } catch (SQLException& e) {
0125 throw(std::runtime_error("RunIOV::fetchID: " + e.getMessage()));
0126 }
0127 }
0128
0129 void MonRunList::fetchRuns(int min_run, int max_run) noexcept(false) {
0130 this->checkConnection();
0131 int nruns = 0;
0132
0133 m_runTag.setConnection(m_env, m_conn);
0134 int tagID = m_runTag.fetchID();
0135 cout << "tag id=" << tagID << endl;
0136 if (!tagID) {
0137 return;
0138 }
0139 m_monrunTag.setConnection(m_env, m_conn);
0140 int montagID = m_monrunTag.fetchID();
0141 cout << "mon tag id=" << montagID << endl;
0142 if (!montagID) {
0143 return;
0144 }
0145
0146 int my_min_run = min_run - 1;
0147 int my_max_run = max_run + 1;
0148 try {
0149 Statement* stmt0 = m_conn->createStatement();
0150 stmt0->setSQL(
0151 "SELECT count(mon_run_iov.iov_id) FROM mon_run_iov, run_iov "
0152 "WHERE mon_run_iov.run_iov_id= run_iov.iov_id "
0153 "and run_iov.tag_id = :tag_id and mon_run_iov.tag_id=:montag_id "
0154 " and run_iov.run_num> :min_run and run_iov.run_num< :max_run ");
0155 stmt0->setInt(1, tagID);
0156 stmt0->setInt(2, montagID);
0157 stmt0->setInt(3, my_min_run);
0158 stmt0->setInt(4, my_max_run);
0159
0160 ResultSet* rset0 = stmt0->executeQuery();
0161 if (rset0->next()) {
0162 nruns = rset0->getInt(1);
0163 }
0164 m_conn->terminateStatement(stmt0);
0165
0166 cout << "nruns=" << nruns << endl;
0167
0168 m_vec_monruniov.reserve(nruns);
0169
0170 Statement* stmt = m_conn->createStatement();
0171 stmt->setSQL(
0172 "SELECT run_iov.run_num, run_iov.run_start, run_iov.run_end, mon_run_iov.tag_id, mon_run_iov.run_iov_id, "
0173 "mon_run_iov.subrun_num, mon_run_iov.subrun_start, mon_run_iov.subrun_end, mon_run_iov.iov_id FROM run_iov, "
0174 "mon_run_iov "
0175 "WHERE mon_run_iov.run_iov_id=run_iov.iov_id and run_iov.tag_id = :tag_id "
0176 " and mon_run_iov.tag_id=:montag_id "
0177 " and run_iov.run_num> :min_run and run_iov.run_num< :max_run "
0178 " order by run_iov.run_num, mon_run_iov.subrun_num ASC ");
0179 stmt->setInt(1, tagID);
0180 stmt->setInt(2, montagID);
0181 stmt->setInt(3, my_min_run);
0182 stmt->setInt(4, my_max_run);
0183
0184 DateHandler dh(m_env, m_conn);
0185 Tm runStart;
0186 Tm runEnd;
0187 Tm lrunStart;
0188 Tm lrunEnd;
0189
0190 ResultSet* rset = stmt->executeQuery();
0191 int i = 0;
0192 while (i < nruns) {
0193 rset->next();
0194 int runNum = rset->getInt(1);
0195 Date startDate = rset->getDate(2);
0196 Date endDate = rset->getDate(3);
0197
0198 int lid = rset->getInt(5);
0199 int subrun = rset->getInt(6);
0200 Date monstartDate = rset->getDate(7);
0201 Date monendDate = rset->getDate(8);
0202 int liov_id = rset->getInt(9);
0203
0204 runStart = dh.dateToTm(startDate);
0205 runEnd = dh.dateToTm(endDate);
0206 lrunStart = dh.dateToTm(monstartDate);
0207 lrunEnd = dh.dateToTm(monendDate);
0208
0209 RunIOV r;
0210 r.setRunNumber(runNum);
0211 r.setRunStart(runStart);
0212 r.setRunEnd(runEnd);
0213 r.setRunTag(m_runTag);
0214 r.setID(lid);
0215
0216 MonRunIOV lr;
0217
0218 lr.setRunIOV(r);
0219 lr.setSubRunNumber(subrun);
0220 lr.setSubRunStart(lrunStart);
0221 lr.setSubRunEnd(lrunEnd);
0222 lr.setMonRunTag(m_monrunTag);
0223 lr.setID(liov_id);
0224 m_vec_monruniov.push_back(lr);
0225
0226 i++;
0227 }
0228
0229 m_conn->terminateStatement(stmt);
0230 } catch (SQLException& e) {
0231 throw(std::runtime_error("RunIOV::fetchID: " + e.getMessage()));
0232 }
0233 }
0234
0235 void MonRunList::fetchLastNRuns(int max_run, int n_runs) noexcept(false) {
0236
0237
0238 this->checkConnection();
0239
0240 m_runTag.setConnection(m_env, m_conn);
0241 int tagID = m_runTag.fetchID();
0242 cout << "tag id=" << tagID << endl;
0243 if (!tagID) {
0244 return;
0245 }
0246 m_monrunTag.setConnection(m_env, m_conn);
0247 int montagID = m_monrunTag.fetchID();
0248 cout << "mon tag id=" << montagID << endl;
0249 if (!montagID) {
0250 return;
0251 }
0252
0253 int my_max_run = max_run + 1;
0254 try {
0255 int nruns = n_runs;
0256 m_vec_monruniov.reserve(nruns);
0257
0258 Statement* stmt = m_conn->createStatement();
0259 stmt->setSQL(
0260 "select run_num, run_start, run_end, tag_id, run_iov_id, subrun_num, subrun_start, subrun_end, mon_iov_id from "
0261 "(SELECT run_iov.run_num, run_iov.run_start, run_iov.run_end, mon_run_iov.tag_id, mon_run_iov.run_iov_id, "
0262 "mon_run_iov.subrun_num, mon_run_iov.subrun_start, mon_run_iov.subrun_end, mon_run_iov.iov_id as mon_iov_id "
0263 "FROM run_iov, mon_run_iov "
0264 "WHERE mon_run_iov.run_iov_id=run_iov.iov_id and run_iov.tag_id = :tag_id "
0265 " and mon_run_iov.tag_id=:montag_id "
0266 " and run_iov.run_num< :max_run "
0267 " order by run_iov.run_num DESC ) where rownum< :n_runs order by run_num DESC ");
0268 stmt->setInt(1, tagID);
0269 stmt->setInt(2, montagID);
0270 stmt->setInt(3, my_max_run);
0271 stmt->setInt(4, n_runs);
0272
0273 DateHandler dh(m_env, m_conn);
0274 Tm runStart;
0275 Tm runEnd;
0276 Tm lrunStart;
0277 Tm lrunEnd;
0278
0279 ResultSet* rset = stmt->executeQuery();
0280 int i = 0;
0281 while (i < nruns) {
0282 rset->next();
0283 int runNum = rset->getInt(1);
0284 Date startDate = rset->getDate(2);
0285 Date endDate = rset->getDate(3);
0286
0287 int lid = rset->getInt(5);
0288 int subrun = rset->getInt(6);
0289 Date monstartDate = rset->getDate(7);
0290 Date monendDate = rset->getDate(8);
0291 int liov_id = rset->getInt(9);
0292
0293 runStart = dh.dateToTm(startDate);
0294 runEnd = dh.dateToTm(endDate);
0295 lrunStart = dh.dateToTm(monstartDate);
0296 lrunEnd = dh.dateToTm(monendDate);
0297
0298 RunIOV r;
0299 r.setRunNumber(runNum);
0300 r.setRunStart(runStart);
0301 r.setRunEnd(runEnd);
0302 r.setRunTag(m_runTag);
0303 r.setID(lid);
0304
0305 MonRunIOV lr;
0306
0307 lr.setRunIOV(r);
0308 lr.setSubRunNumber(subrun);
0309 lr.setSubRunStart(lrunStart);
0310 lr.setSubRunEnd(lrunEnd);
0311 lr.setMonRunTag(m_monrunTag);
0312 lr.setID(liov_id);
0313 m_vec_monruniov.push_back(lr);
0314
0315 i++;
0316 }
0317
0318 m_conn->terminateStatement(stmt);
0319 } catch (SQLException& e) {
0320 throw(std::runtime_error("MonRunList::fetchLastNRuns: " + e.getMessage()));
0321 }
0322 }