CMS 3D CMS Logo

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