CMS 3D CMS Logo

DCUCCSDat.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 = NULL;
15  m_conn = NULL;
16  m_writeStmt = NULL;
17  m_readStmt = NULL;
18 
19  m_m1_vdd1 = 0;
20  m_m2_vdd1 = 0;
21  m_m1_vdd2 = 0;
22  m_m2_vdd2 = 0;
23  m_m1_vinj = 0;
24  m_m2_vinj = 0;
25  m_m1_vcc = 0;
26  m_m2_vcc = 0;
27  m_m1_dcutemp = 0;
28  m_m2_dcutemp = 0;
29  m_ccstemplow = 0;
30  m_ccstemphigh = 0;
31 }
32 
34 {
35 }
36 
39 {
40  this->checkConnection();
41 
42  try {
43  m_writeStmt = m_conn->createStatement();
44  m_writeStmt->setSQL("INSERT INTO dcu_ccs_dat (iov_id, logic_id, "
45  "m1_vdd1, m2_vdd1, m1_vdd2, m2_vdd2, m1_vinj, "
46  "m2_vinj, m1_vcc, m2_vcc, m1_dcutemp, m2_dcutemp, "
47  "ccstemplow, ccstemphigh) "
48  "VALUES (:iov_id, :logic_id, "
49  ":m1_vdd1, :m2_vdd1, :m1_vdd2, :m2_vdd2, :m1_vinj, "
50  ":m2_vinj, :m1_vcc, :m2_vcc, :m1_dcutemp, "
51  ":m2_dcutemp, :ccstemplow, :ccstemphigh)");
52  } catch (SQLException &e) {
53  throw(std::runtime_error("DCUCCSDat::prepareWrite(): " +
54  e.getMessage()));
55  }
56 }
57 
58 
59 
60 void DCUCCSDat::writeDB(const EcalLogicID* ecid, const DCUCCSDat* item,
61  DCUIOV* iov)
62  noexcept(false)
63 {
64  this->checkConnection();
65  this->checkPrepare();
66 
67  int iovID = iov->fetchID();
68  if (!iovID) {
69  throw(std::runtime_error("DCUCCSDat::writeDB: IOV not in DB"));
70  }
71 
72  int logicID = ecid->getLogicID();
73  if (!logicID) {
74  throw(std::runtime_error("DCUCCSDat::writeDB: Bad EcalLogicID"));
75  }
76 
77  try {
78  m_writeStmt->setInt(1, iovID);
79  m_writeStmt->setInt(2, logicID);
80 
81  m_writeStmt->setFloat( 3, item->getM1VDD1() );
82  m_writeStmt->setFloat( 4, item->getM2VDD1() );
83  m_writeStmt->setFloat( 5, item->getM1VDD2() );
84  m_writeStmt->setFloat( 6, item->getM2VDD2() );
85  m_writeStmt->setFloat( 7, item->getM1Vinj() );
86  m_writeStmt->setFloat( 8, item->getM2Vinj() );
87  m_writeStmt->setFloat( 9, item->getM1Vcc() );
88  m_writeStmt->setFloat(10, item->getM2Vcc() );
89  m_writeStmt->setFloat(11, item->getM1DCUTemp() );
90  m_writeStmt->setFloat(12, item->getM2DCUTemp() );
91  m_writeStmt->setFloat(13, item->getCCSTempLow() );
92  m_writeStmt->setFloat(14, item->getCCSTempHigh() );
93 
94  m_writeStmt->executeUpdate();
95  } catch (SQLException &e) {
96  throw(std::runtime_error("DCUCCSDat::writeDB(): " + e.getMessage()));
97  }
98 }
99 
100 void DCUCCSDat::fetchData(std::map< EcalLogicID, DCUCCSDat >* fillMap,
101  DCUIOV* iov)
102  noexcept(false)
103 {
104  this->checkConnection();
105  fillMap->clear();
106 
107  iov->setConnection(m_env, m_conn);
108  int iovID = iov->fetchID();
109  if (!iovID) {
110  // throw(std::runtime_error("DCUCCSDat::writeDB: IOV not in DB"));
111  return;
112  }
113 
114  try {
115 
116  m_readStmt->setSQL("SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, "
117  "cv.maps_to, "
118  "d.m1_vdd1, d.m2_vdd1, d.m1_vdd2, d.m2_vdd2, "
119  "d.m1_vinj, d.m2_vinj, "
120  "d.m1_vcc, d.m2_vcc, "
121  "d.m1_dcutemp, d.m2_dcutemp, "
122  "d.ccstemplow, d.ccstemphigh "
123  "FROM channelview cv JOIN dcu_ccs_dat d "
124  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
125  "WHERE d.iov_id = :iov_id");
126  m_readStmt->setInt(1, iovID);
127  ResultSet* rset = m_readStmt->executeQuery();
128 
129  std::pair< EcalLogicID, DCUCCSDat > p;
130  DCUCCSDat dat;
131  while(rset->next()) {
132  p.first = EcalLogicID( rset->getString(1), // name
133  rset->getInt(2), // logic_id
134  rset->getInt(3), // id1
135  rset->getInt(4), // id2
136  rset->getInt(5), // id3
137  rset->getString(6)); // maps_to
138 
139  dat.setVDD(rset->getFloat(7), rset->getFloat(9), rset->getFloat(8),
140  rset->getFloat(10));
141  dat.setVinj(rset->getFloat(11), rset->getFloat(12));
142  dat.setVcc(rset->getFloat(13), rset->getFloat(14));
143  dat.setDCUTemp(rset->getFloat(15), rset->getFloat(16));
144  dat.setCCSTemp(rset->getFloat(17), rset->getFloat(18));
145  p.second = dat;
146  fillMap->insert(p);
147  }
148  } catch (SQLException &e) {
149  throw(std::runtime_error("DCUCCSDat::fetchData(): "+e.getMessage()));
150  }
151 }
152 
153 void DCUCCSDat::writeArrayDB(const std::map< EcalLogicID, DCUCCSDat >* data, DCUIOV* iov)
154  noexcept(false)
155 {
156  this->checkConnection();
157  this->checkPrepare();
158 
159  int iovID = iov->fetchID();
160  if (!iovID) {
161  throw(std::runtime_error("DCUCCSDat::writeArrayDB: IOV not in DB"));
162  }
163 
164  int nrows=data->size();
165  int* ids= new int[nrows];
166  int* iovid_vec= new int[nrows];
167  float* x1= new float[nrows];
168  float* x2= new float[nrows];
169  float* x3= new float[nrows];
170  float* x4= new float[nrows];
171  float* x5= new float[nrows];
172  float* x6= new float[nrows];
173  float* x7= new float[nrows];
174  float* x8= new float[nrows];
175  float* x9= new float[nrows];
176  float* xa= new float[nrows];
177  float* xb= new float[nrows];
178  float* xc= new float[nrows];
179 
180  ub2* ids_len= new ub2[nrows];
181  ub2* iov_len= new ub2[nrows];
182  ub2* x_len = new ub2[nrows];
183 
184  const EcalLogicID* channel;
185  const DCUCCSDat* dataitem;
186  int count=0;
187  typedef map< EcalLogicID, DCUCCSDat >::const_iterator CI;
188  for (CI p = data->begin(); p != data->end(); ++p) {
189  channel = &(p->first);
190  int logicID = channel->getLogicID();
191  if (!logicID) {
192  throw(std::runtime_error("DCUCCSDat::writeArrayDB: Bad EcalLogicID"));
193  }
194  ids[count]=logicID;
195  iovid_vec[count]=iovID;
196 
197  dataitem = &(p->second);
198 
199  x1[count] = dataitem->getM1VDD1();
200  x2[count] = dataitem->getM2VDD1();
201  x3[count] = dataitem->getM1VDD2();
202  x4[count] = dataitem->getM2VDD2();
203  x5[count] = dataitem->getM1Vinj();
204  x6[count] = dataitem->getM2Vinj();
205  x7[count] = dataitem->getM1Vcc();
206  x8[count] = dataitem->getM2Vcc();
207  x9[count] = dataitem->getM1DCUTemp();
208  xa[count] = dataitem->getM2DCUTemp();
209  xb[count] = dataitem->getCCSTempLow();
210  xc[count] = dataitem->getCCSTempHigh();
211 
212  ids_len[count]=sizeof(ids[count]);
213  iov_len[count]=sizeof(iovid_vec[count]);
214 
215  x_len[count]=sizeof(x1[count]);
216 
217  count++;
218  }
219 
220 
221  try {
222  m_writeStmt->setDataBuffer(1, (dvoid*)iovid_vec, OCCIINT,
223  sizeof(iovid_vec[0]),iov_len);
224  m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT,
225  sizeof(ids[0]), ids_len );
226  m_writeStmt->setDataBuffer(3, (dvoid*)x1, OCCIFLOAT ,
227  sizeof(x1[0]), x_len );
228  m_writeStmt->setDataBuffer(3, (dvoid*)x2, OCCIFLOAT ,
229  sizeof(x1[0]), x_len );
230  m_writeStmt->setDataBuffer(3, (dvoid*)x3, OCCIFLOAT ,
231  sizeof(x1[0]), x_len );
232  m_writeStmt->setDataBuffer(3, (dvoid*)x4, OCCIFLOAT ,
233  sizeof(x1[0]), x_len );
234  m_writeStmt->setDataBuffer(3, (dvoid*)x5, OCCIFLOAT ,
235  sizeof(x1[0]), x_len );
236  m_writeStmt->setDataBuffer(3, (dvoid*)x6, OCCIFLOAT ,
237  sizeof(x1[0]), x_len );
238  m_writeStmt->setDataBuffer(3, (dvoid*)x7, OCCIFLOAT ,
239  sizeof(x1[0]), x_len );
240  m_writeStmt->setDataBuffer(3, (dvoid*)x8, OCCIFLOAT ,
241  sizeof(x1[0]), x_len );
242  m_writeStmt->setDataBuffer(3, (dvoid*)x9, OCCIFLOAT ,
243  sizeof(x1[0]), x_len );
244  m_writeStmt->setDataBuffer(3, (dvoid*)xa, OCCIFLOAT ,
245  sizeof(x1[0]), x_len );
246  m_writeStmt->setDataBuffer(3, (dvoid*)xb, OCCIFLOAT ,
247  sizeof(x1[0]), x_len );
248  m_writeStmt->setDataBuffer(3, (dvoid*)xc, OCCIFLOAT ,
249  sizeof(x1[0]), x_len );
250 
251  m_writeStmt->executeArrayUpdate(nrows);
252 
253  delete [] ids;
254  delete [] iovid_vec;
255  delete [] x1;
256  delete [] x2;
257  delete [] x3;
258  delete [] x4;
259  delete [] x5;
260  delete [] x6;
261  delete [] x7;
262  delete [] x8;
263  delete [] x9;
264  delete [] xa;
265  delete [] xb;
266  delete [] xc;
267 
268  delete [] ids_len;
269  delete [] iov_len;
270  delete [] x_len;
271 
272 
273  } catch (SQLException &e) {
274  throw(std::runtime_error("DCUCCSDat::writeArrayDB(): " + e.getMessage()));
275  }
276 }
void setVinj(float v1, float v2)
Definition: DCUCCSDat.h:33
void setVDD(float m1vdd1, float m1vdd2, float m2vdd1, float m2vdd2)
Definition: DCUCCSDat.h:25
float getM2DCUTemp() const
Definition: DCUCCSDat.h:80
float getM2Vcc() const
Definition: DCUCCSDat.h:78
float getM1VDD2() const
Definition: DCUCCSDat.h:72
float getM1DCUTemp() const
Definition: DCUCCSDat.h:79
#define noexcept
float getM1VDD1() const
Definition: DCUCCSDat.h:71
#define NULL
Definition: scimark2.h:8
void writeDB(const EcalLogicID *ecid, const DCUCCSDat *item, DCUIOV *iov) noexcept(false)
Definition: DCUCCSDat.cc:60
float getM2Vinj() const
Definition: DCUCCSDat.h:76
void writeArrayDB(const std::map< EcalLogicID, DCUCCSDat > *data, DCUIOV *iov) noexcept(false)
Definition: DCUCCSDat.cc:153
Definition: DCUIOV.h:13
void setCCSTemp(float low, float high)
Definition: DCUCCSDat.h:51
float getM1Vcc() const
Definition: DCUCCSDat.h:77
void setVcc(float v1, float v2)
Definition: DCUCCSDat.h:39
float getM2VDD2() const
Definition: DCUCCSDat.h:74
int getLogicID() const
Definition: EcalLogicID.cc:41
void setDCUTemp(float t1, float t2)
Definition: DCUCCSDat.h:45
float getM2VDD1() const
Definition: DCUCCSDat.h:73
float getM1Vinj() const
Definition: DCUCCSDat.h:75
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
float getCCSTempLow() const
Definition: DCUCCSDat.h:81
void prepareWrite() noexcept(false)
Definition: DCUCCSDat.cc:37
float getCCSTempHigh() const
Definition: DCUCCSDat.h:82
~DCUCCSDat()
Definition: DCUCCSDat.cc:33
void fetchData(std::map< EcalLogicID, DCUCCSDat > *fillVec, DCUIOV *iov) noexcept(false)
Definition: DCUCCSDat.cc:100