CMS 3D CMS Logo

FEConfigOddWeightGroupDat.cc
Go to the documentation of this file.
1 #include <stdexcept>
2 #include <string>
4 
8 
9 using namespace std;
10 using namespace oracle::occi;
11 
13  m_env = nullptr;
14  m_conn = nullptr;
15  m_writeStmt = nullptr;
16  m_readStmt = nullptr;
17 
18  m_group_id = 0;
19  m_w0 = 0;
20  m_w1 = 0;
21  m_w2 = 0;
22  m_w3 = 0;
23  m_w4 = 0;
24  m_w5 = 0;
25 }
26 
28 
30  this->checkConnection();
31 
32  try {
33  m_writeStmt = m_conn->createStatement();
34  m_writeStmt->setSQL(
35  "INSERT INTO fe_weight2_per_group_dat (wei2_conf_id, group_id, "
36  " w0, w1, w2, w3, w4, w5 ) "
37  "VALUES (:wei2_conf_id, :group_id, "
38  ":w0, :w1, :w2, :w3, :w4, :w5 )");
39  } catch (SQLException& e) {
40  throw cms::Exception("SQLException") << "FEConfigOddWeightGroupDat::prepareWrite(): " << e.getMessage();
41  }
42 }
43 
46  FEConfigOddWeightInfo* iconf) noexcept(false) {
47  this->checkConnection();
48  this->checkPrepare();
49 
50  int iconfID = iconf->fetchID();
51  if (!iconfID) {
52  throw(std::runtime_error("FEConfigOddWeightGroupDat::writeDB: ICONF not in DB"));
53  }
54  /* no need for the logic id in this table
55  int logicID = ecid->getLogicID();
56  if (!logicID) { throw(std::runtime_error("FEConfigOddWeightGroupDat::writeDB: Bad EcalLogicID")); }
57  */
58 
59  try {
60  m_writeStmt->setInt(1, iconfID);
61 
62  m_writeStmt->setInt(2, item->getWeightGroupId());
63  m_writeStmt->setFloat(3, item->getWeight0());
64  m_writeStmt->setFloat(4, item->getWeight1());
65  m_writeStmt->setFloat(5, item->getWeight2());
66  m_writeStmt->setFloat(6, item->getWeight3());
67  m_writeStmt->setFloat(7, item->getWeight4());
68  m_writeStmt->setFloat(8, item->getWeight5());
69 
70  m_writeStmt->executeUpdate();
71  } catch (SQLException& e) {
72  throw cms::Exception("SQLException") << "FEConfigOddWeightGroupDat::writeDB(): " << e.getMessage();
73  }
74 }
75 
76 void FEConfigOddWeightGroupDat::fetchData(map<EcalLogicID, FEConfigOddWeightGroupDat>* fillMap,
77  FEConfigOddWeightInfo* iconf) noexcept(false) {
78  this->checkConnection();
79  fillMap->clear();
80 
81  iconf->setConnection(m_env, m_conn);
82  int iconfID = iconf->fetchID();
83  if (!iconfID) {
84  throw(std::runtime_error("FEConfigOddWeightGroupDat::fetchData: ICONF not in DB"));
85  return;
86  }
87 
88  try {
89  m_readStmt->setSQL(
90  "SELECT d.group_id, d.w0, d.w1, d.w2, d.w3, d.w4, d.w5 "
91  "FROM fe_weight2_per_group_dat d "
92  "WHERE wei2_conf_id = :wei2_conf_id order by d.group_id ");
93  m_readStmt->setInt(1, iconfID);
94  ResultSet* rset = m_readStmt->executeQuery();
95 
96  std::pair<EcalLogicID, FEConfigOddWeightGroupDat> p;
98  int ig = -1;
99  while (rset->next()) {
100  ig++; // we create a dummy logic_id
101  p.first = EcalLogicID("Group_id", // name
102  ig); // logic_id
103 
104  dat.setWeightGroupId(rset->getInt(1));
105  dat.setWeight0(rset->getFloat(2));
106  dat.setWeight1(rset->getFloat(3));
107  dat.setWeight2(rset->getFloat(4));
108  dat.setWeight3(rset->getFloat(5));
109  dat.setWeight4(rset->getFloat(6));
110  dat.setWeight5(rset->getFloat(7));
111 
112  p.second = dat;
113  fillMap->insert(p);
114  }
115  } catch (SQLException& e) {
116  throw cms::Exception("SQLException") << "FEConfigOddWeightGroupDat::fetchData: " << e.getMessage();
117  }
118 }
119 
120 void FEConfigOddWeightGroupDat::writeArrayDB(const std::map<EcalLogicID, FEConfigOddWeightGroupDat>* data,
121  FEConfigOddWeightInfo* iconf) noexcept(false) {
122  this->checkConnection();
123  this->checkPrepare();
124 
125  int iconfID = iconf->fetchID();
126  if (!iconfID) {
127  throw(std::runtime_error("FEConfigOddWeightGroupDat::writeArrayDB: ICONF not in DB"));
128  }
129 
130  int nrows = data->size();
131  int* ids = new int[nrows];
132  int* iconfid_vec = new int[nrows];
133  int* xx = new int[nrows];
134  float* yy = new float[nrows];
135  float* zz = new float[nrows];
136  float* rr = new float[nrows];
137  float* ss = new float[nrows];
138  float* tt = new float[nrows];
139  float* ww = new float[nrows];
140 
141  ub2* ids_len = new ub2[nrows];
142  ub2* iconf_len = new ub2[nrows];
143  ub2* x_len = new ub2[nrows];
144  ub2* y_len = new ub2[nrows];
145  ub2* z_len = new ub2[nrows];
146  ub2* r_len = new ub2[nrows];
147  ub2* s_len = new ub2[nrows];
148  ub2* t_len = new ub2[nrows];
149  ub2* w_len = new ub2[nrows];
150 
151  // const EcalLogicID* channel;
152  const FEConfigOddWeightGroupDat* dataitem;
153  int count = 0;
154  typedef map<EcalLogicID, FEConfigOddWeightGroupDat>::const_iterator CI;
155  for (CI p = data->begin(); p != data->end(); ++p) {
156  // channel = &(p->first);
157  // int logicID = channel->getLogicID();
158  // if (!logicID) { throw(std::runtime_error("FEConfigOddWeightGroupDat::writeArrayDB: Bad EcalLogicID")); }
159  // ids[count]=logicID;
160  iconfid_vec[count] = iconfID;
161 
162  dataitem = &(p->second);
163  // dataIface.writeDB( channel, dataitem, iconf);
164  int x = dataitem->getWeightGroupId();
165  float y = dataitem->getWeight0();
166  float z = dataitem->getWeight1();
167  float r = dataitem->getWeight2();
168  float s = dataitem->getWeight3();
169  float t = dataitem->getWeight4();
170  float w = dataitem->getWeight5();
171 
172  xx[count] = x;
173  yy[count] = y;
174  zz[count] = z;
175  rr[count] = r;
176  ss[count] = s;
177  tt[count] = t;
178  ww[count] = w;
179 
180  // ids_len[count]=sizeof(ids[count]);
181  iconf_len[count] = sizeof(iconfid_vec[count]);
182 
183  x_len[count] = sizeof(xx[count]);
184  y_len[count] = sizeof(yy[count]);
185  z_len[count] = sizeof(zz[count]);
186  r_len[count] = sizeof(rr[count]);
187  s_len[count] = sizeof(ss[count]);
188  t_len[count] = sizeof(tt[count]);
189  w_len[count] = sizeof(ww[count]);
190 
191  count++;
192  }
193 
194  try {
195  m_writeStmt->setDataBuffer(1, (dvoid*)iconfid_vec, OCCIINT, sizeof(iconfid_vec[0]), iconf_len);
196  m_writeStmt->setDataBuffer(2, (dvoid*)xx, OCCIINT, sizeof(xx[0]), x_len);
197  m_writeStmt->setDataBuffer(3, (dvoid*)yy, OCCIFLOAT, sizeof(yy[0]), y_len);
198  m_writeStmt->setDataBuffer(4, (dvoid*)zz, OCCIFLOAT, sizeof(zz[0]), z_len);
199  m_writeStmt->setDataBuffer(5, (dvoid*)rr, OCCIFLOAT, sizeof(rr[0]), r_len);
200  m_writeStmt->setDataBuffer(6, (dvoid*)ss, OCCIFLOAT, sizeof(ss[0]), s_len);
201  m_writeStmt->setDataBuffer(7, (dvoid*)tt, OCCIFLOAT, sizeof(tt[0]), t_len);
202  m_writeStmt->setDataBuffer(8, (dvoid*)ww, OCCIFLOAT, sizeof(ww[0]), w_len);
203 
204  m_writeStmt->executeArrayUpdate(nrows);
205 
206  delete[] ids;
207  delete[] iconfid_vec;
208  delete[] xx;
209  delete[] yy;
210  delete[] zz;
211  delete[] rr;
212  delete[] ss;
213  delete[] tt;
214  delete[] ww;
215 
216  delete[] ids_len;
217  delete[] iconf_len;
218  delete[] x_len;
219  delete[] y_len;
220  delete[] z_len;
221  delete[] r_len;
222  delete[] s_len;
223  delete[] t_len;
224  delete[] w_len;
225 
226  } catch (SQLException& e) {
227  throw cms::Exception("SQLException") << "FEConfigOddWeightGroupDat::writeArrayDB(): " << e.getMessage();
228  }
229 }
T w() const
Definition: TTTypes.h:54
void writeDB(const EcalLogicID *ecid, const FEConfigOddWeightGroupDat *item, FEConfigOddWeightInfo *iconf) noexcept(false)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
void writeArrayDB(const std::map< EcalLogicID, FEConfigOddWeightGroupDat > *data, FEConfigOddWeightInfo *iconf) noexcept(false)
void fetchData(std::map< EcalLogicID, FEConfigOddWeightGroupDat > *fillMap, FEConfigOddWeightInfo *iconf) noexcept(false)
void prepareWrite() noexcept(false) override