Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:31:56

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