Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:32:10

0001 #include <stdexcept>
0002 #include <string>
0003 #include "OnlineDB/Oracle/interface/Oracle.h"
0004 
0005 #include "OnlineDB/EcalCondDB/interface/RunFEConfigDat.h"
0006 #include "OnlineDB/EcalCondDB/interface/RunIOV.h"
0007 
0008 using namespace std;
0009 using namespace oracle::occi;
0010 
0011 RunFEConfigDat::RunFEConfigDat() {
0012   m_env = nullptr;
0013   m_conn = nullptr;
0014   m_writeStmt = nullptr;
0015   m_readStmt = nullptr;
0016 
0017   m_config = 0;
0018 }
0019 
0020 RunFEConfigDat::~RunFEConfigDat() {}
0021 
0022 void RunFEConfigDat::prepareWrite() noexcept(false) {
0023   this->checkConnection();
0024 
0025   try {
0026     m_writeStmt = m_conn->createStatement();
0027     m_writeStmt->setSQL(
0028         "INSERT INTO run_FEConfig_dat (iov_id, logic_id, "
0029         "Config_id ) "
0030         "VALUES (:iov_id, :logic_id, "
0031         ":Config_id ) ");
0032   } catch (SQLException& e) {
0033     throw(std::runtime_error("RunFEConfigDat::prepareWrite():  " + e.getMessage()));
0034   }
0035 }
0036 
0037 void RunFEConfigDat::writeDB(const EcalLogicID* ecid, const RunFEConfigDat* item, RunIOV* iov) noexcept(false) {
0038   this->checkConnection();
0039   this->checkPrepare();
0040 
0041   int iovID = iov->fetchID();
0042   if (!iovID) {
0043     throw(std::runtime_error("RunFEConfigDat::writeDB:  IOV not in DB"));
0044   }
0045 
0046   int logicID = ecid->getLogicID();
0047   if (!logicID) {
0048     throw(std::runtime_error("RunFEConfigDat::writeDB:  Bad EcalLogicID"));
0049   }
0050 
0051   try {
0052     m_writeStmt->setInt(1, iovID);
0053     m_writeStmt->setInt(2, logicID);
0054     m_writeStmt->setInt(3, item->getConfigId());
0055 
0056     m_writeStmt->executeUpdate();
0057   } catch (SQLException& e) {
0058     throw(std::runtime_error("RunFEConfigDat::writeDB():  " + e.getMessage()));
0059   }
0060 }
0061 
0062 void RunFEConfigDat::fetchData(map<EcalLogicID, RunFEConfigDat>* fillMap, RunIOV* iov) noexcept(false) {
0063   this->checkConnection();
0064   fillMap->clear();
0065 
0066   iov->setConnection(m_env, m_conn);
0067   int iovID = iov->fetchID();
0068   if (!iovID) {
0069     //  throw(std::runtime_error("RunFEConfigDat::writeDB:  IOV not in DB"));
0070     return;
0071   }
0072 
0073   try {
0074     //    createReadStatement();
0075     //    m_readStmt->setSQL("SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
0076     Statement* stmt = m_conn->createStatement();
0077     stmt->setSQL(
0078         "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
0079         "d.Config_id "
0080         "FROM channelview cv JOIN run_FEConfig_dat d "
0081         "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
0082         "WHERE d.iov_id = :iov_id");
0083     stmt->setInt(1, iovID);
0084     //    m_readStmt->setInt(1, iovID);
0085     //    ResultSet* rset = m_readStmt->executeQuery();
0086     ResultSet* rset = stmt->executeQuery();
0087 
0088     std::pair<EcalLogicID, RunFEConfigDat> p;
0089     RunFEConfigDat dat;
0090     while (rset->next()) {
0091       p.first = EcalLogicID(rset->getString(1),   // name
0092                             rset->getInt(2),      // logic_id
0093                             rset->getInt(3),      // id1
0094                             rset->getInt(4),      // id2
0095                             rset->getInt(5),      // id3
0096                             rset->getString(6));  // maps_to
0097 
0098       dat.setConfigId(rset->getInt(7));
0099 
0100       p.second = dat;
0101       fillMap->insert(p);
0102     }
0103     //    terminateReadStatement();
0104     m_conn->terminateStatement(stmt);
0105   } catch (SQLException& e) {
0106     throw(std::runtime_error("RunFEConfigDat::fetchData():  " + e.getMessage()));
0107   }
0108 }