CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/OnlineDB/EcalCondDB/src/ODGolBiasCurrentDat.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/ODGolBiasCurrentDat.h"
00006 
00007 using namespace std;
00008 using namespace oracle::occi;
00009 
00010 ODGolBiasCurrentDat::ODGolBiasCurrentDat()
00011 {
00012   m_env = NULL;
00013   m_conn = NULL;
00014   m_writeStmt = NULL;
00015   m_readStmt = NULL;
00016 
00017 
00018   m_gol = 0;
00019   m_fed = 0;
00020   m_tt = 0;
00021   m_cur = 0;
00022   m_pll_cur=0;
00023   m_sta=0;
00024 }
00025 
00026 
00027 
00028 ODGolBiasCurrentDat::~ODGolBiasCurrentDat()
00029 {
00030 }
00031 
00032 
00033 
00034 void ODGolBiasCurrentDat::prepareWrite()
00035   throw(std::runtime_error)
00036 {
00037   this->checkConnection();
00038 
00039   try {
00040     m_writeStmt = m_conn->createStatement();
00041     m_writeStmt->setSQL("INSERT INTO "+getTable()+" (rec_id, fed_id, tt_id, gol_id, gol_current, pll_current, status ) "
00042                         "VALUES (:1, :2, :3, :4, :5 , :6, :7)");
00043   } catch (SQLException &e) {
00044     throw(std::runtime_error("ODGolBiasCurrentDat::prepareWrite():  "+e.getMessage()));
00045   }
00046 }
00047 
00048 
00049 
00050 void ODGolBiasCurrentDat::writeDB(const ODGolBiasCurrentDat* item, ODGolBiasCurrentInfo* iov )
00051   throw(std::runtime_error)
00052 {
00053   this->checkConnection();
00054 
00055   try {
00056     m_writeStmt->setInt(1, item->getId());
00057     m_writeStmt->setInt(2, item->getFedId() );
00058     m_writeStmt->setInt(3, item->getTTId() );
00059     m_writeStmt->setInt(4, item->getGolId() );
00060     m_writeStmt->setInt(5, item->getCurrent() );
00061     m_writeStmt->setInt(6, item->getPLLCurrent() );
00062     m_writeStmt->setInt(7, item->getStatus() );
00063 
00064 
00065     m_writeStmt->executeUpdate();
00066   } catch (SQLException &e) {
00067     throw(std::runtime_error("ODGolBiasCurrentDat::writeDB():  "+e.getMessage()));
00068   }
00069 }
00070 
00071 
00072 
00073 void ODGolBiasCurrentDat::fetchData(std::vector< ODGolBiasCurrentDat >* p, ODGolBiasCurrentInfo* iov)
00074   throw(std::runtime_error)
00075 {
00076   this->checkConnection();
00077 
00078   iov->setConnection(m_env, m_conn);
00079   int iovID = iov->fetchID();
00080   if (!iovID) { 
00081     std::cout <<"ID not in the DB"<< endl; 
00082     return;
00083   }
00084 
00085   try {
00086     m_readStmt->setSQL("SELECT * FROM " + getTable() + " WHERE rec_id = :rec_id order by fed_id, tt_id, gol_id ");
00087     m_readStmt->setInt(1, iovID);
00088     ResultSet* rset = m_readStmt->executeQuery();
00089     
00090     //    std::vector< ODGolBiasCurrentDat > p;
00091     ODGolBiasCurrentDat dat;
00092     while(rset->next()) {
00093       // dat.setId( rset->getInt(1) );
00094       dat.setFedId( rset->getInt(2) );
00095       dat.setTTId( rset->getInt(3) );
00096       dat.setGolId( rset->getInt(4) );
00097       dat.setCurrent( rset->getInt(5) );
00098       dat.setPLLCurrent( rset->getInt(6) );
00099       dat.setStatus( rset->getInt(7) );
00100 
00101       p->push_back( dat);
00102 
00103     }
00104 
00105 
00106   } catch (SQLException &e) {
00107     throw(std::runtime_error("ODGolBiasCurrentDat::fetchData():  "+e.getMessage()));
00108   }
00109 }
00110 
00111 //  ************************************************************************   // 
00112 
00113 void ODGolBiasCurrentDat::writeArrayDB(const std::vector< ODGolBiasCurrentDat > data, ODGolBiasCurrentInfo* iov)
00114     throw(std::runtime_error)
00115 {
00116   this->checkConnection();
00117 
00118   int iovID = iov->fetchID();
00119   if (!iovID) { throw(std::runtime_error("ODDelays::writeArrayDB:  ODFEDelaysInfo not in DB")); }
00120 
00121 
00122   int nrows=data.size(); 
00123   int* ids= new int[nrows];
00124   int* xx= new int[nrows];
00125   int* yy= new int[nrows];
00126   int* zz= new int[nrows];
00127   int* ww= new int[nrows];
00128   int* kk= new int[nrows];
00129   int* st= new int[nrows];
00130 
00131 
00132 
00133   ub2* ids_len= new ub2[nrows];
00134   ub2* x_len= new ub2[nrows];
00135   ub2* y_len= new ub2[nrows];
00136   ub2* z_len= new ub2[nrows];
00137   ub2* w_len= new ub2[nrows];
00138   ub2* k_len= new ub2[nrows];
00139   ub2* st_len= new ub2[nrows];
00140 
00141   ODGolBiasCurrentDat dataitem;
00142   
00143 
00144   for (int count = 0; count != (int)data.size(); count++) {
00145     dataitem=data[count];
00146     ids[count]=iovID;
00147     xx[count]=dataitem.getFedId();
00148     yy[count]=dataitem.getTTId();
00149     zz[count]=dataitem.getGolId();
00150     ww[count]=dataitem.getCurrent();
00151     kk[count]=dataitem.getPLLCurrent();
00152     st[count]=dataitem.getStatus();
00153 
00154 
00155         ids_len[count]=sizeof(ids[count]);
00156         x_len[count]=sizeof(xx[count]);
00157         y_len[count]=sizeof(yy[count]);
00158         z_len[count]=sizeof(zz[count]);
00159         w_len[count]=sizeof(ww[count]);
00160         k_len[count]=sizeof(kk[count]);
00161         st_len[count]=sizeof(st[count]);
00162 
00163 
00164      }
00165 
00166 
00167   try {
00168     m_writeStmt->setDataBuffer(1, (dvoid*)ids, OCCIINT, sizeof(ids[0]),ids_len);
00169     m_writeStmt->setDataBuffer(2, (dvoid*)xx, OCCIINT , sizeof(xx[0]), x_len );
00170     m_writeStmt->setDataBuffer(3, (dvoid*)yy, OCCIINT , sizeof(yy[0]), y_len );
00171     m_writeStmt->setDataBuffer(4, (dvoid*)zz, OCCIINT , sizeof(zz[0]), z_len );
00172     m_writeStmt->setDataBuffer(5, (dvoid*)ww, OCCIINT , sizeof(ww[0]), w_len );
00173     m_writeStmt->setDataBuffer(6, (dvoid*)kk, OCCIINT , sizeof(kk[0]), k_len );
00174     m_writeStmt->setDataBuffer(7, (dvoid*)st, OCCIINT , sizeof(st[0]), st_len );
00175    
00176 
00177     m_writeStmt->executeArrayUpdate(nrows);
00178 
00179     delete [] ids;
00180     delete [] xx;
00181     delete [] yy;
00182     delete [] zz;
00183     delete [] ww;
00184     delete [] kk;
00185     delete [] st;
00186 
00187     delete [] ids_len;
00188     delete [] x_len;
00189     delete [] y_len;
00190     delete [] z_len;
00191     delete [] w_len;
00192     delete [] k_len;
00193     delete [] st_len;
00194 
00195 
00196   } catch (SQLException &e) {
00197     throw(std::runtime_error("ODGolBiasCurrentDat::writeArrayDB():  "+e.getMessage()));
00198   }
00199 }