CMS 3D CMS Logo

MonPNGreenDat.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_adcMeanG1 =0;
20  m_adcRMSG1 = 0;
21  m_adcMeanG16 = 0;
22  m_adcRMSG16 = 0;
23  m_pedMeanG1 = 0;
24  m_pedRMSG1 = 0;
25  m_pedMeanG16 = 0;
26  m_pedRMSG16 = 0;
27  m_taskStatus = false;
28 }
29 
30 
31 
33 {
34 }
35 
36 
37 
40 {
41  this->checkConnection();
42 
43  try {
44  m_writeStmt = m_conn->createStatement();
45  m_writeStmt->setSQL("INSERT INTO mon_pn_green_dat (iov_id, logic_id, "
46  "adc_mean_g1, adc_rms_g1, adc_mean_g16, adc_rms_g16, ped_mean_g1, ped_rms_g1, ped_mean_g16, ped_rms_g16, task_status) "
47  "VALUES (:iov_id, :logic_id, "
48  ":3, :4, :5, :6, :7, :8, :9, :10, :11)");
49  } catch (SQLException &e) {
50  throw(std::runtime_error("MonPNGreenDat::prepareWrite(): "+e.getMessage()));
51  }
52 }
53 
54 
55 
56 void MonPNGreenDat::writeDB(const EcalLogicID* ecid, const MonPNGreenDat* item, MonRunIOV* iov)
57  noexcept(false)
58 {
59  this->checkConnection();
60  this->checkPrepare();
61 
62  int iovID = iov->fetchID();
63  if (!iovID) { throw(std::runtime_error("MonPNGreenDat::writeDB: IOV not in DB")); }
64 
65  int logicID = ecid->getLogicID();
66  if (!logicID) { throw(std::runtime_error("MonPNGreenDat::writeDB: Bad EcalLogicID")); }
67 
68  try {
69  m_writeStmt->setInt(1, iovID);
70  m_writeStmt->setInt(2, logicID);
71 
72  m_writeStmt->setFloat(3, item->getADCMeanG1() );
73  m_writeStmt->setFloat(4, item->getADCRMSG1() );
74  m_writeStmt->setFloat(5, item->getADCMeanG16() );
75  m_writeStmt->setFloat(6, item->getADCRMSG16() );
76  m_writeStmt->setFloat(7, item->getPedMeanG1() );
77  m_writeStmt->setFloat(8, item->getPedRMSG1() );
78  m_writeStmt->setFloat(9, item->getPedMeanG16() );
79  m_writeStmt->setFloat(10, item->getPedRMSG16() );
80  m_writeStmt->setInt(11, item->getTaskStatus() );
81 
82  m_writeStmt->executeUpdate();
83  } catch (SQLException &e) {
84  throw(std::runtime_error("MonPNGreenDat::writeDB(): "+e.getMessage()));
85  }
86 }
87 
88 
89 
90 void MonPNGreenDat::fetchData(std::map< EcalLogicID, MonPNGreenDat >* fillMap, MonRunIOV* iov)
91  noexcept(false)
92 {
93  this->checkConnection();
94  fillMap->clear();
95 
96  iov->setConnection(m_env, m_conn);
97  int iovID = iov->fetchID();
98  if (!iovID) {
99  // throw(std::runtime_error("MonPNGreenDat::writeDB: IOV not in DB"));
100  return;
101  }
102 
103  try {
104 
105  m_readStmt->setSQL("SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
106  "d.adc_mean_g1, d.adc_rms_g1, d.adc_mean_g16, d.adc_rms_g16, d.ped_mean_g1,d.ped_rms_g1, d.ped_mean_g16, d.ped_rms_g16, d.task_status "
107  "FROM channelview cv JOIN mon_pn_green_dat d "
108  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
109  "WHERE d.iov_id = :iov_id");
110  m_readStmt->setInt(1, iovID);
111  ResultSet* rset = m_readStmt->executeQuery();
112 
113  std::pair< EcalLogicID, MonPNGreenDat > p;
114  MonPNGreenDat dat;
115  while(rset->next()) {
116  p.first = EcalLogicID( rset->getString(1), // name
117  rset->getInt(2), // logic_id
118  rset->getInt(3), // id1
119  rset->getInt(4), // id2
120  rset->getInt(5), // id3
121  rset->getString(6)); // maps_to
122 
123  dat.setADCMeanG1( rset->getFloat(7) );
124  dat.setADCRMSG1( rset->getFloat(8) );
125  dat.setADCMeanG16( rset->getFloat(9) );
126  dat.setADCRMSG16( rset->getFloat(10) );
127  dat.setPedMeanG1( rset->getFloat(11) );
128  dat.setPedRMSG1( rset->getFloat(12) );
129  dat.setPedMeanG16( rset->getFloat(13) );
130  dat.setPedRMSG16( rset->getFloat(14) );
131  dat.setTaskStatus( rset->getInt(15) );
132  p.second = dat;
133  fillMap->insert(p);
134  }
135  } catch (SQLException &e) {
136  throw(std::runtime_error("MonPNGreenDat::fetchData(): "+e.getMessage()));
137  }
138 }
139 void MonPNGreenDat::writeArrayDB(const std::map< EcalLogicID, MonPNGreenDat >* data, MonRunIOV* iov)
140  noexcept(false)
141 {
142  this->checkConnection();
143  this->checkPrepare();
144 
145  int iovID = iov->fetchID();
146  if (!iovID) { throw(std::runtime_error("MonPNGreenDat::writeArrayDB: IOV not in DB")); }
147 
148 
149  int nrows=data->size();
150  int* ids= new int[nrows];
151  int* iovid_vec= new int[nrows];
152  float* xx= new float[nrows];
153  float* yy= new float[nrows];
154  float* zz= new float[nrows];
155  float* ww= new float[nrows];
156  float* uu= new float[nrows];
157  float* tt= new float[nrows];
158  float* rr= new float[nrows];
159  float* pp= new float[nrows];
160  int* st= new int[nrows];
161 
162  ub2* ids_len= new ub2[nrows];
163  ub2* iov_len= new ub2[nrows];
164  ub2* x_len= new ub2[nrows];
165  ub2* y_len= new ub2[nrows];
166  ub2* z_len= new ub2[nrows];
167  ub2* w_len= new ub2[nrows];
168  ub2* u_len= new ub2[nrows];
169  ub2* t_len= new ub2[nrows];
170  ub2* r_len= new ub2[nrows];
171  ub2* p_len= new ub2[nrows];
172  ub2* st_len= new ub2[nrows];
173 
174  const EcalLogicID* channel;
175  const MonPNGreenDat* dataitem;
176  int count=0;
177  typedef map< EcalLogicID, MonPNGreenDat >::const_iterator CI;
178  for (CI p = data->begin(); p != data->end(); ++p) {
179  channel = &(p->first);
180  int logicID = channel->getLogicID();
181  if (!logicID) { throw(std::runtime_error("MonPNGreenDat::writeArrayDB: Bad EcalLogicID")); }
182  ids[count]=logicID;
183  iovid_vec[count]=iovID;
184 
185  dataitem = &(p->second);
186  // dataIface.writeDB( channel, dataitem, iov);
187  float x=dataitem->getADCMeanG1();
188  float y=dataitem->getADCRMSG1();
189  float z=dataitem->getADCMeanG16();
190  float w=dataitem->getADCRMSG16();
191  float u=dataitem->getPedMeanG1();
192  float t=dataitem->getPedRMSG1();
193  float r=dataitem->getPedMeanG16();
194  float pi=dataitem->getPedRMSG16();
195  int statu=dataitem->getTaskStatus();
196 
197 
198 
199  xx[count]=x;
200  yy[count]=y;
201  zz[count]=z;
202  ww[count]=w;
203  uu[count]=u;
204  tt[count]=t;
205  rr[count]=r;
206  pp[count]=pi;
207  st[count]=statu;
208 
209 
210  ids_len[count]=sizeof(ids[count]);
211  iov_len[count]=sizeof(iovid_vec[count]);
212 
213  x_len[count]=sizeof(xx[count]);
214  y_len[count]=sizeof(yy[count]);
215  z_len[count]=sizeof(zz[count]);
216  w_len[count]=sizeof(ww[count]);
217  u_len[count]=sizeof(uu[count]);
218  t_len[count]=sizeof(tt[count]);
219  r_len[count]=sizeof(rr[count]);
220  p_len[count]=sizeof(pp[count]);
221  st_len[count]=sizeof(st[count]);
222 
223  count++;
224  }
225 
226 
227  try {
228  m_writeStmt->setDataBuffer(1, (dvoid*)iovid_vec, OCCIINT, sizeof(iovid_vec[0]),iov_len);
229  m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len );
230  m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIFLOAT , sizeof(xx[0]), x_len );
231  m_writeStmt->setDataBuffer(4, (dvoid*)yy, OCCIFLOAT , sizeof(yy[0]), y_len );
232  m_writeStmt->setDataBuffer(5, (dvoid*)zz, OCCIFLOAT , sizeof(zz[0]), z_len );
233  m_writeStmt->setDataBuffer(6, (dvoid*)ww, OCCIFLOAT , sizeof(ww[0]), w_len );
234  m_writeStmt->setDataBuffer(7, (dvoid*)uu, OCCIFLOAT , sizeof(uu[0]), u_len );
235  m_writeStmt->setDataBuffer(8, (dvoid*)tt, OCCIFLOAT , sizeof(tt[0]), t_len );
236  m_writeStmt->setDataBuffer(9, (dvoid*)rr, OCCIFLOAT , sizeof(rr[0]), r_len );
237  m_writeStmt->setDataBuffer(10, (dvoid*)pp, OCCIFLOAT , sizeof(pp[0]), p_len );
238  m_writeStmt->setDataBuffer(11, (dvoid*)st, OCCIINT , sizeof(st[0]), st_len );
239 
240 
241  m_writeStmt->executeArrayUpdate(nrows);
242 
243  delete [] ids;
244  delete [] iovid_vec;
245  delete [] xx;
246  delete [] yy;
247  delete [] zz;
248  delete [] ww;
249  delete [] uu;
250  delete [] tt;
251  delete [] rr;
252  delete [] pp;
253  delete [] st;
254 
255  delete [] ids_len;
256  delete [] iov_len;
257  delete [] x_len;
258  delete [] y_len;
259  delete [] z_len;
260  delete [] w_len;
261  delete [] u_len;
262  delete [] t_len;
263  delete [] r_len;
264  delete [] p_len;
265  delete [] st_len;
266 
267 
268 
269  } catch (SQLException &e) {
270  throw(std::runtime_error("MonPNGreenDat::writeArrayDB(): "+e.getMessage()));
271  }
272 }
float getADCMeanG1() const
Definition: MonPNGreenDat.h:22
const double w
Definition: UKUtility.cc:23
float getPedRMSG1() const
Definition: MonPNGreenDat.h:37
void setADCRMSG1(float mean)
Definition: MonPNGreenDat.h:24
float getADCRMSG16() const
Definition: MonPNGreenDat.h:31
bool getTaskStatus() const
Definition: MonPNGreenDat.h:46
float getPedMeanG16() const
Definition: MonPNGreenDat.h:40
const Double_t pi
float getADCRMSG1() const
Definition: MonPNGreenDat.h:25
void prepareWrite() noexcept(false) override
void setTaskStatus(bool status)
Definition: MonPNGreenDat.h:45
void setPedRMSG1(float mean)
Definition: MonPNGreenDat.h:36
int getLogicID() const
Definition: EcalLogicID.cc:41
void setADCMeanG1(float mean)
Definition: MonPNGreenDat.h:21
float getADCMeanG16() const
Definition: MonPNGreenDat.h:28
void writeDB(const EcalLogicID *ecid, const MonPNGreenDat *item, MonRunIOV *iov) noexcept(false)
void fetchData(std::map< EcalLogicID, MonPNGreenDat > *fillVec, MonRunIOV *iov) noexcept(false)
void setADCRMSG16(float mean)
Definition: MonPNGreenDat.h:30
#define noexcept
~MonPNGreenDat() override
float getPedMeanG1() const
Definition: MonPNGreenDat.h:34
void setADCMeanG16(float mean)
Definition: MonPNGreenDat.h:27
float getPedRMSG16() const
Definition: MonPNGreenDat.h:43
void setPedMeanG1(float mean)
Definition: MonPNGreenDat.h:33
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
void setPedRMSG16(float mean)
Definition: MonPNGreenDat.h:42
void writeArrayDB(const std::map< EcalLogicID, MonPNGreenDat > *data, MonRunIOV *iov) noexcept(false)
void setPedMeanG16(float mean)
Definition: MonPNGreenDat.h:39