CMS 3D CMS Logo

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