CMS 3D CMS Logo

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