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