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