Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:23:01

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