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