Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include <stdexcept>
0002 #include <string>
0003 #include "OnlineDB/Oracle/interface/Oracle.h"
0004 
0005 #include "OnlineDB/EcalCondDB/interface/MonTestPulseDat.h"
0006 #include "OnlineDB/EcalCondDB/interface/MonRunTag.h"
0007 #include "OnlineDB/EcalCondDB/interface/MonRunIOV.h"
0008 
0009 using namespace std;
0010 using namespace oracle::occi;
0011 
0012 MonTestPulseDat::MonTestPulseDat() {
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_adcMeanG6 = 0;
0021   m_adcRMSG6 = 0;
0022   m_adcMeanG12 = 0;
0023   m_adcRMSG12 = 0;
0024   m_taskStatus = false;
0025 }
0026 
0027 MonTestPulseDat::~MonTestPulseDat() {}
0028 
0029 void MonTestPulseDat::prepareWrite() noexcept(false) {
0030   this->checkConnection();
0031 
0032   try {
0033     m_writeStmt = m_conn->createStatement();
0034     m_writeStmt->setSQL(
0035         "INSERT INTO mon_test_pulse_dat (iov_id, logic_id, "
0036         "adc_mean_g1, adc_rms_g1, adc_mean_g6, adc_rms_g6, adc_mean_g12, adc_rms_g12, task_status) "
0037         "VALUES (:iov_id, :logic_id, "
0038         ":adc_mean_g1, :adc_rms_g1, :adc_rms_g6, :adc_rms_g6, :adc_mean_g12, :adc_rms_g12, :task_status)");
0039   } catch (SQLException& e) {
0040     throw(std::runtime_error("MonTestPulseDat::prepareWrite():  " + e.getMessage()));
0041   }
0042 }
0043 
0044 void MonTestPulseDat::writeDB(const EcalLogicID* ecid, const MonTestPulseDat* item, MonRunIOV* iov) noexcept(false) {
0045   this->checkConnection();
0046   this->checkPrepare();
0047 
0048   int iovID = iov->fetchID();
0049   if (!iovID) {
0050     throw(std::runtime_error("MonTestPulseDat::writeDB:  IOV not in DB"));
0051   }
0052 
0053   int logicID = ecid->getLogicID();
0054   if (!logicID) {
0055     throw(std::runtime_error("MonTestPulseDat::writeDB:  Bad EcalLogicID"));
0056   }
0057 
0058   try {
0059     m_writeStmt->setInt(1, iovID);
0060     m_writeStmt->setInt(2, logicID);
0061     m_writeStmt->setFloat(3, item->getADCMeanG1());
0062     m_writeStmt->setFloat(4, item->getADCRMSG1());
0063     m_writeStmt->setFloat(5, item->getADCMeanG6());
0064     m_writeStmt->setFloat(6, item->getADCRMSG6());
0065     m_writeStmt->setFloat(7, item->getADCMeanG12());
0066     m_writeStmt->setFloat(8, item->getADCRMSG12());
0067     m_writeStmt->setInt(9, item->getTaskStatus());
0068 
0069     m_writeStmt->executeUpdate();
0070   } catch (SQLException& e) {
0071     throw(std::runtime_error("MonTestPulseDat::writeDB():  " + e.getMessage()));
0072   }
0073 }
0074 
0075 void MonTestPulseDat::fetchData(std::map<EcalLogicID, MonTestPulseDat>* fillMap, MonRunIOV* iov) noexcept(false) {
0076   this->checkConnection();
0077   fillMap->clear();
0078 
0079   iov->setConnection(m_env, m_conn);
0080   int iovID = iov->fetchID();
0081   if (!iovID) {
0082     //  throw(std::runtime_error("MonTestPulseDat::writeDB:  IOV not in DB"));
0083     return;
0084   }
0085 
0086   try {
0087     m_readStmt->setSQL(
0088         "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
0089         "d.adc_mean_g1, d.adc_rms_g1, d.adc_mean_g6, d.adc_rms_g6, d.adc_mean_g12, d.adc_rms_g12, d.task_status "
0090         "FROM channelview cv JOIN mon_test_pulse_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, MonTestPulseDat> p;
0097     MonTestPulseDat 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.setADCMeanG1(rset->getFloat(7));
0107       dat.setADCRMSG1(rset->getFloat(8));
0108       dat.setADCMeanG6(rset->getFloat(9));
0109       dat.setADCRMSG6(rset->getFloat(10));
0110       dat.setADCMeanG12(rset->getFloat(11));
0111       dat.setADCRMSG12(rset->getFloat(12));
0112       dat.setTaskStatus(rset->getInt(13));
0113 
0114       p.second = dat;
0115       fillMap->insert(p);
0116     }
0117   } catch (SQLException& e) {
0118     throw(std::runtime_error("MonTestPulseDat::fetchData():  " + e.getMessage()));
0119   }
0120 }
0121 
0122 void MonTestPulseDat::writeArrayDB(const std::map<EcalLogicID, MonTestPulseDat>* data, MonRunIOV* iov) noexcept(false) {
0123   this->checkConnection();
0124   this->checkPrepare();
0125 
0126   int iovID = iov->fetchID();
0127   if (!iovID) {
0128     throw(std::runtime_error("MonTestPulseDat::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   float* xx = new float[nrows];
0135   float* yy = new float[nrows];
0136   float* zz = new float[nrows];
0137   float* ww = new float[nrows];
0138   float* uu = new float[nrows];
0139   float* tt = new float[nrows];
0140   int* st = new int[nrows];
0141 
0142   ub2* ids_len = new ub2[nrows];
0143   ub2* iov_len = new ub2[nrows];
0144   ub2* x_len = new ub2[nrows];
0145   ub2* y_len = new ub2[nrows];
0146   ub2* z_len = new ub2[nrows];
0147   ub2* w_len = new ub2[nrows];
0148   ub2* u_len = new ub2[nrows];
0149   ub2* t_len = new ub2[nrows];
0150   ub2* st_len = new ub2[nrows];
0151 
0152   const EcalLogicID* channel;
0153   const MonTestPulseDat* dataitem;
0154   int count = 0;
0155   typedef map<EcalLogicID, MonTestPulseDat>::const_iterator CI;
0156   for (CI p = data->begin(); p != data->end(); ++p) {
0157     channel = &(p->first);
0158     int logicID = channel->getLogicID();
0159     if (!logicID) {
0160       throw(std::runtime_error("MonTestPulseDat::writeArrayDB:  Bad EcalLogicID"));
0161     }
0162     ids[count] = logicID;
0163     iovid_vec[count] = iovID;
0164 
0165     dataitem = &(p->second);
0166     // dataIface.writeDB( channel, dataitem, iov);
0167     float x = dataitem->getADCMeanG1();
0168     float y = dataitem->getADCRMSG1();
0169     float z = dataitem->getADCMeanG6();
0170     float w = dataitem->getADCRMSG6();
0171     float u = dataitem->getADCMeanG12();
0172     float t = dataitem->getADCRMSG12();
0173     int statu = dataitem->getTaskStatus();
0174 
0175     xx[count] = x;
0176     yy[count] = y;
0177     zz[count] = z;
0178     ww[count] = w;
0179     uu[count] = u;
0180     tt[count] = t;
0181     st[count] = statu;
0182 
0183     ids_len[count] = sizeof(ids[count]);
0184     iov_len[count] = sizeof(iovid_vec[count]);
0185 
0186     x_len[count] = sizeof(xx[count]);
0187     y_len[count] = sizeof(yy[count]);
0188     z_len[count] = sizeof(zz[count]);
0189     w_len[count] = sizeof(ww[count]);
0190     u_len[count] = sizeof(uu[count]);
0191     t_len[count] = sizeof(tt[count]);
0192     st_len[count] = sizeof(st[count]);
0193 
0194     count++;
0195   }
0196 
0197   try {
0198     m_writeStmt->setDataBuffer(1, (dvoid*)iovid_vec, OCCIINT, sizeof(iovid_vec[0]), iov_len);
0199     m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len);
0200     m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIFLOAT, sizeof(xx[0]), x_len);
0201     m_writeStmt->setDataBuffer(4, (dvoid*)yy, OCCIFLOAT, sizeof(yy[0]), y_len);
0202     m_writeStmt->setDataBuffer(5, (dvoid*)zz, OCCIFLOAT, sizeof(zz[0]), z_len);
0203     m_writeStmt->setDataBuffer(6, (dvoid*)ww, OCCIFLOAT, sizeof(ww[0]), w_len);
0204     m_writeStmt->setDataBuffer(7, (dvoid*)uu, OCCIFLOAT, sizeof(uu[0]), u_len);
0205     m_writeStmt->setDataBuffer(8, (dvoid*)tt, OCCIFLOAT, sizeof(tt[0]), t_len);
0206     m_writeStmt->setDataBuffer(9, (dvoid*)st, OCCIINT, sizeof(st[0]), st_len);
0207 
0208     m_writeStmt->executeArrayUpdate(nrows);
0209 
0210     delete[] ids;
0211     delete[] iovid_vec;
0212     delete[] xx;
0213     delete[] yy;
0214     delete[] zz;
0215     delete[] ww;
0216     delete[] uu;
0217     delete[] tt;
0218     delete[] st;
0219 
0220     delete[] ids_len;
0221     delete[] iov_len;
0222     delete[] x_len;
0223     delete[] y_len;
0224     delete[] z_len;
0225     delete[] w_len;
0226     delete[] u_len;
0227     delete[] t_len;
0228     delete[] st_len;
0229 
0230   } catch (SQLException& e) {
0231     throw(std::runtime_error("MonTestPulseDat::writeArrayDB():  " + e.getMessage()));
0232   }
0233 }