CMS 3D CMS Logo

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