CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/OnlineDB/EcalCondDB/src/FEConfigPedDat.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/FEConfigPedDat.h"
00006 #include "OnlineDB/EcalCondDB/interface/FEConfigPedInfo.h"
00007 
00008 using namespace std;
00009 using namespace oracle::occi;
00010 
00011 FEConfigPedDat::FEConfigPedDat()
00012 {
00013   m_env = NULL;
00014   m_conn = NULL;
00015   m_writeStmt = NULL;
00016   m_readStmt = NULL;
00017   m_ID=0;
00018   m_pedMeanG1 = 0;
00019   m_pedMeanG6 = 0;
00020   m_pedMeanG12 = 0;
00021 
00022 }
00023 
00024 
00025 
00026 FEConfigPedDat::~FEConfigPedDat()
00027 {
00028 }
00029 
00030 
00031 void FEConfigPedDat::prepareWrite()
00032   throw(std::runtime_error)
00033 {
00034   this->checkConnection();
00035 
00036   try {
00037     m_writeStmt = m_conn->createStatement();
00038 
00039     m_writeStmt->setSQL("INSERT INTO "+getTable()+" (ped_conf_id, logic_id, "
00040                       "mean_12, mean_6, mean_1 ) "
00041                       "VALUES (:ped_conf_id, :logic_id, "
00042                       ":ped_mean_g12, :ped_mean_g6, :ped_mean_g1 )" );
00043   } catch (SQLException &e) {
00044     throw(std::runtime_error("FEConfigPedDat::prepareWrite():  "+e.getMessage()));
00045   }
00046 }
00047 
00048 
00049 
00050 void FEConfigPedDat::writeDB(const EcalLogicID* ecid, const FEConfigPedDat* item, FEConfigPedInfo* iconf )
00051   throw(std::runtime_error)
00052 {
00053   this->checkConnection();
00054 
00055   int iconfID = iconf->fetchID();
00056   if (!iconfID) { throw(std::runtime_error("FEConfigPedDat::writeDB:  ICONF not in DB")); }
00057 
00058   int logicID = ecid->getLogicID();
00059   if (!logicID) { throw(std::runtime_error("FEConfigPedDat::writeDB:  Bad EcalLogicID")); }
00060  
00061   try {
00062     m_writeStmt->setInt(1, iconfID);
00063     m_writeStmt->setInt(2, logicID);
00064     m_writeStmt->setFloat(3, item->getPedMeanG12());
00065     m_writeStmt->setFloat(4, item->getPedMeanG6());
00066     m_writeStmt->setFloat(5, item->getPedMeanG1());
00067 
00068     m_writeStmt->executeUpdate();
00069   } catch (SQLException &e) {
00070     throw(std::runtime_error("FEConfigPedDat::writeDB():  "+e.getMessage()));
00071   }
00072 }
00073 
00074 
00075 void FEConfigPedDat::fetchData(map< EcalLogicID, FEConfigPedDat >* fillMap, FEConfigPedInfo* iconf)
00076   throw(std::runtime_error)
00077 {
00078   this->checkConnection();
00079   fillMap->clear();
00080 
00081   iconf->setConnection(m_env, m_conn);
00082   int iconfID = iconf->fetchID();
00083   if (!iconfID) { 
00084     //  throw(std::runtime_error("FEConfigPedDat::writeDB:  ICONF not in DB")); 
00085     return;
00086   }
00087   
00088   try {
00089 
00090     m_readStmt->setSQL("SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
00091                  "d.mean_12, d.mean_6, d.mean_1 "
00092                  "FROM channelview cv JOIN fe_config_ped_dat d "
00093                  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
00094                  "WHERE ped_conf_id = :ped_conf_id");
00095     m_readStmt->setInt(1, iconfID);
00096     ResultSet* rset = m_readStmt->executeQuery();
00097     
00098     std::pair< EcalLogicID, FEConfigPedDat > p;
00099     FEConfigPedDat dat;
00100     while(rset->next()) {
00101       p.first = EcalLogicID( rset->getString(1),     // name
00102                              rset->getInt(2),        // logic_id
00103                              rset->getInt(3),        // id1
00104                              rset->getInt(4),        // id2
00105                              rset->getInt(5),        // id3
00106                              rset->getString(6));    // maps_to
00107 
00108       dat.setPedMeanG12( rset->getFloat(7) );  
00109       dat.setPedMeanG6( rset->getFloat(8) );
00110       dat.setPedMeanG1( rset->getFloat(9) );
00111     
00112       p.second = dat;
00113       fillMap->insert(p);
00114     }
00115   } catch (SQLException &e) {
00116     throw(std::runtime_error("FEConfigPedDat::fetchData:  "+e.getMessage()));
00117   }
00118 }
00119 
00120 void FEConfigPedDat::writeArrayDB(const std::map< EcalLogicID, FEConfigPedDat >* data, FEConfigPedInfo* iconf)
00121   throw(std::runtime_error)
00122 {
00123   this->checkConnection();
00124   this->checkPrepare();
00125 
00126   int iconfID = iconf->fetchID();
00127   if (!iconfID) { throw(std::runtime_error("FEConfigPedDat::writeArrayDB:  ICONF not in DB")); }
00128 
00129 
00130   int nrows=data->size(); 
00131   int* ids= new int[nrows];
00132   int* iconfid_vec= new int[nrows];
00133   float* xx= new float[nrows];
00134   float* yy= new float[nrows];
00135   float* zz= new float[nrows];
00136 
00137 
00138   ub2* ids_len= new ub2[nrows];
00139   ub2* iconf_len= new ub2[nrows];
00140   ub2* x_len= new ub2[nrows];
00141   ub2* y_len= new ub2[nrows];
00142   ub2* z_len= new ub2[nrows];
00143 
00144 
00145   const EcalLogicID* channel;
00146   const FEConfigPedDat* dataitem;
00147   int count=0;
00148   typedef map< EcalLogicID, FEConfigPedDat >::const_iterator CI;
00149   for (CI p = data->begin(); p != data->end(); ++p) {
00150         channel = &(p->first);
00151         int logicID = channel->getLogicID();
00152         if (!logicID) { throw(std::runtime_error("FEConfigPedDat::writeArrayDB:  Bad EcalLogicID")); }
00153         ids[count]=logicID;
00154         iconfid_vec[count]=iconfID;
00155 
00156         dataitem = &(p->second);
00157         // dataIface.writeDB( channel, dataitem, iconf);
00158         float x=dataitem->getPedMeanG12();
00159         float y=dataitem->getPedMeanG6();
00160         float z=dataitem->getPedMeanG1();
00161 
00162         xx[count]=x;
00163         yy[count]=y;
00164         zz[count]=z;
00165 
00166         ids_len[count]=sizeof(ids[count]);
00167         iconf_len[count]=sizeof(iconfid_vec[count]);
00168         
00169         x_len[count]=sizeof(xx[count]);
00170         y_len[count]=sizeof(yy[count]);
00171         z_len[count]=sizeof(zz[count]);
00172 
00173         count++;
00174      }
00175 
00176 
00177   try {
00178     m_writeStmt->setDataBuffer(1, (dvoid*)iconfid_vec, OCCIINT, sizeof(iconfid_vec[0]),iconf_len);
00179     m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len );
00180     m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIFLOAT , sizeof(xx[0]), x_len );
00181     m_writeStmt->setDataBuffer(4, (dvoid*)yy, OCCIFLOAT , sizeof(yy[0]), y_len );
00182     m_writeStmt->setDataBuffer(5, (dvoid*)zz, OCCIFLOAT , sizeof(zz[0]), z_len );
00183 
00184     m_writeStmt->executeArrayUpdate(nrows);
00185 
00186     delete [] ids;
00187     delete [] iconfid_vec;
00188     delete [] xx;
00189     delete [] yy;
00190     delete [] zz;
00191 
00192     delete [] ids_len;
00193     delete [] iconf_len;
00194     delete [] x_len;
00195     delete [] y_len;
00196     delete [] z_len;
00197 
00198   } catch (SQLException &e) {
00199     throw(std::runtime_error("FEConfigPedDat::writeArrayDB():  "+e.getMessage()));
00200   }
00201 }