00001 #include <stdexcept>
00002 #include <string>
00003 #include "OnlineDB/Oracle/interface/Oracle.h"
00004
00005 #include "OnlineDB/EcalCondDB/interface/FEConfigFgrGroupDat.h"
00006 #include "OnlineDB/EcalCondDB/interface/FEConfigFgrInfo.h"
00007
00008 using namespace std;
00009 using namespace oracle::occi;
00010
00011 FEConfigFgrGroupDat::FEConfigFgrGroupDat()
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_thresh_low = 0;
00020 m_thresh_high = 0;
00021 m_ratio_low = 0;
00022 m_ratio_high = 0;
00023 m_lut = 0;
00024
00025 }
00026
00027
00028
00029 FEConfigFgrGroupDat::~FEConfigFgrGroupDat()
00030 {
00031 }
00032
00033
00034
00035 void FEConfigFgrGroupDat::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_fgr_per_group_dat (fgr_conf_id, group_id, "
00043 " threshold_low, threshold_high, ratio_low, ratio_high, lut_value ) "
00044 "VALUES (:fgr_conf_id, :group_id, "
00045 ":3, :4, :5, :6, :7 )" );
00046 } catch (SQLException &e) {
00047 throw(std::runtime_error("FEConfigFgrGroupDat::prepareWrite(): "+e.getMessage()));
00048 }
00049 }
00050
00051
00052
00053 void FEConfigFgrGroupDat::writeDB(const EcalLogicID* ecid, const FEConfigFgrGroupDat* item, FEConfigFgrInfo* 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("FEConfigFgrGroupDat::writeDB: ICONF not in DB")); }
00061
00062
00063
00064
00065
00066 try {
00067 m_writeStmt->setInt(1, iconfID);
00068
00069 m_writeStmt->setInt(2, item->getFgrGroupId());
00070 m_writeStmt->setFloat(3, item->getThreshLow());
00071 m_writeStmt->setFloat(4, item->getThreshHigh());
00072 m_writeStmt->setFloat(5, item->getRatioLow());
00073 m_writeStmt->setFloat(6, item->getRatioHigh());
00074 m_writeStmt->setInt(7, item->getLUTValue());
00075
00076 m_writeStmt->executeUpdate();
00077 } catch (SQLException &e) {
00078 throw(std::runtime_error("FEConfigFgrGroupDat::writeDB(): "+e.getMessage()));
00079 }
00080 }
00081
00082
00083
00084 void FEConfigFgrGroupDat::fetchData(map< EcalLogicID, FEConfigFgrGroupDat >* fillMap, FEConfigFgrInfo* 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("FEConfigFgrGroupDat::fetchData: ICONF not in DB"));
00094 return;
00095 }
00096
00097 try {
00098
00099 m_readStmt->setSQL("SELECT d.group_id, d.threshold_low, d.threshold_high, d.ratio_low, d.ratio_high, d.lut_value "
00100 "FROM fe_fgr_per_group_dat d "
00101 "WHERE fgr_conf_id = :fgr_conf_id order by d.group_id ");
00102 m_readStmt->setInt(1, iconfID);
00103 ResultSet* rset = m_readStmt->executeQuery();
00104
00105 std::pair< EcalLogicID, FEConfigFgrGroupDat > p;
00106 FEConfigFgrGroupDat dat;
00107 int ig=-1;
00108 while(rset->next()) {
00109 ig++;
00110 p.first = EcalLogicID( "Group_id",
00111 ig );
00112
00113 dat.setFgrGroupId( rset->getInt(1) );
00114 dat.setThreshLow( rset->getFloat(2) );
00115 dat.setThreshHigh( rset->getFloat(3) );
00116 dat.setRatioLow( rset->getFloat(4) );
00117 dat.setRatioHigh( rset->getFloat(5) );
00118 dat.setLUTValue( rset->getInt(6) );
00119
00120 p.second = dat;
00121 fillMap->insert(p);
00122 }
00123 } catch (SQLException &e) {
00124 throw(std::runtime_error("FEConfigFgrGroupDat::fetchData: "+e.getMessage()));
00125 }
00126 }
00127
00128 void FEConfigFgrGroupDat::writeArrayDB(const std::map< EcalLogicID, FEConfigFgrGroupDat >* data, FEConfigFgrInfo* 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("FEConfigFgrGroupDat::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 int* tt= new int[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
00160 const FEConfigFgrGroupDat* dataitem;
00161 int count=0;
00162 typedef map< EcalLogicID, FEConfigFgrGroupDat >::const_iterator CI;
00163 for (CI p = data->begin(); p != data->end(); ++p) {
00164
00165
00166
00167
00168 iconfid_vec[count]=iconfID;
00169
00170 dataitem = &(p->second);
00171
00172 int x=dataitem->getFgrGroupId();
00173 float y=dataitem->getThreshLow();
00174 float z=dataitem->getThreshHigh();
00175 float r=dataitem->getRatioLow();
00176 float s=dataitem->getRatioHigh();
00177 int t=dataitem->getLUTValue();
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
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, OCCIINT , 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("FEConfigFgrGroupDat::writeArrayDB(): "+e.getMessage()));
00231 }
00232 }