Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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