CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch1/src/OnlineDB/EcalCondDB/src/FEConfigWeightGroupDat.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/FEConfigWeightGroupDat.h"
00006 #include "OnlineDB/EcalCondDB/interface/FEConfigWeightInfo.h"
00007 
00008 using namespace std;
00009 using namespace oracle::occi;
00010 
00011 FEConfigWeightGroupDat::FEConfigWeightGroupDat()
00012 {
00013   m_env = NULL;
00014   m_conn = NULL;
00015   m_writeStmt = NULL;
00016   m_readStmt = NULL;
00017 
00018   m_group_id=0;
00019   m_w0 = 0;
00020   m_w1 = 0;
00021   m_w2 = 0;
00022   m_w3 = 0;
00023   m_w4 = 0;
00024 
00025 }
00026 
00027 
00028 
00029 FEConfigWeightGroupDat::~FEConfigWeightGroupDat()
00030 {
00031 }
00032 
00033 
00034 
00035 void FEConfigWeightGroupDat::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 fe_weight_per_group_dat (wei_conf_id, group_id, "
00043                       " w0, w1, w2, w3, w4 ) "
00044                       "VALUES (:wei_conf_id, :group_id, "
00045                       ":w0, :w1, :w2, :w3, :w4 )" );
00046   } catch (SQLException &e) {
00047     throw(std::runtime_error("FEConfigWeightGroupDat::prepareWrite():  "+e.getMessage()));
00048   }
00049 }
00050 
00051 
00052 
00053 void FEConfigWeightGroupDat::writeDB(const EcalLogicID* ecid, const FEConfigWeightGroupDat* item, FEConfigWeightInfo* iconf)
00054   throw(std::runtime_error)
00055 {
00056   this->checkConnection();
00057   this->checkPrepare();
00058 
00059   int iconfID = iconf->fetchID();
00060   if (!iconfID) { throw(std::runtime_error("FEConfigWeightGroupDat::writeDB:  ICONF not in DB")); }
00061   /* no need for the logic id in this table 
00062      int logicID = ecid->getLogicID();
00063      if (!logicID) { throw(std::runtime_error("FEConfigWeightGroupDat::writeDB:  Bad EcalLogicID")); }
00064   */
00065 
00066   try {
00067     m_writeStmt->setInt(1, iconfID);
00068 
00069     m_writeStmt->setInt(2, item->getWeightGroupId());
00070     m_writeStmt->setFloat(3, item->getWeight0());
00071     m_writeStmt->setFloat(4, item->getWeight1());
00072     m_writeStmt->setFloat(5, item->getWeight2());
00073     m_writeStmt->setFloat(6, item->getWeight3());
00074     m_writeStmt->setFloat(7, item->getWeight4());
00075 
00076     m_writeStmt->executeUpdate();
00077   } catch (SQLException &e) {
00078     throw(std::runtime_error("FEConfigWeightGroupDat::writeDB():  "+e.getMessage()));
00079   }
00080 }
00081 
00082 
00083 
00084 void FEConfigWeightGroupDat::fetchData(map< EcalLogicID, FEConfigWeightGroupDat >* fillMap, FEConfigWeightInfo* iconf)
00085   throw(std::runtime_error)
00086 {
00087   this->checkConnection();
00088   fillMap->clear();
00089 
00090   iconf->setConnection(m_env, m_conn);
00091   int iconfID = iconf->fetchID();
00092   if (!iconfID) { 
00093      throw(std::runtime_error("FEConfigWeightGroupDat::fetchData:  ICONF not in DB")); 
00094     return;
00095   }
00096   
00097   try {
00098 
00099     m_readStmt->setSQL("SELECT d.group_id, d.w0, d.w1, d.w2, d.w3, d.w4 "
00100                  "FROM fe_weight_per_group_dat d "
00101                  "WHERE wei_conf_id = :wei_conf_id order by d.group_id ");
00102     m_readStmt->setInt(1, iconfID);
00103     ResultSet* rset = m_readStmt->executeQuery();
00104     
00105     std::pair< EcalLogicID, FEConfigWeightGroupDat > p;
00106     FEConfigWeightGroupDat dat;
00107     int ig=-1;
00108     while(rset->next()) {
00109       ig++;                          // we create a dummy logic_id
00110       p.first = EcalLogicID( "Group_id",     // name
00111                              ig );        // logic_id
00112                            
00113       dat.setWeightGroupId( rset->getInt(1) );  
00114       dat.setWeight0( rset->getFloat(2) );  
00115       dat.setWeight1( rset->getFloat(3) );  
00116       dat.setWeight2( rset->getFloat(4) );  
00117       dat.setWeight3( rset->getFloat(5) );  
00118       dat.setWeight4( rset->getFloat(6) );  
00119     
00120       p.second = dat;
00121       fillMap->insert(p);
00122     }
00123   } catch (SQLException &e) {
00124     throw(std::runtime_error("FEConfigWeightGroupDat::fetchData:  "+e.getMessage()));
00125   }
00126 }
00127 
00128 void FEConfigWeightGroupDat::writeArrayDB(const std::map< EcalLogicID, FEConfigWeightGroupDat >* data, FEConfigWeightInfo* iconf)
00129   throw(std::runtime_error)
00130 {
00131   this->checkConnection();
00132   this->checkPrepare();
00133 
00134   int iconfID = iconf->fetchID();
00135   if (!iconfID) { throw(std::runtime_error("FEConfigWeightGroupDat::writeArrayDB:  ICONF not in DB")); }
00136 
00137 
00138   int nrows=data->size(); 
00139   int* ids= new int[nrows];
00140   int* iconfid_vec= new int[nrows];
00141   int* xx= new int[nrows];
00142   float* yy= new float[nrows];
00143   float* zz= new float[nrows];
00144   float* rr= new float[nrows];
00145   float* ss= new float[nrows];
00146   float* tt= new float[nrows];
00147 
00148 
00149   ub2* ids_len= new ub2[nrows];
00150   ub2* iconf_len= new ub2[nrows];
00151   ub2* x_len= new ub2[nrows];
00152   ub2* y_len= new ub2[nrows];
00153   ub2* z_len= new ub2[nrows];
00154   ub2* r_len= new ub2[nrows];
00155   ub2* s_len= new ub2[nrows];
00156   ub2* t_len= new ub2[nrows];
00157 
00158 
00159   // const EcalLogicID* channel;
00160   const FEConfigWeightGroupDat* dataitem;
00161   int count=0;
00162   typedef map< EcalLogicID, FEConfigWeightGroupDat >::const_iterator CI;
00163   for (CI p = data->begin(); p != data->end(); ++p) {
00164         // channel = &(p->first);
00165         //      int logicID = channel->getLogicID();
00166         //      if (!logicID) { throw(std::runtime_error("FEConfigWeightGroupDat::writeArrayDB:  Bad EcalLogicID")); }
00167         //      ids[count]=logicID;
00168         iconfid_vec[count]=iconfID;
00169 
00170         dataitem = &(p->second);
00171         // dataIface.writeDB( channel, dataitem, iconf);
00172         int x=dataitem->getWeightGroupId();
00173         float y=dataitem->getWeight0();
00174         float z=dataitem->getWeight1();
00175         float r=dataitem->getWeight2();
00176         float s=dataitem->getWeight3();
00177         float t=dataitem->getWeight4();
00178 
00179         xx[count]=x;
00180         yy[count]=y;
00181         zz[count]=z;
00182         rr[count]=r;
00183         ss[count]=s;
00184         tt[count]=t;
00185 
00186         //      ids_len[count]=sizeof(ids[count]);
00187         iconf_len[count]=sizeof(iconfid_vec[count]);
00188         
00189         x_len[count]=sizeof(xx[count]);
00190         y_len[count]=sizeof(yy[count]);
00191         z_len[count]=sizeof(zz[count]);
00192         r_len[count]=sizeof(rr[count]);
00193         s_len[count]=sizeof(ss[count]);
00194         t_len[count]=sizeof(tt[count]);
00195 
00196         count++;
00197      }
00198 
00199 
00200   try {
00201     m_writeStmt->setDataBuffer(1, (dvoid*)iconfid_vec, OCCIINT, sizeof(iconfid_vec[0]),iconf_len);
00202     m_writeStmt->setDataBuffer(2, (dvoid*)xx, OCCIINT, sizeof(xx[0]), x_len );
00203     m_writeStmt->setDataBuffer(3, (dvoid*)yy, OCCIFLOAT , sizeof(yy[0]), y_len );
00204     m_writeStmt->setDataBuffer(4, (dvoid*)zz, OCCIFLOAT , sizeof(zz[0]), z_len );
00205     m_writeStmt->setDataBuffer(5, (dvoid*)rr, OCCIFLOAT , sizeof(rr[0]), r_len );
00206     m_writeStmt->setDataBuffer(6, (dvoid*)ss, OCCIFLOAT , sizeof(ss[0]), s_len );
00207     m_writeStmt->setDataBuffer(7, (dvoid*)tt, OCCIFLOAT , sizeof(tt[0]), t_len );
00208 
00209     m_writeStmt->executeArrayUpdate(nrows);
00210 
00211     delete [] ids;
00212     delete [] iconfid_vec;
00213     delete [] xx;
00214     delete [] yy;
00215     delete [] zz;
00216     delete [] rr;
00217     delete [] ss;
00218     delete [] tt;
00219 
00220     delete [] ids_len;
00221     delete [] iconf_len;
00222     delete [] x_len;
00223     delete [] y_len;
00224     delete [] z_len;
00225     delete [] r_len;
00226     delete [] s_len;
00227     delete [] t_len;
00228 
00229   } catch (SQLException &e) {
00230     throw(std::runtime_error("FEConfigWeightGroupDat::writeArrayDB():  "+e.getMessage()));
00231   }
00232 }