CMS 3D CMS Logo

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