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