Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:23:07

0001 #include <stdexcept>
0002 #include <string>
0003 #include "OnlineDB/Oracle/interface/Oracle.h"
0004 
0005 #include "OnlineDB/EcalCondDB/interface/MonMemChConsistencyDat.h"
0006 
0007 using namespace std;
0008 using namespace oracle::occi;
0009 
0010 MonMemChConsistencyDat::MonMemChConsistencyDat() {
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 MonMemChConsistencyDat::~MonMemChConsistencyDat() {}
0025 
0026 void MonMemChConsistencyDat::prepareWrite() noexcept(false) {
0027   this->checkConnection();
0028 
0029   try {
0030     m_writeStmt = m_conn->createStatement();
0031     m_writeStmt->setSQL(
0032         "INSERT INTO mon_mem_ch_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("MonMemChConsistencyDat::prepareWrite():  " + e.getMessage()));
0038   }
0039 }
0040 
0041 void MonMemChConsistencyDat::writeDB(const EcalLogicID* ecid,
0042                                      const MonMemChConsistencyDat* 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("MonMemChConsistencyDat::writeDB:  IOV not in DB"));
0050   }
0051 
0052   int logicID = ecid->getLogicID();
0053   if (!logicID) {
0054     throw(std::runtime_error("MonMemChConsistencyDat::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("MonMemChConsistencyDat::writeDB():  " + e.getMessage()));
0070   }
0071 }
0072 
0073 void MonMemChConsistencyDat::fetchData(std::map<EcalLogicID, MonMemChConsistencyDat>* 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     //  throw(std::runtime_error("MonMemChConsistencyDat::writeDB:  IOV not in DB"));
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_mem_ch_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, MonMemChConsistencyDat> p;
0097     MonMemChConsistencyDat dat;
0098     while (rset->next()) {
0099       p.first = EcalLogicID(rset->getString(1),   // name
0100                             rset->getInt(2),      // logic_id
0101                             rset->getInt(3),      // id1
0102                             rset->getInt(4),      // id2
0103                             rset->getInt(5),      // id3
0104                             rset->getString(6));  // maps_to
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   } catch (SQLException& e) {
0117     throw(std::runtime_error("MonMemChConsistencyDat::fetchData():  " + e.getMessage()));
0118   }
0119 }
0120 
0121 void MonMemChConsistencyDat::writeArrayDB(const std::map<EcalLogicID, MonMemChConsistencyDat>* data,
0122                                           MonRunIOV* iov) noexcept(false) {
0123   this->checkConnection();
0124   this->checkPrepare();
0125 
0126   int iovID = iov->fetchID();
0127   if (!iovID) {
0128     throw(std::runtime_error("MonMemChConsistencyDat::writeArrayDB:  IOV not in DB"));
0129   }
0130 
0131   int nrows = data->size();
0132   int* ids = new int[nrows];
0133   int* iovid_vec = new int[nrows];
0134   int* xx = new int[nrows];
0135   int* yy = new int[nrows];
0136   int* zz = new int[nrows];
0137   int* ww = new int[nrows];
0138   int* uu = new int[nrows];
0139   int* st = new int[nrows];
0140 
0141   ub2* ids_len = new ub2[nrows];
0142   ub2* iov_len = new ub2[nrows];
0143   ub2* x_len = new ub2[nrows];
0144   ub2* y_len = new ub2[nrows];
0145   ub2* z_len = new ub2[nrows];
0146   ub2* w_len = new ub2[nrows];
0147   ub2* u_len = new ub2[nrows];
0148   ub2* st_len = new ub2[nrows];
0149 
0150   const EcalLogicID* channel;
0151   const MonMemChConsistencyDat* dataitem;
0152   int count = 0;
0153   typedef map<EcalLogicID, MonMemChConsistencyDat>::const_iterator CI;
0154   for (CI p = data->begin(); p != data->end(); ++p) {
0155     channel = &(p->first);
0156     int logicID = channel->getLogicID();
0157     if (!logicID) {
0158       throw(std::runtime_error("MonMemChConsistencyDat::writeArrayDB:  Bad EcalLogicID"));
0159     }
0160     ids[count] = logicID;
0161     iovid_vec[count] = iovID;
0162 
0163     dataitem = &(p->second);
0164     // dataIface.writeDB( channel, dataitem, iov);
0165     int x = dataitem->getProcessedEvents();
0166     int y = dataitem->getProblematicEvents();
0167     int z = dataitem->getProblemsID();
0168     int w = dataitem->getProblemsGainZero();
0169     int u = dataitem->getProblemsGainSwitch();
0170     int statu = dataitem->getTaskStatus();
0171 
0172     xx[count] = x;
0173     yy[count] = y;
0174     zz[count] = z;
0175     ww[count] = w;
0176     uu[count] = u;
0177     st[count] = statu;
0178 
0179     ids_len[count] = sizeof(ids[count]);
0180     iov_len[count] = sizeof(iovid_vec[count]);
0181 
0182     x_len[count] = sizeof(xx[count]);
0183     y_len[count] = sizeof(yy[count]);
0184     z_len[count] = sizeof(zz[count]);
0185     w_len[count] = sizeof(ww[count]);
0186     u_len[count] = sizeof(uu[count]);
0187     st_len[count] = sizeof(st[count]);
0188 
0189     count++;
0190   }
0191 
0192   try {
0193     m_writeStmt->setDataBuffer(1, (dvoid*)iovid_vec, OCCIINT, sizeof(iovid_vec[0]), iov_len);
0194     m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len);
0195     m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIINT, sizeof(xx[0]), x_len);
0196     m_writeStmt->setDataBuffer(4, (dvoid*)yy, OCCIINT, sizeof(yy[0]), y_len);
0197     m_writeStmt->setDataBuffer(5, (dvoid*)zz, OCCIINT, sizeof(zz[0]), z_len);
0198     m_writeStmt->setDataBuffer(6, (dvoid*)ww, OCCIINT, sizeof(ww[0]), w_len);
0199     m_writeStmt->setDataBuffer(7, (dvoid*)uu, OCCIINT, sizeof(uu[0]), u_len);
0200     m_writeStmt->setDataBuffer(8, (dvoid*)st, OCCIINT, sizeof(st[0]), st_len);
0201 
0202     m_writeStmt->executeArrayUpdate(nrows);
0203 
0204     delete[] ids;
0205     delete[] iovid_vec;
0206     delete[] xx;
0207     delete[] yy;
0208     delete[] zz;
0209     delete[] ww;
0210     delete[] uu;
0211     delete[] st;
0212 
0213     delete[] ids_len;
0214     delete[] iov_len;
0215     delete[] x_len;
0216     delete[] y_len;
0217     delete[] z_len;
0218     delete[] w_len;
0219     delete[] u_len;
0220     delete[] st_len;
0221 
0222   } catch (SQLException& e) {
0223     throw(std::runtime_error("MonMemChConsistencyDat::writeArrayDB():  " + e.getMessage()));
0224   }
0225 }