Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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