CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
MonMemTTConsistencyDat.cc
Go to the documentation of this file.
1 #include <stdexcept>
2 #include <string>
4 
6 
7 using namespace std;
8 using namespace oracle::occi;
9 
11  m_env = nullptr;
12  m_conn = nullptr;
13  m_writeStmt = nullptr;
14  m_readStmt = nullptr;
15 
16  m_processedEvents = 0;
17  m_problematicEvents = 0;
18  m_problemsID = 0;
19  m_problemsSize = 0;
20  m_problemsLV1 = 0;
21  m_problemsBunchX = 0;
22  m_taskStatus = false;
23 }
24 
26 
28  this->checkConnection();
29 
30  try {
31  m_writeStmt = m_conn->createStatement();
32  m_writeStmt->setSQL(
33  "INSERT INTO mon_mem_tt_consistency_dat (iov_id, logic_id, "
34  "processed_events, problematic_events, problems_id, problems_size, problems_LV1, problems_bunch_X, "
35  "task_status) "
36  "VALUES (:iov_id, :logic_id, "
37  ":3, :4, :5, :6, :7, :8, :9)");
38  } catch (SQLException& e) {
39  throw(std::runtime_error("MonMemTTConsistencyDat::prepareWrite(): " + e.getMessage()));
40  }
41 }
42 
45  MonRunIOV* iov) noexcept(false) {
46  this->checkConnection();
47  this->checkPrepare();
48 
49  int iovID = iov->fetchID();
50  if (!iovID) {
51  throw(std::runtime_error("MonMemTTConsistencyDat::writeDB: IOV not in DB"));
52  }
53 
54  int logicID = ecid->getLogicID();
55  if (!logicID) {
56  throw(std::runtime_error("MonMemTTConsistencyDat::writeDB: Bad EcalLogicID"));
57  }
58 
59  try {
60  m_writeStmt->setInt(1, iovID);
61  m_writeStmt->setInt(2, logicID);
62 
63  m_writeStmt->setInt(3, item->getProcessedEvents());
64  m_writeStmt->setInt(4, item->getProblematicEvents());
65  m_writeStmt->setInt(5, item->getProblemsID());
66  m_writeStmt->setInt(6, item->getProblemsSize());
67  m_writeStmt->setInt(7, item->getProblemsLV1());
68  m_writeStmt->setInt(8, item->getProblemsBunchX());
69  m_writeStmt->setInt(9, item->getTaskStatus());
70  m_writeStmt->executeUpdate();
71  } catch (SQLException& e) {
72  throw(std::runtime_error("MonMemTTConsistencyDat::writeDB(): " + e.getMessage()));
73  }
74 }
75 
76 void MonMemTTConsistencyDat::fetchData(std::map<EcalLogicID, MonMemTTConsistencyDat>* fillMap,
77  MonRunIOV* iov) noexcept(false) {
78  this->checkConnection();
79  fillMap->clear();
80 
81  iov->setConnection(m_env, m_conn);
82  int iovID = iov->fetchID();
83  if (!iovID) {
84  // throw(std::runtime_error("MonMemTTConsistencyDat::writeDB: IOV not in DB"));
85  return;
86  }
87 
88  try {
89  m_readStmt->setSQL(
90  "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
91  "d.processed_events, d.problematic_events, d.problems_id, d.problems_size, d.problems_LV1, d.problems_bunch_X, "
92  "d.task_status "
93  "FROM channelview cv JOIN mon_mem_tt_consistency_dat d "
94  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
95  "WHERE d.iov_id = :iov_id");
96  m_readStmt->setInt(1, iovID);
97  ResultSet* rset = m_readStmt->executeQuery();
98 
99  std::pair<EcalLogicID, MonMemTTConsistencyDat> p;
101  while (rset->next()) {
102  p.first = EcalLogicID(rset->getString(1), // name
103  rset->getInt(2), // logic_id
104  rset->getInt(3), // id1
105  rset->getInt(4), // id2
106  rset->getInt(5), // id3
107  rset->getString(6)); // maps_to
108 
109  dat.setProcessedEvents(rset->getInt(7));
110  dat.setProblematicEvents(rset->getInt(8));
111  dat.setProblemsID(rset->getInt(9));
112  dat.setProblemsSize(rset->getInt(10));
113  dat.setProblemsLV1(rset->getInt(11));
114  dat.setProblemsBunchX(rset->getInt(12));
115  dat.setTaskStatus(rset->getInt(13));
116 
117  p.second = dat;
118  fillMap->insert(p);
119  }
120  } catch (SQLException& e) {
121  throw(std::runtime_error("MonMemTTConsistencyDat::fetchData(): " + e.getMessage()));
122  }
123 }
124 
125 void MonMemTTConsistencyDat::writeArrayDB(const std::map<EcalLogicID, MonMemTTConsistencyDat>* data,
126  MonRunIOV* iov) noexcept(false) {
127  this->checkConnection();
128  this->checkPrepare();
129 
130  int iovID = iov->fetchID();
131  if (!iovID) {
132  throw(std::runtime_error("MonMemTTConsistencyDat::writeArrayDB: IOV not in DB"));
133  }
134 
135  int nrows = data->size();
136  int* ids = new int[nrows];
137  int* iovid_vec = new int[nrows];
138  int* xx = new int[nrows];
139  int* yy = new int[nrows];
140  int* zz = new int[nrows];
141  int* ww = new int[nrows];
142  int* uu = new int[nrows];
143  int* tt = new int[nrows];
144  int* st = new int[nrows];
145 
146  ub2* ids_len = new ub2[nrows];
147  ub2* iov_len = new ub2[nrows];
148  ub2* x_len = new ub2[nrows];
149  ub2* y_len = new ub2[nrows];
150  ub2* z_len = new ub2[nrows];
151  ub2* w_len = new ub2[nrows];
152  ub2* u_len = new ub2[nrows];
153  ub2* t_len = new ub2[nrows];
154  ub2* st_len = new ub2[nrows];
155 
156  const EcalLogicID* channel;
157  const MonMemTTConsistencyDat* dataitem;
158  int count = 0;
159  typedef map<EcalLogicID, MonMemTTConsistencyDat>::const_iterator CI;
160  for (CI p = data->begin(); p != data->end(); ++p) {
161  channel = &(p->first);
162  int logicID = channel->getLogicID();
163  if (!logicID) {
164  throw(std::runtime_error("MonMemTTConsistencyDat::writeArrayDB: Bad EcalLogicID"));
165  }
166  ids[count] = logicID;
167  iovid_vec[count] = iovID;
168 
169  dataitem = &(p->second);
170  // dataIface.writeDB( channel, dataitem, iov);
171  int x = dataitem->getProcessedEvents();
172  int y = dataitem->getProblematicEvents();
173  int z = dataitem->getProblemsID();
174  int w = dataitem->getProblemsSize();
175  int u = dataitem->getProblemsLV1();
176  int t = dataitem->getProblemsBunchX();
177  int statu = dataitem->getTaskStatus();
178 
179  xx[count] = x;
180  yy[count] = y;
181  zz[count] = z;
182  ww[count] = w;
183  uu[count] = u;
184  tt[count] = t;
185  st[count] = statu;
186 
187  ids_len[count] = sizeof(ids[count]);
188  iov_len[count] = sizeof(iovid_vec[count]);
189 
190  x_len[count] = sizeof(xx[count]);
191  y_len[count] = sizeof(yy[count]);
192  z_len[count] = sizeof(zz[count]);
193  w_len[count] = sizeof(ww[count]);
194  u_len[count] = sizeof(uu[count]);
195  t_len[count] = sizeof(tt[count]);
196  st_len[count] = sizeof(st[count]);
197 
198  count++;
199  }
200 
201  try {
202  m_writeStmt->setDataBuffer(1, (dvoid*)iovid_vec, OCCIINT, sizeof(iovid_vec[0]), iov_len);
203  m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len);
204  m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIINT, sizeof(xx[0]), x_len);
205  m_writeStmt->setDataBuffer(4, (dvoid*)yy, OCCIINT, sizeof(yy[0]), y_len);
206  m_writeStmt->setDataBuffer(5, (dvoid*)zz, OCCIINT, sizeof(zz[0]), z_len);
207  m_writeStmt->setDataBuffer(6, (dvoid*)ww, OCCIINT, sizeof(ww[0]), w_len);
208  m_writeStmt->setDataBuffer(7, (dvoid*)uu, OCCIINT, sizeof(uu[0]), u_len);
209  m_writeStmt->setDataBuffer(8, (dvoid*)tt, OCCIINT, sizeof(tt[0]), t_len);
210  m_writeStmt->setDataBuffer(9, (dvoid*)st, OCCIINT, sizeof(st[0]), st_len);
211 
212  m_writeStmt->executeArrayUpdate(nrows);
213 
214  delete[] ids;
215  delete[] iovid_vec;
216  delete[] xx;
217  delete[] yy;
218  delete[] zz;
219  delete[] ww;
220  delete[] uu;
221  delete[] tt;
222  delete[] st;
223 
224  delete[] ids_len;
225  delete[] iov_len;
226  delete[] x_len;
227  delete[] y_len;
228  delete[] z_len;
229  delete[] w_len;
230  delete[] u_len;
231  delete[] t_len;
232  delete[] st_len;
233 
234  } catch (SQLException& e) {
235  throw(std::runtime_error("MonMemTTConsistencyDat::writeArrayDB(): " + e.getMessage()));
236  }
237 }
void writeDB(const EcalLogicID *ecid, const MonMemTTConsistencyDat *item, MonRunIOV *iov) noexcept(false)
const double w
Definition: UKUtility.cc:23
void setProblemsBunchX(int bunchX)
int getLogicID() const
Definition: EcalLogicID.cc:28
void fetchData(std::map< EcalLogicID, MonMemTTConsistencyDat > *fillVec, MonRunIOV *iov) noexcept(false)
void prepareWrite() noexcept(false) override
static std::vector< std::string > checklist dat
void setTaskStatus(bool status)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
void writeArrayDB(const std::map< EcalLogicID, MonMemTTConsistencyDat > *data, MonRunIOV *iov) noexcept(false)