Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:23:03

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