CMS 3D CMS Logo

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