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