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/MonLaserBlueDat.h"
0006 
0007 using namespace std;
0008 using namespace oracle::occi;
0009 
0010 MonLaserBlueDat::MonLaserBlueDat() {
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 MonLaserBlueDat::~MonLaserBlueDat() {}
0024 
0025 void MonLaserBlueDat::prepareWrite() noexcept(false) {
0026   this->checkConnection();
0027 
0028   try {
0029     m_writeStmt = m_conn->createStatement();
0030     m_writeStmt->setSQL(
0031         "INSERT INTO mon_laser_blue_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("MonLaserBlueDat::prepareWrite():  " + e.getMessage()));
0037   }
0038 }
0039 
0040 void MonLaserBlueDat::writeDB(const EcalLogicID* ecid, const MonLaserBlueDat* 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("MonLaserBlueDat::writeDB:  IOV not in DB"));
0047   }
0048 
0049   int logicID = ecid->getLogicID();
0050   if (!logicID) {
0051     throw(std::runtime_error("MonLaserBlueDat::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("MonLaserBlueDat::writeDB():  " + e.getMessage()));
0067   }
0068 }
0069 
0070 void MonLaserBlueDat::fetchData(std::map<EcalLogicID, MonLaserBlueDat>* 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("MonLaserBlueDat::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_blue_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, MonLaserBlueDat> p;
0093     MonLaserBlueDat 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("MonLaserBlueDat::fetchData():  " + e.getMessage()));
0113   }
0114 }
0115 
0116 void MonLaserBlueDat::writeArrayDB(const std::map<EcalLogicID, MonLaserBlueDat>* data, MonRunIOV* iov) noexcept(false) {
0117   this->checkConnection();
0118   this->checkPrepare();
0119 
0120   int iovID = iov->fetchID();
0121   if (!iovID) {
0122     throw(std::runtime_error("MonLaserBlueDat::writeArrayDB:  IOV not in DB"));
0123   }
0124 
0125   int nrows = data->size();
0126   int* ids = new int[nrows];
0127   int* iovid_vec = new int[nrows];
0128   float* xx = new float[nrows];
0129   float* yy = new float[nrows];
0130   float* zz = new float[nrows];
0131   float* ww = new float[nrows];
0132   int* st = new int[nrows];
0133 
0134   ub2* ids_len = new ub2[nrows];
0135   ub2* iov_len = new ub2[nrows];
0136   ub2* x_len = new ub2[nrows];
0137   ub2* y_len = new ub2[nrows];
0138   ub2* z_len = new ub2[nrows];
0139   ub2* w_len = new ub2[nrows];
0140   ub2* st_len = new ub2[nrows];
0141 
0142   const EcalLogicID* channel;
0143   const MonLaserBlueDat* dataitem;
0144   int count = 0;
0145   typedef map<EcalLogicID, MonLaserBlueDat>::const_iterator CI;
0146   for (CI p = data->begin(); p != data->end(); ++p) {
0147     channel = &(p->first);
0148     int logicID = channel->getLogicID();
0149     if (!logicID) {
0150       throw(std::runtime_error("MonLaserBlueDat::writeArrayDB:  Bad EcalLogicID"));
0151     }
0152     ids[count] = logicID;
0153     iovid_vec[count] = iovID;
0154 
0155     dataitem = &(p->second);
0156     // dataIface.writeDB( channel, dataitem, iov);
0157     float x = dataitem->getAPDMean();
0158     float y = dataitem->getAPDRMS();
0159     float z = dataitem->getAPDOverPNMean();
0160     float w = dataitem->getAPDOverPNRMS();
0161     int statu = dataitem->getTaskStatus();
0162 
0163     xx[count] = x;
0164     yy[count] = y;
0165     zz[count] = z;
0166     ww[count] = w;
0167     st[count] = statu;
0168 
0169     ids_len[count] = sizeof(ids[count]);
0170     iov_len[count] = sizeof(iovid_vec[count]);
0171 
0172     x_len[count] = sizeof(xx[count]);
0173     y_len[count] = sizeof(yy[count]);
0174     z_len[count] = sizeof(zz[count]);
0175     w_len[count] = sizeof(ww[count]);
0176     st_len[count] = sizeof(st[count]);
0177 
0178     count++;
0179   }
0180 
0181   try {
0182     m_writeStmt->setDataBuffer(1, (dvoid*)iovid_vec, OCCIINT, sizeof(iovid_vec[0]), iov_len);
0183     m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len);
0184     m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIFLOAT, sizeof(xx[0]), x_len);
0185     m_writeStmt->setDataBuffer(4, (dvoid*)yy, OCCIFLOAT, sizeof(yy[0]), y_len);
0186     m_writeStmt->setDataBuffer(5, (dvoid*)zz, OCCIFLOAT, sizeof(zz[0]), z_len);
0187     m_writeStmt->setDataBuffer(6, (dvoid*)ww, OCCIFLOAT, sizeof(ww[0]), w_len);
0188     m_writeStmt->setDataBuffer(7, (dvoid*)st, OCCIINT, sizeof(st[0]), st_len);
0189 
0190     m_writeStmt->executeArrayUpdate(nrows);
0191 
0192     delete[] ids;
0193     delete[] iovid_vec;
0194     delete[] xx;
0195     delete[] yy;
0196     delete[] zz;
0197     delete[] ww;
0198     delete[] st;
0199 
0200     delete[] ids_len;
0201     delete[] iov_len;
0202     delete[] x_len;
0203     delete[] y_len;
0204     delete[] z_len;
0205     delete[] w_len;
0206     delete[] st_len;
0207 
0208   } catch (SQLException& e) {
0209     throw(std::runtime_error("MonLaserBlueDat::writeArrayDB():  " + e.getMessage()));
0210   }
0211 }