CMS 3D CMS Logo

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