CMS 3D CMS Logo

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