CMS 3D CMS Logo

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