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/FEConfigFgrEETowerDat.h"
0006 #include "OnlineDB/EcalCondDB/interface/FEConfigFgrInfo.h"
0007
0008 using namespace std;
0009 using namespace oracle::occi;
0010
0011 FEConfigFgrEETowerDat::FEConfigFgrEETowerDat() {
0012 m_env = nullptr;
0013 m_conn = nullptr;
0014 m_writeStmt = nullptr;
0015 m_readStmt = nullptr;
0016
0017 m_lut = 0;
0018 }
0019
0020 FEConfigFgrEETowerDat::~FEConfigFgrEETowerDat() {}
0021
0022 void FEConfigFgrEETowerDat::prepareWrite() noexcept(false) {
0023 this->checkConnection();
0024
0025 try {
0026 m_writeStmt = m_conn->createStatement();
0027 m_writeStmt->setSQL("INSERT INTO " + getTable() +
0028 " (fgr_conf_id, logic_id, "
0029 "lut_value ) "
0030 "VALUES (:fgr_conf_id, :logic_id, "
0031 ":lut_value )");
0032 } catch (SQLException& e) {
0033 throw(std::runtime_error("FEConfigFgrEETowerDat::prepareWrite(): " + e.getMessage()));
0034 }
0035 }
0036
0037 void FEConfigFgrEETowerDat::writeDB(const EcalLogicID* ecid,
0038 const FEConfigFgrEETowerDat* item,
0039 FEConfigFgrInfo* iconf) noexcept(false) {
0040 this->checkConnection();
0041 this->checkPrepare();
0042
0043 int iconfID = iconf->fetchID();
0044 if (!iconfID) {
0045 throw(std::runtime_error("FEConfigFgrEETowerDat::writeDB: ICONF not in DB"));
0046 }
0047
0048 int logicID = ecid->getLogicID();
0049 if (!logicID) {
0050 throw(std::runtime_error("FEConfigFgrEETowerDat::writeDB: Bad EcalLogicID"));
0051 }
0052
0053 try {
0054 m_writeStmt->setInt(1, iconfID);
0055 m_writeStmt->setInt(2, logicID);
0056 m_writeStmt->setInt(3, item->getLutValue());
0057
0058 m_writeStmt->executeUpdate();
0059 } catch (SQLException& e) {
0060 throw(std::runtime_error("FEConfigFgrEETowerDat::writeDB(): " + e.getMessage()));
0061 }
0062 }
0063
0064 void FEConfigFgrEETowerDat::fetchData(map<EcalLogicID, FEConfigFgrEETowerDat>* fillMap,
0065 FEConfigFgrInfo* iconf) noexcept(false) {
0066 this->checkConnection();
0067 fillMap->clear();
0068
0069 iconf->setConnection(m_env, m_conn);
0070 int iconfID = iconf->fetchID();
0071 if (!iconfID) {
0072
0073 return;
0074 }
0075
0076 try {
0077 m_readStmt->setSQL(
0078 "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
0079 "d.lut_value "
0080 "FROM channelview cv JOIN " +
0081 getTable() +
0082 " d "
0083 "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
0084 "WHERE fgr_conf_id = :fgr_conf_id");
0085 m_readStmt->setInt(1, iconfID);
0086 ResultSet* rset = m_readStmt->executeQuery();
0087
0088 std::pair<EcalLogicID, FEConfigFgrEETowerDat> p;
0089 FEConfigFgrEETowerDat dat;
0090 while (rset->next()) {
0091 p.first = EcalLogicID(rset->getString(1),
0092 rset->getInt(2),
0093 rset->getInt(3),
0094 rset->getInt(4),
0095 rset->getInt(5),
0096 rset->getString(6));
0097
0098 dat.setLutValue(rset->getInt(7));
0099
0100 p.second = dat;
0101 fillMap->insert(p);
0102 }
0103 } catch (SQLException& e) {
0104 throw(std::runtime_error("FEConfigFgrEETowerDat::fetchData: " + e.getMessage()));
0105 }
0106 }
0107
0108 void FEConfigFgrEETowerDat::writeArrayDB(const std::map<EcalLogicID, FEConfigFgrEETowerDat>* data,
0109 FEConfigFgrInfo* iconf) noexcept(false) {
0110 this->checkConnection();
0111 this->checkPrepare();
0112
0113 int iconfID = iconf->fetchID();
0114 if (!iconfID) {
0115 throw(std::runtime_error("FEConfigFgrEETowerDat::writeArrayDB: ICONF not in DB"));
0116 }
0117
0118 int nrows = data->size();
0119 int* ids = new int[nrows];
0120 int* iconfid_vec = new int[nrows];
0121 int* xx = new int[nrows];
0122
0123 ub2* ids_len = new ub2[nrows];
0124 ub2* iconf_len = new ub2[nrows];
0125 ub2* x_len = new ub2[nrows];
0126
0127 const EcalLogicID* channel;
0128 const FEConfigFgrEETowerDat* dataitem;
0129 int count = 0;
0130 typedef map<EcalLogicID, FEConfigFgrEETowerDat>::const_iterator CI;
0131 for (CI p = data->begin(); p != data->end(); ++p) {
0132 channel = &(p->first);
0133 int logicID = channel->getLogicID();
0134 if (!logicID) {
0135 throw(std::runtime_error("FEConfigFgrEETowerDat::writeArrayDB: Bad EcalLogicID"));
0136 }
0137 ids[count] = logicID;
0138 iconfid_vec[count] = iconfID;
0139
0140 dataitem = &(p->second);
0141
0142 int x = dataitem->getLutValue();
0143
0144 xx[count] = x;
0145
0146 ids_len[count] = sizeof(ids[count]);
0147 iconf_len[count] = sizeof(iconfid_vec[count]);
0148
0149 x_len[count] = sizeof(xx[count]);
0150
0151 count++;
0152 }
0153
0154 try {
0155 m_writeStmt->setDataBuffer(1, (dvoid*)iconfid_vec, OCCIINT, sizeof(iconfid_vec[0]), iconf_len);
0156 m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len);
0157 m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIINT, sizeof(xx[0]), x_len);
0158
0159 m_writeStmt->executeArrayUpdate(nrows);
0160
0161 delete[] ids;
0162 delete[] iconfid_vec;
0163 delete[] xx;
0164
0165 delete[] ids_len;
0166 delete[] iconf_len;
0167 delete[] x_len;
0168
0169 } catch (SQLException& e) {
0170 throw(std::runtime_error("FEConfigFgrEETowerDat::writeArrayDB(): " + e.getMessage()));
0171 }
0172 }