Go to the documentation of this file.00001 #include "OnlineDB/EcalCondDB/interface/LMFLmrSubIOV.h"
00002
00003 void LMFLmrSubIOV::init() {
00004 m_className = "LMFLmrSubIOV";
00005
00006 m_lmfIOV = 0;
00007 m_t[0] = Tm();
00008 m_t[1] = Tm();
00009 m_t[2] = Tm();
00010 }
00011
00012 LMFLmrSubIOV::LMFLmrSubIOV() {
00013 init();
00014 }
00015
00016 LMFLmrSubIOV::LMFLmrSubIOV(EcalDBConnection *c): LMFUnique(c) {
00017 init();
00018 }
00019
00020 LMFLmrSubIOV::LMFLmrSubIOV(oracle::occi::Environment* env,
00021 oracle::occi::Connection* conn): LMFUnique(env, conn)
00022 {
00023 init();
00024 }
00025
00026 LMFLmrSubIOV::~LMFLmrSubIOV() {
00027 }
00028
00029 LMFLmrSubIOV& LMFLmrSubIOV::setLMFIOV(const LMFIOV &iov) {
00030 if (m_debug) {
00031 std::cout << "[LMFLmrSubIOV] Setting IOV_ID as " << iov.getID()
00032 << std::endl << std::flush;
00033 }
00034 m_lmfIOV = iov.getID();
00035 return *this;
00036 }
00037
00038 LMFLmrSubIOV& LMFLmrSubIOV::setTimes(Tm *t) {
00039 m_t[0] = t[0];
00040 m_t[1] = t[1];
00041 m_t[2] = t[2];
00042 return *this;
00043 }
00044
00045 LMFLmrSubIOV& LMFLmrSubIOV::setTimes(Tm t1, Tm t2, Tm t3) {
00046 m_t[0] = t1;
00047 m_t[1] = t2;
00048 m_t[2] = t3;
00049 return *this;
00050 }
00051
00052 std::string LMFLmrSubIOV::fetchIdSql(Statement *stmt) {
00053 if (!m_lmfIOV) {
00054 if (m_debug) {
00055 std::cout << m_className << ": LMFIOV not set" << std::endl;
00056 }
00057 return "";
00058 }
00059
00060 std::string sql = "SELECT LMR_SUB_IOV_ID FROM "
00061 "CMS_ECAL_LASER_COND.LMF_LMR_SUB_IOV "
00062 "WHERE "
00063 "IOV_ID = :1 AND "
00064 "T1 = :2 AND "
00065 "T2 = :3 AND "
00066 "T3 = :4";
00067 stmt->setSQL(sql);
00068 stmt->setInt(1, m_lmfIOV);
00069 DateHandler dh(m_env, m_conn);
00070 for (int i = 0; i < 3; i++) {
00071 oracle::occi::Date t = dh.tmToDate(m_t[i]);
00072 stmt->setDate(i + 2, t);
00073 }
00074 return sql;
00075
00076 }
00077
00078 std::string LMFLmrSubIOV::setByIDSql(Statement *stmt, int id) {
00079 std::string sql = "SELECT IOV_ID, T1, T2, T3 FROM "
00080 "CMS_ECAL_LASER_COND.LMF_LMR_SUB_IOV "
00081 "WHERE LMR_SUB_IOV_ID = :1";
00082 stmt->setSQL(sql);
00083 stmt->setInt(1, id);
00084 return sql;
00085 }
00086
00087 std::string LMFLmrSubIOV::writeDBSql(Statement *stmt) {
00088
00089 DateHandler dh(m_env, m_conn);
00090
00091 for (int i = 0; i < 3; i++) {
00092 if (m_t[i].isNull()) {
00093 m_t[i] = dh.getPlusInfTm();
00094 }
00095 }
00096
00097 if (m_lmfIOV == 0) {
00098 throw(std::runtime_error(m_className + "::writeDB: LMFIOV not set"));
00099 }
00100 std::string sp = sequencePostfix(m_t[0]);
00101 std::string sql = "INSERT INTO LMF_LMR_SUB_IOV (LMR_SUB_IOV_ID, "
00102 "IOV_ID, T1, T2, T3) "
00103 "VALUES (LMF_LMR_SUB_IOV_ID_" + sp + "_SQ.NextVal, :1, :2, :3, :4)";
00104 stmt->setSQL(sql);
00105 stmt->setInt(1, m_lmfIOV);
00106 for (int i = 0; i < 3; i++) {
00107 stmt->setDate(i + 2, dh.tmToDate(m_t[i]));
00108 }
00109 return sql;
00110 }
00111
00112 void LMFLmrSubIOV::getParameters(ResultSet *rset) {
00113 m_lmfIOV = rset->getInt(1);
00114 for (int i = 0; i < 3; i++) {
00115 oracle::occi::Date t = rset->getDate(i + 2);
00116 m_t[i].setToString(t.toText("YYYY-MM-DD HH24:MI:SS"));
00117 }
00118 }
00119
00120 std::list<int> LMFLmrSubIOV::getIOVIDsLaterThan(const Tm &t)
00121 throw(std::runtime_error) {
00122 Tm tinf;
00123 tinf.setToString("9999-12-31 23:59:59");
00124 return getIOVIDsLaterThan(t, tinf, 0);
00125 }
00126
00127 std::list<int> LMFLmrSubIOV::getIOVIDsLaterThan(const Tm &t, int howmany)
00128 throw(std::runtime_error) {
00129 Tm tinf;
00130 tinf.setToString("9999-12-31 23:59:59");
00131 return getIOVIDsLaterThan(t, tinf, howmany);
00132 }
00133
00134 std::list<int> LMFLmrSubIOV::getIOVIDsLaterThan(const Tm &tmin,
00135 const Tm &tmax)
00136 throw(std::runtime_error) {
00137 return getIOVIDsLaterThan(tmin, tmax, 0);
00138 }
00139
00140 std::list<int> LMFLmrSubIOV::getIOVIDsLaterThan(const Tm &tmin, const Tm &tmax,
00141 int howMany)
00142 throw(std::runtime_error) {
00143 Tm tinf;
00144 tinf.setToString("9999-12-31 23:59:59");
00145 std::string sql = "SELECT * FROM (SELECT LMR_SUB_IOV_ID "
00146 "FROM CMS_ECAL_LASER_COND.LMF_LMR_SUB_IOV WHERE T3 > :1 ";
00147 if (tmax != tinf) {
00148 sql += "AND T3 < :2 ORDER BY T3 ASC) ";
00149 if (howMany > 0) {
00150 sql += "WHERE ROWNUM <= :3";
00151 }
00152 } else {
00153 sql += "ORDER BY T3 ASC) ";
00154 if (howMany > 0) {
00155 sql += "WHERE ROWNUM <= :2";
00156 }
00157 }
00158 if (m_debug) {
00159 std::cout << "Executing query: " << std::endl << sql << std::endl;
00160 }
00161 std::list<int> ret;
00162 if (m_conn != NULL) {
00163 try {
00164 DateHandler dh(m_env, m_conn);
00165 Statement *stmt = m_conn->createStatement();
00166 stmt->setPrefetchRowCount(10000);
00167 stmt->setSQL(sql);
00168 stmt->setDate(1, dh.tmToDate(tmin));
00169 if (tmax != tinf) {
00170 stmt->setDate(2, dh.tmToDate(tmax));
00171 if (howMany > 0) {
00172 stmt->setInt(3, howMany);
00173 }
00174 } else {
00175 if (howMany > 0) {
00176 stmt->setInt(2, howMany);
00177 }
00178 }
00179 ResultSet *rset = stmt->executeQuery();
00180 int row = 1;
00181 while (rset->next() != 0) {
00182 if (m_debug) {
00183 std::cout << "Getting row " << row++ << std::endl;
00184 }
00185 ret.push_back(rset->getInt(1));
00186 }
00187 stmt->setPrefetchRowCount(0);
00188 m_conn->terminateStatement(stmt);
00189 }
00190 catch (oracle::occi::SQLException e) {
00191 throw(std::runtime_error(m_className + "::getLmrSubIOVLaterThan: " +
00192 e.getMessage()));
00193 }
00194 } else {
00195 throw(std::runtime_error(m_className + "::getLmrSubIOVLaterThan: " +
00196 "Connection not set"));
00197 }
00198 if (m_debug) {
00199 std::cout << "Sorting..." << std::flush;
00200 }
00201 ret.sort();
00202 if (m_debug) {
00203 std::cout << "Done!" << std::endl << std::flush;
00204 }
00205 return ret;
00206 }
00207
00208