CMS 3D CMS Logo

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