CMS 3D CMS Logo

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