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/FEConfigLUTGroupDat.h"
0006 #include "OnlineDB/EcalCondDB/interface/FEConfigLUTInfo.h"
0007
0008 using namespace std;
0009 using namespace oracle::occi;
0010
0011 FEConfigLUTGroupDat::FEConfigLUTGroupDat() {
0012 m_env = nullptr;
0013 m_conn = nullptr;
0014 m_writeStmt = nullptr;
0015 m_readStmt = nullptr;
0016
0017 m_group_id = 0;
0018 for (int i = 0; i < 1024; i++) {
0019 m_lut[i] = 0;
0020 }
0021 }
0022
0023 FEConfigLUTGroupDat::~FEConfigLUTGroupDat() {}
0024
0025 void FEConfigLUTGroupDat::prepareWrite() noexcept(false) {
0026 this->checkConnection();
0027
0028 try {
0029 m_writeStmt = m_conn->createStatement();
0030 m_writeStmt->setSQL(
0031 "INSERT INTO fe_lut_per_group_dat (lut_conf_id, group_id, "
0032 " lut_id, lut_value ) "
0033 "VALUES (:lut_conf_id, :group_id, "
0034 ":lut_id, :lut_value )");
0035 } catch (SQLException& e) {
0036 throw(std::runtime_error(std::string("FEConfigLUTGroupDat::prepareWrite(): ") + e.getMessage()));
0037 }
0038 }
0039
0040 void FEConfigLUTGroupDat::writeDB(const EcalLogicID* ecid,
0041 const FEConfigLUTGroupDat* item,
0042 FEConfigLUTInfo* iconf) noexcept(false) {
0043 this->checkConnection();
0044 this->checkPrepare();
0045
0046 int iconfID = iconf->fetchID();
0047
0048 cout << "iconf=" << iconfID << endl;
0049
0050 if (!iconfID) {
0051 throw(std::runtime_error("FEConfigLUTGroupDat::writeArrayDB: ICONF not in DB"));
0052 }
0053
0054 int nrows = 1024;
0055 int* iconfid_vec = new int[nrows];
0056 int* xx = new int[nrows];
0057 int* yy = new int[nrows];
0058 int* zz = new int[nrows];
0059
0060 ub2* iconf_len = new ub2[nrows];
0061 ub2* x_len = new ub2[nrows];
0062 ub2* y_len = new ub2[nrows];
0063 ub2* z_len = new ub2[nrows];
0064
0065 for (int count = 0; count < nrows; count++) {
0066 iconfid_vec[count] = iconfID;
0067 int x = item->getLUTGroupId();
0068 int y = count;
0069 int z = m_lut[count];
0070
0071 xx[count] = x;
0072 yy[count] = y;
0073 zz[count] = z;
0074
0075 iconf_len[count] = sizeof(iconfid_vec[count]);
0076
0077 x_len[count] = sizeof(xx[count]);
0078 y_len[count] = sizeof(yy[count]);
0079 z_len[count] = sizeof(zz[count]);
0080 }
0081
0082 try {
0083 m_writeStmt->setDataBuffer(1, (dvoid*)iconfid_vec, OCCIINT, sizeof(iconfid_vec[0]), iconf_len);
0084 m_writeStmt->setDataBuffer(2, (dvoid*)xx, OCCIINT, sizeof(xx[0]), x_len);
0085 m_writeStmt->setDataBuffer(3, (dvoid*)yy, OCCIINT, sizeof(yy[0]), y_len);
0086 m_writeStmt->setDataBuffer(4, (dvoid*)zz, OCCIINT, sizeof(zz[0]), z_len);
0087
0088 m_writeStmt->executeArrayUpdate(nrows);
0089
0090 delete[] iconfid_vec;
0091 delete[] xx;
0092 delete[] yy;
0093 delete[] zz;
0094
0095 delete[] iconf_len;
0096 delete[] x_len;
0097 delete[] y_len;
0098 delete[] z_len;
0099
0100 } catch (SQLException& e) {
0101 throw(std::runtime_error(std::string("FEConfigLUTGroupDat::writeArrayDB(): ") + e.getMessage()));
0102 }
0103 }
0104
0105 void FEConfigLUTGroupDat::fetchData(map<EcalLogicID, FEConfigLUTGroupDat>* fillMap,
0106 FEConfigLUTInfo* iconf) noexcept(false) {
0107 this->checkConnection();
0108 fillMap->clear();
0109
0110 iconf->setConnection(m_env, m_conn);
0111 int iconfID = iconf->fetchID();
0112 if (!iconfID) {
0113 throw(std::runtime_error("FEConfigLUTGroupDat::fetchData: ICONF not in DB"));
0114 return;
0115 }
0116
0117 try {
0118 m_readStmt->setSQL(
0119 "SELECT d.group_id, d.lut_id, d.lut_value "
0120 "FROM fe_lut_per_group_dat d "
0121 "WHERE lut_conf_id = :lut_conf_id order by d.group_id, d.lut_id ");
0122 m_readStmt->setInt(1, iconfID);
0123 ResultSet* rset = m_readStmt->executeQuery();
0124
0125 FEConfigLUTGroupDat dat;
0126 std::pair<EcalLogicID, FEConfigLUTGroupDat> p;
0127
0128 int nrows = 1024;
0129
0130 int igold = -1;
0131 int ig = igold;
0132
0133 while (rset->next()) {
0134 ig = rset->getInt(1);
0135 int il = rset->getInt(2);
0136 int ival = rset->getInt(3);
0137 if (il == 0) {
0138 p.first = EcalLogicID("Group_id", ig);
0139 dat = FEConfigLUTGroupDat();
0140 dat.setLUTGroupId(ig);
0141 dat.setLUTValue(il, ival);
0142 } else {
0143 dat.setLUTValue(il, ival);
0144 }
0145
0146 if (il == (nrows - 1)) {
0147 p.second = dat;
0148 fillMap->insert(p);
0149 }
0150 }
0151 } catch (SQLException& e) {
0152 throw(std::runtime_error(std::string("FEConfigLUTGroupDat::fetchData: ") + e.getMessage()));
0153 }
0154 }
0155
0156 void FEConfigLUTGroupDat::writeArrayDB(const std::map<EcalLogicID, FEConfigLUTGroupDat>* data,
0157 FEConfigLUTInfo* iconf) noexcept(false) {
0158 this->checkConnection();
0159 this->checkPrepare();
0160
0161 int iconfID = iconf->fetchID();
0162 if (!iconfID) {
0163 throw(std::runtime_error("FEConfigLUTGroupDat::writeArrayDB: ICONF not in DB"));
0164 }
0165
0166 int nrows = data->size() * 1024;
0167
0168 int* iconfid_vec = new int[nrows];
0169 int* xx = new int[nrows];
0170 int* yy = new int[nrows];
0171 int* zz = new int[nrows];
0172
0173 ub2* iconf_len = new ub2[nrows];
0174 ub2* x_len = new ub2[nrows];
0175 ub2* y_len = new ub2[nrows];
0176 ub2* z_len = new ub2[nrows];
0177
0178 const FEConfigLUTGroupDat* dataitem;
0179 int count = 0;
0180 typedef map<EcalLogicID, FEConfigLUTGroupDat>::const_iterator CI;
0181 for (CI p = data->begin(); p != data->end(); ++p) {
0182 dataitem = &(p->second);
0183 int x = dataitem->getLUTGroupId();
0184
0185 for (int i = 0; i < 1024; i++) {
0186 iconfid_vec[count] = iconfID;
0187 int y = i;
0188 int z = dataitem->getLUTValue(i);
0189
0190 xx[count] = x;
0191 yy[count] = y;
0192 zz[count] = z;
0193
0194 iconf_len[count] = sizeof(iconfid_vec[count]);
0195
0196 x_len[count] = sizeof(xx[count]);
0197 y_len[count] = sizeof(yy[count]);
0198 z_len[count] = sizeof(zz[count]);
0199
0200 count++;
0201 }
0202 }
0203
0204 try {
0205
0206
0207 int i = 0;
0208 cout << "about to insert " << iconfid_vec[i] << " " << xx[i] << " " << yy[i] << " " << zz[i] << endl;
0209 i = nrows - 1;
0210 cout << "about to insert " << iconfid_vec[i] << " " << xx[i] << " " << yy[i] << " " << zz[i] << endl;
0211
0212 m_writeStmt->setDataBuffer(1, (dvoid*)iconfid_vec, OCCIINT, sizeof(iconfid_vec[0]), iconf_len);
0213 m_writeStmt->setDataBuffer(2, (dvoid*)xx, OCCIINT, sizeof(xx[0]), x_len);
0214 m_writeStmt->setDataBuffer(3, (dvoid*)yy, OCCIINT, sizeof(yy[0]), y_len);
0215 m_writeStmt->setDataBuffer(4, (dvoid*)zz, OCCIINT, sizeof(zz[0]), z_len);
0216
0217 m_writeStmt->executeArrayUpdate(nrows);
0218
0219 delete[] iconfid_vec;
0220 delete[] xx;
0221 delete[] yy;
0222 delete[] zz;
0223
0224 delete[] iconf_len;
0225 delete[] x_len;
0226 delete[] y_len;
0227 delete[] z_len;
0228
0229 } catch (SQLException& e) {
0230 throw(std::runtime_error(std::string("FEConfigLUTGroupDat::writeArrayDB(): ") + e.getMessage()));
0231 }
0232 }