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