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