CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/OnlineDB/EcalCondDB/src/ODPedestalOffsetsDat.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/ODPedestalOffsetsDat.h"
00006 
00007 using namespace std;
00008 using namespace oracle::occi;
00009 
00010 ODPedestalOffsetsDat::ODPedestalOffsetsDat()
00011 {
00012   m_env = NULL;
00013   m_conn = NULL;
00014   m_writeStmt = NULL;
00015   m_readStmt = NULL;
00016 
00017   m_sm = 0;
00018   m_fed = 0;
00019   m_tt = 0;
00020   m_xt = 0;
00021   m_low = 0;
00022   m_mid = 0;
00023   m_high = 0;
00024 }
00025 
00026 
00027 
00028 ODPedestalOffsetsDat::~ODPedestalOffsetsDat()
00029 {
00030 }
00031 
00032 
00033 
00034 void ODPedestalOffsetsDat::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, sm_id, fed_id, tt_id, cry_id, low, mid, high) "
00042                         "VALUES (:1, :2, :3, :4, :5, :6, :7, :8 )");
00043   } catch (SQLException &e) {
00044     throw(std::runtime_error("ODPedestalOffsetsDat::prepareWrite():  "+e.getMessage()));
00045   }
00046 }
00047 
00048 
00049 
00050 void ODPedestalOffsetsDat::writeDB(const ODPedestalOffsetsDat* item, ODFEPedestalOffsetInfo* 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->getSMId());
00058     m_writeStmt->setInt(3, item->getFedId() );
00059     m_writeStmt->setInt(4, item->getTTId() );
00060     m_writeStmt->setInt(5, item->getCrystalId() );
00061     m_writeStmt->setInt(6, item->getLow() );
00062     m_writeStmt->setInt(7, item->getMid() );
00063     m_writeStmt->setInt(8, item->getHigh() );
00064 
00065     m_writeStmt->executeUpdate();
00066   } catch (SQLException &e) {
00067     throw(std::runtime_error("ODPedestalOffsetsDat::writeDB():  "+e.getMessage()));
00068   }
00069 }
00070 
00071 
00072 
00073 void ODPedestalOffsetsDat::fetchData(std::vector< ODPedestalOffsetsDat >* p, ODFEPedestalOffsetInfo* 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 sm_id, fed_id, tt_id, cry_id");
00087     m_readStmt->setInt(1, iovID);
00088     ResultSet* rset = m_readStmt->executeQuery();
00089     
00090     //    std::vector< ODPedestalOffsetsDat > p;
00091     ODPedestalOffsetsDat dat;
00092     while(rset->next()) {
00093       // dat.setId( rset->getInt(1) );
00094       dat.setSMId( rset->getInt(2) );
00095       dat.setFedId( rset->getInt(3) );
00096       dat.setTTId( rset->getInt(4) );
00097       dat.setCrystalId( rset->getInt(5) );
00098       dat.setLow( rset->getInt(6) );
00099       dat.setMid( rset->getInt(7) );
00100       dat.setHigh( rset->getInt(8) );
00101 
00102       p->push_back( dat);
00103 
00104     }
00105 
00106 
00107   } catch (SQLException &e) {
00108     throw(std::runtime_error("ODPedestalOffsetsDat::fetchData():  "+e.getMessage()));
00109   }
00110 }
00111 
00112 //  ************************************************************************   // 
00113 
00114 void ODPedestalOffsetsDat::writeArrayDB(const std::vector< ODPedestalOffsetsDat > data, ODFEPedestalOffsetInfo* iov)
00115     throw(std::runtime_error)
00116 {
00117   this->checkConnection();
00118 
00119   int iovID = iov->fetchID();
00120   if (!iovID) { throw(std::runtime_error("ODDelays::writeArrayDB:  ODFEDelaysInfo not in DB")); }
00121 
00122 
00123   int nrows=data.size(); 
00124   int* ids= new int[nrows];
00125   int* xx= new int[nrows];
00126   int* yy= new int[nrows];
00127   int* zz= new int[nrows];
00128   int* st= new int[nrows];
00129   int* xx1= new int[nrows];
00130   int* yy1= new int[nrows];
00131   int* zz1= new int[nrows];
00132 
00133 
00134   ub2* ids_len= new ub2[nrows];
00135   ub2* x_len= new ub2[nrows];
00136   ub2* y_len= new ub2[nrows];
00137   ub2* z_len= new ub2[nrows];
00138   ub2* st_len= new ub2[nrows];
00139   ub2* x1_len= new ub2[nrows];
00140   ub2* y1_len= new ub2[nrows];
00141   ub2* z1_len= new ub2[nrows];
00142 
00143   ODPedestalOffsetsDat dataitem;
00144   
00145   int n_data= (int) data.size();
00146   for (int count = 0; count <n_data ; count++) {
00147     dataitem=data[count];
00148     ids[count]=iovID;
00149     xx[count]=dataitem.getSMId();
00150     yy[count]=dataitem.getFedId();
00151     zz[count]=dataitem.getTTId();
00152     st[count]=dataitem.getCrystalId();
00153     xx1[count]=dataitem.getLow();
00154     yy1[count]=dataitem.getMid();
00155     zz1[count]=dataitem.getHigh();
00156 
00157 
00158         ids_len[count]=sizeof(ids[count]);
00159         x_len[count]=sizeof(xx[count]);
00160         y_len[count]=sizeof(yy[count]);
00161         z_len[count]=sizeof(zz[count]);
00162         st_len[count]=sizeof(st[count]);
00163         x1_len[count]=sizeof(xx1[count]);
00164         y1_len[count]=sizeof(yy1[count]);
00165         z1_len[count]=sizeof(zz1[count]);
00166 
00167 
00168      }
00169 
00170 
00171   try {
00172     m_writeStmt->setDataBuffer(1, (dvoid*)ids, OCCIINT, sizeof(ids[0]),ids_len);
00173     m_writeStmt->setDataBuffer(2, (dvoid*)xx, OCCIINT , sizeof(xx[0]), x_len );
00174     m_writeStmt->setDataBuffer(3, (dvoid*)yy, OCCIINT , sizeof(yy[0]), y_len );
00175     m_writeStmt->setDataBuffer(4, (dvoid*)zz, OCCIINT , sizeof(zz[0]), z_len );
00176     m_writeStmt->setDataBuffer(5, (dvoid*)st, OCCIINT , sizeof(st[0]), st_len );
00177     m_writeStmt->setDataBuffer(6, (dvoid*)xx1, OCCIINT , sizeof(xx1[0]), x1_len );
00178     m_writeStmt->setDataBuffer(7, (dvoid*)yy1, OCCIINT , sizeof(yy1[0]), y1_len );
00179     m_writeStmt->setDataBuffer(8, (dvoid*)zz1, OCCIINT , sizeof(zz1[0]), z1_len );
00180    
00181 
00182     m_writeStmt->executeArrayUpdate(nrows);
00183 
00184     delete [] ids;
00185     delete [] xx;
00186     delete [] yy;
00187     delete [] zz;
00188     delete [] st;
00189     delete [] xx1;
00190     delete [] yy1;
00191     delete [] zz1;
00192 
00193     delete [] ids_len;
00194     delete [] x_len;
00195     delete [] y_len;
00196     delete [] z_len;
00197     delete [] st_len;
00198     delete [] x1_len;
00199     delete [] y1_len;
00200     delete [] z1_len;
00201 
00202   } catch (SQLException &e) {
00203     throw(std::runtime_error("ODPedestalOffsetsDat::writeArrayDB():  "+e.getMessage()));
00204   }
00205 }