00001 #include <stdexcept>
00002 #include <string>
00003 #include "OnlineDB/Oracle/interface/Oracle.h"
00004
00005 #include "OnlineDB/EcalCondDB/interface/MonPNIRedDat.h"
00006 #include "OnlineDB/EcalCondDB/interface/RunTag.h"
00007 #include "OnlineDB/EcalCondDB/interface/RunIOV.h"
00008
00009 using namespace std;
00010 using namespace oracle::occi;
00011
00012 MonPNIRedDat::MonPNIRedDat()
00013 {
00014 m_env = NULL;
00015 m_conn = NULL;
00016 m_writeStmt = NULL;
00017 m_readStmt = NULL;
00018
00019 m_adcMeanG1 =0;
00020 m_adcRMSG1 = 0;
00021 m_adcMeanG16 = 0;
00022 m_adcRMSG16 = 0;
00023 m_pedMeanG1 = 0;
00024 m_pedRMSG1 = 0;
00025 m_pedMeanG16 = 0;
00026 m_pedRMSG16 = 0;
00027 m_taskStatus = 0;
00028 }
00029
00030
00031
00032 MonPNIRedDat::~MonPNIRedDat()
00033 {
00034 }
00035
00036
00037
00038 void MonPNIRedDat::prepareWrite()
00039 throw(std::runtime_error)
00040 {
00041 this->checkConnection();
00042
00043 try {
00044 m_writeStmt = m_conn->createStatement();
00045 m_writeStmt->setSQL("INSERT INTO mon_pn_ired_dat (iov_id, logic_id, "
00046 "adc_mean_g1, adc_rms_g1, adc_mean_g16, adc_rms_g16, ped_mean_g1, ped_rms_g1, ped_mean_g16, ped_rms_g16, task_status) "
00047 "VALUES (:iov_id, :logic_id, "
00048 ":3, :4, :5, :6, :7, :8, :9, :10, :11)");
00049 } catch (SQLException &e) {
00050 throw(std::runtime_error("MonPNIRedDat::prepareWrite(): "+e.getMessage()));
00051 }
00052 }
00053
00054
00055
00056 void MonPNIRedDat::writeDB(const EcalLogicID* ecid, const MonPNIRedDat* item, MonRunIOV* iov)
00057 throw(std::runtime_error)
00058 {
00059 this->checkConnection();
00060 this->checkPrepare();
00061
00062 int iovID = iov->fetchID();
00063 if (!iovID) { throw(std::runtime_error("MonPNIRedDat::writeDB: IOV not in DB")); }
00064
00065 int logicID = ecid->getLogicID();
00066 if (!logicID) { throw(std::runtime_error("MonPNIRedDat::writeDB: Bad EcalLogicID")); }
00067
00068 try {
00069 m_writeStmt->setInt(1, iovID);
00070 m_writeStmt->setInt(2, logicID);
00071
00072 m_writeStmt->setFloat(3, item->getADCMeanG1() );
00073 m_writeStmt->setFloat(4, item->getADCRMSG1() );
00074 m_writeStmt->setFloat(5, item->getADCMeanG16() );
00075 m_writeStmt->setFloat(6, item->getADCRMSG16() );
00076 m_writeStmt->setFloat(7, item->getPedMeanG1() );
00077 m_writeStmt->setFloat(8, item->getPedRMSG1() );
00078 m_writeStmt->setFloat(9, item->getPedMeanG16() );
00079 m_writeStmt->setFloat(10, item->getPedRMSG16() );
00080 m_writeStmt->setInt(11, item->getTaskStatus() );
00081
00082 m_writeStmt->executeUpdate();
00083 } catch (SQLException &e) {
00084 throw(std::runtime_error("MonPNIRedDat::writeDB(): "+e.getMessage()));
00085 }
00086 }
00087
00088
00089
00090 void MonPNIRedDat::fetchData(std::map< EcalLogicID, MonPNIRedDat >* fillMap, MonRunIOV* iov)
00091 throw(std::runtime_error)
00092 {
00093 this->checkConnection();
00094 fillMap->clear();
00095
00096 iov->setConnection(m_env, m_conn);
00097 int iovID = iov->fetchID();
00098 if (!iovID) {
00099
00100 return;
00101 }
00102
00103 try {
00104
00105 m_readStmt->setSQL("SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
00106 "d.adc_mean_g1, d.adc_rms_g1, d.adc_mean_g16, d.adc_rms_g16, d.ped_mean_g1,d.ped_rms_g1, d.ped_mean_g16, d.ped_rms_g16, d.task_status "
00107 "FROM channelview cv JOIN mon_pn_ired_dat d "
00108 "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
00109 "WHERE d.iov_id = :iov_id");
00110 m_readStmt->setInt(1, iovID);
00111 ResultSet* rset = m_readStmt->executeQuery();
00112
00113 std::pair< EcalLogicID, MonPNIRedDat > p;
00114 MonPNIRedDat dat;
00115 while(rset->next()) {
00116 p.first = EcalLogicID( rset->getString(1),
00117 rset->getInt(2),
00118 rset->getInt(3),
00119 rset->getInt(4),
00120 rset->getInt(5),
00121 rset->getString(6));
00122
00123 dat.setADCMeanG1( rset->getFloat(7) );
00124 dat.setADCRMSG1( rset->getFloat(8) );
00125 dat.setADCMeanG16( rset->getFloat(9) );
00126 dat.setADCRMSG16( rset->getFloat(10) );
00127 dat.setPedMeanG1( rset->getFloat(11) );
00128 dat.setPedRMSG1( rset->getFloat(12) );
00129 dat.setPedMeanG16( rset->getFloat(13) );
00130 dat.setPedRMSG16( rset->getFloat(14) );
00131 dat.setTaskStatus( rset->getInt(15) );
00132 p.second = dat;
00133 fillMap->insert(p);
00134 }
00135 } catch (SQLException &e) {
00136 throw(std::runtime_error("MonPNIRedDat::fetchData(): "+e.getMessage()));
00137 }
00138 }
00139 void MonPNIRedDat::writeArrayDB(const std::map< EcalLogicID, MonPNIRedDat >* data, MonRunIOV* iov)
00140 throw(std::runtime_error)
00141 {
00142 this->checkConnection();
00143 this->checkPrepare();
00144
00145 int iovID = iov->fetchID();
00146 if (!iovID) { throw(std::runtime_error("MonPNIRedDat::writeArrayDB: IOV not in DB")); }
00147
00148
00149 int nrows=data->size();
00150 int* ids= new int[nrows];
00151 int* iovid_vec= new int[nrows];
00152 float* xx= new float[nrows];
00153 float* yy= new float[nrows];
00154 float* zz= new float[nrows];
00155 float* ww= new float[nrows];
00156 float* uu= new float[nrows];
00157 float* tt= new float[nrows];
00158 float* rr= new float[nrows];
00159 float* pp= new float[nrows];
00160 int* st= new int[nrows];
00161
00162 ub2* ids_len= new ub2[nrows];
00163 ub2* iov_len= new ub2[nrows];
00164 ub2* x_len= new ub2[nrows];
00165 ub2* y_len= new ub2[nrows];
00166 ub2* z_len= new ub2[nrows];
00167 ub2* w_len= new ub2[nrows];
00168 ub2* u_len= new ub2[nrows];
00169 ub2* t_len= new ub2[nrows];
00170 ub2* r_len= new ub2[nrows];
00171 ub2* p_len= new ub2[nrows];
00172 ub2* st_len= new ub2[nrows];
00173
00174 const EcalLogicID* channel;
00175 const MonPNIRedDat* dataitem;
00176 int count=0;
00177 typedef map< EcalLogicID, MonPNIRedDat >::const_iterator CI;
00178 for (CI p = data->begin(); p != data->end(); ++p) {
00179 channel = &(p->first);
00180 int logicID = channel->getLogicID();
00181 if (!logicID) { throw(std::runtime_error("MonPNIRedDat::writeArrayDB: Bad EcalLogicID")); }
00182 ids[count]=logicID;
00183 iovid_vec[count]=iovID;
00184
00185 dataitem = &(p->second);
00186
00187 float x=dataitem->getADCMeanG1();
00188 float y=dataitem->getADCRMSG1();
00189 float z=dataitem->getADCMeanG16();
00190 float w=dataitem->getADCRMSG16();
00191 float u=dataitem->getPedMeanG1();
00192 float t=dataitem->getPedRMSG1();
00193 float r=dataitem->getPedMeanG16();
00194 float pi=dataitem->getPedRMSG16();
00195 int statu=dataitem->getTaskStatus();
00196
00197
00198
00199 xx[count]=x;
00200 yy[count]=y;
00201 zz[count]=z;
00202 ww[count]=w;
00203 uu[count]=u;
00204 tt[count]=t;
00205 rr[count]=r;
00206 pp[count]=pi;
00207 st[count]=statu;
00208
00209
00210 ids_len[count]=sizeof(ids[count]);
00211 iov_len[count]=sizeof(iovid_vec[count]);
00212
00213 x_len[count]=sizeof(xx[count]);
00214 y_len[count]=sizeof(yy[count]);
00215 z_len[count]=sizeof(zz[count]);
00216 w_len[count]=sizeof(ww[count]);
00217 u_len[count]=sizeof(uu[count]);
00218 t_len[count]=sizeof(tt[count]);
00219 r_len[count]=sizeof(rr[count]);
00220 p_len[count]=sizeof(pp[count]);
00221 st_len[count]=sizeof(st[count]);
00222
00223 count++;
00224 }
00225
00226
00227 try {
00228 m_writeStmt->setDataBuffer(1, (dvoid*)iovid_vec, OCCIINT, sizeof(iovid_vec[0]),iov_len);
00229 m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len );
00230 m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIFLOAT , sizeof(xx[0]), x_len );
00231 m_writeStmt->setDataBuffer(4, (dvoid*)yy, OCCIFLOAT , sizeof(yy[0]), y_len );
00232 m_writeStmt->setDataBuffer(5, (dvoid*)zz, OCCIFLOAT , sizeof(zz[0]), z_len );
00233 m_writeStmt->setDataBuffer(6, (dvoid*)ww, OCCIFLOAT , sizeof(ww[0]), w_len );
00234 m_writeStmt->setDataBuffer(7, (dvoid*)uu, OCCIFLOAT , sizeof(uu[0]), u_len );
00235 m_writeStmt->setDataBuffer(8, (dvoid*)tt, OCCIFLOAT , sizeof(tt[0]), t_len );
00236 m_writeStmt->setDataBuffer(9, (dvoid*)rr, OCCIFLOAT , sizeof(rr[0]), r_len );
00237 m_writeStmt->setDataBuffer(10, (dvoid*)pp, OCCIFLOAT , sizeof(pp[0]), p_len );
00238 m_writeStmt->setDataBuffer(11, (dvoid*)st, OCCIINT , sizeof(st[0]), st_len );
00239
00240
00241 m_writeStmt->executeArrayUpdate(nrows);
00242
00243 delete [] ids;
00244 delete [] iovid_vec;
00245 delete [] xx;
00246 delete [] yy;
00247 delete [] zz;
00248 delete [] ww;
00249 delete [] uu;
00250 delete [] tt;
00251 delete [] rr;
00252 delete [] pp;
00253 delete [] st;
00254
00255 delete [] ids_len;
00256 delete [] iov_len;
00257 delete [] x_len;
00258 delete [] y_len;
00259 delete [] z_len;
00260 delete [] w_len;
00261 delete [] u_len;
00262 delete [] t_len;
00263 delete [] r_len;
00264 delete [] p_len;
00265 delete [] st_len;
00266
00267
00268
00269 } catch (SQLException &e) {
00270 throw(std::runtime_error("MonPNIRedDat::writeArrayDB(): "+e.getMessage()));
00271 }
00272 }