CMS 3D CMS Logo

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