CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch1/src/OnlineDB/EcalCondDB/src/RunTPGConfigDat.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/RunTPGConfigDat.h"
00006 #include "OnlineDB/EcalCondDB/interface/RunIOV.h"
00007 
00008 using namespace std;
00009 using namespace oracle::occi;
00010 
00011 RunTPGConfigDat::RunTPGConfigDat()
00012 {
00013   m_env = NULL;
00014   m_conn = NULL;
00015   m_writeStmt = NULL;
00016   m_readStmt = NULL;
00017 
00018   m_config = "";
00019   m_version=0;
00020 }
00021 
00022 
00023 
00024 RunTPGConfigDat::~RunTPGConfigDat()
00025 {
00026 }
00027 
00028 
00029 
00030 void RunTPGConfigDat::prepareWrite()
00031   throw(std::runtime_error)
00032 {
00033   this->checkConnection();
00034 
00035   try {
00036     m_writeStmt = m_conn->createStatement();
00037     m_writeStmt->setSQL("INSERT INTO run_TPGConfig_dat (iov_id, logic_id, "
00038                         "Config_tag , version ) "
00039                         "VALUES (:iov_id, :logic_id, "
00040                         ":Config_tag , :version ) ");
00041   } catch (SQLException &e) {
00042     throw(std::runtime_error("RunTPGConfigDat::prepareWrite():  "+e.getMessage()));
00043   }
00044 }
00045 
00046 
00047 
00048 void RunTPGConfigDat::writeDB(const EcalLogicID* ecid, const RunTPGConfigDat* item, RunIOV* iov)
00049   throw(std::runtime_error)
00050 {
00051   this->checkConnection();
00052   this->checkPrepare();
00053 
00054   int iovID = iov->fetchID();
00055   if (!iovID) { throw(std::runtime_error("RunTPGConfigDat::writeDB:  IOV not in DB")); }
00056 
00057   int logicID = ecid->getLogicID();
00058   if (!logicID) { throw(std::runtime_error("RunTPGConfigDat::writeDB:  Bad EcalLogicID")); }
00059   
00060   try {
00061     m_writeStmt->setInt(1, iovID);
00062     m_writeStmt->setInt(2, logicID);
00063     m_writeStmt->setString(3, item->getConfigTag());
00064     m_writeStmt->setInt(4, item->getVersion());
00065 
00066 
00067     m_writeStmt->executeUpdate();
00068   } catch (SQLException &e) {
00069     throw(std::runtime_error("RunTPGConfigDat::writeDB():  "+e.getMessage()));
00070   }
00071 }
00072 
00073 
00074 
00075 void RunTPGConfigDat::fetchData(map< EcalLogicID, RunTPGConfigDat >* fillMap, RunIOV* iov)
00076   throw(std::runtime_error)
00077 {
00078   this->checkConnection();
00079   fillMap->clear();
00080 
00081   iov->setConnection(m_env, m_conn);
00082   int iovID = iov->fetchID();
00083   if (!iovID) { 
00084     //  throw(std::runtime_error("RunTPGConfigDat::writeDB:  IOV not in DB")); 
00085     return;
00086   }
00087 
00088   try {
00089 
00090     m_readStmt->setSQL("SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
00091                  "d.Config_tag, d.version "
00092                  "FROM channelview cv JOIN run_TPGConfig_dat d "
00093                  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
00094                  "WHERE d.iov_id = :iov_id");
00095     m_readStmt->setInt(1, iovID);
00096     ResultSet* rset = m_readStmt->executeQuery();
00097     
00098     std::pair< EcalLogicID, RunTPGConfigDat > p;
00099     RunTPGConfigDat dat;
00100     while(rset->next()) {
00101       p.first = EcalLogicID( rset->getString(1),     // name
00102                              rset->getInt(2),        // logic_id
00103                              rset->getInt(3),        // id1
00104                              rset->getInt(4),        // id2
00105                              rset->getInt(5),        // id3
00106                              rset->getString(6));    // maps_to
00107 
00108       dat.setConfigTag( rset->getString(7) );
00109       dat.setVersion( rset->getInt(8) );
00110  
00111 
00112       p.second = dat;
00113       fillMap->insert(p);
00114     }
00115   } catch (SQLException &e) {
00116     throw(std::runtime_error("RunTPGConfigDat::fetchData():  "+e.getMessage()));
00117   }
00118 }