CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/OnlineDB/EcalCondDB/src/MonPNPedDat.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/MonPNPedDat.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 MonPNPedDat::MonPNPedDat()
00013 {
00014   m_env = NULL;
00015   m_conn = NULL;
00016   m_writeStmt = NULL;
00017   m_readStmt = NULL;
00018 
00019   m_pedMeanG1 = 0;
00020   m_pedRMSG1 = 0;
00021   m_pedMeanG16 = 0;
00022   m_pedRMSG16 = 0;
00023   m_taskStatus = 0;
00024 }
00025 
00026 
00027 
00028 MonPNPedDat::~MonPNPedDat()
00029 {
00030 }
00031 
00032 
00033 
00034 void MonPNPedDat::prepareWrite()
00035   throw(std::runtime_error)
00036 {
00037   this->checkConnection();
00038 
00039   try {
00040     m_writeStmt = m_conn->createStatement();
00041     m_writeStmt->setSQL("INSERT INTO mon_pn_ped_dat (iov_id, logic_id, "
00042                         "ped_mean_g1, ped_rms_g1, ped_mean_g16, ped_rms_g16, task_status) "
00043                         "VALUES (:iov_id, :logic_id, "
00044                         ":3, :4, :5, :6, :7)");
00045   } catch (SQLException &e) {
00046     throw(std::runtime_error("MonPNPedDat::prepareWrite():  "+e.getMessage()));
00047   }
00048 }
00049 
00050 
00051 
00052 void MonPNPedDat::writeDB(const EcalLogicID* ecid, const MonPNPedDat* item, MonRunIOV* iov)
00053   throw(std::runtime_error)
00054 {
00055   this->checkConnection();
00056   this->checkPrepare();
00057 
00058   int iovID = iov->fetchID();
00059   if (!iovID) { throw(std::runtime_error("MonPNPedDat::writeDB:  IOV not in DB")); }
00060 
00061   int logicID = ecid->getLogicID();
00062   if (!logicID) { throw(std::runtime_error("MonPNPedDat::writeDB:  Bad EcalLogicID")); }
00063   
00064   try {
00065     m_writeStmt->setInt(1, iovID);
00066     m_writeStmt->setInt(2, logicID);
00067 
00068     m_writeStmt->setFloat(3, item->getPedMeanG1() );
00069     m_writeStmt->setFloat(4, item->getPedRMSG1() );
00070     m_writeStmt->setFloat(5, item->getPedMeanG16() );
00071     m_writeStmt->setFloat(6, item->getPedRMSG16() );
00072     m_writeStmt->setInt(7, item->getTaskStatus() );
00073 
00074     m_writeStmt->executeUpdate();
00075   } catch (SQLException &e) {
00076     throw(std::runtime_error("MonPNPedDat::writeDB():  "+e.getMessage()));
00077   }
00078 }
00079 
00080 
00081 
00082 void MonPNPedDat::fetchData(std::map< EcalLogicID, MonPNPedDat >* fillMap, MonRunIOV* iov)
00083   throw(std::runtime_error)
00084 {
00085   this->checkConnection();
00086   fillMap->clear();
00087 
00088   iov->setConnection(m_env, m_conn);
00089   int iovID = iov->fetchID();
00090   if (!iovID) { 
00091     //  throw(std::runtime_error("MonPNPedDat::writeDB:  IOV not in DB")); 
00092     return;
00093   }
00094 
00095   try {
00096 
00097     m_readStmt->setSQL("SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
00098                  "d.ped_mean_g1,d.ped_rms_g1, d.ped_mean_g16, d.ped_rms_g16, d.task_status "
00099                  "FROM channelview cv JOIN mon_pn_ped_dat d "
00100                  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
00101                  "WHERE d.iov_id = :iov_id");
00102     m_readStmt->setInt(1, iovID);
00103     ResultSet* rset = m_readStmt->executeQuery();
00104     
00105     std::pair< EcalLogicID, MonPNPedDat > p;
00106     MonPNPedDat dat;
00107     while(rset->next()) {
00108       p.first = EcalLogicID( rset->getString(1),     // name
00109                              rset->getInt(2),        // logic_id
00110                              rset->getInt(3),        // id1
00111                              rset->getInt(4),        // id2
00112                              rset->getInt(5),        // id3
00113                              rset->getString(6));    // maps_to
00114 
00115       dat.setPedMeanG1( rset->getFloat(7) );
00116       dat.setPedRMSG1( rset->getFloat(8) );
00117       dat.setPedMeanG16( rset->getFloat(9) );
00118       dat.setPedRMSG16( rset->getFloat(10) );
00119       dat.setTaskStatus( rset->getInt(11) );
00120       p.second = dat;
00121       fillMap->insert(p);
00122     }
00123   } catch (SQLException &e) {
00124     throw(std::runtime_error("MonPNPedDat::fetchData():  "+e.getMessage()));
00125   }
00126 }
00127 
00128 void MonPNPedDat::writeArrayDB(const std::map< EcalLogicID, MonPNPedDat >* 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("MonPNPedDat::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   float* xx= new float[nrows];
00142   float* yy= new float[nrows];
00143   float* zz= new float[nrows];
00144   float* ww= new float[nrows];
00145   int* st= new int[nrows];
00146 
00147   ub2* ids_len= new ub2[nrows];
00148   ub2* iov_len= new ub2[nrows];
00149   ub2* x_len= new ub2[nrows];
00150   ub2* y_len= new ub2[nrows];
00151   ub2* z_len= new ub2[nrows];
00152   ub2* w_len= new ub2[nrows];
00153 
00154   ub2* st_len= new ub2[nrows];
00155 
00156   const EcalLogicID* channel;
00157   const MonPNPedDat* dataitem;
00158   int count=0;
00159   typedef map< EcalLogicID, MonPNPedDat >::const_iterator CI;
00160   for (CI p = data->begin(); p != data->end(); ++p) {
00161         channel = &(p->first);
00162         int logicID = channel->getLogicID();
00163         if (!logicID) { throw(std::runtime_error("MonPNPedDat::writeArrayDB:  Bad EcalLogicID")); }
00164         ids[count]=logicID;
00165         iovid_vec[count]=iovID;
00166 
00167         dataitem = &(p->second);
00168         // dataIface.writeDB( channel, dataitem, iov);
00169         float x=dataitem->getPedMeanG1();
00170         float y=dataitem->getPedRMSG1();
00171         float z=dataitem->getPedMeanG16();
00172         float w=dataitem->getPedRMSG16();
00173         int statu=dataitem->getTaskStatus();
00174 
00175 
00176 
00177         xx[count]=x;
00178         yy[count]=y;
00179         zz[count]=z;
00180         ww[count]=w;
00181 
00182         st[count]=statu;
00183 
00184 
00185         ids_len[count]=sizeof(ids[count]);
00186         iov_len[count]=sizeof(iovid_vec[count]);
00187         
00188         x_len[count]=sizeof(xx[count]);
00189         y_len[count]=sizeof(yy[count]);
00190         z_len[count]=sizeof(zz[count]);
00191         w_len[count]=sizeof(ww[count]);
00192 
00193         st_len[count]=sizeof(st[count]);
00194 
00195         count++;
00196      }
00197 
00198 
00199   try {
00200     m_writeStmt->setDataBuffer(1, (dvoid*)iovid_vec, OCCIINT, sizeof(iovid_vec[0]),iov_len);
00201     m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len );
00202     m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIFLOAT , sizeof(xx[0]), x_len );
00203     m_writeStmt->setDataBuffer(4, (dvoid*)yy, OCCIFLOAT , sizeof(yy[0]), y_len );
00204     m_writeStmt->setDataBuffer(5, (dvoid*)zz, OCCIFLOAT , sizeof(zz[0]), z_len );
00205     m_writeStmt->setDataBuffer(6, (dvoid*)ww, OCCIFLOAT , sizeof(ww[0]), w_len );
00206     m_writeStmt->setDataBuffer(7, (dvoid*)st, OCCIINT , sizeof(st[0]), st_len );
00207    
00208 
00209     m_writeStmt->executeArrayUpdate(nrows);
00210 
00211     delete [] ids;
00212     delete [] iovid_vec;
00213     delete [] xx;
00214     delete [] yy;
00215     delete [] zz;
00216     delete [] ww;
00217 
00218     delete [] st;
00219 
00220     delete [] ids_len;
00221     delete [] iov_len;
00222     delete [] x_len;
00223     delete [] y_len;
00224     delete [] z_len;
00225     delete [] w_len;
00226 
00227     delete [] st_len;
00228 
00229 
00230 
00231   } catch (SQLException &e) {
00232     throw(std::runtime_error("MonPNPedDat::writeArrayDB():  "+e.getMessage()));
00233   }
00234 }