File indexing completed on 2024-04-06 12:23:02
0001 #include <stdexcept>
0002 #include <string>
0003 #include "OnlineDB/Oracle/interface/Oracle.h"
0004
0005 #include "OnlineDB/EcalCondDB/interface/FEConfigFgrGroupDat.h"
0006 #include "OnlineDB/EcalCondDB/interface/FEConfigFgrInfo.h"
0007
0008 using namespace std;
0009 using namespace oracle::occi;
0010
0011 FEConfigFgrGroupDat::FEConfigFgrGroupDat() {
0012 m_env = nullptr;
0013 m_conn = nullptr;
0014 m_writeStmt = nullptr;
0015 m_readStmt = nullptr;
0016
0017 m_group_id = 0;
0018 m_thresh_low = 0;
0019 m_thresh_high = 0;
0020 m_ratio_low = 0;
0021 m_ratio_high = 0;
0022 m_lut = 0;
0023 }
0024
0025 FEConfigFgrGroupDat::~FEConfigFgrGroupDat() {}
0026
0027 void FEConfigFgrGroupDat::prepareWrite() noexcept(false) {
0028 this->checkConnection();
0029
0030 try {
0031 m_writeStmt = m_conn->createStatement();
0032 m_writeStmt->setSQL(
0033 "INSERT INTO fe_fgr_per_group_dat (fgr_conf_id, group_id, "
0034 " threshold_low, threshold_high, ratio_low, ratio_high, lut_value ) "
0035 "VALUES (:fgr_conf_id, :group_id, "
0036 ":3, :4, :5, :6, :7 )");
0037 } catch (SQLException& e) {
0038 throw(std::runtime_error("FEConfigFgrGroupDat::prepareWrite(): " + e.getMessage()));
0039 }
0040 }
0041
0042 void FEConfigFgrGroupDat::writeDB(const EcalLogicID* ecid,
0043 const FEConfigFgrGroupDat* item,
0044 FEConfigFgrInfo* iconf) noexcept(false) {
0045 this->checkConnection();
0046 this->checkPrepare();
0047
0048 int iconfID = iconf->fetchID();
0049 if (!iconfID) {
0050 throw(std::runtime_error("FEConfigFgrGroupDat::writeDB: ICONF not in DB"));
0051 }
0052
0053
0054
0055
0056
0057 try {
0058 m_writeStmt->setInt(1, iconfID);
0059
0060 m_writeStmt->setInt(2, item->getFgrGroupId());
0061 m_writeStmt->setFloat(3, item->getThreshLow());
0062 m_writeStmt->setFloat(4, item->getThreshHigh());
0063 m_writeStmt->setFloat(5, item->getRatioLow());
0064 m_writeStmt->setFloat(6, item->getRatioHigh());
0065 m_writeStmt->setInt(7, item->getLUTValue());
0066
0067 m_writeStmt->executeUpdate();
0068 } catch (SQLException& e) {
0069 throw(std::runtime_error("FEConfigFgrGroupDat::writeDB(): " + e.getMessage()));
0070 }
0071 }
0072
0073 void FEConfigFgrGroupDat::fetchData(map<EcalLogicID, FEConfigFgrGroupDat>* fillMap,
0074 FEConfigFgrInfo* iconf) noexcept(false) {
0075 this->checkConnection();
0076 fillMap->clear();
0077
0078 iconf->setConnection(m_env, m_conn);
0079 int iconfID = iconf->fetchID();
0080 if (!iconfID) {
0081 throw(std::runtime_error("FEConfigFgrGroupDat::fetchData: ICONF not in DB"));
0082 return;
0083 }
0084
0085 try {
0086 m_readStmt->setSQL(
0087 "SELECT d.group_id, d.threshold_low, d.threshold_high, d.ratio_low, d.ratio_high, d.lut_value "
0088 "FROM fe_fgr_per_group_dat d "
0089 "WHERE fgr_conf_id = :fgr_conf_id order by d.group_id ");
0090 m_readStmt->setInt(1, iconfID);
0091 ResultSet* rset = m_readStmt->executeQuery();
0092
0093 std::pair<EcalLogicID, FEConfigFgrGroupDat> p;
0094 FEConfigFgrGroupDat dat;
0095 int ig = -1;
0096 while (rset->next()) {
0097 ig++;
0098 p.first = EcalLogicID("Group_id",
0099 ig);
0100
0101 dat.setFgrGroupId(rset->getInt(1));
0102 dat.setThreshLow(rset->getFloat(2));
0103 dat.setThreshHigh(rset->getFloat(3));
0104 dat.setRatioLow(rset->getFloat(4));
0105 dat.setRatioHigh(rset->getFloat(5));
0106 dat.setLUTValue(rset->getInt(6));
0107
0108 p.second = dat;
0109 fillMap->insert(p);
0110 }
0111 } catch (SQLException& e) {
0112 throw(std::runtime_error("FEConfigFgrGroupDat::fetchData: " + e.getMessage()));
0113 }
0114 }
0115
0116 void FEConfigFgrGroupDat::writeArrayDB(const std::map<EcalLogicID, FEConfigFgrGroupDat>* data,
0117 FEConfigFgrInfo* iconf) noexcept(false) {
0118 this->checkConnection();
0119 this->checkPrepare();
0120
0121 int iconfID = iconf->fetchID();
0122 if (!iconfID) {
0123 throw(std::runtime_error("FEConfigFgrGroupDat::writeArrayDB: ICONF not in DB"));
0124 }
0125
0126 int nrows = data->size();
0127 int* ids = new int[nrows];
0128 int* iconfid_vec = new int[nrows];
0129 int* xx = new int[nrows];
0130 float* yy = new float[nrows];
0131 float* zz = new float[nrows];
0132 float* rr = new float[nrows];
0133 float* ss = new float[nrows];
0134 int* tt = new int[nrows];
0135
0136 ub2* ids_len = new ub2[nrows];
0137 ub2* iconf_len = new ub2[nrows];
0138 ub2* x_len = new ub2[nrows];
0139 ub2* y_len = new ub2[nrows];
0140 ub2* z_len = new ub2[nrows];
0141 ub2* r_len = new ub2[nrows];
0142 ub2* s_len = new ub2[nrows];
0143 ub2* t_len = new ub2[nrows];
0144
0145
0146 const FEConfigFgrGroupDat* dataitem;
0147 int count = 0;
0148 typedef map<EcalLogicID, FEConfigFgrGroupDat>::const_iterator CI;
0149 for (CI p = data->begin(); p != data->end(); ++p) {
0150
0151
0152
0153
0154 iconfid_vec[count] = iconfID;
0155
0156 dataitem = &(p->second);
0157
0158 int x = dataitem->getFgrGroupId();
0159 float y = dataitem->getThreshLow();
0160 float z = dataitem->getThreshHigh();
0161 float r = dataitem->getRatioLow();
0162 float s = dataitem->getRatioHigh();
0163 int t = dataitem->getLUTValue();
0164
0165 xx[count] = x;
0166 yy[count] = y;
0167 zz[count] = z;
0168 rr[count] = r;
0169 ss[count] = s;
0170 tt[count] = t;
0171
0172
0173 iconf_len[count] = sizeof(iconfid_vec[count]);
0174
0175 x_len[count] = sizeof(xx[count]);
0176 y_len[count] = sizeof(yy[count]);
0177 z_len[count] = sizeof(zz[count]);
0178 r_len[count] = sizeof(rr[count]);
0179 s_len[count] = sizeof(ss[count]);
0180 t_len[count] = sizeof(tt[count]);
0181
0182 count++;
0183 }
0184
0185 try {
0186 m_writeStmt->setDataBuffer(1, (dvoid*)iconfid_vec, OCCIINT, sizeof(iconfid_vec[0]), iconf_len);
0187 m_writeStmt->setDataBuffer(2, (dvoid*)xx, OCCIINT, sizeof(xx[0]), x_len);
0188 m_writeStmt->setDataBuffer(3, (dvoid*)yy, OCCIFLOAT, sizeof(yy[0]), y_len);
0189 m_writeStmt->setDataBuffer(4, (dvoid*)zz, OCCIFLOAT, sizeof(zz[0]), z_len);
0190 m_writeStmt->setDataBuffer(5, (dvoid*)rr, OCCIFLOAT, sizeof(rr[0]), r_len);
0191 m_writeStmt->setDataBuffer(6, (dvoid*)ss, OCCIFLOAT, sizeof(ss[0]), s_len);
0192 m_writeStmt->setDataBuffer(7, (dvoid*)tt, OCCIINT, sizeof(tt[0]), t_len);
0193
0194 m_writeStmt->executeArrayUpdate(nrows);
0195
0196 delete[] ids;
0197 delete[] iconfid_vec;
0198 delete[] xx;
0199 delete[] yy;
0200 delete[] zz;
0201 delete[] rr;
0202 delete[] ss;
0203 delete[] tt;
0204
0205 delete[] ids_len;
0206 delete[] iconf_len;
0207 delete[] x_len;
0208 delete[] y_len;
0209 delete[] z_len;
0210 delete[] r_len;
0211 delete[] s_len;
0212 delete[] t_len;
0213
0214 } catch (SQLException& e) {
0215 throw(std::runtime_error("FEConfigFgrGroupDat::writeArrayDB(): " + e.getMessage()));
0216 }
0217 }