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