CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/OnlineDB/EcalCondDB/src/FEConfigSlidingDat.cc

Go to the documentation of this file.
00001 #include <stdexcept>
00002 #include <string>
00003 #include "OnlineDB/Oracle/interface/Oracle.h"
00004 
00005 #include "OnlineDB/EcalCondDB/interface/FEConfigSlidingDat.h"
00006 #include "OnlineDB/EcalCondDB/interface/FEConfigSlidingInfo.h"
00007 
00008 using namespace std;
00009 using namespace oracle::occi;
00010 
00011 FEConfigSlidingDat::FEConfigSlidingDat()
00012 {
00013   m_env = NULL;
00014   m_conn = NULL;
00015   m_writeStmt = NULL;
00016   m_readStmt = NULL;
00017 
00018   m_sliding = 0;
00019 
00020 }
00021 
00022 
00023 
00024 FEConfigSlidingDat::~FEConfigSlidingDat()
00025 {
00026 }
00027 
00028 
00029 
00030 void FEConfigSlidingDat::prepareWrite()
00031   throw(std::runtime_error)
00032 {
00033   this->checkConnection();
00034 
00035   try {
00036     m_writeStmt = m_conn->createStatement();
00037     m_writeStmt->setSQL("INSERT INTO fe_config_sliding_dat (sli_conf_id, logic_id, "
00038                       "sliding ) "
00039                       "VALUES (:sli_conf_id, :logic_id, "
00040                       ":sliding )" );
00041   } catch (SQLException &e) {
00042     throw(std::runtime_error("FEConfigSlidingDat::prepareWrite():  "+e.getMessage()));
00043   }
00044 }
00045 
00046 
00047 
00048 void FEConfigSlidingDat::writeDB(const EcalLogicID* ecid, const FEConfigSlidingDat* item, FEConfigSlidingInfo* iconf)
00049   throw(std::runtime_error)
00050 {
00051   this->checkConnection();
00052   this->checkPrepare();
00053 
00054   int iconfID = iconf->fetchID();
00055   if (!iconfID) { throw(std::runtime_error("FEConfigSlidingDat::writeDB:  ICONF not in DB")); }
00056 
00057   int logicID = ecid->getLogicID();
00058   if (!logicID) { throw(std::runtime_error("FEConfigSlidingDat::writeDB:  Bad EcalLogicID")); }
00059  
00060   try {
00061     m_writeStmt->setInt(1, iconfID);
00062     m_writeStmt->setInt(2, logicID);
00063     m_writeStmt->setFloat(3, item->getSliding());
00064 
00065     m_writeStmt->executeUpdate();
00066   } catch (SQLException &e) {
00067     throw(std::runtime_error("FEConfigSlidingDat::writeDB():  "+e.getMessage()));
00068   }
00069 }
00070 
00071 
00072 
00073 void FEConfigSlidingDat::fetchData(map< EcalLogicID, FEConfigSlidingDat >* fillMap, FEConfigSlidingInfo* iconf)
00074   throw(std::runtime_error)
00075 {
00076   this->checkConnection();
00077   fillMap->clear();
00078 
00079   iconf->setConnection(m_env, m_conn);
00080   int iconfID = iconf->fetchID();
00081   if (!iconfID) { 
00082     //  throw(std::runtime_error("FEConfigSlidingDat::writeDB:  ICONF not in DB")); 
00083     return;
00084   }
00085   
00086   try {
00087 
00088     m_readStmt->setSQL("SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
00089                  "d.sliding "
00090                  "FROM channelview cv JOIN fe_config_sliding_dat d "
00091                  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
00092                  "WHERE sli_conf_id = :sli_conf_id");
00093     m_readStmt->setInt(1, iconfID);
00094     ResultSet* rset = m_readStmt->executeQuery();
00095     
00096     std::pair< EcalLogicID, FEConfigSlidingDat > p;
00097     FEConfigSlidingDat dat;
00098     while(rset->next()) {
00099       p.first = EcalLogicID( rset->getString(1),     // name
00100                              rset->getInt(2),        // logic_id
00101                              rset->getInt(3),        // id1
00102                              rset->getInt(4),        // id2
00103                              rset->getInt(5),        // id3
00104                              rset->getString(6));    // maps_to
00105 
00106       dat.setSliding( rset->getFloat(7) );  
00107 
00108       p.second = dat;
00109       fillMap->insert(p);
00110     }
00111   } catch (SQLException &e) {
00112     throw(std::runtime_error("FEConfigSlidingDat::fetchData:  "+e.getMessage()));
00113   }
00114 }
00115 
00116 void FEConfigSlidingDat::writeArrayDB(const std::map< EcalLogicID, FEConfigSlidingDat >* data, FEConfigSlidingInfo* iconf)
00117   throw(std::runtime_error)
00118 {
00119   this->checkConnection();
00120   this->checkPrepare();
00121 
00122   int iconfID = iconf->fetchID();
00123   if (!iconfID) { throw(std::runtime_error("FEConfigSlidingDat::writeArrayDB:  ICONF not in DB")); }
00124 
00125 
00126   int nrows=data->size(); 
00127   int* ids= new int[nrows];
00128   int* iconfid_vec= new int[nrows];
00129   float* xx= new float[nrows];
00130 
00131 
00132   ub2* ids_len= new ub2[nrows];
00133   ub2* iconf_len= new ub2[nrows];
00134   ub2* x_len= new ub2[nrows];
00135 
00136 
00137   const EcalLogicID* channel;
00138   const FEConfigSlidingDat* dataitem;
00139   int count=0;
00140   typedef map< EcalLogicID, FEConfigSlidingDat >::const_iterator CI;
00141   for (CI p = data->begin(); p != data->end(); ++p) {
00142         channel = &(p->first);
00143         int logicID = channel->getLogicID();
00144         if (!logicID) { throw(std::runtime_error("FEConfigSlidingDat::writeArrayDB:  Bad EcalLogicID")); }
00145         ids[count]=logicID;
00146         iconfid_vec[count]=iconfID;
00147 
00148         dataitem = &(p->second);
00149         // dataIface.writeDB( channel, dataitem, iconf);
00150         float x=dataitem->getSliding();
00151 
00152         xx[count]=x;
00153 
00154 
00155         ids_len[count]=sizeof(ids[count]);
00156         iconf_len[count]=sizeof(iconfid_vec[count]);
00157         
00158         x_len[count]=sizeof(xx[count]);
00159 
00160 
00161         count++;
00162      }
00163 
00164 
00165   try {
00166     m_writeStmt->setDataBuffer(1, (dvoid*)iconfid_vec, OCCIINT, sizeof(iconfid_vec[0]),iconf_len);
00167     m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len );
00168     m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIFLOAT , sizeof(xx[0]), x_len );
00169 
00170     m_writeStmt->executeArrayUpdate(nrows);
00171 
00172     delete [] ids;
00173     delete [] iconfid_vec;
00174     delete [] xx;
00175 
00176     delete [] ids_len;
00177     delete [] iconf_len;
00178     delete [] x_len;
00179 
00180   } catch (SQLException &e) {
00181     throw(std::runtime_error("FEConfigSlidingDat::writeArrayDB():  "+e.getMessage()));
00182   }
00183 }