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/MonPNMGPADat.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 MonPNMGPADat::MonPNMGPADat() {
0013 m_env = nullptr;
0014 m_conn = nullptr;
0015 m_writeStmt = nullptr;
0016 m_readStmt = nullptr;
0017
0018 m_adcMeanG1 = 0;
0019 m_adcRMSG1 = 0;
0020 m_adcMeanG16 = 0;
0021 m_adcRMSG16 = 0;
0022 m_pedMeanG1 = 0;
0023 m_pedRMSG1 = 0;
0024 m_pedMeanG16 = 0;
0025 m_pedRMSG16 = 0;
0026 m_taskStatus = false;
0027 }
0028
0029 MonPNMGPADat::~MonPNMGPADat() {}
0030
0031 void MonPNMGPADat::prepareWrite() noexcept(false) {
0032 this->checkConnection();
0033
0034 try {
0035 m_writeStmt = m_conn->createStatement();
0036 m_writeStmt->setSQL(
0037 "INSERT INTO mon_pn_mgpa_dat (iov_id, logic_id, "
0038 "adc_mean_g1, adc_rms_g1, adc_mean_g16, adc_rms_g16, ped_mean_g1, ped_rms_g1, ped_mean_g16, ped_rms_g16, "
0039 "task_status) "
0040 "VALUES (:iov_id, :logic_id, "
0041 ":3, :4, :5, :6, :7, :8, :9, :10, :11)");
0042 } catch (SQLException& e) {
0043 throw(std::runtime_error("MonPNMGPADat::prepareWrite(): " + e.getMessage()));
0044 }
0045 }
0046
0047 void MonPNMGPADat::writeDB(const EcalLogicID* ecid, const MonPNMGPADat* item, MonRunIOV* iov) noexcept(false) {
0048 this->checkConnection();
0049 this->checkPrepare();
0050
0051 int iovID = iov->fetchID();
0052 if (!iovID) {
0053 throw(std::runtime_error("MonPNMGPADat::writeDB: IOV not in DB"));
0054 }
0055
0056 int logicID = ecid->getLogicID();
0057 if (!logicID) {
0058 throw(std::runtime_error("MonPNMGPADat::writeDB: Bad EcalLogicID"));
0059 }
0060
0061 try {
0062 m_writeStmt->setInt(1, iovID);
0063 m_writeStmt->setInt(2, logicID);
0064
0065 m_writeStmt->setFloat(3, item->getADCMeanG1());
0066 m_writeStmt->setFloat(4, item->getADCRMSG1());
0067 m_writeStmt->setFloat(5, item->getADCMeanG16());
0068 m_writeStmt->setFloat(6, item->getADCRMSG16());
0069 m_writeStmt->setFloat(7, item->getPedMeanG1());
0070 m_writeStmt->setFloat(8, item->getPedRMSG1());
0071 m_writeStmt->setFloat(9, item->getPedMeanG16());
0072 m_writeStmt->setFloat(10, item->getPedRMSG16());
0073 m_writeStmt->setInt(11, item->getTaskStatus());
0074
0075 m_writeStmt->executeUpdate();
0076 } catch (SQLException& e) {
0077 throw(std::runtime_error("MonPNMGPADat::writeDB(): " + e.getMessage()));
0078 }
0079 }
0080
0081 void MonPNMGPADat::fetchData(std::map<EcalLogicID, MonPNMGPADat>* fillMap, MonRunIOV* iov) noexcept(false) {
0082 this->checkConnection();
0083 fillMap->clear();
0084
0085 iov->setConnection(m_env, m_conn);
0086 int iovID = iov->fetchID();
0087 if (!iovID) {
0088
0089 return;
0090 }
0091
0092 try {
0093 m_readStmt->setSQL(
0094 "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
0095 "d.adc_mean_g1, d.adc_rms_g1, d.adc_mean_g16, d.adc_rms_g16, d.ped_mean_g1,d.ped_rms_g1, d.ped_mean_g16, "
0096 "d.ped_rms_g16, d.task_status "
0097 "FROM channelview cv JOIN mon_pn_mgpa_dat d "
0098 "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
0099 "WHERE d.iov_id = :iov_id");
0100 m_readStmt->setInt(1, iovID);
0101 ResultSet* rset = m_readStmt->executeQuery();
0102
0103 std::pair<EcalLogicID, MonPNMGPADat> p;
0104 MonPNMGPADat dat;
0105 while (rset->next()) {
0106 p.first = EcalLogicID(rset->getString(1),
0107 rset->getInt(2),
0108 rset->getInt(3),
0109 rset->getInt(4),
0110 rset->getInt(5),
0111 rset->getString(6));
0112
0113 dat.setADCMeanG1(rset->getFloat(7));
0114 dat.setADCRMSG1(rset->getFloat(8));
0115 dat.setADCMeanG16(rset->getFloat(9));
0116 dat.setADCRMSG16(rset->getFloat(10));
0117 dat.setPedMeanG1(rset->getFloat(11));
0118 dat.setPedRMSG1(rset->getFloat(12));
0119 dat.setPedMeanG16(rset->getFloat(13));
0120 dat.setPedRMSG16(rset->getFloat(14));
0121 dat.setTaskStatus(rset->getInt(15));
0122 p.second = dat;
0123 fillMap->insert(p);
0124 }
0125 } catch (SQLException& e) {
0126 throw(std::runtime_error("MonPNMGPADat::fetchData(): " + e.getMessage()));
0127 }
0128 }
0129
0130 void MonPNMGPADat::writeArrayDB(const std::map<EcalLogicID, MonPNMGPADat>* data, MonRunIOV* iov) noexcept(false) {
0131 this->checkConnection();
0132 this->checkPrepare();
0133
0134 int iovID = iov->fetchID();
0135 if (!iovID) {
0136 throw(std::runtime_error("MonPNMGPADat::writeArrayDB: IOV not in DB"));
0137 }
0138
0139 int nrows = data->size();
0140 int* ids = new int[nrows];
0141 int* iovid_vec = new int[nrows];
0142 float* xx = new float[nrows];
0143 float* yy = new float[nrows];
0144 float* zz = new float[nrows];
0145 float* ww = new float[nrows];
0146 float* uu = new float[nrows];
0147 float* tt = new float[nrows];
0148 float* rr = new float[nrows];
0149 float* pp = new float[nrows];
0150 int* st = new int[nrows];
0151
0152 ub2* ids_len = new ub2[nrows];
0153 ub2* iov_len = new ub2[nrows];
0154 ub2* x_len = new ub2[nrows];
0155 ub2* y_len = new ub2[nrows];
0156 ub2* z_len = new ub2[nrows];
0157 ub2* w_len = new ub2[nrows];
0158 ub2* u_len = new ub2[nrows];
0159 ub2* t_len = new ub2[nrows];
0160 ub2* r_len = new ub2[nrows];
0161 ub2* p_len = new ub2[nrows];
0162 ub2* st_len = new ub2[nrows];
0163
0164 const EcalLogicID* channel;
0165 const MonPNMGPADat* dataitem;
0166 int count = 0;
0167 typedef map<EcalLogicID, MonPNMGPADat>::const_iterator CI;
0168 for (CI p = data->begin(); p != data->end(); ++p) {
0169 channel = &(p->first);
0170 int logicID = channel->getLogicID();
0171 if (!logicID) {
0172 throw(std::runtime_error("MonPNMGPADat::writeArrayDB: Bad EcalLogicID"));
0173 }
0174 ids[count] = logicID;
0175 iovid_vec[count] = iovID;
0176
0177 dataitem = &(p->second);
0178
0179 float x = dataitem->getADCMeanG1();
0180 float y = dataitem->getADCRMSG1();
0181 float z = dataitem->getADCMeanG16();
0182 float w = dataitem->getADCRMSG16();
0183 float u = dataitem->getPedMeanG1();
0184 float t = dataitem->getPedRMSG1();
0185 float r = dataitem->getPedMeanG16();
0186 float pi = dataitem->getPedRMSG16();
0187 int statu = dataitem->getTaskStatus();
0188
0189 xx[count] = x;
0190 yy[count] = y;
0191 zz[count] = z;
0192 ww[count] = w;
0193 uu[count] = u;
0194 tt[count] = t;
0195 rr[count] = r;
0196 pp[count] = pi;
0197 st[count] = statu;
0198
0199 ids_len[count] = sizeof(ids[count]);
0200 iov_len[count] = sizeof(iovid_vec[count]);
0201
0202 x_len[count] = sizeof(xx[count]);
0203 y_len[count] = sizeof(yy[count]);
0204 z_len[count] = sizeof(zz[count]);
0205 w_len[count] = sizeof(ww[count]);
0206 u_len[count] = sizeof(uu[count]);
0207 t_len[count] = sizeof(tt[count]);
0208 r_len[count] = sizeof(rr[count]);
0209 p_len[count] = sizeof(pp[count]);
0210 st_len[count] = sizeof(st[count]);
0211
0212 count++;
0213 }
0214
0215 try {
0216 m_writeStmt->setDataBuffer(1, (dvoid*)iovid_vec, OCCIINT, sizeof(iovid_vec[0]), iov_len);
0217 m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len);
0218 m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIFLOAT, sizeof(xx[0]), x_len);
0219 m_writeStmt->setDataBuffer(4, (dvoid*)yy, OCCIFLOAT, sizeof(yy[0]), y_len);
0220 m_writeStmt->setDataBuffer(5, (dvoid*)zz, OCCIFLOAT, sizeof(zz[0]), z_len);
0221 m_writeStmt->setDataBuffer(6, (dvoid*)ww, OCCIFLOAT, sizeof(ww[0]), w_len);
0222 m_writeStmt->setDataBuffer(7, (dvoid*)uu, OCCIFLOAT, sizeof(uu[0]), u_len);
0223 m_writeStmt->setDataBuffer(8, (dvoid*)tt, OCCIFLOAT, sizeof(tt[0]), t_len);
0224 m_writeStmt->setDataBuffer(9, (dvoid*)rr, OCCIFLOAT, sizeof(rr[0]), r_len);
0225 m_writeStmt->setDataBuffer(10, (dvoid*)pp, OCCIFLOAT, sizeof(pp[0]), p_len);
0226 m_writeStmt->setDataBuffer(11, (dvoid*)st, OCCIINT, sizeof(st[0]), st_len);
0227
0228 m_writeStmt->executeArrayUpdate(nrows);
0229
0230 delete[] ids;
0231 delete[] iovid_vec;
0232 delete[] xx;
0233 delete[] yy;
0234 delete[] zz;
0235 delete[] ww;
0236 delete[] uu;
0237 delete[] tt;
0238 delete[] rr;
0239 delete[] pp;
0240 delete[] st;
0241
0242 delete[] ids_len;
0243 delete[] iov_len;
0244 delete[] x_len;
0245 delete[] y_len;
0246 delete[] z_len;
0247 delete[] w_len;
0248 delete[] u_len;
0249 delete[] t_len;
0250 delete[] r_len;
0251 delete[] p_len;
0252 delete[] st_len;
0253
0254 } catch (SQLException& e) {
0255 throw(std::runtime_error("MonPNMGPADat::writeArrayDB(): " + e.getMessage()));
0256 }
0257 }