CMS 3D CMS Logo

MonPNPedDat.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_pedMeanG1 = 0;
19  m_pedRMSG1 = 0;
20  m_pedMeanG16 = 0;
21  m_pedRMSG16 = 0;
22  m_taskStatus = false;
23 }
24 
26 
27 void MonPNPedDat::prepareWrite() noexcept(false) {
28  this->checkConnection();
29 
30  try {
31  m_writeStmt = m_conn->createStatement();
32  m_writeStmt->setSQL(
33  "INSERT INTO mon_pn_ped_dat (iov_id, logic_id, "
34  "ped_mean_g1, ped_rms_g1, ped_mean_g16, ped_rms_g16, task_status) "
35  "VALUES (:iov_id, :logic_id, "
36  ":3, :4, :5, :6, :7)");
37  } catch (SQLException& e) {
38  throw(std::runtime_error("MonPNPedDat::prepareWrite(): " + e.getMessage()));
39  }
40 }
41 
42 void MonPNPedDat::writeDB(const EcalLogicID* ecid, const MonPNPedDat* item, MonRunIOV* iov) noexcept(false) {
43  this->checkConnection();
44  this->checkPrepare();
45 
46  int iovID = iov->fetchID();
47  if (!iovID) {
48  throw(std::runtime_error("MonPNPedDat::writeDB: IOV not in DB"));
49  }
50 
51  int logicID = ecid->getLogicID();
52  if (!logicID) {
53  throw(std::runtime_error("MonPNPedDat::writeDB: Bad EcalLogicID"));
54  }
55 
56  try {
57  m_writeStmt->setInt(1, iovID);
58  m_writeStmt->setInt(2, logicID);
59 
60  m_writeStmt->setFloat(3, item->getPedMeanG1());
61  m_writeStmt->setFloat(4, item->getPedRMSG1());
62  m_writeStmt->setFloat(5, item->getPedMeanG16());
63  m_writeStmt->setFloat(6, item->getPedRMSG16());
64  m_writeStmt->setInt(7, item->getTaskStatus());
65 
66  m_writeStmt->executeUpdate();
67  } catch (SQLException& e) {
68  throw(std::runtime_error("MonPNPedDat::writeDB(): " + e.getMessage()));
69  }
70 }
71 
72 void MonPNPedDat::fetchData(std::map<EcalLogicID, MonPNPedDat>* fillMap, MonRunIOV* iov) noexcept(false) {
73  this->checkConnection();
74  fillMap->clear();
75 
76  iov->setConnection(m_env, m_conn);
77  int iovID = iov->fetchID();
78  if (!iovID) {
79  // throw(std::runtime_error("MonPNPedDat::writeDB: IOV not in DB"));
80  return;
81  }
82 
83  try {
84  m_readStmt->setSQL(
85  "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
86  "d.ped_mean_g1,d.ped_rms_g1, d.ped_mean_g16, d.ped_rms_g16, d.task_status "
87  "FROM channelview cv JOIN mon_pn_ped_dat d "
88  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
89  "WHERE d.iov_id = :iov_id");
90  m_readStmt->setInt(1, iovID);
91  ResultSet* rset = m_readStmt->executeQuery();
92 
93  std::pair<EcalLogicID, MonPNPedDat> p;
94  MonPNPedDat dat;
95  while (rset->next()) {
96  p.first = EcalLogicID(rset->getString(1), // name
97  rset->getInt(2), // logic_id
98  rset->getInt(3), // id1
99  rset->getInt(4), // id2
100  rset->getInt(5), // id3
101  rset->getString(6)); // maps_to
102 
103  dat.setPedMeanG1(rset->getFloat(7));
104  dat.setPedRMSG1(rset->getFloat(8));
105  dat.setPedMeanG16(rset->getFloat(9));
106  dat.setPedRMSG16(rset->getFloat(10));
107  dat.setTaskStatus(rset->getInt(11));
108  p.second = dat;
109  fillMap->insert(p);
110  }
111  } catch (SQLException& e) {
112  throw(std::runtime_error("MonPNPedDat::fetchData(): " + e.getMessage()));
113  }
114 }
115 
116 void MonPNPedDat::writeArrayDB(const std::map<EcalLogicID, MonPNPedDat>* data, MonRunIOV* iov) noexcept(false) {
117  this->checkConnection();
118  this->checkPrepare();
119 
120  int iovID = iov->fetchID();
121  if (!iovID) {
122  throw(std::runtime_error("MonPNPedDat::writeArrayDB: IOV not in DB"));
123  }
124 
125  int nrows = data->size();
126  int* ids = new int[nrows];
127  int* iovid_vec = new int[nrows];
128  float* xx = new float[nrows];
129  float* yy = new float[nrows];
130  float* zz = new float[nrows];
131  float* ww = new float[nrows];
132  int* st = new int[nrows];
133 
134  ub2* ids_len = new ub2[nrows];
135  ub2* iov_len = new ub2[nrows];
136  ub2* x_len = new ub2[nrows];
137  ub2* y_len = new ub2[nrows];
138  ub2* z_len = new ub2[nrows];
139  ub2* w_len = new ub2[nrows];
140 
141  ub2* st_len = new ub2[nrows];
142 
143  const EcalLogicID* channel;
144  const MonPNPedDat* dataitem;
145  int count = 0;
146  typedef map<EcalLogicID, MonPNPedDat>::const_iterator CI;
147  for (CI p = data->begin(); p != data->end(); ++p) {
148  channel = &(p->first);
149  int logicID = channel->getLogicID();
150  if (!logicID) {
151  throw(std::runtime_error("MonPNPedDat::writeArrayDB: Bad EcalLogicID"));
152  }
153  ids[count] = logicID;
154  iovid_vec[count] = iovID;
155 
156  dataitem = &(p->second);
157  // dataIface.writeDB( channel, dataitem, iov);
158  float x = dataitem->getPedMeanG1();
159  float y = dataitem->getPedRMSG1();
160  float z = dataitem->getPedMeanG16();
161  float w = dataitem->getPedRMSG16();
162  int statu = dataitem->getTaskStatus();
163 
164  xx[count] = x;
165  yy[count] = y;
166  zz[count] = z;
167  ww[count] = w;
168 
169  st[count] = statu;
170 
171  ids_len[count] = sizeof(ids[count]);
172  iov_len[count] = sizeof(iovid_vec[count]);
173 
174  x_len[count] = sizeof(xx[count]);
175  y_len[count] = sizeof(yy[count]);
176  z_len[count] = sizeof(zz[count]);
177  w_len[count] = sizeof(ww[count]);
178 
179  st_len[count] = sizeof(st[count]);
180 
181  count++;
182  }
183 
184  try {
185  m_writeStmt->setDataBuffer(1, (dvoid*)iovid_vec, OCCIINT, sizeof(iovid_vec[0]), iov_len);
186  m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len);
187  m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIFLOAT, sizeof(xx[0]), x_len);
188  m_writeStmt->setDataBuffer(4, (dvoid*)yy, OCCIFLOAT, sizeof(yy[0]), y_len);
189  m_writeStmt->setDataBuffer(5, (dvoid*)zz, OCCIFLOAT, sizeof(zz[0]), z_len);
190  m_writeStmt->setDataBuffer(6, (dvoid*)ww, OCCIFLOAT, sizeof(ww[0]), w_len);
191  m_writeStmt->setDataBuffer(7, (dvoid*)st, OCCIINT, sizeof(st[0]), st_len);
192 
193  m_writeStmt->executeArrayUpdate(nrows);
194 
195  delete[] ids;
196  delete[] iovid_vec;
197  delete[] xx;
198  delete[] yy;
199  delete[] zz;
200  delete[] ww;
201 
202  delete[] st;
203 
204  delete[] ids_len;
205  delete[] iov_len;
206  delete[] x_len;
207  delete[] y_len;
208  delete[] z_len;
209  delete[] w_len;
210 
211  delete[] st_len;
212 
213  } catch (SQLException& e) {
214  throw(std::runtime_error("MonPNPedDat::writeArrayDB(): " + e.getMessage()));
215  }
216 }
T w() const
void setPedRMSG16(float mean)
Definition: MonPNPedDat.h:30
void writeDB(const EcalLogicID *ecid, const MonPNPedDat *item, MonRunIOV *iov) noexcept(false)
Definition: MonPNPedDat.cc:42
float getPedMeanG16() const
Definition: MonPNPedDat.h:28
void fetchData(std::map< EcalLogicID, MonPNPedDat > *fillVec, MonRunIOV *iov) noexcept(false)
Definition: MonPNPedDat.cc:72
void setPedRMSG1(float mean)
Definition: MonPNPedDat.h:24
void setPedMeanG1(float mean)
Definition: MonPNPedDat.h:21
void prepareWrite() noexcept(false) override
Definition: MonPNPedDat.cc:27
int getLogicID() const
Definition: EcalLogicID.cc:28
void setPedMeanG16(float mean)
Definition: MonPNPedDat.h:27
bool getTaskStatus() const
Definition: MonPNPedDat.h:34
void writeArrayDB(const std::map< EcalLogicID, MonPNPedDat > *data, MonRunIOV *iov) noexcept(false)
Definition: MonPNPedDat.cc:116
~MonPNPedDat() override
Definition: MonPNPedDat.cc:25
float getPedRMSG1() const
Definition: MonPNPedDat.h:25
float getPedMeanG1() const
Definition: MonPNPedDat.h:22
float getPedRMSG16() const
Definition: MonPNPedDat.h:31
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
void setTaskStatus(bool status)
Definition: MonPNPedDat.h:33