CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FEConfigParamDat.cc
Go to the documentation of this file.
1 #include <stdexcept>
2 #include <string>
4 
7 
8 using namespace std;
9 using namespace oracle::occi;
10 
12 {
13  m_env = NULL;
14  m_conn = NULL;
15  m_writeStmt = NULL;
16  m_readStmt = NULL;
17 
18  m_etsat = 0;
19  m_tthreshlow = 0;
20  m_tthreshhigh = 0;
21  m_fglowthresh = 0;
22  m_fghighthresh = 0;
23  m_lowratio = 0;
24  m_highratio = 0;
25 
26 }
27 
28 
29 
31 {
32 }
33 
34 
35 
37  throw(std::runtime_error)
38 {
39  this->checkConnection();
40 
41  try {
42  m_writeStmt = m_conn->createStatement();
43  m_writeStmt->setSQL("INSERT INTO fe_config_param_dat (lin_conf_id, logic_id, "
44  " etsat, ttthreshlow, ttthreshhigh, fg_lowthresh, fg_highthresh, fg_lowratio, fg_highratio ) "
45  "VALUES (:lin_conf_id, :logic_id, "
46  ":etsat, :ttthreshlow, :ttthreshhigh, :fg_lowthresh, :fg_highthresh, :fg_lowratio, :fg_highratio )" );
47  } catch (SQLException &e) {
48  throw(std::runtime_error("FEConfigParamDat::prepareWrite(): "+e.getMessage()));
49  }
50 }
51 
52 
53 
55  throw(std::runtime_error)
56 {
57  this->checkConnection();
58  this->checkPrepare();
59 
60  int iconfID = iconf->fetchID();
61  if (!iconfID) { throw(std::runtime_error("FEConfigParamDat::writeDB: ICONF not in DB")); }
62 
63  int logicID = ecid->getLogicID();
64  if (!logicID) { throw(std::runtime_error("FEConfigParamDat::writeDB: Bad EcalLogicID")); }
65 
66  try {
67  m_writeStmt->setInt(1, iconfID);
68  m_writeStmt->setInt(2, logicID);
69  m_writeStmt->setFloat(3, item->getETSat());
70  m_writeStmt->setFloat(4, item->getTTThreshlow());
71  m_writeStmt->setFloat(5, item->getTTThreshhigh());
72  m_writeStmt->setFloat(6, item->getFGlowthresh());
73  m_writeStmt->setFloat(7, item->getFGhighthresh());
74  m_writeStmt->setFloat(8, item->getFGlowratio());
75  m_writeStmt->setFloat(9, item->getFGhighratio());
76 
77  m_writeStmt->executeUpdate();
78  } catch (SQLException &e) {
79  throw(std::runtime_error("FEConfigParamDat::writeDB(): "+e.getMessage()));
80  }
81 }
82 
83 
84 
85 void FEConfigParamDat::fetchData(map< EcalLogicID, FEConfigParamDat >* fillMap, FEConfigLinInfo* iconf)
86  throw(std::runtime_error)
87 {
88  this->checkConnection();
89  fillMap->clear();
90 
91  iconf->setConnection(m_env, m_conn);
92  int iconfID = iconf->fetchID();
93  if (!iconfID) {
94  // throw(std::runtime_error("FEConfigParamDat::writeDB: ICONF not in DB"));
95  return;
96  }
97 
98  try {
99 
100  m_readStmt->setSQL("SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
101  " d.etsat, d.ttthreshlow, d.ttthreshhigh, d.fg_lowthresh, d.fg_highthresh, d.fg_lowratio, d.fg_highratio "
102  "FROM channelview cv JOIN fe_config_param_dat d "
103  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
104  "WHERE lin_conf_id = :lin_conf_id");
105  m_readStmt->setInt(1, iconfID);
106  ResultSet* rset = m_readStmt->executeQuery();
107 
108  std::pair< EcalLogicID, FEConfigParamDat > p;
109  FEConfigParamDat dat;
110  while(rset->next()) {
111  p.first = EcalLogicID( rset->getString(1), // name
112  rset->getInt(2), // logic_id
113  rset->getInt(3), // id1
114  rset->getInt(4), // id2
115  rset->getInt(5), // id3
116  rset->getString(6)); // maps_to
117 
118 
119 
120  dat.setETSat( rset->getFloat(7) );
121  dat.setTTThreshlow( rset->getFloat(8) );
122  dat.setTTThreshhigh( rset->getFloat(9) );
123  dat.setFGlowthresh( rset->getFloat(10) );
124  dat.setFGhighthresh( rset->getFloat(11) );
125  dat.setFGlowratio( rset->getFloat(12) );
126  dat.setFGhighratio( rset->getFloat(13) );
127 
128  p.second = dat;
129  fillMap->insert(p);
130  }
131  } catch (SQLException &e) {
132  throw(std::runtime_error("FEConfigParamDat::fetchData: "+e.getMessage()));
133  }
134 }
135 
136 void FEConfigParamDat::writeArrayDB(const std::map< EcalLogicID, FEConfigParamDat >* data, FEConfigLinInfo* iconf)
137  throw(std::runtime_error)
138 {
139  this->checkConnection();
140  this->checkPrepare();
141 
142  int iconfID = iconf->fetchID();
143  if (!iconfID) { throw(std::runtime_error("FEConfigParamDat::writeArrayDB: ICONF not in DB")); }
144 
145 
146  int nrows=data->size();
147  int* ids= new int[nrows];
148  int* iov_vec= new int[nrows];
149  float* xx= new float[nrows];
150  float* yy= new float[nrows];
151  float* zz= new float[nrows];
152  float* ww= new float[nrows];
153  float* uu= new float[nrows];
154  float* tt= new float[nrows];
155  float* st= new float[nrows];
156 
157  ub2* ids_len= new ub2[nrows];
158  ub2* iov_len= new ub2[nrows];
159  ub2* x_len= new ub2[nrows];
160  ub2* y_len= new ub2[nrows];
161  ub2* z_len= new ub2[nrows];
162  ub2* w_len= new ub2[nrows];
163  ub2* u_len= new ub2[nrows];
164  ub2* t_len= new ub2[nrows];
165  ub2* st_len= new ub2[nrows];
166 
167  const EcalLogicID* channel;
168  const FEConfigParamDat* dataitem;
169  int count=0;
170  typedef map< EcalLogicID, FEConfigParamDat >::const_iterator CI;
171  for (CI p = data->begin(); p != data->end(); ++p) {
172  channel = &(p->first);
173  int logicID = channel->getLogicID();
174  if (!logicID) { throw(std::runtime_error("FEConfigParamDat::writeArrayDB: Bad EcalLogicID")); }
175  ids[count]=logicID;
176  iov_vec[count]=iconfID;
177 
178  dataitem = &(p->second);
179  // dataIface.writeDB( channel, dataitem, conf);
180  float x=dataitem->getETSat();
181  float y=dataitem->getTTThreshlow();
182  float z=dataitem->getTTThreshhigh();
183  float w=dataitem->getFGlowthresh();
184  float u=dataitem->getFGhighthresh();
185  float t=dataitem->getFGlowratio();
186  float r=dataitem->getFGhighratio();
187 
188  xx[count]=x;
189  yy[count]=y;
190  zz[count]=z;
191  ww[count]=w;
192  uu[count]=u;
193  tt[count]=t;
194  st[count]=r;
195 
196 
197  ids_len[count]=sizeof(ids[count]);
198  iov_len[count]=sizeof(iov_vec[count]);
199 
200  x_len[count]=sizeof(xx[count]);
201  y_len[count]=sizeof(yy[count]);
202  z_len[count]=sizeof(zz[count]);
203  w_len[count]=sizeof(ww[count]);
204  u_len[count]=sizeof(uu[count]);
205  t_len[count]=sizeof(tt[count]);
206  st_len[count]=sizeof(st[count]);
207 
208  count++;
209  }
210 
211 
212  try {
213  m_writeStmt->setDataBuffer(1, (dvoid*)iov_vec, OCCIINT, sizeof(iov_vec[0]),iov_len);
214  m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len );
215  m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIFLOAT , sizeof(xx[0]), x_len );
216  m_writeStmt->setDataBuffer(4, (dvoid*)yy, OCCIFLOAT , sizeof(yy[0]), y_len );
217  m_writeStmt->setDataBuffer(5, (dvoid*)zz, OCCIFLOAT , sizeof(zz[0]), z_len );
218  m_writeStmt->setDataBuffer(6, (dvoid*)ww, OCCIFLOAT , sizeof(ww[0]), w_len );
219  m_writeStmt->setDataBuffer(7, (dvoid*)uu, OCCIFLOAT , sizeof(uu[0]), u_len );
220  m_writeStmt->setDataBuffer(8, (dvoid*)tt, OCCIFLOAT , sizeof(tt[0]), t_len );
221  m_writeStmt->setDataBuffer(9, (dvoid*)st, OCCIFLOAT , sizeof(st[0]), st_len );
222 
223 
224  m_writeStmt->executeArrayUpdate(nrows);
225 
226  delete [] ids;
227  delete [] iov_vec;
228  delete [] xx;
229  delete [] yy;
230  delete [] zz;
231  delete [] ww;
232  delete [] uu;
233  delete [] tt;
234  delete [] st;
235 
236  delete [] ids_len;
237  delete [] iov_len;
238  delete [] x_len;
239  delete [] y_len;
240  delete [] z_len;
241  delete [] w_len;
242  delete [] u_len;
243  delete [] t_len;
244  delete [] st_len;
245 
246  } catch (SQLException &e) {
247  throw(std::runtime_error("FEConfigParamDat::writeArrayDB(): "+e.getMessage()));
248  }
249 }
float getTTThreshlow() const
void setTTThreshlow(float x)
void fetchData(std::map< EcalLogicID, FEConfigParamDat > *fillMap, FEConfigLinInfo *iconf)
void setFGlowratio(float x)
float getETSat() const
const double w
Definition: UKUtility.cc:23
void setFGlowthresh(float x)
void writeArrayDB(const std::map< EcalLogicID, FEConfigParamDat > *data, FEConfigLinInfo *iconf)
#define NULL
Definition: scimark2.h:8
void setFGhighthresh(float x)
void setETSat(float x)
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:27
float getFGhighthresh() const
float getFGlowratio() const
int getLogicID() const
Definition: EcalLogicID.cc:41
void writeDB(const EcalLogicID *ecid, const FEConfigParamDat *item, FEConfigLinInfo *iconf)
float getFGlowthresh() const
float getTTThreshhigh() const
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:26
void setTTThreshhigh(float x)
float getFGhighratio() const
void setFGhighratio(float x)