CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/OnlineDB/EcalCondDB/src/MonRunList.cc

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