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/RunH4TablePositionDat.h"
0006 #include "OnlineDB/EcalCondDB/interface/RunIOV.h"
0007 
0008 using namespace std;
0009 using namespace oracle::occi;
0010 
0011 RunH4TablePositionDat::RunH4TablePositionDat() {
0012   m_env = nullptr;
0013   m_conn = nullptr;
0014   m_writeStmt = nullptr;
0015   m_readStmt = nullptr;
0016 
0017   m_table_x = 0;
0018   m_table_y = 0;
0019   m_numSpills = 0;
0020   m_numEvents = 0;
0021 }
0022 
0023 RunH4TablePositionDat::~RunH4TablePositionDat() {}
0024 
0025 void RunH4TablePositionDat::prepareWrite() noexcept(false) {
0026   this->checkConnection();
0027 
0028   try {
0029     m_writeStmt = m_conn->createStatement();
0030     m_writeStmt->setSQL(
0031         "INSERT INTO run_h4_table_position_dat (iov_id, logic_id, "
0032         "table_x, table_y, number_of_spills, number_of_events ) "
0033         "VALUES (:iov_id, :logic_id, "
0034         ":table_x, :table_y, :number_of_spills, :number_of_events)");
0035   } catch (SQLException& e) {
0036     throw(std::runtime_error("RunH4TablePositionDat::prepareWrite():  " + e.getMessage()));
0037   }
0038 }
0039 
0040 void RunH4TablePositionDat::writeDB(const EcalLogicID* ecid,
0041                                     const RunH4TablePositionDat* item,
0042                                     RunIOV* iov) noexcept(false) {
0043   this->checkConnection();
0044   this->checkPrepare();
0045 
0046   int iovID = iov->fetchID();
0047   if (!iovID) {
0048     throw(std::runtime_error("RunH4TablePositionDat::writeDB:  IOV not in DB"));
0049   }
0050 
0051   int logicID = ecid->getLogicID();
0052   if (!logicID) {
0053     throw(std::runtime_error("RunH4TablePositionDat::writeDB:  Bad EcalLogicID"));
0054   }
0055 
0056   try {
0057     m_writeStmt->setInt(1, iovID);
0058     m_writeStmt->setInt(2, logicID);
0059     m_writeStmt->setInt(3, item->getTableX());
0060     m_writeStmt->setInt(4, item->getTableY());
0061     m_writeStmt->setInt(5, item->getNumSpills());
0062     m_writeStmt->setInt(6, item->getNumEvents());
0063 
0064     m_writeStmt->executeUpdate();
0065   } catch (SQLException& e) {
0066     throw(std::runtime_error("RunH4TablePositionDat::writeDB():  " + e.getMessage()));
0067   }
0068 }
0069 
0070 void RunH4TablePositionDat::fetchData(map<EcalLogicID, RunH4TablePositionDat>* fillMap, RunIOV* 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("RunH4TablePositionDat::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.table_x, d.table_y, d.number_of_spills, d.number_of_events "
0085         "FROM channelview cv JOIN run_h4_table_position_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, RunH4TablePositionDat> p;
0092     RunH4TablePositionDat 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.setTableX(rset->getInt(7));
0102       dat.setTableY(rset->getInt(8));
0103       dat.setNumSpills(rset->getInt(9));
0104       dat.setNumEvents(rset->getInt(10));
0105 
0106       p.second = dat;
0107       fillMap->insert(p);
0108     }
0109 
0110   } catch (SQLException& e) {
0111     throw(std::runtime_error("RunH4TablePositionDat::fetchData():  " + e.getMessage()));
0112   }
0113 }