CMS 3D CMS Logo

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