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