Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:32:03

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