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