00001 #include <stdexcept>
00002 #include "OnlineDB/Oracle/interface/Oracle.h"
00003
00004 #include "OnlineDB/EcalCondDB/interface/LMFRunList.h"
00005 #include "OnlineDB/EcalCondDB/interface/RunIOV.h"
00006 #include "OnlineDB/EcalCondDB/interface/RunTag.h"
00007 #include "OnlineDB/EcalCondDB/interface/LMFRunIOV.h"
00008 #include "OnlineDB/EcalCondDB/interface/Tm.h"
00009 #include "OnlineDB/EcalCondDB/interface/DateHandler.h"
00010
00011 using namespace std;
00012 using namespace oracle::occi;
00013
00014 LMFRunList::LMFRunList()
00015 {
00016 m_conn = NULL;
00017 }
00018
00019 LMFRunList::~LMFRunList()
00020 {
00021 }
00022
00023 void LMFRunList::setRunTag(RunTag tag)
00024 {
00025 if (tag != m_runTag) {
00026 m_runTag = tag;
00027 }
00028 }
00029 void LMFRunList::setLMFRunTag(LMFRunTag tag)
00030 {
00031 if (tag != m_lmfrunTag) {
00032 m_lmfrunTag = tag;
00033 }
00034 }
00035
00036
00037 RunTag LMFRunList::getRunTag() const
00038 {
00039 return m_runTag;
00040 }
00041 LMFRunTag LMFRunList::getLMFRunTag() const
00042 {
00043 return m_lmfrunTag;
00044 }
00045
00046 std::vector<LMFRunIOV> LMFRunList::getRuns()
00047 {
00048 return m_vec_lmfruniov;
00049 }
00050
00051
00052 void LMFRunList::fetchRuns()
00053 throw(runtime_error)
00054 {
00055
00056
00057 this->checkConnection();
00058 int nruns=0;
00059
00060 m_runTag.setConnection(m_env, m_conn);
00061 int tagID = m_runTag.fetchID();
00062 cout <<"tag id="<< tagID << endl;
00063 if (!tagID) {
00064 return ;
00065 }
00066 m_lmfrunTag.setConnection(m_env, m_conn);
00067 int lmftagID = m_lmfrunTag.fetchID();
00068 cout <<"lmf tag id="<< lmftagID << endl;
00069 if (!lmftagID) {
00070 return ;
00071 }
00072
00073 try {
00074 Statement* stmt0 = m_conn->createStatement();
00075 stmt0->setSQL("SELECT count(lmf_run_iov.lmf_iov_id) FROM lmf_run_iov, run_iov "
00076 "WHERE lmf_run_iov.run_iov_id= run_iov.iov_id and run_iov.tag_id = :tag_id and lmf_run_iov.tag_id=:lmftag_id " );
00077 stmt0->setInt(1, tagID);
00078 stmt0->setInt(2, lmftagID);
00079
00080 ResultSet* rset0 = stmt0->executeQuery();
00081 if (rset0->next()) {
00082 nruns = rset0->getInt(1);
00083 }
00084 m_conn->terminateStatement(stmt0);
00085
00086 cout <<"number of LMF runs is ="<< nruns << endl;
00087
00088 m_vec_lmfruniov.reserve(nruns);
00089
00090 Statement* stmt = m_conn->createStatement();
00091 stmt->setSQL("SELECT run_iov.run_num, run_iov.run_start, run_iov.run_end, lmf_run_iov.tag_id, lmf_run_iov.run_iov_id, lmf_run_iov.subrun_num, lmf_run_iov.subrun_start, lmf_run_iov.subrun_end, lmf_run_iov.subrun_type, lmf_run_iov.db_timestamp, lmf_run_iov.lmf_iov_id FROM run_iov, lmf_run_iov "
00092 "WHERE lmf_run_iov.run_iov_id=run_iov.iov_id and run_iov.tag_id = :tag_id order by run_iov.run_num, lmf_run_iov.subrun_num " );
00093 stmt->setInt(1, tagID);
00094
00095 DateHandler dh(m_env, m_conn);
00096 Tm runStart;
00097 Tm runEnd;
00098 Tm lrunStart;
00099 Tm ldbtime;
00100 Tm lrunEnd;
00101
00102 ResultSet* rset = stmt->executeQuery();
00103 int i=0;
00104 while (i<nruns) {
00105 rset->next();
00106 int runNum = rset->getInt(1);
00107 Date startDate = rset->getDate(2);
00108 Date endDate = rset->getDate(3);
00109
00110 int lid=rset->getInt(5);
00111 int subrun=rset->getInt(6);
00112 Date lmfstartDate = rset->getDate(7);
00113 Date lmfendDate = rset->getDate(8);
00114 std::string lmf_type= rset->getString(9);
00115 Date lmfDBtime = rset->getDate(10);
00116 int liov_id=rset->getInt(11);
00117
00118 runStart = dh.dateToTm( startDate );
00119 runEnd = dh.dateToTm( endDate );
00120 lrunStart = dh.dateToTm( lmfstartDate );
00121 lrunEnd = dh.dateToTm( lmfendDate );
00122 ldbtime = dh.dateToTm( lmfDBtime );
00123
00124 RunIOV r ;
00125 r.setRunNumber(runNum);
00126 r.setRunStart(runStart);
00127 r.setRunEnd(runEnd);
00128 r.setRunTag(m_runTag);
00129 r.setID(lid);
00130
00131 LMFRunIOV lr ;
00132
00133 lr.setRunIOV(r);
00134 lr.setSubRunNumber(subrun);
00135 lr.setSubRunStart(lrunStart);
00136 lr.setSubRunEnd(lrunEnd);
00137 lr.setDBInsertionTime(ldbtime);
00138 lr.setSubRunType(lmf_type);
00139 lr.setLMFRunTag(m_lmfrunTag);
00140 lr.setID(liov_id);
00141 m_vec_lmfruniov.push_back(lr);
00142
00143 i++;
00144 }
00145
00146
00147 m_conn->terminateStatement(stmt);
00148 } catch (SQLException &e) {
00149 throw(runtime_error("RunIOV::fetchID: "+e.getMessage()));
00150 }
00151
00152
00153 }
00154
00155 void LMFRunList::fetchRuns(int min_run, int max_run)
00156 throw(runtime_error)
00157 {
00158
00159
00160 this->checkConnection();
00161 int nruns=0;
00162
00163 m_runTag.setConnection(m_env, m_conn);
00164 int tagID = m_runTag.fetchID();
00165 cout <<"tag id="<< tagID << endl;
00166 if (!tagID) {
00167 return ;
00168 }
00169 m_lmfrunTag.setConnection(m_env, m_conn);
00170 int lmftagID = m_lmfrunTag.fetchID();
00171 cout <<"lmf tag id="<< lmftagID << endl;
00172 if (!lmftagID) {
00173 return ;
00174 }
00175
00176 int my_min_run=min_run-1;
00177 int my_max_run=max_run+1;
00178 try {
00179 Statement* stmt0 = m_conn->createStatement();
00180 stmt0->setSQL("SELECT count(lmf_run_iov.lmf_iov_id) FROM lmf_run_iov, run_iov "
00181 "WHERE lmf_run_iov.run_iov_id= run_iov.iov_id "
00182 "and run_iov.tag_id = :tag_id and lmf_run_iov.tag_id=:lmftag_id "
00183 " and run_iov.run_num> :min_run and run_iov.run_num< :max_run "
00184 );
00185 stmt0->setInt(1, tagID);
00186 stmt0->setInt(2, lmftagID);
00187 stmt0->setInt(3, my_min_run);
00188 stmt0->setInt(4, my_max_run);
00189
00190 ResultSet* rset0 = stmt0->executeQuery();
00191 if (rset0->next()) {
00192 nruns = rset0->getInt(1);
00193 }
00194 m_conn->terminateStatement(stmt0);
00195
00196 cout <<"number of LMF runs="<< nruns << endl;
00197
00198 m_vec_lmfruniov.reserve(nruns);
00199
00200 Statement* stmt = m_conn->createStatement();
00201 stmt->setSQL("SELECT run_iov.run_num, run_iov.run_start, run_iov.run_end, lmf_run_iov.tag_id, lmf_run_iov.run_iov_id, lmf_run_iov.subrun_num, lmf_run_iov.subrun_start, lmf_run_iov.subrun_end, lmf_run_iov.lmf_iov_id, lmf_run_iov.subrun_type, lmf_run_iov.db_timestamp FROM run_iov, lmf_run_iov "
00202 "WHERE lmf_run_iov.run_iov_id=run_iov.iov_id and run_iov.tag_id = :tag_id "
00203 " and lmf_run_iov.tag_id=:lmftag_id "
00204 " and run_iov.run_num> :min_run and run_iov.run_num< :max_run "
00205 " order by run_iov.run_num, lmf_run_iov.subrun_num " );
00206 stmt->setInt(1, tagID);
00207 stmt->setInt(2, lmftagID);
00208 stmt->setInt(3, my_min_run);
00209 stmt->setInt(4, my_max_run);
00210
00211 DateHandler dh(m_env, m_conn);
00212 Tm runStart;
00213 Tm runEnd;
00214 Tm lrunStart;
00215 Tm ldbtime;
00216 Tm lrunEnd;
00217
00218 ResultSet* rset = stmt->executeQuery();
00219 int i=0;
00220 while (i<nruns) {
00221 rset->next();
00222 int runNum = rset->getInt(1);
00223 Date startDate = rset->getDate(2);
00224 Date endDate = rset->getDate(3);
00225
00226 int lid=rset->getInt(5);
00227 int subrun=rset->getInt(6);
00228 Date lmfstartDate = rset->getDate(7);
00229 Date lmfendDate = rset->getDate(8);
00230 int liov_id=rset->getInt(9);
00231 std::string lmf_type=rset->getString(10);
00232 Date lmfdbtime = rset->getDate(11);
00233
00234 runStart = dh.dateToTm( startDate );
00235 runEnd = dh.dateToTm( endDate );
00236 lrunStart = dh.dateToTm( lmfstartDate );
00237 lrunEnd = dh.dateToTm( lmfendDate );
00238 ldbtime = dh.dateToTm( lmfdbtime );
00239
00240 RunIOV r ;
00241 r.setRunNumber(runNum);
00242 r.setRunStart(runStart);
00243 r.setRunEnd(runEnd);
00244 r.setRunTag(m_runTag);
00245 r.setID(lid);
00246
00247 LMFRunIOV lr ;
00248
00249 lr.setRunIOV(r);
00250 lr.setSubRunNumber(subrun);
00251 lr.setSubRunStart(lrunStart);
00252 lr.setSubRunEnd(lrunEnd);
00253 lr.setLMFRunTag(m_lmfrunTag);
00254 lr.setDBInsertionTime(ldbtime);
00255 lr.setSubRunType(lmf_type);
00256 lr.setID(liov_id);
00257
00258 m_vec_lmfruniov.push_back(lr);
00259
00260 i++;
00261 }
00262
00263
00264 m_conn->terminateStatement(stmt);
00265 } catch (SQLException &e) {
00266 throw(runtime_error("RunIOV::fetchID: "+e.getMessage()));
00267 }
00268
00269
00270 }
00271
00272 void LMFRunList::fetchLastNRuns( int max_run, int n_runs )
00273 throw(runtime_error)
00274 {
00275
00276
00277
00278 this->checkConnection();
00279
00280
00281 m_runTag.setConnection(m_env, m_conn);
00282 int tagID = m_runTag.fetchID();
00283 cout <<"tag id="<< tagID << endl;
00284 if (!tagID) {
00285 return ;
00286 }
00287 m_lmfrunTag.setConnection(m_env, m_conn);
00288 int lmftagID = m_lmfrunTag.fetchID();
00289 cout <<"lmf tag id="<< lmftagID << endl;
00290 if (!lmftagID) {
00291 return ;
00292 }
00293
00294 int my_max_run=max_run+1;
00295 try {
00296
00297 int nruns=n_runs;
00298 m_vec_lmfruniov.reserve(nruns);
00299
00300 Statement* stmt = m_conn->createStatement();
00301 stmt->setSQL("select run_num, run_start, run_end, tag_id, run_iov_id, subrun_num, subrun_start, subrun_end, lmf_iov_id, lmf_db_date, subrun_type from (SELECT run_iov.run_num, run_iov.run_start, run_iov.run_end, lmf_run_iov.tag_id, lmf_run_iov.run_iov_id, lmf_run_iov.subrun_num, lmf_run_iov.subrun_start, lmf_run_iov.subrun_end, lmf_run_iov.lmf_iov_id as lmf_iov_id, lmf_run_iov.db_timestamp as lmf_db_date, lmf_run_iov.subrun_type as subrun_type FROM run_iov, lmf_run_iov "
00302 "WHERE lmf_run_iov.run_iov_id=run_iov.iov_id and run_iov.tag_id = :tag_id "
00303 " and lmf_run_iov.tag_id=:lmftag_id "
00304 " and run_iov.run_num< :max_run "
00305 " order by run_iov.run_num, lmf_run_iov.subrun_num DESC ) where rownum< :n_runs" );
00306 stmt->setInt(1, tagID);
00307 stmt->setInt(2, lmftagID);
00308 stmt->setInt(3, my_max_run);
00309 stmt->setInt(4, n_runs);
00310
00311 DateHandler dh(m_env, m_conn);
00312 Tm runStart;
00313 Tm runEnd;
00314 Tm lrunStart;
00315 Tm lrunEnd;
00316 Tm ldbtime;
00317
00318 ResultSet* rset = stmt->executeQuery();
00319 int i=0;
00320 while (i<nruns) {
00321 rset->next();
00322 int runNum = rset->getInt(1);
00323 Date startDate = rset->getDate(2);
00324 Date endDate = rset->getDate(3);
00325
00326 int lid=rset->getInt(5);
00327 int subrun=rset->getInt(6);
00328 Date lmfstartDate = rset->getDate(7);
00329 Date lmfendDate = rset->getDate(8);
00330 int liov_id=rset->getInt(9);
00331 Date lmfDBDate = rset->getDate(10);
00332 string lmf_type=rset->getString(11);
00333
00334 runStart = dh.dateToTm( startDate );
00335 runEnd = dh.dateToTm( endDate );
00336 lrunStart = dh.dateToTm( lmfstartDate );
00337 lrunEnd = dh.dateToTm( lmfendDate );
00338 ldbtime = dh.dateToTm( lmfDBDate );
00339
00340 RunIOV r ;
00341 r.setRunNumber(runNum);
00342 r.setRunStart(runStart);
00343 r.setRunEnd(runEnd);
00344 r.setRunTag(m_runTag);
00345 r.setID(lid);
00346
00347 LMFRunIOV lr ;
00348
00349 lr.setRunIOV(r);
00350 lr.setSubRunNumber(subrun);
00351 lr.setSubRunStart(lrunStart);
00352 lr.setDBInsertionTime(ldbtime);
00353 lr.setSubRunEnd(lrunEnd);
00354 lr.setSubRunType(lmf_type);
00355 lr.setLMFRunTag(m_lmfrunTag);
00356 lr.setID(liov_id);
00357 m_vec_lmfruniov.push_back(lr);
00358
00359 i++;
00360 }
00361
00362
00363 m_conn->terminateStatement(stmt);
00364 } catch (SQLException &e) {
00365 throw(runtime_error("RunIOV::fetchID: "+e.getMessage()));
00366 }
00367
00368
00369 }