CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_4/src/OnlineDB/EcalCondDB/src/MonPNMGPADat.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/MonPNMGPADat.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 MonPNMGPADat::MonPNMGPADat()
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 MonPNMGPADat::~MonPNMGPADat()
00033 {
00034 }
00035 
00036 
00037 
00038 void MonPNMGPADat::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_mgpa_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("MonPNMGPADat::prepareWrite():  "+e.getMessage()));
00051   }
00052 }
00053 
00054 
00055 
00056 void MonPNMGPADat::writeDB(const EcalLogicID* ecid, const MonPNMGPADat* 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("MonPNMGPADat::writeDB:  IOV not in DB")); }
00064 
00065   int logicID = ecid->getLogicID();
00066   if (!logicID) { throw(std::runtime_error("MonPNMGPADat::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("MonPNMGPADat::writeDB():  "+e.getMessage()));
00085   }
00086 }
00087 
00088 
00089 
00090 void MonPNMGPADat::fetchData(std::map< EcalLogicID, MonPNMGPADat >* 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     //  throw(std::runtime_error("MonPNMGPADat::writeDB:  IOV not in DB")); 
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_mgpa_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, MonPNMGPADat > p;
00114     MonPNMGPADat dat;
00115     while(rset->next()) {
00116       p.first = EcalLogicID( rset->getString(1),     // name
00117                              rset->getInt(2),        // logic_id
00118                              rset->getInt(3),        // id1
00119                              rset->getInt(4),        // id2
00120                              rset->getInt(5),        // id3
00121                              rset->getString(6));    // maps_to
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("MonPNMGPADat::fetchData():  "+e.getMessage()));
00137   }
00138 }
00139 
00140 void MonPNMGPADat::writeArrayDB(const std::map< EcalLogicID, MonPNMGPADat >* data, MonRunIOV* iov)
00141   throw(std::runtime_error)
00142 {
00143   this->checkConnection();
00144   this->checkPrepare();
00145 
00146   int iovID = iov->fetchID();
00147   if (!iovID) { throw(std::runtime_error("MonPNMGPADat::writeArrayDB:  IOV not in DB")); }
00148 
00149 
00150   int nrows=data->size(); 
00151   int* ids= new int[nrows];
00152   int* iovid_vec= new int[nrows];
00153   float* xx= new float[nrows];
00154   float* yy= new float[nrows];
00155   float* zz= new float[nrows];
00156   float* ww= new float[nrows];
00157   float* uu= new float[nrows];
00158   float* tt= new float[nrows];
00159   float* rr= new float[nrows];
00160   float* pp= new float[nrows];
00161   int* st= new int[nrows];
00162 
00163   ub2* ids_len= new ub2[nrows];
00164   ub2* iov_len= new ub2[nrows];
00165   ub2* x_len= new ub2[nrows];
00166   ub2* y_len= new ub2[nrows];
00167   ub2* z_len= new ub2[nrows];
00168   ub2* w_len= new ub2[nrows];
00169   ub2* u_len= new ub2[nrows];
00170   ub2* t_len= new ub2[nrows];
00171   ub2* r_len= new ub2[nrows];
00172   ub2* p_len= new ub2[nrows];
00173   ub2* st_len= new ub2[nrows];
00174 
00175   const EcalLogicID* channel;
00176   const MonPNMGPADat* dataitem;
00177   int count=0;
00178   typedef map< EcalLogicID, MonPNMGPADat >::const_iterator CI;
00179   for (CI p = data->begin(); p != data->end(); ++p) {
00180         channel = &(p->first);
00181         int logicID = channel->getLogicID();
00182         if (!logicID) { throw(std::runtime_error("MonPNMGPADat::writeArrayDB:  Bad EcalLogicID")); }
00183         ids[count]=logicID;
00184         iovid_vec[count]=iovID;
00185 
00186         dataitem = &(p->second);
00187         // dataIface.writeDB( channel, dataitem, iov);
00188         float x=dataitem->getADCMeanG1();
00189         float y=dataitem->getADCRMSG1();
00190         float z=dataitem->getADCMeanG16();
00191         float w=dataitem->getADCRMSG16();
00192         float u=dataitem->getPedMeanG1();
00193         float t=dataitem->getPedRMSG1();
00194         float r=dataitem->getPedMeanG16();
00195         float pi=dataitem->getPedRMSG16();
00196         int statu=dataitem->getTaskStatus();
00197 
00198 
00199 
00200         xx[count]=x;
00201         yy[count]=y;
00202         zz[count]=z;
00203         ww[count]=w;
00204         uu[count]=u;
00205         tt[count]=t;
00206         rr[count]=r;
00207         pp[count]=pi;
00208         st[count]=statu;
00209 
00210 
00211         ids_len[count]=sizeof(ids[count]);
00212         iov_len[count]=sizeof(iovid_vec[count]);
00213         
00214         x_len[count]=sizeof(xx[count]);
00215         y_len[count]=sizeof(yy[count]);
00216         z_len[count]=sizeof(zz[count]);
00217         w_len[count]=sizeof(ww[count]);
00218         u_len[count]=sizeof(uu[count]);
00219         t_len[count]=sizeof(tt[count]);
00220         r_len[count]=sizeof(rr[count]);
00221         p_len[count]=sizeof(pp[count]);
00222         st_len[count]=sizeof(st[count]);
00223 
00224         count++;
00225      }
00226 
00227 
00228   try {
00229     m_writeStmt->setDataBuffer(1, (dvoid*)iovid_vec, OCCIINT, sizeof(iovid_vec[0]),iov_len);
00230     m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len );
00231     m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIFLOAT , sizeof(xx[0]), x_len );
00232     m_writeStmt->setDataBuffer(4, (dvoid*)yy, OCCIFLOAT , sizeof(yy[0]), y_len );
00233     m_writeStmt->setDataBuffer(5, (dvoid*)zz, OCCIFLOAT , sizeof(zz[0]), z_len );
00234     m_writeStmt->setDataBuffer(6, (dvoid*)ww, OCCIFLOAT , sizeof(ww[0]), w_len );
00235     m_writeStmt->setDataBuffer(7, (dvoid*)uu, OCCIFLOAT , sizeof(uu[0]), u_len );
00236     m_writeStmt->setDataBuffer(8, (dvoid*)tt, OCCIFLOAT , sizeof(tt[0]), t_len );
00237     m_writeStmt->setDataBuffer(9, (dvoid*)rr, OCCIFLOAT , sizeof(rr[0]), r_len );
00238     m_writeStmt->setDataBuffer(10, (dvoid*)pp, OCCIFLOAT , sizeof(pp[0]), p_len );
00239     m_writeStmt->setDataBuffer(11, (dvoid*)st, OCCIINT , sizeof(st[0]), st_len );
00240    
00241 
00242     m_writeStmt->executeArrayUpdate(nrows);
00243 
00244     delete [] ids;
00245     delete [] iovid_vec;
00246     delete [] xx;
00247     delete [] yy;
00248     delete [] zz;
00249     delete [] ww;
00250     delete [] uu;
00251     delete [] tt;
00252     delete [] rr;
00253     delete [] pp;
00254     delete [] st;
00255 
00256     delete [] ids_len;
00257     delete [] iov_len;
00258     delete [] x_len;
00259     delete [] y_len;
00260     delete [] z_len;
00261     delete [] w_len;
00262     delete [] u_len;
00263     delete [] t_len;
00264     delete [] r_len;
00265     delete [] p_len;
00266     delete [] st_len;
00267 
00268 
00269 
00270   } catch (SQLException &e) {
00271     throw(std::runtime_error("MonPNMGPADat::writeArrayDB():  "+e.getMessage()));
00272   }
00273 }