Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include <stdexcept>
0002 #include <string>
0003 #include "OnlineDB/Oracle/interface/Oracle.h"
0004 
0005 #include "OnlineDB/EcalCondDB/interface/MonLaserStatusDat.h"
0006 
0007 using namespace std;
0008 using namespace oracle::occi;
0009 
0010 MonLaserStatusDat::MonLaserStatusDat() {
0011   m_env = nullptr;
0012   m_conn = nullptr;
0013   m_writeStmt = nullptr;
0014   m_readStmt = nullptr;
0015 
0016   m_laserPower = 0;
0017   m_laserFilter = 0;
0018   m_laserWavelength = 0;
0019   m_laserFanout = 0;
0020 }
0021 
0022 MonLaserStatusDat::~MonLaserStatusDat() {}
0023 
0024 void MonLaserStatusDat::prepareWrite() noexcept(false) {
0025   this->checkConnection();
0026 
0027   try {
0028     m_writeStmt = m_conn->createStatement();
0029     m_writeStmt->setSQL(
0030         "INSERT INTO mon_laser_status_dat (iov_id, logic_id, "
0031         "laser_power, laser_filter, laser_wavelength, laser_fanout) "
0032         "VALUES (:iov_id, :logic_id, "
0033         ":3, :4, :5, :6)");
0034   } catch (SQLException& e) {
0035     throw(std::runtime_error("MonLaserStatusDat::prepareWrite():  " + e.getMessage()));
0036   }
0037 }
0038 
0039 void MonLaserStatusDat::writeDB(const EcalLogicID* ecid,
0040                                 const MonLaserStatusDat* item,
0041                                 MonRunIOV* iov) noexcept(false) {
0042   this->checkConnection();
0043   this->checkPrepare();
0044 
0045   int iovID = iov->fetchID();
0046   if (!iovID) {
0047     throw(std::runtime_error("MonLaserStatusDat::writeDB:  IOV not in DB"));
0048   }
0049 
0050   int logicID = ecid->getLogicID();
0051   if (!logicID) {
0052     throw(std::runtime_error("MonLaserStatusDat::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->getLaserPower());
0060     m_writeStmt->setFloat(4, item->getLaserFilter());
0061     m_writeStmt->setFloat(5, item->getLaserWavelength());
0062     m_writeStmt->setFloat(6, item->getLaserFanout());
0063 
0064     m_writeStmt->executeUpdate();
0065   } catch (SQLException& e) {
0066     throw(std::runtime_error("MonLaserStatusDat::writeDB():  " + e.getMessage()));
0067   }
0068 }
0069 
0070 void MonLaserStatusDat::fetchData(std::map<EcalLogicID, MonLaserStatusDat>* fillMap, MonRunIOV* iov) noexcept(false) {
0071   this->checkConnection();
0072   fillMap->clear();
0073 
0074   iov->setConnection(m_env, m_conn);
0075   int iovID = iov->fetchID();
0076   if (!iovID) {
0077     //  throw(std::runtime_error("MonLaserStatusDat::writeDB:  IOV not in DB"));
0078     return;
0079   }
0080 
0081   try {
0082     m_readStmt->setSQL(
0083         "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
0084         "d.laser_power, d.laser_filter, d.laser_wavelength, d.laser_fanout "
0085         "FROM channelview cv JOIN mon_laser_status_dat d "
0086         "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
0087         "WHERE d.iov_id = :iov_id");
0088     m_readStmt->setInt(1, iovID);
0089     ResultSet* rset = m_readStmt->executeQuery();
0090 
0091     std::pair<EcalLogicID, MonLaserStatusDat> p;
0092     MonLaserStatusDat 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.setLaserPower(rset->getFloat(7));
0102       dat.setLaserFilter(rset->getFloat(8));
0103       dat.setLaserWavelength(rset->getFloat(9));
0104       dat.setLaserFanout(rset->getFloat(10));
0105 
0106       p.second = dat;
0107       fillMap->insert(p);
0108     }
0109   } catch (SQLException& e) {
0110     throw(std::runtime_error("MonLaserStatusDat::fetchData():  " + e.getMessage()));
0111   }
0112 }