Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-09-09 02:18:49

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