CMS 3D CMS Logo

DCULVRVoltagesDat.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 {
14  m_env = nullptr;
15  m_conn = nullptr;
16  m_writeStmt = nullptr;
17  m_readStmt = nullptr;
18 
19  m_vfe1_A = 0;
20  m_vfe2_A = 0;
21  m_vfe3_A = 0;
22  m_vfe4_A = 0;
23  m_vfe5_A = 0;
24  m_VCC = 0;
25  m_vfe4_5_D = 0;
26  m_vfe1_2_3_D = 0;
27  m_buffer = 0;
28  m_fenix = 0;
29  m_V43_A = 0;
30  m_OCM = 0;
31  m_GOH = 0;
32  m_INH = 0;
33  m_V43_D = 0;
34 }
35 
36 
37 
39 {
40 }
41 
42 
43 
46 {
47  this->checkConnection();
48 
49  try {
50  m_writeStmt = m_conn->createStatement();
51  m_writeStmt->setSQL("INSERT INTO dcu_lvr_voltages_dat (iov_id, logic_id, "
52  "vfe1_A, vfe2_A, vfe3_A, vfe4_A, vfe5_A, VCC, vfe4_5_D, vfe1_2_3_D, buffer, fenix, V43_A, OCM, GOH, INH, V43_D) "
53  "VALUES (:iov_id, :logic_id, "
54  ":3, :4, :5, :6, :7, :8, :9, :10, :11, :12, :13, :14, :15, :16, :17)");
55  } catch (SQLException &e) {
56  throw(std::runtime_error("DCULVRVoltagesDat::prepareWrite(): "+e.getMessage()));
57  }
58 }
59 
60 
61 
62 void DCULVRVoltagesDat::writeDB(const EcalLogicID* ecid, const DCULVRVoltagesDat* item, DCUIOV* iov)
63  noexcept(false)
64 {
65  this->checkConnection();
66  this->checkPrepare();
67 
68  int iovID = iov->fetchID();
69  if (!iovID) { throw(std::runtime_error("DCULVRVoltagesDat::writeDB: IOV not in DB")); }
70 
71  int logicID = ecid->getLogicID();
72  if (!logicID) { throw(std::runtime_error("DCULVRVoltagesDat::writeDB: Bad EcalLogicID")); }
73 
74  try {
75  m_writeStmt->setInt(1, iovID);
76  m_writeStmt->setInt(2, logicID);
77 
78  m_writeStmt->setFloat(3, item->getVFE1_A() );
79  m_writeStmt->setFloat(4, item->getVFE2_A() );
80  m_writeStmt->setFloat(5, item->getVFE3_A() );
81  m_writeStmt->setFloat(6, item->getVFE4_A() );
82  m_writeStmt->setFloat(7, item->getVFE5_A() );
83  m_writeStmt->setFloat(8, item->getVCC() );
84  m_writeStmt->setFloat(9, item->getVFE4_5_D() );
85  m_writeStmt->setFloat(10, item->getVFE1_2_3_D() );
86  m_writeStmt->setFloat(11, item->getBuffer() );
87  m_writeStmt->setFloat(12, item->getFenix() );
88  m_writeStmt->setFloat(13, item->getV43_A() );
89  m_writeStmt->setFloat(14, item->getOCM() );
90  m_writeStmt->setFloat(15, item->getGOH() );
91  m_writeStmt->setFloat(16, item->getINH() );
92  m_writeStmt->setFloat(17, item->getV43_D() );
93 
94  m_writeStmt->executeUpdate();
95  } catch (SQLException &e) {
96  throw(std::runtime_error("DCULVRVoltagesDat::writeDB(): "+e.getMessage()));
97  }
98 }
99 
100 
101 
102 void DCULVRVoltagesDat::fetchData(std::map< EcalLogicID, DCULVRVoltagesDat >* fillMap, DCUIOV* iov)
103  noexcept(false)
104 {
105  this->checkConnection();
106  fillMap->clear();
107 
108  iov->setConnection(m_env, m_conn);
109  int iovID = iov->fetchID();
110  if (!iovID) {
111  // throw(std::runtime_error("DCULVRVoltagesDat::writeDB: IOV not in DB"));
112  return;
113  }
114 
115  try {
116 
117  m_readStmt->setSQL("SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
118  "d.vfe1_A, d.vfe2_A, d.vfe3_A, d.vfe4_A, d.vfe5_A, d.VCC, d.vfe4_5_D, d.vfe1_2_3_D, d.buffer, d.fenix, d.V43_A, d.OCM, d.GOH, d.INH, d.V43_D "
119  "FROM channelview cv JOIN dcu_lvr_voltages_dat d "
120  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
121  "WHERE d.iov_id = :iov_id");
122  m_readStmt->setInt(1, iovID);
123  ResultSet* rset = m_readStmt->executeQuery();
124 
125  std::pair< EcalLogicID, DCULVRVoltagesDat > p;
126  DCULVRVoltagesDat dat;
127  while(rset->next()) {
128  p.first = EcalLogicID( rset->getString(1), // name
129  rset->getInt(2), // logic_id
130  rset->getInt(3), // id1
131  rset->getInt(4), // id2
132  rset->getInt(5), // id3
133  rset->getString(6)); // maps_to
134 
135  dat.setVFE1_A( rset->getFloat(7) );
136  dat.setVFE2_A( rset->getFloat(8) );
137  dat.setVFE3_A( rset->getFloat(9) );
138  dat.setVFE4_A( rset->getFloat(10) );
139  dat.setVFE5_A( rset->getFloat(11) );
140  dat.setVCC( rset->getFloat(12) );
141  dat.setVFE4_5_D( rset->getFloat(13) );
142  dat.setVFE1_2_3_D( rset->getFloat(14) );
143  dat.setBuffer( rset->getFloat(15) );
144  dat.setFenix( rset->getFloat(16) );
145  dat.setV43_A( rset->getFloat(17) );
146  dat.setOCM( rset->getFloat(18) );
147  dat.setGOH( rset->getFloat(19) );
148  dat.setINH( rset->getFloat(20) );
149  dat.setV43_D( rset->getFloat(21) );
150 
151  p.second = dat;
152  fillMap->insert(p);
153  }
154  } catch (SQLException &e) {
155  throw(std::runtime_error("DCULVRVoltagesDat::fetchData(): "+e.getMessage()));
156  }
157 }
158 void DCULVRVoltagesDat::writeArrayDB(const std::map< EcalLogicID, DCULVRVoltagesDat >* data, DCUIOV* iov)
159  noexcept(false)
160 {
161  this->checkConnection();
162  this->checkPrepare();
163 
164  int iovID = iov->fetchID();
165  if (!iovID) { throw(std::runtime_error("DCULVRVoltagesDat::writeArrayDB: IOV not in DB")); }
166 
167 
168  int nrows=data->size();
169  int* ids= new int[nrows];
170  int* iovid_vec= new int[nrows];
171  float* xx= new float[nrows];
172  float* yy= new float[nrows];
173  float* zz= new float[nrows];
174  float* ww= new float[nrows];
175  float* uu= new float[nrows];
176  float* tt= new float[nrows];
177  float* rr= new float[nrows];
178  float* pp= new float[nrows];
179  float* ll= new float[nrows];
180  float* mm= new float[nrows];
181  float* nn= new float[nrows];
182  float* qq= new float[nrows];
183  float* ss= new float[nrows];
184  float* vv= new float[nrows];
185  float* hh= new float[nrows];
186 
187 
188  ub2* ids_len= new ub2[nrows];
189  ub2* iov_len= new ub2[nrows];
190  ub2* x_len= new ub2[nrows];
191  ub2* y_len= new ub2[nrows];
192  ub2* z_len= new ub2[nrows];
193  ub2* w_len= new ub2[nrows];
194  ub2* u_len= new ub2[nrows];
195  ub2* t_len= new ub2[nrows];
196  ub2* r_len= new ub2[nrows];
197  ub2* p_len= new ub2[nrows];
198  ub2* l_len= new ub2[nrows];
199  ub2* m_len= new ub2[nrows];
200  ub2* n_len= new ub2[nrows];
201  ub2* q_len= new ub2[nrows];
202  ub2* s_len= new ub2[nrows];
203  ub2* v_len= new ub2[nrows];
204  ub2* h_len= new ub2[nrows];
205 
206  const EcalLogicID* channel;
207  const DCULVRVoltagesDat* dataitem;
208  int count=0;
209  typedef map< EcalLogicID, DCULVRVoltagesDat >::const_iterator CI;
210  for (CI p = data->begin(); p != data->end(); ++p) {
211  channel = &(p->first);
212  int logicID = channel->getLogicID();
213  if (!logicID) { throw(std::runtime_error("DCULVRVoltagesDat::writeArrayDB: Bad EcalLogicID")); }
214  ids[count]=logicID;
215  iovid_vec[count]=iovID;
216 
217  dataitem = &(p->second);
218  // dataIface.writeDB( channel, dataitem, iov);
219  float x=dataitem->getVFE1_A();
220  float y=dataitem->getVFE2_A();
221  float z=dataitem->getVFE3_A();
222  float w=dataitem->getVFE4_A();
223  float u=dataitem->getVFE5_A();
224  float t=dataitem->getVCC();
225  float r=dataitem->getVFE4_5_D();
226  float pi=dataitem->getVFE1_2_3_D();
227  float l=dataitem->getBuffer();
228  float m=dataitem->getFenix();
229  float n=dataitem->getV43_A();
230  float q=dataitem->getOCM();
231  float s=dataitem->getGOH();
232  float v=dataitem->getINH();
233  float h=dataitem->getV43_D();
234 
235  xx[count]=x;
236  yy[count]=y;
237  zz[count]=z;
238  ww[count]=w;
239  uu[count]=u;
240  tt[count]=t;
241  rr[count]=r;
242  pp[count]=pi;
243  ll[count]=l;
244  mm[count]=m;
245  nn[count]=n;
246  qq[count]=q;
247  ss[count]=s;
248  vv[count]=v;
249  hh[count]=h;
250 
251  ids_len[count]=sizeof(ids[count]);
252  iov_len[count]=sizeof(iovid_vec[count]);
253 
254  x_len[count]=sizeof(xx[count]);
255  y_len[count]=sizeof(yy[count]);
256  z_len[count]=sizeof(zz[count]);
257  w_len[count]=sizeof(ww[count]);
258  u_len[count]=sizeof(uu[count]);
259  t_len[count]=sizeof(tt[count]);
260  r_len[count]=sizeof(rr[count]);
261  p_len[count]=sizeof(pp[count]);
262  l_len[count]=sizeof(ll[count]);
263  m_len[count]=sizeof(mm[count]);
264  n_len[count]=sizeof(nn[count]);
265  q_len[count]=sizeof(qq[count]);
266  s_len[count]=sizeof(ss[count]);
267  v_len[count]=sizeof(vv[count]);
268  h_len[count]=sizeof(hh[count]);
269  count++;
270  }
271  try {
272  m_writeStmt->setDataBuffer(1, (dvoid*)iovid_vec, OCCIINT, sizeof(iovid_vec[0]),iov_len);
273  m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len );
274  m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIFLOAT , sizeof(xx[0]), x_len );
275  m_writeStmt->setDataBuffer(4, (dvoid*)yy, OCCIFLOAT , sizeof(yy[0]), y_len );
276  m_writeStmt->setDataBuffer(5, (dvoid*)zz, OCCIFLOAT , sizeof(zz[0]), z_len );
277  m_writeStmt->setDataBuffer(6, (dvoid*)ww, OCCIFLOAT , sizeof(ww[0]), w_len );
278  m_writeStmt->setDataBuffer(7, (dvoid*)uu, OCCIFLOAT , sizeof(uu[0]), u_len );
279  m_writeStmt->setDataBuffer(8, (dvoid*)tt, OCCIFLOAT , sizeof(tt[0]), t_len );
280  m_writeStmt->setDataBuffer(9, (dvoid*)rr, OCCIFLOAT , sizeof(rr[0]), r_len );
281  m_writeStmt->setDataBuffer(10, (dvoid*)pp, OCCIFLOAT , sizeof(pp[0]), p_len );
282  m_writeStmt->setDataBuffer(11, (dvoid*)ll, OCCIFLOAT , sizeof(ll[0]), l_len );
283  m_writeStmt->setDataBuffer(12, (dvoid*)mm, OCCIFLOAT , sizeof(mm[0]), m_len );
284  m_writeStmt->setDataBuffer(13, (dvoid*)nn, OCCIFLOAT , sizeof(nn[0]), n_len );
285  m_writeStmt->setDataBuffer(14, (dvoid*)qq, OCCIFLOAT , sizeof(qq[0]), q_len );
286  m_writeStmt->setDataBuffer(15, (dvoid*)ss, OCCIFLOAT , sizeof(ss[0]), s_len );
287  m_writeStmt->setDataBuffer(16, (dvoid*)vv, OCCIFLOAT , sizeof(vv[0]), v_len );
288  m_writeStmt->setDataBuffer(17, (dvoid*)hh, OCCIFLOAT , sizeof(hh[0]), h_len );
289 
290 
291  m_writeStmt->executeArrayUpdate(nrows);
292 
293  delete [] ids;
294  delete [] iovid_vec;
295  delete [] xx;
296  delete [] yy;
297  delete [] zz;
298  delete [] ww;
299  delete [] uu;
300  delete [] tt;
301  delete [] rr;
302  delete [] pp;
303  delete [] ll;
304  delete [] mm;
305  delete [] nn;
306  delete [] qq;
307  delete [] ss;
308  delete [] vv;
309  delete [] hh;
310 
311  delete [] ids_len;
312  delete [] iov_len;
313  delete [] x_len;
314  delete [] y_len;
315  delete [] z_len;
316  delete [] w_len;
317  delete [] u_len;
318  delete [] t_len;
319  delete [] r_len;
320  delete [] p_len;
321  delete [] l_len;
322  delete [] m_len;
323  delete [] n_len;
324  delete [] q_len;
325  delete [] s_len;
326  delete [] v_len;
327  delete [] h_len;
328 
329  } catch (SQLException &e) {
330  throw(std::runtime_error("DCULVRVoltagesDat::writeArrayDB(): "+e.getMessage()));
331  }
332 }
void setVFE5_A(float v)
float getBuffer() const
void setINH(float v)
const double w
Definition: UKUtility.cc:23
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
void setV43_A(float v)
void setOCM(float v)
void prepareWrite() noexcept(false) override
float getVCC() const
float getOCM() const
void setFenix(float v)
float getVFE4_A() const
~DCULVRVoltagesDat() override
Definition: DCUIOV.h:13
void writeDB(const EcalLogicID *ecid, const DCULVRVoltagesDat *item, DCUIOV *iov) noexcept(false)
const Double_t pi
float getFenix() const
void setGOH(float v)
float getVFE2_A() const
float getVFE5_A() const
int getLogicID() const
Definition: EcalLogicID.cc:41
void fetchData(std::map< EcalLogicID, DCULVRVoltagesDat > *fillVec, DCUIOV *iov) noexcept(false)
void setVFE4_5_D(float v)
#define noexcept
void setVFE4_A(float v)
float getGOH() const
void writeArrayDB(const std::map< EcalLogicID, DCULVRVoltagesDat > *data, DCUIOV *iov) noexcept(false)
float getV43_D() const
void setVFE1_A(float v)
float getVFE4_5_D() const
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
float getV43_A() const
void setBuffer(float v)
void setVFE3_A(float v)
float getVFE3_A() const
void setVCC(float v)
void setVFE2_A(float v)
float getVFE1_2_3_D() const
float getVFE1_A() const
void setV43_D(float v)
void setVFE1_2_3_D(float v)
float getINH() const