CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/OnlineDB/EcalCondDB/src/MODDCCDetailsDat.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/MODDCCDetailsDat.h"
00006 #include "OnlineDB/EcalCondDB/interface/MODRunIOV.h"
00007 
00008 using namespace std;
00009 using namespace oracle::occi;
00010 
00011 MODDCCDetailsDat::MODDCCDetailsDat()
00012 {
00013   m_env = NULL;
00014   m_conn = NULL;
00015   m_writeStmt = NULL;
00016   m_readStmt = NULL;
00017 
00018    m_qpll=0;
00019    m_opto=0;
00020    m_tout=0;
00021    m_head=0;
00022    m_evnu=0;
00023    m_bxnu=0;
00024    m_evpa=0;
00025    m_odpa=0;
00026    m_blsi=0;
00027    m_alff=0;
00028    m_fuff=0;
00029    m_fusu=0;
00030 
00031 }
00032 
00033 
00034 
00035 MODDCCDetailsDat::~MODDCCDetailsDat()
00036 {
00037 }
00038 
00039 
00040 
00041 void MODDCCDetailsDat::prepareWrite()
00042   throw(std::runtime_error)
00043 {
00044   this->checkConnection();
00045 
00046   try {
00047     m_writeStmt = m_conn->createStatement();
00048     m_writeStmt->setSQL(" INSERT INTO "+getTable()+" (iov_id, logic_id, "
00049                         " qpll_error, optical_link, data_timeout, dcc_header, event_number, bx_number, "
00050                         " even_parity, odd_parity, block_size, almost_full_fifo, full_fifo, "
00051                         " forced_full_supp ) "
00052                         " VALUES (:iov_id, :logic_id, "
00053                         " :1, :2, :3, :4, :5, :6, :7, :8, :9, :10, :11, :12 ) ");
00054   } catch (SQLException &e) {
00055     throw(std::runtime_error("MODDCCDetailsDat::prepareWrite():  "+e.getMessage()));
00056   }
00057 }
00058 
00059 
00060 
00061 void MODDCCDetailsDat::writeDB(const EcalLogicID* ecid, const MODDCCDetailsDat* item, MODRunIOV* iov )
00062   throw(std::runtime_error)
00063 {
00064   this->checkConnection();
00065   this->checkPrepare();
00066 
00067   int iovID = iov->fetchID();
00068   if (!iovID) { throw(std::runtime_error("MODDCCDetailsDat::writeDB:  IOV not in DB")); }
00069 
00070   int logicID = ecid->getLogicID();
00071   if (!logicID) { throw(std::runtime_error("MODDCCDetailsDat::writeDB:  Bad EcalLogicID")); }
00072   
00073   try {
00074     m_writeStmt->setInt(1, iovID);
00075     m_writeStmt->setInt(2, logicID);
00076     m_writeStmt->setInt(3, item->getQPLL() );
00077     m_writeStmt->setInt(4, item->getOpticalLink() );
00078     m_writeStmt->setInt(5, item->getDataTimeout() );
00079     m_writeStmt->setInt(6, item->getHeader() );
00080     m_writeStmt->setInt(7, item->getEventNumber() );
00081     m_writeStmt->setInt(8, item->getBXNumber() );
00082     m_writeStmt->setInt(9, item->getEvenParity() );
00083     m_writeStmt->setInt(10, item->getOddParity() );
00084     m_writeStmt->setInt(11, item->getBlockSize() );
00085     m_writeStmt->setInt(12, item->getAlmostFullFIFO() );
00086     m_writeStmt->setInt(13, item->getFullFIFO() );
00087     m_writeStmt->setInt(14, item->getForcedFullSupp() );
00088 
00089     m_writeStmt->executeUpdate();
00090   } catch (SQLException &e) {
00091     throw(std::runtime_error("MODDCCDetailsDat::writeDB():  "+e.getMessage()));
00092   }
00093 }
00094 
00095 
00096 
00097 void MODDCCDetailsDat::fetchData(std::map< EcalLogicID, MODDCCDetailsDat >* fillMap, MODRunIOV* iov)
00098   throw(std::runtime_error)
00099 {
00100   this->checkConnection();
00101   fillMap->clear();
00102 
00103   iov->setConnection(m_env, m_conn);
00104   int iovID = iov->fetchID();
00105   if (!iovID) { 
00106     //  throw(std::runtime_error("MODDCCDetailsDat::writeDB:  IOV not in DB")); 
00107     return;
00108   }
00109 
00110   try {
00111 
00112     m_readStmt->setSQL("SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
00113                  " d.qpll_error, d.optical_link, d.data_timeout, d.dcc_header, d.event_number, d.bx_number, d.even_parity, d.odd_parity, d.block_size, d.almost_full_fifo, d.full_fifo, d.forced_full_supp " 
00114                  "FROM channelview cv JOIN "+getTable()+" d "
00115                  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
00116                  "WHERE d.iov_id = :iov_id");
00117     m_readStmt->setInt(1, iovID);
00118     ResultSet* rset = m_readStmt->executeQuery();
00119     
00120     std::pair< EcalLogicID, MODDCCDetailsDat > p;
00121     MODDCCDetailsDat dat;
00122     while(rset->next()) {
00123       p.first = EcalLogicID( rset->getString(1),     // name
00124                              rset->getInt(2),        // logic_id
00125                              rset->getInt(3),        // id1
00126                              rset->getInt(4),        // id2
00127                              rset->getInt(5),        // id3
00128                              rset->getString(6));    // maps_to
00129 
00130       dat.setQPLL( rset->getInt(7) );
00131       dat.setOpticalLink( rset->getInt(8) );
00132       dat.setDataTimeout( rset->getInt(9) );
00133       dat.setHeader( rset->getInt(10) );
00134       dat.setEventNumber( rset->getInt(11) );
00135       dat.setBXNumber( rset->getInt(12) );
00136       dat.setEvenParity( rset->getInt(13) );
00137       dat.setOddParity( rset->getInt(14) );
00138       dat.setBlockSize( rset->getInt(15) );
00139       dat.setAlmostFullFIFO( rset->getInt(16) );
00140       dat.setFullFIFO( rset->getInt(17) );
00141       dat.setForcedFullSupp( rset->getInt(18) );
00142 
00143       p.second = dat;
00144       fillMap->insert(p);
00145     }
00146   } catch (SQLException &e) {
00147     throw(std::runtime_error("MODDCCDetailsDat::fetchData():  "+e.getMessage()));
00148   }
00149 }
00150 
00151 void MODDCCDetailsDat::writeArrayDB(const std::map< EcalLogicID, MODDCCDetailsDat >* data, MODRunIOV* iov)
00152   throw(std::runtime_error)
00153 {
00154   this->checkConnection();
00155   this->checkPrepare();
00156 
00157   int iovID = iov->fetchID();
00158   if (!iovID) { throw(std::runtime_error("MODDCCDetailsDat::writeArrayDB:  IOV not in DB")); }
00159 
00160 
00161   int nrows=data->size(); 
00162   int* ids= new int[nrows];
00163   int* iovid_vec= new int[nrows];
00164   int* xx1= new int[nrows];
00165   int* xx2= new int[nrows];
00166   int* xx3= new int[nrows];
00167   int* xx4= new int[nrows];
00168   int* xx5= new int[nrows];
00169   int* xx6= new int[nrows];
00170   int* xx7= new int[nrows];
00171   int* xx8= new int[nrows];
00172   int* xx9= new int[nrows];
00173   int* xx10= new int[nrows];
00174   int* xx11= new int[nrows];
00175   int* xx12= new int[nrows];
00176 
00177   ub2* ids_len= new ub2[nrows];
00178   ub2* iov_len= new ub2[nrows];
00179   ub2* x1_len= new ub2[nrows];
00180   ub2* x2_len= new ub2[nrows];
00181   ub2* x3_len= new ub2[nrows];
00182   ub2* x4_len= new ub2[nrows];
00183   ub2* x5_len= new ub2[nrows];
00184   ub2* x6_len= new ub2[nrows];
00185   ub2* x7_len= new ub2[nrows];
00186   ub2* x8_len= new ub2[nrows];
00187   ub2* x9_len= new ub2[nrows];
00188   ub2* x10_len= new ub2[nrows];
00189   ub2* x11_len= new ub2[nrows];
00190   ub2* x12_len= new ub2[nrows];
00191 
00192   const EcalLogicID* channel;
00193   const MODDCCDetailsDat* dataitem;
00194   int count=0;
00195   typedef map< EcalLogicID, MODDCCDetailsDat >::const_iterator CI;
00196   for (CI p = data->begin(); p != data->end(); ++p) {
00197         channel = &(p->first);
00198         int logicID = channel->getLogicID();
00199         if (!logicID) { throw(std::runtime_error("MODDCCDetailsDat::writeArrayDB:  Bad EcalLogicID")); }
00200         ids[count]=logicID;
00201         iovid_vec[count]=iovID;
00202 
00203         dataitem = &(p->second);
00204         // dataIface.writeDB( channel, dataitem, iov);
00205         int x1= dataitem->getQPLL();
00206         int x2= dataitem->getOpticalLink();
00207         int x3= dataitem->getDataTimeout();
00208         int x4= dataitem->getHeader();
00209         int x5= dataitem->getEventNumber();
00210         int x6= dataitem->getBXNumber();
00211         int x7= dataitem->getEvenParity();
00212         int x8= dataitem->getOddParity();
00213         int x9= dataitem->getBlockSize();
00214         int x10=dataitem->getAlmostFullFIFO();
00215         int x11=dataitem->getFullFIFO();
00216         int x12=dataitem->getForcedFullSupp();
00217 
00218         xx1[count]=x1;
00219         xx2[count]=x2;
00220         xx3[count]=x3;
00221         xx4[count]=x4;
00222         xx5[count]=x5;
00223         xx6[count]=x6;
00224         xx7[count]=x7;
00225         xx8[count]=x8;
00226         xx9[count]=x9;
00227         xx10[count]=x10;
00228         xx11[count]=x11;
00229         xx12[count]=x12;
00230 
00231 
00232         ids_len[count]=sizeof(ids[count]);
00233         iov_len[count]=sizeof(iovid_vec[count]);
00234         
00235         x1_len[count]=sizeof(xx1[count]);
00236         x2_len[count]=sizeof(xx2[count]);
00237         x3_len[count]=sizeof(xx3[count]);
00238         x4_len[count]=sizeof(xx4[count]);
00239         x5_len[count]=sizeof(xx5[count]);
00240         x6_len[count]=sizeof(xx6[count]);
00241         x7_len[count]=sizeof(xx7[count]);
00242         x8_len[count]=sizeof(xx8[count]);
00243         x9_len[count]=sizeof(xx9[count]);
00244         x10_len[count]=sizeof(xx10[count]);
00245         x11_len[count]=sizeof(xx11[count]);
00246         x12_len[count]=sizeof(xx12[count]);
00247 
00248         count++;
00249      }
00250 
00251 
00252   try {
00253     m_writeStmt->setDataBuffer(1, (dvoid*)iovid_vec, OCCIINT, sizeof(iovid_vec[0]),iov_len);
00254     m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len );
00255     m_writeStmt->setDataBuffer(3, (dvoid*)xx1, OCCIINT , sizeof(xx1[0]), x1_len );
00256     m_writeStmt->setDataBuffer(4, (dvoid*)xx2, OCCIINT , sizeof(xx2[0]), x2_len );
00257     m_writeStmt->setDataBuffer(5, (dvoid*)xx3, OCCIINT , sizeof(xx3[0]), x3_len );
00258     m_writeStmt->setDataBuffer(6, (dvoid*)xx4, OCCIINT , sizeof(xx4[0]), x4_len );
00259     m_writeStmt->setDataBuffer(7, (dvoid*)xx5, OCCIINT , sizeof(xx5[0]), x5_len );
00260     m_writeStmt->setDataBuffer(8, (dvoid*)xx6, OCCIINT , sizeof(xx6[0]), x6_len );
00261     m_writeStmt->setDataBuffer(9, (dvoid*)xx7, OCCIINT , sizeof(xx7[0]), x7_len );
00262     m_writeStmt->setDataBuffer(10, (dvoid*)xx8, OCCIINT , sizeof(xx8[0]), x8_len );
00263     m_writeStmt->setDataBuffer(11, (dvoid*)xx9, OCCIINT , sizeof(xx9[0]), x9_len );
00264     m_writeStmt->setDataBuffer(12, (dvoid*)xx10, OCCIINT , sizeof(xx10[0]), x10_len );
00265     m_writeStmt->setDataBuffer(13, (dvoid*)xx11, OCCIINT , sizeof(xx11[0]), x11_len );
00266     m_writeStmt->setDataBuffer(14, (dvoid*)xx12, OCCIINT , sizeof(xx12[0]), x12_len );
00267 
00268     m_writeStmt->executeArrayUpdate(nrows);
00269 
00270     delete [] ids;
00271     delete [] iovid_vec;
00272     delete [] xx1;
00273     delete [] xx2;
00274     delete [] xx3;
00275     delete [] xx4;
00276     delete [] xx5;
00277     delete [] xx6;
00278     delete [] xx7;
00279     delete [] xx8;
00280     delete [] xx9;
00281     delete [] xx10;
00282     delete [] xx11;
00283     delete [] xx12;
00284 
00285 
00286     delete [] ids_len;
00287     delete [] iov_len;
00288     delete [] x1_len;
00289     delete [] x2_len;
00290     delete [] x3_len;
00291     delete [] x4_len;
00292     delete [] x5_len;
00293     delete [] x6_len;
00294     delete [] x7_len;
00295     delete [] x8_len;
00296     delete [] x9_len;
00297     delete [] x10_len;
00298     delete [] x11_len;
00299     delete [] x12_len;
00300 
00301 
00302   } catch (SQLException &e) {
00303     throw(std::runtime_error("MonPedestalsDat::writeArrayDB():  "+e.getMessage()));
00304   }
00305 }