00001 #include <stdexcept>
00002 #include <string>
00003 #include "OnlineDB/Oracle/interface/Oracle.h"
00004
00005 #include "OnlineDB/EcalCondDB/interface/MonMemTTConsistencyDat.h"
00006
00007 using namespace std;
00008 using namespace oracle::occi;
00009
00010 MonMemTTConsistencyDat::MonMemTTConsistencyDat()
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 MonMemTTConsistencyDat::~MonMemTTConsistencyDat()
00029 {
00030 }
00031
00032
00033
00034 void MonMemTTConsistencyDat::prepareWrite()
00035 throw(runtime_error)
00036 {
00037 this->checkConnection();
00038
00039 try {
00040 m_writeStmt = m_conn->createStatement();
00041 m_writeStmt->setSQL("INSERT INTO mon_mem_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(runtime_error("MonMemTTConsistencyDat::prepareWrite(): "+e.getMessage()));
00047 }
00048 }
00049
00050
00051
00052 void MonMemTTConsistencyDat::writeDB(const EcalLogicID* ecid, const MonMemTTConsistencyDat* item, MonRunIOV* iov)
00053 throw(runtime_error)
00054 {
00055 this->checkConnection();
00056 this->checkPrepare();
00057
00058 int iovID = iov->fetchID();
00059 if (!iovID) { throw(runtime_error("MonMemTTConsistencyDat::writeDB: IOV not in DB")); }
00060
00061 int logicID = ecid->getLogicID();
00062 if (!logicID) { throw(runtime_error("MonMemTTConsistencyDat::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(runtime_error("MonMemTTConsistencyDat::writeDB(): "+e.getMessage()));
00078 }
00079 }
00080
00081
00082
00083 void MonMemTTConsistencyDat::fetchData(std::map< EcalLogicID, MonMemTTConsistencyDat >* fillMap, MonRunIOV* iov)
00084 throw(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
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_mem_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, MonMemTTConsistencyDat > p;
00107 MonMemTTConsistencyDat dat;
00108 while(rset->next()) {
00109 p.first = EcalLogicID( rset->getString(1),
00110 rset->getInt(2),
00111 rset->getInt(3),
00112 rset->getInt(4),
00113 rset->getInt(5),
00114 rset->getString(6));
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(runtime_error("MonMemTTConsistencyDat::fetchData(): "+e.getMessage()));
00129 }
00130 }
00131
00132 void MonMemTTConsistencyDat::writeArrayDB(const std::map< EcalLogicID, MonMemTTConsistencyDat >* data, MonRunIOV* iov)
00133 throw(runtime_error)
00134 {
00135 this->checkConnection();
00136 this->checkPrepare();
00137
00138 int iovID = iov->fetchID();
00139 if (!iovID) { throw(runtime_error("MonMemTTConsistencyDat::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 MonMemTTConsistencyDat* dataitem;
00165 int count=0;
00166 typedef map< EcalLogicID, MonMemTTConsistencyDat >::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(runtime_error("MonMemTTConsistencyDat::writeArrayDB: Bad EcalLogicID")); }
00171 ids[count]=logicID;
00172 iovid_vec[count]=iovID;
00173
00174 dataitem = &(p->second);
00175
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
00187 xx[count]=x;
00188 yy[count]=y;
00189 zz[count]=z;
00190 ww[count]=w;
00191 uu[count]=u;
00192 tt[count]=t;
00193 st[count]=statu;
00194
00195
00196 ids_len[count]=sizeof(ids[count]);
00197 iov_len[count]=sizeof(iovid_vec[count]);
00198
00199 x_len[count]=sizeof(xx[count]);
00200 y_len[count]=sizeof(yy[count]);
00201 z_len[count]=sizeof(zz[count]);
00202 w_len[count]=sizeof(ww[count]);
00203 u_len[count]=sizeof(uu[count]);
00204 t_len[count]=sizeof(tt[count]);
00205 st_len[count]=sizeof(st[count]);
00206
00207 count++;
00208 }
00209
00210
00211 try {
00212 m_writeStmt->setDataBuffer(1, (dvoid*)iovid_vec, OCCIINT, sizeof(iovid_vec[0]),iov_len);
00213 m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len );
00214 m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIINT , sizeof(xx[0]), x_len );
00215 m_writeStmt->setDataBuffer(4, (dvoid*)yy, OCCIINT , sizeof(yy[0]), y_len );
00216 m_writeStmt->setDataBuffer(5, (dvoid*)zz, OCCIINT , sizeof(zz[0]), z_len );
00217 m_writeStmt->setDataBuffer(6, (dvoid*)ww, OCCIINT , sizeof(ww[0]), w_len );
00218 m_writeStmt->setDataBuffer(7, (dvoid*)uu, OCCIINT , sizeof(uu[0]), u_len );
00219 m_writeStmt->setDataBuffer(8, (dvoid*)tt, OCCIINT , sizeof(tt[0]), t_len );
00220 m_writeStmt->setDataBuffer(9, (dvoid*)st, OCCIINT , sizeof(st[0]), st_len );
00221
00222
00223 m_writeStmt->executeArrayUpdate(nrows);
00224
00225 delete [] ids;
00226 delete [] iovid_vec;
00227 delete [] xx;
00228 delete [] yy;
00229 delete [] zz;
00230 delete [] ww;
00231 delete [] uu;
00232 delete [] tt;
00233 delete [] st;
00234
00235 delete [] ids_len;
00236 delete [] iov_len;
00237 delete [] x_len;
00238 delete [] y_len;
00239 delete [] z_len;
00240 delete [] w_len;
00241 delete [] u_len;
00242 delete [] t_len;
00243 delete [] st_len;
00244
00245
00246
00247 } catch (SQLException &e) {
00248 throw(runtime_error("MonMemTTConsistencyDat::writeArrayDB(): "+e.getMessage()));
00249 }
00250 }