CMS 3D CMS Logo

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