CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/OnlineDB/EcalCondDB/src/MonRunDat.cc

Go to the documentation of this file.
00001 #include <stdexcept>
00002 #include <string>
00003 #include "OnlineDB/Oracle/interface/Oracle.h"
00004 
00005 #include "OnlineDB/EcalCondDB/interface/MonRunDat.h"
00006 #include "OnlineDB/EcalCondDB/interface/MonRunIOV.h"
00007 #include "OnlineDB/EcalCondDB/interface/MonRunOutcomeDef.h"
00008 
00009 using namespace std;
00010 using namespace oracle::occi;
00011 
00012 MonRunDat::MonRunDat()
00013 {
00014   m_env = NULL;
00015   m_conn = NULL;
00016   m_writeStmt = NULL;
00017   m_readStmt = NULL;
00018 
00019   m_numEvents = 0;
00020   m_outcomeDef = MonRunOutcomeDef();
00021   m_rootfileName = "";
00022   m_taskList = 0;
00023   m_taskOutcome = 0;
00024 }
00025 
00026 
00027 
00028 MonRunDat::~MonRunDat()
00029 {
00030 }
00031 
00032 
00033 
00034 void MonRunDat::prepareWrite()
00035   throw(std::runtime_error)
00036 {
00037   this->checkConnection();
00038 
00039   try {
00040     m_writeStmt = m_conn->createStatement();
00041     m_writeStmt->setSQL("INSERT INTO mon_run_dat (iov_id, logic_id, "
00042                         "num_events, run_outcome_id, rootfile_name, task_list, task_outcome) "
00043                         "VALUES (:iov_id, :logic_id, "
00044                         ":num_events, :run_outcome_id, :rootfile_name, :task_list, :task_outcome) ");
00045   } catch (SQLException &e) {
00046     throw(std::runtime_error("MonRunDat::prepareWrite():  "+e.getMessage()));
00047   }
00048 }
00049 
00050 
00051 
00052 void MonRunDat::writeDB(const EcalLogicID* ecid, const MonRunDat* item, MonRunIOV* iov)
00053   throw(std::runtime_error)
00054 {
00055   this->checkConnection();
00056   this->checkPrepare();
00057 
00058   int iovID = iov->fetchID();
00059   if (!iovID) { throw(std::runtime_error("MonRunDat::writeDB:  IOV not in DB")); }
00060 
00061   MonRunOutcomeDef monRunOutcomeDef = item->getMonRunOutcomeDef(); // XXX object copy every row!
00062   monRunOutcomeDef.setConnection(m_env, m_conn);
00063   int outcomeID = monRunOutcomeDef.fetchID();
00064   if (!outcomeID) { throw(std::runtime_error("MonRunDat::writeDB:  Outcome Definition not in DB")); }
00065 
00066   int logicID = ecid->getLogicID();
00067   if (!logicID) { throw(std::runtime_error("MonRunDat::writeDB:  Bad EcalLogicID")); }
00068   
00069   try {
00070     m_writeStmt->setInt(1, iovID);
00071     m_writeStmt->setInt(2, logicID);
00072     m_writeStmt->setInt(3, item->getNumEvents());
00073     m_writeStmt->setInt(4, outcomeID);
00074     m_writeStmt->setString(5, item->getRootfileName());
00075     m_writeStmt->setInt(6, item->getTaskList());
00076     m_writeStmt->setInt(7, item->getTaskOutcome());
00077 
00078     m_writeStmt->executeUpdate();
00079   } catch (SQLException &e) {
00080     throw(std::runtime_error("MonRunDat::writeDB():  "+e.getMessage()));
00081   }
00082 }
00083 
00084 
00085 
00086 void MonRunDat::fetchData(map< EcalLogicID, MonRunDat >* fillMap, MonRunIOV* iov)
00087   throw(std::runtime_error)
00088 {
00089   this->checkConnection();
00090   fillMap->clear();
00091 
00092   iov->setConnection(m_env, m_conn);
00093   int iovID = iov->fetchID();
00094   if (!iovID) { 
00095     //  throw(std::runtime_error("MonRunDat::writeDB:  IOV not in DB")); 
00096     return;
00097   }
00098 
00099   try {
00100 
00101     m_readStmt->setSQL("SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
00102                  "d.num_events, d.run_outcome_id, d.rootfile_name, d.task_list, d.task_outcome "
00103                  "FROM channelview cv JOIN mon_run_dat d "
00104                  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
00105                  "WHERE d.iov_id = :iov_id");
00106     m_readStmt->setInt(1, iovID);
00107     ResultSet* rset = m_readStmt->executeQuery();
00108     
00109     std::pair< EcalLogicID, MonRunDat > p;
00110     MonRunDat dat;
00111     MonRunOutcomeDef outcomeDef;
00112     outcomeDef.setConnection(m_env, m_conn);
00113     while(rset->next()) {
00114       p.first = EcalLogicID( rset->getString(1),     // name
00115                              rset->getInt(2),        // logic_id
00116                              rset->getInt(3),        // id1
00117                              rset->getInt(4),        // id2
00118                              rset->getInt(5),        // id3
00119                              rset->getString(6));    // maps_to
00120 
00121       dat.setNumEvents( rset->getInt(7) );
00122       outcomeDef.setByID( rset->getInt(8) );
00123       dat.setMonRunOutcomeDef( outcomeDef );
00124       dat.setRootfileName( rset->getString(9) );
00125       dat.setTaskList( rset->getInt(10) );
00126       dat.setTaskOutcome( rset->getInt(11) );
00127 
00128       p.second = dat;
00129       fillMap->insert(p);
00130     }
00131   } catch (SQLException &e) {
00132     throw(std::runtime_error("MonRunDat::fetchData():  "+e.getMessage()));
00133   }
00134 }