Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include <stdexcept>
0002 #include <string>
0003 #include "OnlineDB/Oracle/interface/Oracle.h"
0004 
0005 #include "OnlineDB/EcalCondDB/interface/FEConfigParamDat.h"
0006 #include "OnlineDB/EcalCondDB/interface/FEConfigLinInfo.h"
0007 
0008 using namespace std;
0009 using namespace oracle::occi;
0010 
0011 FEConfigParamDat::FEConfigParamDat() {
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   m_fglowthresh = 0;
0021   m_fghighthresh = 0;
0022   m_lowratio = 0;
0023   m_highratio = 0;
0024 }
0025 
0026 FEConfigParamDat::~FEConfigParamDat() {}
0027 
0028 void FEConfigParamDat::prepareWrite() noexcept(false) {
0029   this->checkConnection();
0030 
0031   try {
0032     m_writeStmt = m_conn->createStatement();
0033     m_writeStmt->setSQL(
0034         "INSERT INTO fe_config_param_dat (lin_conf_id, logic_id, "
0035         " etsat, ttthreshlow, ttthreshhigh, fg_lowthresh, fg_highthresh, fg_lowratio, fg_highratio ) "
0036         "VALUES (:lin_conf_id, :logic_id, "
0037         ":etsat, :ttthreshlow, :ttthreshhigh, :fg_lowthresh, :fg_highthresh, :fg_lowratio, :fg_highratio )");
0038   } catch (SQLException& e) {
0039     throw(std::runtime_error("FEConfigParamDat::prepareWrite():  " + e.getMessage()));
0040   }
0041 }
0042 
0043 void FEConfigParamDat::writeDB(const EcalLogicID* ecid,
0044                                const FEConfigParamDat* item,
0045                                FEConfigLinInfo* iconf) noexcept(false) {
0046   this->checkConnection();
0047   this->checkPrepare();
0048 
0049   int iconfID = iconf->fetchID();
0050   if (!iconfID) {
0051     throw(std::runtime_error("FEConfigParamDat::writeDB:  ICONF not in DB"));
0052   }
0053 
0054   int logicID = ecid->getLogicID();
0055   if (!logicID) {
0056     throw(std::runtime_error("FEConfigParamDat::writeDB:  Bad EcalLogicID"));
0057   }
0058 
0059   try {
0060     m_writeStmt->setInt(1, iconfID);
0061     m_writeStmt->setInt(2, logicID);
0062     m_writeStmt->setFloat(3, item->getETSat());
0063     m_writeStmt->setFloat(4, item->getTTThreshlow());
0064     m_writeStmt->setFloat(5, item->getTTThreshhigh());
0065     m_writeStmt->setFloat(6, item->getFGlowthresh());
0066     m_writeStmt->setFloat(7, item->getFGhighthresh());
0067     m_writeStmt->setFloat(8, item->getFGlowratio());
0068     m_writeStmt->setFloat(9, item->getFGhighratio());
0069 
0070     m_writeStmt->executeUpdate();
0071   } catch (SQLException& e) {
0072     throw(std::runtime_error("FEConfigParamDat::writeDB():  " + e.getMessage()));
0073   }
0074 }
0075 
0076 void FEConfigParamDat::fetchData(map<EcalLogicID, FEConfigParamDat>* fillMap, FEConfigLinInfo* iconf) noexcept(false) {
0077   this->checkConnection();
0078   fillMap->clear();
0079 
0080   iconf->setConnection(m_env, m_conn);
0081   int iconfID = iconf->fetchID();
0082   if (!iconfID) {
0083     //  throw(std::runtime_error("FEConfigParamDat::writeDB:  ICONF 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.etsat, d.ttthreshlow, d.ttthreshhigh, d.fg_lowthresh, d.fg_highthresh, d.fg_lowratio, d.fg_highratio "
0091         "FROM channelview cv JOIN fe_config_param_dat d "
0092         "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
0093         "WHERE lin_conf_id = :lin_conf_id");
0094     m_readStmt->setInt(1, iconfID);
0095     ResultSet* rset = m_readStmt->executeQuery();
0096 
0097     std::pair<EcalLogicID, FEConfigParamDat> p;
0098     FEConfigParamDat dat;
0099     while (rset->next()) {
0100       p.first = EcalLogicID(rset->getString(1),   // name
0101                             rset->getInt(2),      // logic_id
0102                             rset->getInt(3),      // id1
0103                             rset->getInt(4),      // id2
0104                             rset->getInt(5),      // id3
0105                             rset->getString(6));  // maps_to
0106 
0107       dat.setETSat(rset->getFloat(7));
0108       dat.setTTThreshlow(rset->getFloat(8));
0109       dat.setTTThreshhigh(rset->getFloat(9));
0110       dat.setFGlowthresh(rset->getFloat(10));
0111       dat.setFGhighthresh(rset->getFloat(11));
0112       dat.setFGlowratio(rset->getFloat(12));
0113       dat.setFGhighratio(rset->getFloat(13));
0114 
0115       p.second = dat;
0116       fillMap->insert(p);
0117     }
0118   } catch (SQLException& e) {
0119     throw(std::runtime_error("FEConfigParamDat::fetchData:  " + e.getMessage()));
0120   }
0121 }
0122 
0123 void FEConfigParamDat::writeArrayDB(const std::map<EcalLogicID, FEConfigParamDat>* data,
0124                                     FEConfigLinInfo* iconf) noexcept(false) {
0125   this->checkConnection();
0126   this->checkPrepare();
0127 
0128   int iconfID = iconf->fetchID();
0129   if (!iconfID) {
0130     throw(std::runtime_error("FEConfigParamDat::writeArrayDB:  ICONF not in DB"));
0131   }
0132 
0133   int nrows = data->size();
0134   int* ids = new int[nrows];
0135   int* iov_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   float* st = new float[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 FEConfigParamDat* dataitem;
0156   int count = 0;
0157   typedef map<EcalLogicID, FEConfigParamDat>::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("FEConfigParamDat::writeArrayDB:  Bad EcalLogicID"));
0163     }
0164     ids[count] = logicID;
0165     iov_vec[count] = iconfID;
0166 
0167     dataitem = &(p->second);
0168     // dataIface.writeDB( channel, dataitem, conf);
0169     float x = dataitem->getETSat();
0170     float y = dataitem->getTTThreshlow();
0171     float z = dataitem->getTTThreshhigh();
0172     float w = dataitem->getFGlowthresh();
0173     float u = dataitem->getFGhighthresh();
0174     float t = dataitem->getFGlowratio();
0175     float r = dataitem->getFGhighratio();
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] = r;
0184 
0185     ids_len[count] = sizeof(ids[count]);
0186     iov_len[count] = sizeof(iov_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*)iov_vec, OCCIINT, sizeof(iov_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, OCCIFLOAT, sizeof(st[0]), st_len);
0209 
0210     m_writeStmt->executeArrayUpdate(nrows);
0211 
0212     delete[] ids;
0213     delete[] iov_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("FEConfigParamDat::writeArrayDB():  " + e.getMessage()));
0234   }
0235 }