CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 = NULL;
14  m_conn = NULL;
15  m_writeStmt = NULL;
16  m_readStmt = NULL;
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 
34  throw(std::runtime_error)
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("FEConfigLUTGroupDat::prepareWrite(): "+e.getMessage()));
46  }
47 }
48 
50  throw(std::runtime_error)
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("FEConfigLUTGroupDat::writeArrayDB(): "+e.getMessage()));
120  }
121 }
122 
123 
124 void FEConfigLUTGroupDat::fetchData(map< EcalLogicID, FEConfigLUTGroupDat >* fillMap, FEConfigLUTInfo* iconf)
125  throw(std::runtime_error)
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 
145  FEConfigLUTGroupDat* dat(0);
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=new 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  delete dat;
173  }
174  }
175  } catch (SQLException &e) {
176  throw(std::runtime_error("FEConfigLUTGroupDat::fetchData: "+e.getMessage()));
177  }
178 }
179 
180 void FEConfigLUTGroupDat::writeArrayDB(const std::map< EcalLogicID, FEConfigLUTGroupDat >* data, FEConfigLUTInfo* iconf)
181  throw(std::runtime_error)
182 {
183  this->checkConnection();
184  this->checkPrepare();
185 
186  int iconfID = iconf->fetchID();
187  if (!iconfID) { throw(std::runtime_error("FEConfigLUTGroupDat::writeArrayDB: ICONF not in DB")); }
188 
189 
190  int nrows=data->size()*1024;
191 
192  int* iconfid_vec= new int[nrows];
193  int* xx= new int[nrows];
194  int* yy= new int[nrows];
195  int* zz= new int[nrows];
196 
197 
198 
199  ub2* iconf_len= new ub2[nrows];
200  ub2* x_len= new ub2[nrows];
201  ub2* y_len= new ub2[nrows];
202  ub2* z_len= new ub2[nrows];
203 
204 
205  const FEConfigLUTGroupDat* dataitem;
206  int count=0;
207  typedef map< EcalLogicID, FEConfigLUTGroupDat >::const_iterator CI;
208  for (CI p = data->begin(); p != data->end(); ++p) {
209 
210 
211  dataitem = &(p->second);
212  int x=dataitem->getLUTGroupId();
213 
214 
215  for (int i=0; i<1024; i++){
216  iconfid_vec[count]=iconfID;
217  int y=i;
218  int z=dataitem->getLUTValue(i);
219 
220  xx[count]=x;
221  yy[count]=y;
222  zz[count]=z;
223 
224 
225  iconf_len[count]=sizeof(iconfid_vec[count]);
226 
227  x_len[count]=sizeof(xx[count]);
228  y_len[count]=sizeof(yy[count]);
229  z_len[count]=sizeof(zz[count]);
230 
231  count++;
232 
233  }
234  }
235 
236 
237  try {
238 
239  // for (int i=0; i<nrows; i++){
240 
241  int i=0;
242  cout << "about to insert "<< iconfid_vec[i]<<" " <<xx[i]<< " "<< yy[i]<< " "<< zz[i]<< endl;
243  i=nrows-1;
244  cout << "about to insert "<< iconfid_vec[i]<<" " <<xx[i]<< " "<< yy[i]<< " "<< zz[i]<< endl;
245  // }
246  m_writeStmt->setDataBuffer(1, (dvoid*)iconfid_vec, OCCIINT, sizeof(iconfid_vec[0]),iconf_len);
247  m_writeStmt->setDataBuffer(2, (dvoid*)xx, OCCIINT, sizeof(xx[0]), x_len );
248  m_writeStmt->setDataBuffer(3, (dvoid*)yy, OCCIINT , sizeof(yy[0]), y_len );
249  m_writeStmt->setDataBuffer(4, (dvoid*)zz, OCCIINT , sizeof(zz[0]), z_len );
250 
251  m_writeStmt->executeArrayUpdate(nrows);
252 
253 
254  delete [] iconfid_vec;
255  delete [] xx;
256  delete [] yy;
257  delete [] zz;
258 
259 
260 
261  delete [] iconf_len;
262  delete [] x_len;
263  delete [] y_len;
264  delete [] z_len;
265 
266 
267  } catch (SQLException &e) {
268  throw(std::runtime_error("FEConfigLUTGroupDat::writeArrayDB(): "+e.getMessage()));
269  }
270 }
int i
Definition: DBlmapReader.cc:9
void writeDB(const EcalLogicID *ecid, const FEConfigLUTGroupDat *item, FEConfigLUTInfo *iconf)
void fetchData(std::map< EcalLogicID, FEConfigLUTGroupDat > *fillMap, FEConfigLUTInfo *iconf)
#define NULL
Definition: scimark2.h:8
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:27
void writeArrayDB(const std::map< EcalLogicID, FEConfigLUTGroupDat > *data, FEConfigLUTInfo *iconf)
void setLUTValue(int i, int x)
int getLUTValue(int i) const
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:26
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
tuple cout
Definition: gather_cfg.py:121