Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include <stdexcept>
0002 #include <string>
0003 #include "OnlineDB/Oracle/interface/Oracle.h"
0004 
0005 #include "OnlineDB/EcalCondDB/interface/MonPNGreenDat.h"
0006 #include "OnlineDB/EcalCondDB/interface/RunTag.h"
0007 #include "OnlineDB/EcalCondDB/interface/RunIOV.h"
0008 
0009 using namespace std;
0010 using namespace oracle::occi;
0011 
0012 MonPNGreenDat::MonPNGreenDat() {
0013   m_env = nullptr;
0014   m_conn = nullptr;
0015   m_writeStmt = nullptr;
0016   m_readStmt = nullptr;
0017 
0018   m_adcMeanG1 = 0;
0019   m_adcRMSG1 = 0;
0020   m_adcMeanG16 = 0;
0021   m_adcRMSG16 = 0;
0022   m_pedMeanG1 = 0;
0023   m_pedRMSG1 = 0;
0024   m_pedMeanG16 = 0;
0025   m_pedRMSG16 = 0;
0026   m_taskStatus = false;
0027 }
0028 
0029 MonPNGreenDat::~MonPNGreenDat() {}
0030 
0031 void MonPNGreenDat::prepareWrite() noexcept(false) {
0032   this->checkConnection();
0033 
0034   try {
0035     m_writeStmt = m_conn->createStatement();
0036     m_writeStmt->setSQL(
0037         "INSERT INTO mon_pn_green_dat (iov_id, logic_id, "
0038         "adc_mean_g1, adc_rms_g1, adc_mean_g16, adc_rms_g16, ped_mean_g1, ped_rms_g1, ped_mean_g16, ped_rms_g16, "
0039         "task_status) "
0040         "VALUES (:iov_id, :logic_id, "
0041         ":3, :4, :5, :6, :7, :8, :9, :10, :11)");
0042   } catch (SQLException& e) {
0043     throw(std::runtime_error("MonPNGreenDat::prepareWrite():  " + e.getMessage()));
0044   }
0045 }
0046 
0047 void MonPNGreenDat::writeDB(const EcalLogicID* ecid, const MonPNGreenDat* item, MonRunIOV* iov) noexcept(false) {
0048   this->checkConnection();
0049   this->checkPrepare();
0050 
0051   int iovID = iov->fetchID();
0052   if (!iovID) {
0053     throw(std::runtime_error("MonPNGreenDat::writeDB:  IOV not in DB"));
0054   }
0055 
0056   int logicID = ecid->getLogicID();
0057   if (!logicID) {
0058     throw(std::runtime_error("MonPNGreenDat::writeDB:  Bad EcalLogicID"));
0059   }
0060 
0061   try {
0062     m_writeStmt->setInt(1, iovID);
0063     m_writeStmt->setInt(2, logicID);
0064 
0065     m_writeStmt->setFloat(3, item->getADCMeanG1());
0066     m_writeStmt->setFloat(4, item->getADCRMSG1());
0067     m_writeStmt->setFloat(5, item->getADCMeanG16());
0068     m_writeStmt->setFloat(6, item->getADCRMSG16());
0069     m_writeStmt->setFloat(7, item->getPedMeanG1());
0070     m_writeStmt->setFloat(8, item->getPedRMSG1());
0071     m_writeStmt->setFloat(9, item->getPedMeanG16());
0072     m_writeStmt->setFloat(10, item->getPedRMSG16());
0073     m_writeStmt->setInt(11, item->getTaskStatus());
0074 
0075     m_writeStmt->executeUpdate();
0076   } catch (SQLException& e) {
0077     throw(std::runtime_error("MonPNGreenDat::writeDB():  " + e.getMessage()));
0078   }
0079 }
0080 
0081 void MonPNGreenDat::fetchData(std::map<EcalLogicID, MonPNGreenDat>* fillMap, MonRunIOV* iov) noexcept(false) {
0082   this->checkConnection();
0083   fillMap->clear();
0084 
0085   iov->setConnection(m_env, m_conn);
0086   int iovID = iov->fetchID();
0087   if (!iovID) {
0088     //  throw(std::runtime_error("MonPNGreenDat::writeDB:  IOV not in DB"));
0089     return;
0090   }
0091 
0092   try {
0093     m_readStmt->setSQL(
0094         "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
0095         "d.adc_mean_g1, d.adc_rms_g1, d.adc_mean_g16, d.adc_rms_g16, d.ped_mean_g1,d.ped_rms_g1, d.ped_mean_g16, "
0096         "d.ped_rms_g16, d.task_status "
0097         "FROM channelview cv JOIN mon_pn_green_dat d "
0098         "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
0099         "WHERE d.iov_id = :iov_id");
0100     m_readStmt->setInt(1, iovID);
0101     ResultSet* rset = m_readStmt->executeQuery();
0102 
0103     std::pair<EcalLogicID, MonPNGreenDat> p;
0104     MonPNGreenDat dat;
0105     while (rset->next()) {
0106       p.first = EcalLogicID(rset->getString(1),   // name
0107                             rset->getInt(2),      // logic_id
0108                             rset->getInt(3),      // id1
0109                             rset->getInt(4),      // id2
0110                             rset->getInt(5),      // id3
0111                             rset->getString(6));  // maps_to
0112 
0113       dat.setADCMeanG1(rset->getFloat(7));
0114       dat.setADCRMSG1(rset->getFloat(8));
0115       dat.setADCMeanG16(rset->getFloat(9));
0116       dat.setADCRMSG16(rset->getFloat(10));
0117       dat.setPedMeanG1(rset->getFloat(11));
0118       dat.setPedRMSG1(rset->getFloat(12));
0119       dat.setPedMeanG16(rset->getFloat(13));
0120       dat.setPedRMSG16(rset->getFloat(14));
0121       dat.setTaskStatus(rset->getInt(15));
0122       p.second = dat;
0123       fillMap->insert(p);
0124     }
0125   } catch (SQLException& e) {
0126     throw(std::runtime_error("MonPNGreenDat::fetchData():  " + e.getMessage()));
0127   }
0128 }
0129 void MonPNGreenDat::writeArrayDB(const std::map<EcalLogicID, MonPNGreenDat>* data, MonRunIOV* iov) noexcept(false) {
0130   this->checkConnection();
0131   this->checkPrepare();
0132 
0133   int iovID = iov->fetchID();
0134   if (!iovID) {
0135     throw(std::runtime_error("MonPNGreenDat::writeArrayDB:  IOV not in DB"));
0136   }
0137 
0138   int nrows = data->size();
0139   int* ids = new int[nrows];
0140   int* iovid_vec = new int[nrows];
0141   float* xx = new float[nrows];
0142   float* yy = new float[nrows];
0143   float* zz = new float[nrows];
0144   float* ww = new float[nrows];
0145   float* uu = new float[nrows];
0146   float* tt = new float[nrows];
0147   float* rr = new float[nrows];
0148   float* pp = new float[nrows];
0149   int* st = new int[nrows];
0150 
0151   ub2* ids_len = new ub2[nrows];
0152   ub2* iov_len = new ub2[nrows];
0153   ub2* x_len = new ub2[nrows];
0154   ub2* y_len = new ub2[nrows];
0155   ub2* z_len = new ub2[nrows];
0156   ub2* w_len = new ub2[nrows];
0157   ub2* u_len = new ub2[nrows];
0158   ub2* t_len = new ub2[nrows];
0159   ub2* r_len = new ub2[nrows];
0160   ub2* p_len = new ub2[nrows];
0161   ub2* st_len = new ub2[nrows];
0162 
0163   const EcalLogicID* channel;
0164   const MonPNGreenDat* dataitem;
0165   int count = 0;
0166   typedef map<EcalLogicID, MonPNGreenDat>::const_iterator CI;
0167   for (CI p = data->begin(); p != data->end(); ++p) {
0168     channel = &(p->first);
0169     int logicID = channel->getLogicID();
0170     if (!logicID) {
0171       throw(std::runtime_error("MonPNGreenDat::writeArrayDB:  Bad EcalLogicID"));
0172     }
0173     ids[count] = logicID;
0174     iovid_vec[count] = iovID;
0175 
0176     dataitem = &(p->second);
0177     // dataIface.writeDB( channel, dataitem, iov);
0178     float x = dataitem->getADCMeanG1();
0179     float y = dataitem->getADCRMSG1();
0180     float z = dataitem->getADCMeanG16();
0181     float w = dataitem->getADCRMSG16();
0182     float u = dataitem->getPedMeanG1();
0183     float t = dataitem->getPedRMSG1();
0184     float r = dataitem->getPedMeanG16();
0185     float pi = dataitem->getPedRMSG16();
0186     int statu = dataitem->getTaskStatus();
0187 
0188     xx[count] = x;
0189     yy[count] = y;
0190     zz[count] = z;
0191     ww[count] = w;
0192     uu[count] = u;
0193     tt[count] = t;
0194     rr[count] = r;
0195     pp[count] = pi;
0196     st[count] = statu;
0197 
0198     ids_len[count] = sizeof(ids[count]);
0199     iov_len[count] = sizeof(iovid_vec[count]);
0200 
0201     x_len[count] = sizeof(xx[count]);
0202     y_len[count] = sizeof(yy[count]);
0203     z_len[count] = sizeof(zz[count]);
0204     w_len[count] = sizeof(ww[count]);
0205     u_len[count] = sizeof(uu[count]);
0206     t_len[count] = sizeof(tt[count]);
0207     r_len[count] = sizeof(rr[count]);
0208     p_len[count] = sizeof(pp[count]);
0209     st_len[count] = sizeof(st[count]);
0210 
0211     count++;
0212   }
0213 
0214   try {
0215     m_writeStmt->setDataBuffer(1, (dvoid*)iovid_vec, OCCIINT, sizeof(iovid_vec[0]), iov_len);
0216     m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len);
0217     m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIFLOAT, sizeof(xx[0]), x_len);
0218     m_writeStmt->setDataBuffer(4, (dvoid*)yy, OCCIFLOAT, sizeof(yy[0]), y_len);
0219     m_writeStmt->setDataBuffer(5, (dvoid*)zz, OCCIFLOAT, sizeof(zz[0]), z_len);
0220     m_writeStmt->setDataBuffer(6, (dvoid*)ww, OCCIFLOAT, sizeof(ww[0]), w_len);
0221     m_writeStmt->setDataBuffer(7, (dvoid*)uu, OCCIFLOAT, sizeof(uu[0]), u_len);
0222     m_writeStmt->setDataBuffer(8, (dvoid*)tt, OCCIFLOAT, sizeof(tt[0]), t_len);
0223     m_writeStmt->setDataBuffer(9, (dvoid*)rr, OCCIFLOAT, sizeof(rr[0]), r_len);
0224     m_writeStmt->setDataBuffer(10, (dvoid*)pp, OCCIFLOAT, sizeof(pp[0]), p_len);
0225     m_writeStmt->setDataBuffer(11, (dvoid*)st, OCCIINT, sizeof(st[0]), st_len);
0226 
0227     m_writeStmt->executeArrayUpdate(nrows);
0228 
0229     delete[] ids;
0230     delete[] iovid_vec;
0231     delete[] xx;
0232     delete[] yy;
0233     delete[] zz;
0234     delete[] ww;
0235     delete[] uu;
0236     delete[] tt;
0237     delete[] rr;
0238     delete[] pp;
0239     delete[] st;
0240 
0241     delete[] ids_len;
0242     delete[] iov_len;
0243     delete[] x_len;
0244     delete[] y_len;
0245     delete[] z_len;
0246     delete[] w_len;
0247     delete[] u_len;
0248     delete[] t_len;
0249     delete[] r_len;
0250     delete[] p_len;
0251     delete[] st_len;
0252 
0253   } catch (SQLException& e) {
0254     throw(std::runtime_error("MonPNGreenDat::writeArrayDB():  " + e.getMessage()));
0255   }
0256 }