CMS 3D CMS Logo

CaliCrystalIntercalDat.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 
17  m_cali = 0;
18  m_caliRMS = 0;
19  m_numEvents = 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 cali_crystal_intercal_dat (iov_id, logic_id, "
32  "cali, cali_rms, num_events, task_status) "
33  "VALUES (:iov_id, :logic_id, "
34  ":3, :4, :5, :6)");
35  } catch (SQLException& e) {
36  throw(std::runtime_error("CaliCrystalIntercalDat::prepareWrite(): " + e.getMessage()));
37  }
38 }
39 
42  CaliIOV* iov) noexcept(false) {
43  this->checkConnection();
44  this->checkPrepare();
45 
46  int iovID = iov->fetchID();
47  if (!iovID) {
48  throw(std::runtime_error("CaliCrystalIntercalDat::writeDB: IOV not in DB"));
49  }
50 
51  int logicID = ecid->getLogicID();
52  if (!logicID) {
53  throw(std::runtime_error("CaliCrystalIntercalDat::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->getCali());
61  m_writeStmt->setFloat(4, item->getCaliRMS());
62  m_writeStmt->setInt(5, item->getNumEvents());
63  m_writeStmt->setInt(6, item->getTaskStatus());
64 
65  m_writeStmt->executeUpdate();
66  } catch (SQLException& e) {
67  throw(std::runtime_error("CaliCrystalIntercalDat::writeDB(): " + e.getMessage()));
68  }
69 }
70 
71 void CaliCrystalIntercalDat::fetchData(std::map<EcalLogicID, CaliCrystalIntercalDat>* fillMap,
72  CaliIOV* 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("CaliCrystalIntercalDat::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.cali, d.cali_rms, d.num_events, d.task_status "
87  "FROM channelview cv JOIN cali_crystal_intercal_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, CaliCrystalIntercalDat> p;
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.setCali(rset->getFloat(7));
104  dat.setCaliRMS(rset->getFloat(8));
105  dat.setNumEvents(rset->getInt(9));
106  dat.setTaskStatus(rset->getInt(10));
107 
108  p.second = dat;
109  fillMap->insert(p);
110  }
111  } catch (SQLException& e) {
112  throw(std::runtime_error("CaliCrystalIntercalDat::fetchData(): " + e.getMessage()));
113  }
114 }
115 
116 void CaliCrystalIntercalDat::writeArrayDB(const std::map<EcalLogicID, CaliCrystalIntercalDat>* data,
117  CaliIOV* iov) noexcept(false) {
118  this->checkConnection();
119  this->checkPrepare();
120 
121  int iovID = iov->fetchID();
122  if (!iovID) {
123  throw(std::runtime_error("CaliCrystalIntercalDat::writeArrayDB: IOV not in DB"));
124  }
125 
126  int nrows = data->size();
127  int* ids = new int[nrows];
128  int* iovid_vec = new int[nrows];
129  float* xx = new float[nrows];
130  float* yy = new float[nrows];
131  int* tt = new int[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* tt_len = new ub2[nrows];
139  ub2* st_len = new ub2[nrows];
140 
141  const EcalLogicID* channel;
142  const CaliCrystalIntercalDat* dataitem;
143  int count = 0;
144  typedef map<EcalLogicID, CaliCrystalIntercalDat>::const_iterator CI;
145  for (CI p = data->begin(); p != data->end(); ++p) {
146  channel = &(p->first);
147  int logicID = channel->getLogicID();
148  if (!logicID) {
149  throw(std::runtime_error("CaliCrystalIntercalDat::writeArrayDB: Bad EcalLogicID"));
150  }
151  ids[count] = logicID;
152  iovid_vec[count] = iovID;
153 
154  dataitem = &(p->second);
155  // dataIface.writeDB( channel, dataitem, iov);
156  float x = dataitem->getCali();
157  float y = dataitem->getCaliRMS();
158  int xtt = dataitem->getNumEvents();
159  int statu = dataitem->getTaskStatus();
160 
161  xx[count] = x;
162  yy[count] = y;
163  tt[count] = xtt;
164  st[count] = statu;
165 
166  ids_len[count] = sizeof(ids[count]);
167  iov_len[count] = sizeof(iovid_vec[count]);
168 
169  x_len[count] = sizeof(xx[count]);
170  y_len[count] = sizeof(yy[count]);
171  tt_len[count] = sizeof(tt[count]);
172  st_len[count] = sizeof(st[count]);
173 
174  count++;
175  }
176 
177  try {
178  m_writeStmt->setDataBuffer(1, (dvoid*)iovid_vec, OCCIINT, sizeof(iovid_vec[0]), iov_len);
179  m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len);
180  m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIFLOAT, sizeof(xx[0]), x_len);
181  m_writeStmt->setDataBuffer(4, (dvoid*)yy, OCCIFLOAT, sizeof(yy[0]), y_len);
182  m_writeStmt->setDataBuffer(5, (dvoid*)tt, OCCIINT, sizeof(tt[0]), tt_len);
183  m_writeStmt->setDataBuffer(6, (dvoid*)st, OCCIINT, sizeof(st[0]), st_len);
184 
185  m_writeStmt->executeArrayUpdate(nrows);
186 
187  delete[] ids;
188  delete[] iovid_vec;
189  delete[] xx;
190  delete[] yy;
191  delete[] st;
192  delete[] tt;
193 
194  delete[] ids_len;
195  delete[] iov_len;
196  delete[] x_len;
197  delete[] y_len;
198  delete[] tt_len;
199  delete[] st_len;
200 
201  } catch (SQLException& e) {
202  throw(std::runtime_error("MonPedestalsDat::writeArrayDB(): " + e.getMessage()));
203  }
204 }
void fetchData(std::map< EcalLogicID, CaliCrystalIntercalDat > *fillVec, CaliIOV *iov) noexcept(false)
void writeArrayDB(const std::map< EcalLogicID, CaliCrystalIntercalDat > *data, CaliIOV *iov) noexcept(false)
int getLogicID() const
Definition: EcalLogicID.cc:28
void writeDB(const EcalLogicID *ecid, const CaliCrystalIntercalDat *item, CaliIOV *iov) noexcept(false)
#define noexcept
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
void prepareWrite() noexcept(false) override