CMS 3D CMS Logo

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