CMS 3D CMS Logo

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