Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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