Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:31:58

0001 #include <stdexcept>
0002 #include <string>
0003 #include "OnlineDB/Oracle/interface/Oracle.h"
0004 
0005 #include "OnlineDB/EcalCondDB/interface/FEConfigFgrEEStripDat.h"
0006 #include "OnlineDB/EcalCondDB/interface/FEConfigFgrInfo.h"
0007 
0008 using namespace std;
0009 using namespace oracle::occi;
0010 
0011 FEConfigFgrEEStripDat::FEConfigFgrEEStripDat() {
0012   m_env = nullptr;
0013   m_conn = nullptr;
0014   m_writeStmt = nullptr;
0015   m_readStmt = nullptr;
0016 
0017   m_thresh = 0;
0018   m_lut_fg = 0;
0019 }
0020 
0021 FEConfigFgrEEStripDat::~FEConfigFgrEEStripDat() {}
0022 
0023 void FEConfigFgrEEStripDat::prepareWrite() noexcept(false) {
0024   this->checkConnection();
0025 
0026   try {
0027     m_writeStmt = m_conn->createStatement();
0028     m_writeStmt->setSQL("INSERT INTO " + getTable() +
0029                         " (fgr_conf_id, logic_id, "
0030                         "threshold, lut_fg ) "
0031                         "VALUES (:fgr_conf_id, :logic_id, "
0032                         ":threshold, :lut_fg )");
0033   } catch (SQLException& e) {
0034     throw(std::runtime_error("FEConfigFgrEEStripDat::prepareWrite():  " + e.getMessage()));
0035   }
0036 }
0037 
0038 void FEConfigFgrEEStripDat::writeDB(const EcalLogicID* ecid,
0039                                     const FEConfigFgrEEStripDat* item,
0040                                     FEConfigFgrInfo* iconf) noexcept(false) {
0041   this->checkConnection();
0042   this->checkPrepare();
0043 
0044   int iconfID = iconf->fetchID();
0045   if (!iconfID) {
0046     throw(std::runtime_error("FEConfigFgrEEStripDat::writeDB:  ICONF not in DB"));
0047   }
0048 
0049   int logicID = ecid->getLogicID();
0050   if (!logicID) {
0051     throw(std::runtime_error("FEConfigFgrEEStripDat::writeDB:  Bad EcalLogicID"));
0052   }
0053 
0054   try {
0055     m_writeStmt->setInt(1, iconfID);
0056     m_writeStmt->setInt(2, logicID);
0057     m_writeStmt->setUInt(3, item->getThreshold());
0058     m_writeStmt->setUInt(4, item->getLutFg());
0059 
0060     m_writeStmt->executeUpdate();
0061   } catch (SQLException& e) {
0062     throw(std::runtime_error("FEConfigFgrEEStripDat::writeDB():  " + e.getMessage()));
0063   }
0064 }
0065 
0066 void FEConfigFgrEEStripDat::fetchData(map<EcalLogicID, FEConfigFgrEEStripDat>* fillMap,
0067                                       FEConfigFgrInfo* iconf) noexcept(false) {
0068   this->checkConnection();
0069   fillMap->clear();
0070 
0071   iconf->setConnection(m_env, m_conn);
0072   int iconfID = iconf->fetchID();
0073   if (!iconfID) {
0074     //  throw(std::runtime_error("FEConfigFgrEEStripDat::writeDB:  ICONF not in DB"));
0075     return;
0076   }
0077 
0078   try {
0079     m_readStmt->setSQL(
0080         "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
0081         "d.threshold, d.lut_fg "
0082         "FROM channelview cv JOIN " +
0083         getTable() +
0084         " d "
0085         "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
0086         "WHERE fgr_conf_id = :fgr_conf_id");
0087     m_readStmt->setInt(1, iconfID);
0088     ResultSet* rset = m_readStmt->executeQuery();
0089 
0090     std::pair<EcalLogicID, FEConfigFgrEEStripDat> p;
0091     FEConfigFgrEEStripDat dat;
0092     while (rset->next()) {
0093       p.first = EcalLogicID(rset->getString(1),   // name
0094                             rset->getInt(2),      // logic_id
0095                             rset->getInt(3),      // id1
0096                             rset->getInt(4),      // id2
0097                             rset->getInt(5),      // id3
0098                             rset->getString(6));  // maps_to
0099 
0100       dat.setThreshold(rset->getUInt(7));
0101       dat.setLutFg(rset->getUInt(8));
0102 
0103       p.second = dat;
0104       fillMap->insert(p);
0105     }
0106   } catch (SQLException& e) {
0107     throw(std::runtime_error("FEConfigFgrEEStripDat::fetchData:  " + e.getMessage()));
0108   }
0109 }
0110 
0111 void FEConfigFgrEEStripDat::writeArrayDB(const std::map<EcalLogicID, FEConfigFgrEEStripDat>* data,
0112                                          FEConfigFgrInfo* iconf) noexcept(false) {
0113   this->checkConnection();
0114   this->checkPrepare();
0115 
0116   int iconfID = iconf->fetchID();
0117   if (!iconfID) {
0118     throw(std::runtime_error("FEConfigFgrEEStripDat::writeArrayDB:  ICONF not in DB"));
0119   }
0120 
0121   int nrows = data->size();
0122   int* ids = new int[nrows];
0123   int* iconfid_vec = new int[nrows];
0124   unsigned int* xx = new unsigned int[nrows];
0125   unsigned int* yy = new unsigned int[nrows];
0126 
0127   ub2* ids_len = new ub2[nrows];
0128   ub2* iconf_len = new ub2[nrows];
0129   ub2* x_len = new ub2[nrows];
0130   ub2* y_len = new ub2[nrows];
0131 
0132   const EcalLogicID* channel;
0133   const FEConfigFgrEEStripDat* dataitem;
0134   int count = 0;
0135   typedef map<EcalLogicID, FEConfigFgrEEStripDat>::const_iterator CI;
0136   for (CI p = data->begin(); p != data->end(); ++p) {
0137     channel = &(p->first);
0138     int logicID = channel->getLogicID();
0139     if (!logicID) {
0140       throw(std::runtime_error("FEConfigFgrEEStripDat::writeArrayDB:  Bad EcalLogicID"));
0141     }
0142     ids[count] = logicID;
0143     iconfid_vec[count] = iconfID;
0144 
0145     dataitem = &(p->second);
0146     // dataIface.writeDB( channel, dataitem, iconf);
0147     unsigned int x = dataitem->getThreshold();
0148     unsigned int y = dataitem->getLutFg();
0149 
0150     xx[count] = x;
0151     yy[count] = y;
0152 
0153     ids_len[count] = sizeof(ids[count]);
0154     iconf_len[count] = sizeof(iconfid_vec[count]);
0155 
0156     x_len[count] = sizeof(xx[count]);
0157     y_len[count] = sizeof(yy[count]);
0158 
0159     count++;
0160   }
0161 
0162   try {
0163     m_writeStmt->setDataBuffer(1, (dvoid*)iconfid_vec, OCCIINT, sizeof(iconfid_vec[0]), iconf_len);
0164     m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len);
0165     m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIUNSIGNED_INT, sizeof(xx[0]), x_len);
0166     m_writeStmt->setDataBuffer(4, (dvoid*)yy, OCCIUNSIGNED_INT, sizeof(yy[0]), y_len);
0167 
0168     m_writeStmt->executeArrayUpdate(nrows);
0169 
0170     delete[] ids;
0171     delete[] iconfid_vec;
0172     delete[] xx;
0173     delete[] yy;
0174 
0175     delete[] ids_len;
0176     delete[] iconf_len;
0177     delete[] x_len;
0178     delete[] y_len;
0179 
0180   } catch (SQLException& e) {
0181     throw(std::runtime_error("FEConfigFgrEEStripDat::writeArrayDB():  " + e.getMessage()));
0182   }
0183 }