CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/OnlineDB/EcalCondDB/src/FEConfigParamDat.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/FEConfigParamDat.h"
00006 #include "OnlineDB/EcalCondDB/interface/FEConfigLinInfo.h"
00007 
00008 using namespace std;
00009 using namespace oracle::occi;
00010 
00011 FEConfigParamDat::FEConfigParamDat()
00012 {
00013   m_env = NULL;
00014   m_conn = NULL;
00015   m_writeStmt = NULL;
00016   m_readStmt = NULL;
00017 
00018   m_etsat = 0;
00019   m_tthreshlow = 0;
00020   m_tthreshhigh = 0;
00021   m_fglowthresh = 0;
00022   m_fghighthresh = 0;
00023   m_lowratio = 0;
00024   m_highratio = 0;
00025 
00026 }
00027 
00028 
00029 
00030 FEConfigParamDat::~FEConfigParamDat()
00031 {
00032 }
00033 
00034 
00035 
00036 void FEConfigParamDat::prepareWrite()
00037   throw(std::runtime_error)
00038 {
00039   this->checkConnection();
00040 
00041   try {
00042     m_writeStmt = m_conn->createStatement();
00043     m_writeStmt->setSQL("INSERT INTO fe_config_param_dat (lin_conf_id, logic_id, "
00044                       " etsat, ttthreshlow, ttthreshhigh, fg_lowthresh, fg_highthresh, fg_lowratio, fg_highratio ) "
00045                       "VALUES (:lin_conf_id, :logic_id, "
00046                       ":etsat, :ttthreshlow, :ttthreshhigh, :fg_lowthresh, :fg_highthresh, :fg_lowratio, :fg_highratio )" );
00047   } catch (SQLException &e) {
00048     throw(std::runtime_error("FEConfigParamDat::prepareWrite():  "+e.getMessage()));
00049   }
00050 }
00051 
00052 
00053 
00054 void FEConfigParamDat::writeDB(const EcalLogicID* ecid, const FEConfigParamDat* item, FEConfigLinInfo* iconf)
00055   throw(std::runtime_error)
00056 {
00057   this->checkConnection();
00058   this->checkPrepare();
00059 
00060   int iconfID = iconf->fetchID();
00061   if (!iconfID) { throw(std::runtime_error("FEConfigParamDat::writeDB:  ICONF not in DB")); }
00062 
00063   int logicID = ecid->getLogicID();
00064   if (!logicID) { throw(std::runtime_error("FEConfigParamDat::writeDB:  Bad EcalLogicID")); }
00065  
00066   try {
00067     m_writeStmt->setInt(1, iconfID);
00068     m_writeStmt->setInt(2, logicID);
00069     m_writeStmt->setFloat(3, item->getETSat());
00070     m_writeStmt->setFloat(4, item->getTTThreshlow());
00071     m_writeStmt->setFloat(5, item->getTTThreshhigh());
00072     m_writeStmt->setFloat(6, item->getFGlowthresh());
00073     m_writeStmt->setFloat(7, item->getFGhighthresh());
00074     m_writeStmt->setFloat(8, item->getFGlowratio());
00075     m_writeStmt->setFloat(9, item->getFGhighratio());
00076 
00077     m_writeStmt->executeUpdate();
00078   } catch (SQLException &e) {
00079     throw(std::runtime_error("FEConfigParamDat::writeDB():  "+e.getMessage()));
00080   }
00081 }
00082 
00083 
00084 
00085 void FEConfigParamDat::fetchData(map< EcalLogicID, FEConfigParamDat >* fillMap, FEConfigLinInfo* iconf)
00086   throw(std::runtime_error)
00087 {
00088   this->checkConnection();
00089   fillMap->clear();
00090 
00091   iconf->setConnection(m_env, m_conn);
00092   int iconfID = iconf->fetchID();
00093   if (!iconfID) { 
00094     //  throw(std::runtime_error("FEConfigParamDat::writeDB:  ICONF not in DB")); 
00095     return;
00096   }
00097   
00098   try {
00099 
00100     m_readStmt->setSQL("SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
00101                  " d.etsat, d.ttthreshlow, d.ttthreshhigh, d.fg_lowthresh, d.fg_highthresh, d.fg_lowratio, d.fg_highratio "
00102                  "FROM channelview cv JOIN fe_config_param_dat d "
00103                  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
00104                  "WHERE lin_conf_id = :lin_conf_id");
00105     m_readStmt->setInt(1, iconfID);
00106     ResultSet* rset = m_readStmt->executeQuery();
00107     
00108     std::pair< EcalLogicID, FEConfigParamDat > p;
00109     FEConfigParamDat dat;
00110     while(rset->next()) {
00111       p.first = EcalLogicID( rset->getString(1),     // name
00112                              rset->getInt(2),        // logic_id
00113                              rset->getInt(3),        // id1
00114                              rset->getInt(4),        // id2
00115                              rset->getInt(5),        // id3
00116                              rset->getString(6));    // maps_to
00117 
00118 
00119 
00120       dat.setETSat( rset->getFloat(7) );  
00121       dat.setTTThreshlow(  rset->getFloat(8) );
00122       dat.setTTThreshhigh(  rset->getFloat(9) );
00123       dat.setFGlowthresh( rset->getFloat(10) );  
00124       dat.setFGhighthresh(  rset->getFloat(11) );
00125       dat.setFGlowratio(  rset->getFloat(12) );
00126       dat.setFGhighratio(  rset->getFloat(13) );
00127     
00128       p.second = dat;
00129       fillMap->insert(p);
00130     }
00131   } catch (SQLException &e) {
00132     throw(std::runtime_error("FEConfigParamDat::fetchData:  "+e.getMessage()));
00133   }
00134 }
00135 
00136 void FEConfigParamDat::writeArrayDB(const std::map< EcalLogicID, FEConfigParamDat >* data, FEConfigLinInfo* iconf)
00137   throw(std::runtime_error)
00138 {
00139   this->checkConnection();
00140   this->checkPrepare();
00141 
00142   int iconfID = iconf->fetchID();
00143   if (!iconfID) { throw(std::runtime_error("FEConfigParamDat::writeArrayDB:  ICONF not in DB")); }
00144 
00145 
00146   int nrows=data->size(); 
00147   int* ids= new int[nrows];
00148   int* iov_vec= new int[nrows];
00149   float* xx= new float[nrows];
00150   float* yy= new float[nrows];
00151   float* zz= new float[nrows];
00152   float* ww= new float[nrows];
00153   float* uu= new float[nrows];
00154   float* tt= new float[nrows];
00155   float* st= new float[nrows];
00156 
00157   ub2* ids_len= new ub2[nrows];
00158   ub2* iov_len= new ub2[nrows];
00159   ub2* x_len= new ub2[nrows];
00160   ub2* y_len= new ub2[nrows];
00161   ub2* z_len= new ub2[nrows];
00162   ub2* w_len= new ub2[nrows];
00163   ub2* u_len= new ub2[nrows];
00164   ub2* t_len= new ub2[nrows];
00165   ub2* st_len= new ub2[nrows];
00166 
00167   const EcalLogicID* channel;
00168   const FEConfigParamDat* dataitem;
00169   int count=0;
00170   typedef map< EcalLogicID, FEConfigParamDat >::const_iterator CI;
00171   for (CI p = data->begin(); p != data->end(); ++p) {
00172         channel = &(p->first);
00173         int logicID = channel->getLogicID();
00174         if (!logicID) { throw(std::runtime_error("FEConfigParamDat::writeArrayDB:  Bad EcalLogicID")); }
00175         ids[count]=logicID;
00176         iov_vec[count]=iconfID;
00177 
00178         dataitem = &(p->second);
00179         // dataIface.writeDB( channel, dataitem, conf);
00180         float x=dataitem->getETSat();
00181         float y=dataitem->getTTThreshlow();
00182         float z=dataitem->getTTThreshhigh();
00183         float w=dataitem->getFGlowthresh();
00184         float u=dataitem->getFGhighthresh();
00185         float t=dataitem->getFGlowratio();
00186         float r=dataitem->getFGhighratio();
00187 
00188         xx[count]=x;
00189         yy[count]=y;
00190         zz[count]=z;
00191         ww[count]=w;
00192         uu[count]=u;
00193         tt[count]=t;
00194         st[count]=r;
00195 
00196 
00197         ids_len[count]=sizeof(ids[count]);
00198         iov_len[count]=sizeof(iov_vec[count]);
00199         
00200         x_len[count]=sizeof(xx[count]);
00201         y_len[count]=sizeof(yy[count]);
00202         z_len[count]=sizeof(zz[count]);
00203         w_len[count]=sizeof(ww[count]);
00204         u_len[count]=sizeof(uu[count]);
00205         t_len[count]=sizeof(tt[count]);
00206         st_len[count]=sizeof(st[count]);
00207 
00208         count++;
00209      }
00210 
00211 
00212   try {
00213     m_writeStmt->setDataBuffer(1, (dvoid*)iov_vec, OCCIINT, sizeof(iov_vec[0]),iov_len);
00214     m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len );
00215     m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIFLOAT , sizeof(xx[0]), x_len );
00216     m_writeStmt->setDataBuffer(4, (dvoid*)yy, OCCIFLOAT , sizeof(yy[0]), y_len );
00217     m_writeStmt->setDataBuffer(5, (dvoid*)zz, OCCIFLOAT , sizeof(zz[0]), z_len );
00218     m_writeStmt->setDataBuffer(6, (dvoid*)ww, OCCIFLOAT , sizeof(ww[0]), w_len );
00219     m_writeStmt->setDataBuffer(7, (dvoid*)uu, OCCIFLOAT , sizeof(uu[0]), u_len );
00220     m_writeStmt->setDataBuffer(8, (dvoid*)tt, OCCIFLOAT , sizeof(tt[0]), t_len );
00221     m_writeStmt->setDataBuffer(9, (dvoid*)st, OCCIFLOAT , sizeof(st[0]), st_len );
00222    
00223 
00224     m_writeStmt->executeArrayUpdate(nrows);
00225 
00226     delete [] ids;
00227     delete [] iov_vec;
00228     delete [] xx;
00229     delete [] yy;
00230     delete [] zz;
00231     delete [] ww;
00232     delete [] uu;
00233     delete [] tt;
00234     delete [] st;
00235 
00236     delete [] ids_len;
00237     delete [] iov_len;
00238     delete [] x_len;
00239     delete [] y_len;
00240     delete [] z_len;
00241     delete [] w_len;
00242     delete [] u_len;
00243     delete [] t_len;
00244     delete [] st_len;
00245 
00246   } catch (SQLException &e) {
00247     throw(std::runtime_error("FEConfigParamDat::writeArrayDB():  "+e.getMessage()));
00248   }
00249 }