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