CMS 3D CMS Logo

FEConfigLUTGroupDat.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_group_id = 0;
18  for (int i = 0; i < 1024; i++) {
19  m_lut[i] = 0;
20  }
21 }
22 
24 
26  this->checkConnection();
27 
28  try {
29  m_writeStmt = m_conn->createStatement();
30  m_writeStmt->setSQL(
31  "INSERT INTO fe_lut_per_group_dat (lut_conf_id, group_id, "
32  " lut_id, lut_value ) "
33  "VALUES (:lut_conf_id, :group_id, "
34  ":lut_id, :lut_value )");
35  } catch (SQLException& e) {
36  throw(std::runtime_error(std::string("FEConfigLUTGroupDat::prepareWrite(): ") + e.getMessage()));
37  }
38 }
39 
42  FEConfigLUTInfo* iconf) noexcept(false) {
43  this->checkConnection();
44  this->checkPrepare();
45 
46  int iconfID = iconf->fetchID();
47 
48  cout << "iconf=" << iconfID << endl;
49 
50  if (!iconfID) {
51  throw(std::runtime_error("FEConfigLUTGroupDat::writeArrayDB: ICONF not in DB"));
52  }
53 
54  int nrows = 1024;
55  int* iconfid_vec = new int[nrows];
56  int* xx = new int[nrows];
57  int* yy = new int[nrows];
58  int* zz = new int[nrows];
59 
60  ub2* iconf_len = new ub2[nrows];
61  ub2* x_len = new ub2[nrows];
62  ub2* y_len = new ub2[nrows];
63  ub2* z_len = new ub2[nrows];
64 
65  for (int count = 0; count < nrows; count++) {
66  iconfid_vec[count] = iconfID;
67  int x = item->getLUTGroupId();
68  int y = count;
69  int z = m_lut[count];
70 
71  xx[count] = x;
72  yy[count] = y;
73  zz[count] = z;
74 
75  iconf_len[count] = sizeof(iconfid_vec[count]);
76 
77  x_len[count] = sizeof(xx[count]);
78  y_len[count] = sizeof(yy[count]);
79  z_len[count] = sizeof(zz[count]);
80  }
81 
82  try {
83  m_writeStmt->setDataBuffer(1, (dvoid*)iconfid_vec, OCCIINT, sizeof(iconfid_vec[0]), iconf_len);
84  m_writeStmt->setDataBuffer(2, (dvoid*)xx, OCCIINT, sizeof(xx[0]), x_len);
85  m_writeStmt->setDataBuffer(3, (dvoid*)yy, OCCIINT, sizeof(yy[0]), y_len);
86  m_writeStmt->setDataBuffer(4, (dvoid*)zz, OCCIINT, sizeof(zz[0]), z_len);
87 
88  m_writeStmt->executeArrayUpdate(nrows);
89 
90  delete[] iconfid_vec;
91  delete[] xx;
92  delete[] yy;
93  delete[] zz;
94 
95  delete[] iconf_len;
96  delete[] x_len;
97  delete[] y_len;
98  delete[] z_len;
99 
100  } catch (SQLException& e) {
101  throw(std::runtime_error(std::string("FEConfigLUTGroupDat::writeArrayDB(): ") + e.getMessage()));
102  }
103 }
104 
105 void FEConfigLUTGroupDat::fetchData(map<EcalLogicID, FEConfigLUTGroupDat>* fillMap,
106  FEConfigLUTInfo* iconf) noexcept(false) {
107  this->checkConnection();
108  fillMap->clear();
109 
110  iconf->setConnection(m_env, m_conn);
111  int iconfID = iconf->fetchID();
112  if (!iconfID) {
113  throw(std::runtime_error("FEConfigLUTGroupDat::fetchData: ICONF not in DB"));
114  return;
115  }
116 
117  try {
118  m_readStmt->setSQL(
119  "SELECT d.group_id, d.lut_id, d.lut_value "
120  "FROM fe_lut_per_group_dat d "
121  "WHERE lut_conf_id = :lut_conf_id order by d.group_id, d.lut_id ");
122  m_readStmt->setInt(1, iconfID);
123  ResultSet* rset = m_readStmt->executeQuery();
124 
126  std::pair<EcalLogicID, FEConfigLUTGroupDat> p;
127 
128  int nrows = 1024;
129 
130  int igold = -1;
131  int ig = igold;
132 
133  while (rset->next()) {
134  ig = rset->getInt(1);
135  int il = rset->getInt(2);
136  int ival = rset->getInt(3);
137  if (il == 0) {
138  p.first = EcalLogicID("Group_id", ig); // a dummy logic_id
139  dat = FEConfigLUTGroupDat();
140  dat.setLUTGroupId(ig);
141  dat.setLUTValue(il, ival);
142  } else {
143  dat.setLUTValue(il, ival);
144  }
145 
146  if (il == (nrows - 1)) {
147  p.second = dat;
148  fillMap->insert(p);
149  }
150  }
151  } catch (SQLException& e) {
152  throw(std::runtime_error(std::string("FEConfigLUTGroupDat::fetchData: ") + e.getMessage()));
153  }
154 }
155 
156 void FEConfigLUTGroupDat::writeArrayDB(const std::map<EcalLogicID, FEConfigLUTGroupDat>* data,
157  FEConfigLUTInfo* iconf) noexcept(false) {
158  this->checkConnection();
159  this->checkPrepare();
160 
161  int iconfID = iconf->fetchID();
162  if (!iconfID) {
163  throw(std::runtime_error("FEConfigLUTGroupDat::writeArrayDB: ICONF not in DB"));
164  }
165 
166  int nrows = data->size() * 1024;
167 
168  int* iconfid_vec = new int[nrows];
169  int* xx = new int[nrows];
170  int* yy = new int[nrows];
171  int* zz = new int[nrows];
172 
173  ub2* iconf_len = new ub2[nrows];
174  ub2* x_len = new ub2[nrows];
175  ub2* y_len = new ub2[nrows];
176  ub2* z_len = new ub2[nrows];
177 
178  const FEConfigLUTGroupDat* dataitem;
179  int count = 0;
180  typedef map<EcalLogicID, FEConfigLUTGroupDat>::const_iterator CI;
181  for (CI p = data->begin(); p != data->end(); ++p) {
182  dataitem = &(p->second);
183  int x = dataitem->getLUTGroupId();
184 
185  for (int i = 0; i < 1024; i++) {
186  iconfid_vec[count] = iconfID;
187  int y = i;
188  int z = dataitem->getLUTValue(i);
189 
190  xx[count] = x;
191  yy[count] = y;
192  zz[count] = z;
193 
194  iconf_len[count] = sizeof(iconfid_vec[count]);
195 
196  x_len[count] = sizeof(xx[count]);
197  y_len[count] = sizeof(yy[count]);
198  z_len[count] = sizeof(zz[count]);
199 
200  count++;
201  }
202  }
203 
204  try {
205  // for (int i=0; i<nrows; i++){
206 
207  int i = 0;
208  cout << "about to insert " << iconfid_vec[i] << " " << xx[i] << " " << yy[i] << " " << zz[i] << endl;
209  i = nrows - 1;
210  cout << "about to insert " << iconfid_vec[i] << " " << xx[i] << " " << yy[i] << " " << zz[i] << endl;
211  // }
212  m_writeStmt->setDataBuffer(1, (dvoid*)iconfid_vec, OCCIINT, sizeof(iconfid_vec[0]), iconf_len);
213  m_writeStmt->setDataBuffer(2, (dvoid*)xx, OCCIINT, sizeof(xx[0]), x_len);
214  m_writeStmt->setDataBuffer(3, (dvoid*)yy, OCCIINT, sizeof(yy[0]), y_len);
215  m_writeStmt->setDataBuffer(4, (dvoid*)zz, OCCIINT, sizeof(zz[0]), z_len);
216 
217  m_writeStmt->executeArrayUpdate(nrows);
218 
219  delete[] iconfid_vec;
220  delete[] xx;
221  delete[] yy;
222  delete[] zz;
223 
224  delete[] iconf_len;
225  delete[] x_len;
226  delete[] y_len;
227  delete[] z_len;
228 
229  } catch (SQLException& e) {
230  throw(std::runtime_error(std::string("FEConfigLUTGroupDat::writeArrayDB(): ") + e.getMessage()));
231  }
232 }
int getLUTValue(int i) const
void writeArrayDB(const std::map< EcalLogicID, FEConfigLUTGroupDat > *data, FEConfigLUTInfo *iconf) noexcept(false)
void prepareWrite() noexcept(false) override
void fetchData(std::map< EcalLogicID, FEConfigLUTGroupDat > *fillMap, FEConfigLUTInfo *iconf) noexcept(false)
void setLUTValue(int i, int x)
void writeDB(const EcalLogicID *ecid, const FEConfigLUTGroupDat *item, FEConfigLUTInfo *iconf) noexcept(false)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79