CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/OnlineDB/EcalCondDB/src/FEConfigLinDat.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/FEConfigLinDat.h"
00006 #include "OnlineDB/EcalCondDB/interface/FEConfigLinInfo.h"
00007 
00008 using namespace std;
00009 using namespace oracle::occi;
00010 
00011 FEConfigLinDat::FEConfigLinDat()
00012 {
00013   m_env = NULL;
00014   m_conn = NULL;
00015   m_writeStmt = NULL;
00016   m_readStmt = NULL;
00017 
00018   m_multx12 = 0;
00019   m_multx6 = 0;
00020   m_multx1 = 0;
00021   m_shift12 = 0;
00022   m_shift6 = 0;
00023   m_shift1 = 0;
00024 
00025 
00026 }
00027 
00028 
00029 
00030 FEConfigLinDat::~FEConfigLinDat()
00031 {
00032 }
00033 
00034 
00035 
00036 void FEConfigLinDat::prepareWrite()
00037   throw(std::runtime_error)
00038 {
00039   this->checkConnection();
00040 
00041   try {
00042     m_writeStmt = m_conn->createStatement();
00043     m_writeStmt->setSQL("INSERT INTO fe_config_lin_dat (lin_conf_id, logic_id, "
00044                       " multx12, multx6, multx1, shift12, shift6, shift1 ) "
00045                       "VALUES (:lin_conf_id, :logic_id, "
00046                       ":multx12, :multx6, :multx1, :shift12, :shift6, :shift1 )" );
00047   } catch (SQLException &e) {
00048     throw(std::runtime_error("FEConfigLinDat::prepareWrite():  "+e.getMessage()));
00049   }
00050 }
00051 
00052 
00053 
00054 void FEConfigLinDat::writeDB(const EcalLogicID* ecid, const FEConfigLinDat* item, FEConfigLinInfo* iconf)
00055   throw(std::runtime_error)
00056 {
00057   this->checkConnection();
00058   this->checkPrepare();
00059 
00060   int iconfID = iconf->fetchID();
00061   if (!iconfID) { throw(std::runtime_error("FEConfigLinDat::writeDB:  ICONF not in DB")); }
00062 
00063   int logicID = ecid->getLogicID();
00064   if (!logicID) { throw(std::runtime_error("FEConfigLinDat::writeDB:  Bad EcalLogicID")); }
00065  
00066   try {
00067     m_writeStmt->setInt(1, iconfID);
00068     m_writeStmt->setInt(2, logicID);
00069     m_writeStmt->setInt(3, item->getMultX12());
00070     m_writeStmt->setInt(4, item->getMultX6());
00071     m_writeStmt->setInt(5, item->getMultX1());
00072     m_writeStmt->setInt(6, item->getShift12());
00073     m_writeStmt->setInt(7, item->getShift6());
00074     m_writeStmt->setInt(8, item->getShift1());
00075 
00076     m_writeStmt->executeUpdate();
00077   } catch (SQLException &e) {
00078     throw(std::runtime_error("FEConfigLinDat::writeDB():  "+e.getMessage()));
00079   }
00080 }
00081 
00082 
00083 
00084 void FEConfigLinDat::fetchData(map< EcalLogicID, FEConfigLinDat >* fillMap, FEConfigLinInfo* 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("FEConfigLinDat::writeDB:  ICONF not in DB")); 
00094     return;
00095   }
00096   
00097   try {
00098 
00099     m_readStmt->setSQL("SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
00100                  "d.multx12, d.multx6, d.multx1, d.shift12, d.shift6, d.shift1 "
00101                  "FROM channelview cv JOIN fe_config_lin_dat d "
00102                  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
00103                  "WHERE lin_conf_id = :lin_conf_id");
00104     m_readStmt->setInt(1, iconfID);
00105     ResultSet* rset = m_readStmt->executeQuery();
00106     
00107     std::pair< EcalLogicID, FEConfigLinDat > p;
00108     FEConfigLinDat dat;
00109     while(rset->next()) {
00110       p.first = EcalLogicID( rset->getString(1),     // name
00111                              rset->getInt(2),        // logic_id
00112                              rset->getInt(3),        // id1
00113                              rset->getInt(4),        // id2
00114                              rset->getInt(5),        // id3
00115                              rset->getString(6));    // maps_to
00116 
00117       dat.setMultX12( rset->getInt(7) );  
00118       dat.setMultX6( rset->getInt(8) );  
00119       dat.setMultX1( rset->getInt(9) );  
00120       dat.setShift12( rset->getInt(10) );  
00121       dat.setShift6( rset->getInt(11) );  
00122       dat.setShift1( rset->getInt(12) );  
00123     
00124       p.second = dat;
00125       fillMap->insert(p);
00126     }
00127   } catch (SQLException &e) {
00128     throw(std::runtime_error("FEConfigLinDat::fetchData:  "+e.getMessage()));
00129   }
00130 }
00131 
00132 void FEConfigLinDat::writeArrayDB(const std::map< EcalLogicID, FEConfigLinDat >* data, FEConfigLinInfo* iconf)
00133   throw(std::runtime_error)
00134 {
00135   this->checkConnection();
00136   this->checkPrepare();
00137 
00138   int iconfID = iconf->fetchID();
00139   if (!iconfID) { throw(std::runtime_error("FEConfigLinDat::writeArrayDB:  ICONF not in DB")); }
00140 
00141 
00142   int nrows=data->size(); 
00143   int* ids= new int[nrows];
00144   int* iconfid_vec= new int[nrows];
00145   int* xx= new int[nrows];
00146   int* yy= new int[nrows];
00147   int* zz= new int[nrows];
00148   int* ww= new int[nrows];
00149   int* rr= new int[nrows];
00150   int* ss= new int[nrows];
00151 
00152   ub2* ids_len= new ub2[nrows];
00153   ub2* iconf_len= new ub2[nrows];
00154   ub2* x_len= new ub2[nrows];
00155   ub2* y_len= new ub2[nrows];
00156   ub2* z_len= new ub2[nrows];
00157   ub2* w_len= new ub2[nrows];
00158   ub2* r_len= new ub2[nrows];
00159   ub2* s_len= new ub2[nrows];
00160 
00161 
00162   const EcalLogicID* channel;
00163   const FEConfigLinDat* dataitem;
00164   int count=0;
00165   typedef map< EcalLogicID, FEConfigLinDat >::const_iterator CI;
00166   for (CI p = data->begin(); p != data->end(); ++p) {
00167         channel = &(p->first);
00168         int logicID = channel->getLogicID();
00169         if (!logicID) { throw(std::runtime_error("FEConfigLinDat::writeArrayDB:  Bad EcalLogicID")); }
00170         ids[count]=logicID;
00171         iconfid_vec[count]=iconfID;
00172 
00173         dataitem = &(p->second);
00174         // dataIface.writeDB( channel, dataitem, iconf);
00175         int x=dataitem->getMultX12();
00176         int y=dataitem->getMultX6();
00177         int z=dataitem->getMultX1();
00178         int w=dataitem->getShift12();
00179         int r=dataitem->getShift6();
00180         int s=dataitem->getShift1();
00181 
00182         xx[count]=x;
00183         yy[count]=y;
00184         zz[count]=z;
00185         ww[count]=w;
00186         rr[count]=r;
00187         ss[count]=s;
00188 
00189         ids_len[count]=sizeof(ids[count]);
00190         iconf_len[count]=sizeof(iconfid_vec[count]);
00191         
00192         x_len[count]=sizeof(xx[count]);
00193         y_len[count]=sizeof(yy[count]);
00194         z_len[count]=sizeof(zz[count]);
00195         w_len[count]=sizeof(ww[count]);
00196         r_len[count]=sizeof(rr[count]);
00197         s_len[count]=sizeof(ss[count]);
00198 
00199         count++;
00200      }
00201 
00202 
00203   try {
00204     m_writeStmt->setDataBuffer(1, (dvoid*)iconfid_vec, OCCIINT, sizeof(iconfid_vec[0]),iconf_len);
00205     m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len );
00206     m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIINT , sizeof(xx[0]), x_len );
00207     m_writeStmt->setDataBuffer(4, (dvoid*)yy, OCCIINT , sizeof(yy[0]), y_len );
00208     m_writeStmt->setDataBuffer(5, (dvoid*)zz, OCCIINT , sizeof(zz[0]), z_len );
00209     m_writeStmt->setDataBuffer(6, (dvoid*)ww, OCCIINT , sizeof(ww[0]), w_len );
00210     m_writeStmt->setDataBuffer(7, (dvoid*)rr, OCCIINT , sizeof(rr[0]), r_len );
00211     m_writeStmt->setDataBuffer(8, (dvoid*)ss, OCCIINT , sizeof(ss[0]), s_len );
00212 
00213     m_writeStmt->executeArrayUpdate(nrows);
00214 
00215     delete [] ids;
00216     delete [] iconfid_vec;
00217     delete [] xx;
00218     delete [] yy;
00219     delete [] zz;
00220     delete [] ww;
00221     delete [] rr;
00222     delete [] ss;
00223 
00224     delete [] ids_len;
00225     delete [] iconf_len;
00226     delete [] x_len;
00227     delete [] y_len;
00228     delete [] z_len;
00229     delete [] w_len;
00230     delete [] r_len;
00231     delete [] s_len;
00232 
00233   } catch (SQLException &e) {
00234     throw(std::runtime_error("FEConfigLinDat::writeArrayDB():  "+e.getMessage()));
00235   }
00236 }