CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/OnlineDB/EcalCondDB/src/MonMemChConsistencyDat.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/MonMemChConsistencyDat.h"
00006 
00007 using namespace std;
00008 using namespace oracle::occi;
00009 
00010 MonMemChConsistencyDat::MonMemChConsistencyDat()
00011 {
00012   m_env = NULL;
00013   m_conn = NULL;
00014   m_writeStmt = NULL;
00015   m_readStmt = NULL;
00016 
00017   m_processedEvents = 0;
00018   m_problematicEvents = 0;
00019   m_problemsID = 0;
00020   m_problemsGainZero = 0;
00021   m_problemsGainSwitch = 0;
00022   m_taskStatus = 0;
00023 }
00024 
00025 
00026 
00027 MonMemChConsistencyDat::~MonMemChConsistencyDat()
00028 {
00029 }
00030 
00031 
00032 
00033 void MonMemChConsistencyDat::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 mon_mem_ch_consistency_dat (iov_id, logic_id, "
00041                         "processed_events, problematic_events, problems_id, problems_gain_zero, problems_gain_switch, task_status) "
00042                         "VALUES (:iov_id, :logic_id, "
00043                         ":3, :4, :5, :6, :7, :8)");
00044   } catch (SQLException &e) {
00045     throw(std::runtime_error("MonMemChConsistencyDat::prepareWrite():  "+e.getMessage()));
00046   }
00047 }
00048 
00049 
00050 
00051 void MonMemChConsistencyDat::writeDB(const EcalLogicID* ecid, const MonMemChConsistencyDat* item, MonRunIOV* iov)
00052   throw(std::runtime_error)
00053 {
00054   this->checkConnection();
00055   this->checkPrepare();
00056 
00057   int iovID = iov->fetchID();
00058   if (!iovID) { throw(std::runtime_error("MonMemChConsistencyDat::writeDB:  IOV not in DB")); }
00059 
00060   int logicID = ecid->getLogicID();
00061   if (!logicID) { throw(std::runtime_error("MonMemChConsistencyDat::writeDB:  Bad EcalLogicID")); }
00062   
00063   try {
00064     m_writeStmt->setInt(1, iovID);
00065     m_writeStmt->setInt(2, logicID);
00066 
00067     m_writeStmt->setInt(3, item->getProcessedEvents() );
00068     m_writeStmt->setInt(4, item->getProblematicEvents() );
00069     m_writeStmt->setInt(5, item->getProblemsID() );
00070     m_writeStmt->setInt(6, item->getProblemsGainZero() );
00071     m_writeStmt->setInt(7, item->getProblemsGainSwitch() );
00072     m_writeStmt->setInt(8, item->getTaskStatus() );
00073     m_writeStmt->executeUpdate();
00074   } catch (SQLException &e) {
00075     throw(std::runtime_error("MonMemChConsistencyDat::writeDB():  "+e.getMessage()));
00076   }
00077 }
00078 
00079 
00080 
00081 void MonMemChConsistencyDat::fetchData(std::map< EcalLogicID, MonMemChConsistencyDat >* fillMap, MonRunIOV* iov)
00082   throw(std::runtime_error)
00083 {
00084   this->checkConnection();
00085   fillMap->clear();
00086 
00087   iov->setConnection(m_env, m_conn);
00088   int iovID = iov->fetchID();
00089   if (!iovID) { 
00090     //  throw(std::runtime_error("MonMemChConsistencyDat::writeDB:  IOV not in DB")); 
00091     return;
00092   }
00093 
00094   try {
00095 
00096     m_readStmt->setSQL("SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
00097                  "d.processed_events, d.problematic_events, d.problems_id, d.problems_gain_zero, d.problems_gain_switch, d.task_status "
00098                  "FROM channelview cv JOIN mon_mem_ch_consistency_dat d "
00099                  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
00100                  "WHERE d.iov_id = :iov_id");
00101     m_readStmt->setInt(1, iovID);
00102     ResultSet* rset = m_readStmt->executeQuery();
00103     
00104     std::pair< EcalLogicID, MonMemChConsistencyDat > p;
00105     MonMemChConsistencyDat dat;
00106     while(rset->next()) {
00107       p.first = EcalLogicID( rset->getString(1),     // name
00108                              rset->getInt(2),        // logic_id
00109                              rset->getInt(3),        // id1
00110                              rset->getInt(4),        // id2
00111                              rset->getInt(5),        // id3
00112                              rset->getString(6));    // maps_to
00113 
00114       dat.setProcessedEvents( rset->getInt(7) );
00115       dat.setProblematicEvents( rset->getInt(8) );
00116       dat.setProblemsID( rset->getInt(9) );
00117       dat.setProblemsGainZero( rset->getInt(10) );
00118       dat.setProblemsGainSwitch( rset->getInt(11) );
00119       dat.setTaskStatus( rset->getInt(12) );
00120 
00121       p.second = dat;
00122       fillMap->insert(p);
00123     }
00124   } catch (SQLException &e) {
00125     throw(std::runtime_error("MonMemChConsistencyDat::fetchData():  "+e.getMessage()));
00126   }
00127 }
00128 
00129 void MonMemChConsistencyDat::writeArrayDB(const std::map< EcalLogicID, MonMemChConsistencyDat >* data, MonRunIOV* iov)
00130   throw(std::runtime_error)
00131 {
00132   this->checkConnection();
00133   this->checkPrepare();
00134 
00135   int iovID = iov->fetchID();
00136   if (!iovID) { throw(std::runtime_error("MonMemChConsistencyDat::writeArrayDB:  IOV not in DB")); }
00137 
00138 
00139   int nrows=data->size(); 
00140   int* ids= new int[nrows];
00141   int* iovid_vec= new int[nrows];
00142   int* xx= new int[nrows];
00143   int* yy= new int[nrows];
00144   int* zz= new int[nrows];
00145   int* ww= new int[nrows];
00146   int* uu= new int[nrows];
00147   int* st= new int[nrows];
00148 
00149   ub2* ids_len= new ub2[nrows];
00150   ub2* iov_len= new ub2[nrows];
00151   ub2* x_len= new ub2[nrows];
00152   ub2* y_len= new ub2[nrows];
00153   ub2* z_len= new ub2[nrows];
00154   ub2* w_len= new ub2[nrows];
00155   ub2* u_len= new ub2[nrows];
00156   ub2* st_len= new ub2[nrows];
00157 
00158   const EcalLogicID* channel;
00159   const MonMemChConsistencyDat* dataitem;
00160   int count=0;
00161   typedef map< EcalLogicID, MonMemChConsistencyDat >::const_iterator CI;
00162   for (CI p = data->begin(); p != data->end(); ++p) {
00163         channel = &(p->first);
00164         int logicID = channel->getLogicID();
00165         if (!logicID) { throw(std::runtime_error("MonMemChConsistencyDat::writeArrayDB:  Bad EcalLogicID")); }
00166         ids[count]=logicID;
00167         iovid_vec[count]=iovID;
00168 
00169         dataitem = &(p->second);
00170         // dataIface.writeDB( channel, dataitem, iov);
00171         int x=dataitem->getProcessedEvents();
00172         int y=dataitem->getProblematicEvents();
00173         int z=dataitem->getProblemsID();
00174         int w=dataitem->getProblemsGainZero();
00175         int u=dataitem->getProblemsGainSwitch();
00176         int statu=dataitem->getTaskStatus();
00177 
00178 
00179 
00180         xx[count]=x;
00181         yy[count]=y;
00182         zz[count]=z;
00183         ww[count]=w;
00184         uu[count]=u;
00185         st[count]=statu;
00186 
00187 
00188         ids_len[count]=sizeof(ids[count]);
00189         iov_len[count]=sizeof(iovid_vec[count]);
00190         
00191         x_len[count]=sizeof(xx[count]);
00192         y_len[count]=sizeof(yy[count]);
00193         z_len[count]=sizeof(zz[count]);
00194         w_len[count]=sizeof(ww[count]);
00195         u_len[count]=sizeof(uu[count]);
00196         st_len[count]=sizeof(st[count]);
00197 
00198         count++;
00199      }
00200 
00201 
00202   try {
00203     m_writeStmt->setDataBuffer(1, (dvoid*)iovid_vec, OCCIINT, sizeof(iovid_vec[0]),iov_len);
00204     m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len );
00205     m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIINT , sizeof(xx[0]), x_len );
00206     m_writeStmt->setDataBuffer(4, (dvoid*)yy, OCCIINT , sizeof(yy[0]), y_len );
00207     m_writeStmt->setDataBuffer(5, (dvoid*)zz, OCCIINT , sizeof(zz[0]), z_len );
00208     m_writeStmt->setDataBuffer(6, (dvoid*)ww, OCCIINT , sizeof(ww[0]), w_len );
00209     m_writeStmt->setDataBuffer(7, (dvoid*)uu, OCCIINT , sizeof(uu[0]), u_len );
00210     m_writeStmt->setDataBuffer(8, (dvoid*)st, OCCIINT , sizeof(st[0]), st_len );
00211    
00212 
00213     m_writeStmt->executeArrayUpdate(nrows);
00214 
00215     delete [] ids;
00216     delete [] iovid_vec;
00217     delete [] xx;
00218     delete [] yy;
00219     delete [] zz;
00220     delete [] ww;
00221     delete [] uu;
00222     delete [] st;
00223 
00224     delete [] ids_len;
00225     delete [] iov_len;
00226     delete [] x_len;
00227     delete [] y_len;
00228     delete [] z_len;
00229     delete [] w_len;
00230     delete [] u_len;
00231     delete [] st_len;
00232 
00233 
00234 
00235   } catch (SQLException &e) {
00236     throw(std::runtime_error("MonMemChConsistencyDat::writeArrayDB():  "+e.getMessage()));
00237   }
00238 }