CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/OnlineDB/EcalCondDB/src/FEConfigFgrEETowerDat.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/FEConfigFgrEETowerDat.h"
00006 #include "OnlineDB/EcalCondDB/interface/FEConfigFgrInfo.h"
00007 
00008 using namespace std;
00009 using namespace oracle::occi;
00010 
00011 FEConfigFgrEETowerDat::FEConfigFgrEETowerDat()
00012 {
00013   m_env = NULL;
00014   m_conn = NULL;
00015   m_writeStmt = NULL;
00016   m_readStmt = NULL;
00017 
00018   m_lut = 0;
00019 
00020 }
00021 
00022 
00023 
00024 FEConfigFgrEETowerDat::~FEConfigFgrEETowerDat()
00025 {
00026 }
00027 
00028 
00029 
00030 void FEConfigFgrEETowerDat::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 "+getTable()+" (fgr_conf_id, logic_id, "
00038                       "lut_value ) "
00039                       "VALUES (:fgr_conf_id, :logic_id, "
00040                       ":lut_value )" );
00041   } catch (SQLException &e) {
00042     throw(std::runtime_error("FEConfigFgrEETowerDat::prepareWrite():  "+e.getMessage()));
00043   }
00044 }
00045 
00046 
00047 
00048 void FEConfigFgrEETowerDat::writeDB(const EcalLogicID* ecid, const FEConfigFgrEETowerDat* item, FEConfigFgrInfo* 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("FEConfigFgrEETowerDat::writeDB:  ICONF not in DB")); }
00056 
00057   int logicID = ecid->getLogicID();
00058   if (!logicID) { throw(std::runtime_error("FEConfigFgrEETowerDat::writeDB:  Bad EcalLogicID")); }
00059  
00060   try {
00061     m_writeStmt->setInt(1, iconfID);
00062     m_writeStmt->setInt(2, logicID);
00063     m_writeStmt->setInt(3, item->getLutValue());
00064 
00065     m_writeStmt->executeUpdate();
00066   } catch (SQLException &e) {
00067     throw(std::runtime_error("FEConfigFgrEETowerDat::writeDB():  "+e.getMessage()));
00068   }
00069 }
00070 
00071 
00072 
00073 void FEConfigFgrEETowerDat::fetchData(map< EcalLogicID, FEConfigFgrEETowerDat >* fillMap, FEConfigFgrInfo* 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("FEConfigFgrEETowerDat::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.lut_value "
00090                  "FROM channelview cv JOIN "+getTable()+" d "
00091                  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
00092                  "WHERE fgr_conf_id = :fgr_conf_id");
00093     m_readStmt->setInt(1, iconfID);
00094     ResultSet* rset = m_readStmt->executeQuery();
00095     
00096     std::pair< EcalLogicID, FEConfigFgrEETowerDat > p;
00097     FEConfigFgrEETowerDat 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.setLutValue( rset->getInt(7) );  
00107 
00108       p.second = dat;
00109       fillMap->insert(p);
00110     }
00111   } catch (SQLException &e) {
00112     throw(std::runtime_error("FEConfigFgrEETowerDat::fetchData:  "+e.getMessage()));
00113   }
00114 }
00115 
00116 void FEConfigFgrEETowerDat::writeArrayDB(const std::map< EcalLogicID, FEConfigFgrEETowerDat >* data, FEConfigFgrInfo* 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("FEConfigFgrEETowerDat::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   int* xx= new int[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 FEConfigFgrEETowerDat* dataitem;
00139   int count=0;
00140   typedef map< EcalLogicID, FEConfigFgrEETowerDat >::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("FEConfigFgrEETowerDat::writeArrayDB:  Bad EcalLogicID")); }
00145         ids[count]=logicID;
00146         iconfid_vec[count]=iconfID;
00147 
00148         dataitem = &(p->second);
00149         // dataIface.writeDB( channel, dataitem, iconf);
00150         int x=dataitem->getLutValue();
00151 
00152         xx[count]=x;
00153 
00154         ids_len[count]=sizeof(ids[count]);
00155         iconf_len[count]=sizeof(iconfid_vec[count]);
00156         
00157         x_len[count]=sizeof(xx[count]);
00158 
00159 
00160         count++;
00161      }
00162 
00163 
00164   try {
00165     m_writeStmt->setDataBuffer(1, (dvoid*)iconfid_vec, OCCIINT, sizeof(iconfid_vec[0]),iconf_len);
00166     m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len );
00167     m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIINT , sizeof(xx[0]), x_len );
00168 
00169     m_writeStmt->executeArrayUpdate(nrows);
00170 
00171     delete [] ids;
00172     delete [] iconfid_vec;
00173     delete [] xx;
00174 
00175     delete [] ids_len;
00176     delete [] iconf_len;
00177     delete [] x_len;
00178 
00179   } catch (SQLException &e) {
00180     throw(std::runtime_error("FEConfigFgrEETowerDat::writeArrayDB():  "+e.getMessage()));
00181   }
00182 }