File indexing completed on 2024-04-06 12:23:03
0001 #include <stdexcept>
0002 #include <string>
0003 #include "OnlineDB/Oracle/interface/Oracle.h"
0004
0005 #include "OnlineDB/EcalCondDB/interface/FEConfigFgrParamDat.h"
0006 #include "OnlineDB/EcalCondDB/interface/FEConfigFgrInfo.h"
0007
0008 using namespace std;
0009 using namespace oracle::occi;
0010
0011 FEConfigFgrParamDat::FEConfigFgrParamDat() {
0012 m_env = nullptr;
0013 m_conn = nullptr;
0014 m_writeStmt = nullptr;
0015 m_readStmt = nullptr;
0016
0017 m_fglowthresh = 0;
0018 m_fghighthresh = 0;
0019 m_lowratio = 0;
0020 m_highratio = 0;
0021 }
0022
0023 FEConfigFgrParamDat::~FEConfigFgrParamDat() {}
0024
0025 void FEConfigFgrParamDat::prepareWrite() noexcept(false) {
0026 this->checkConnection();
0027
0028 try {
0029 m_writeStmt = m_conn->createStatement();
0030 m_writeStmt->setSQL("INSERT INTO " + getTable() +
0031 " (fgr_conf_id, logic_id, "
0032 " fg_lowthresh, fg_highthresh, fg_lowratio, fg_highratio ) "
0033 "VALUES (:fgr_conf_id, :logic_id, "
0034 " :fg_lowthresh, :fg_highthresh, :fg_lowratio, :fg_highratio )");
0035 } catch (SQLException& e) {
0036 throw(std::runtime_error("FEConfigFgrParamDat::prepareWrite(): " + e.getMessage()));
0037 }
0038 }
0039
0040 void FEConfigFgrParamDat::writeDB(const EcalLogicID* ecid,
0041 const FEConfigFgrParamDat* item,
0042 FEConfigFgrInfo* iconf) noexcept(false) {
0043 this->checkConnection();
0044 this->checkPrepare();
0045
0046 int iconfID = iconf->fetchID();
0047 if (!iconfID) {
0048 throw(std::runtime_error("FEConfigFgrParamDat::writeDB: ICONF not in DB"));
0049 }
0050
0051 int logicID = ecid->getLogicID();
0052 if (!logicID) {
0053 throw(std::runtime_error("FEConfigFgrParamDat::writeDB: Bad EcalLogicID"));
0054 }
0055
0056 try {
0057 m_writeStmt->setInt(1, iconfID);
0058 m_writeStmt->setInt(2, logicID);
0059 m_writeStmt->setFloat(3, item->getFGlowthresh());
0060 m_writeStmt->setFloat(4, item->getFGhighthresh());
0061 m_writeStmt->setFloat(5, item->getFGlowratio());
0062 m_writeStmt->setFloat(6, item->getFGhighratio());
0063
0064 m_writeStmt->executeUpdate();
0065 } catch (SQLException& e) {
0066 throw(std::runtime_error("FEConfigFgrParamDat::writeDB(): " + e.getMessage()));
0067 }
0068 }
0069
0070 void FEConfigFgrParamDat::fetchData(map<EcalLogicID, FEConfigFgrParamDat>* fillMap,
0071 FEConfigFgrInfo* iconf) noexcept(false) {
0072 this->checkConnection();
0073 fillMap->clear();
0074
0075 iconf->setConnection(m_env, m_conn);
0076 int iconfID = iconf->fetchID();
0077 if (!iconfID) {
0078
0079 return;
0080 }
0081
0082 try {
0083 m_readStmt->setSQL(
0084 "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
0085 " d.fg_lowthresh, d.fg_highthresh, d.fg_lowratio, d.fg_highratio "
0086 "FROM channelview cv JOIN " +
0087 getTable() +
0088 " d "
0089 "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
0090 "WHERE fgr_conf_id = :fgr_conf_id");
0091 m_readStmt->setInt(1, iconfID);
0092 ResultSet* rset = m_readStmt->executeQuery();
0093
0094 std::pair<EcalLogicID, FEConfigFgrParamDat> p;
0095 FEConfigFgrParamDat dat;
0096 while (rset->next()) {
0097 p.first = EcalLogicID(rset->getString(1),
0098 rset->getInt(2),
0099 rset->getInt(3),
0100 rset->getInt(4),
0101 rset->getInt(5),
0102 rset->getString(6));
0103
0104 dat.setFGlowthresh(rset->getFloat(7));
0105 dat.setFGhighthresh(rset->getFloat(8));
0106 dat.setFGlowratio(rset->getFloat(9));
0107 dat.setFGhighratio(rset->getFloat(10));
0108
0109 p.second = dat;
0110 fillMap->insert(p);
0111 }
0112 } catch (SQLException& e) {
0113 throw(std::runtime_error("FEConfigFgrParamDat::fetchData: " + e.getMessage()));
0114 }
0115 }
0116
0117 void FEConfigFgrParamDat::writeArrayDB(const std::map<EcalLogicID, FEConfigFgrParamDat>* data,
0118 FEConfigFgrInfo* iconf) noexcept(false) {
0119 this->checkConnection();
0120 this->checkPrepare();
0121
0122 int iconfID = iconf->fetchID();
0123 if (!iconfID) {
0124 throw(std::runtime_error("FEConfigFgrParamDat::writeArrayDB: ICONF not in DB"));
0125 }
0126
0127 int nrows = data->size();
0128 int* ids = new int[nrows];
0129 int* iov_vec = new int[nrows];
0130 float* ww = new float[nrows];
0131 float* uu = new float[nrows];
0132 float* tt = new float[nrows];
0133 float* st = new float[nrows];
0134
0135 ub2* ids_len = new ub2[nrows];
0136 ub2* iov_len = new ub2[nrows];
0137 ub2* w_len = new ub2[nrows];
0138 ub2* u_len = new ub2[nrows];
0139 ub2* t_len = new ub2[nrows];
0140 ub2* st_len = new ub2[nrows];
0141
0142 const EcalLogicID* channel;
0143 const FEConfigFgrParamDat* dataitem;
0144 int count = 0;
0145 typedef map<EcalLogicID, FEConfigFgrParamDat>::const_iterator CI;
0146 for (CI p = data->begin(); p != data->end(); ++p) {
0147 channel = &(p->first);
0148 int logicID = channel->getLogicID();
0149 if (!logicID) {
0150 throw(std::runtime_error("FEConfigFgrParamDat::writeArrayDB: Bad EcalLogicID"));
0151 }
0152 ids[count] = logicID;
0153 iov_vec[count] = iconfID;
0154
0155 dataitem = &(p->second);
0156
0157 float w = dataitem->getFGlowthresh();
0158 float u = dataitem->getFGhighthresh();
0159 float t = dataitem->getFGlowratio();
0160 float r = dataitem->getFGhighratio();
0161
0162 ww[count] = w;
0163 uu[count] = u;
0164 tt[count] = t;
0165 st[count] = r;
0166
0167 ids_len[count] = sizeof(ids[count]);
0168 iov_len[count] = sizeof(iov_vec[count]);
0169
0170 w_len[count] = sizeof(ww[count]);
0171 u_len[count] = sizeof(uu[count]);
0172 t_len[count] = sizeof(tt[count]);
0173 st_len[count] = sizeof(st[count]);
0174
0175 count++;
0176 }
0177
0178 try {
0179 m_writeStmt->setDataBuffer(1, (dvoid*)iov_vec, OCCIINT, sizeof(iov_vec[0]), iov_len);
0180 m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len);
0181 m_writeStmt->setDataBuffer(3, (dvoid*)ww, OCCIFLOAT, sizeof(ww[0]), w_len);
0182 m_writeStmt->setDataBuffer(4, (dvoid*)uu, OCCIFLOAT, sizeof(uu[0]), u_len);
0183 m_writeStmt->setDataBuffer(5, (dvoid*)tt, OCCIFLOAT, sizeof(tt[0]), t_len);
0184 m_writeStmt->setDataBuffer(6, (dvoid*)st, OCCIFLOAT, sizeof(st[0]), st_len);
0185
0186 m_writeStmt->executeArrayUpdate(nrows);
0187
0188 delete[] ids;
0189 delete[] iov_vec;
0190 delete[] ww;
0191 delete[] uu;
0192 delete[] tt;
0193 delete[] st;
0194
0195 delete[] ids_len;
0196 delete[] iov_len;
0197 delete[] w_len;
0198 delete[] u_len;
0199 delete[] t_len;
0200 delete[] st_len;
0201
0202 } catch (SQLException& e) {
0203 throw(std::runtime_error("FEConfigFgrParamDat::writeArrayDB(): " + e.getMessage()));
0204 }
0205 }