CMS 3D CMS Logo

DCUIDarkDat.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_apdIDark = 0;
19 }
20 
22 
23 void DCUIDarkDat::prepareWrite() noexcept(false) {
24  this->checkConnection();
25 
26  try {
27  m_writeStmt = m_conn->createStatement();
28  m_writeStmt->setSQL(
29  "INSERT INTO dcu_idark_dat (iov_id, logic_id, "
30  "apd_idark) "
31  "VALUES (:iov_id, :logic_id, "
32  ":apd_idark)");
33  } catch (SQLException& e) {
34  throw(std::runtime_error("DCUIDarkDat::prepareWrite(): " + e.getMessage()));
35  }
36 }
37 
38 void DCUIDarkDat::writeDB(const EcalLogicID* ecid, const DCUIDarkDat* 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("DCUIDarkDat::writeDB: IOV not in DB"));
45  }
46 
47  int logicID = ecid->getLogicID();
48  if (!logicID) {
49  throw(std::runtime_error("DCUIDarkDat::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->getAPDIDark());
57 
58  m_writeStmt->executeUpdate();
59  } catch (SQLException& e) {
60  throw(std::runtime_error("DCUIDarkDat::writeDB(): " + e.getMessage()));
61  }
62 }
63 
64 void DCUIDarkDat::fetchData(std::map<EcalLogicID, DCUIDarkDat>* 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("DCUIDarkDat::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.apd_idark "
79  "FROM channelview cv JOIN dcu_idark_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, DCUIDarkDat> p;
86  DCUIDarkDat dat;
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.setAPDIDark(rset->getFloat(7));
96 
97  p.second = dat;
98  fillMap->insert(p);
99  }
100  } catch (SQLException& e) {
101  throw(std::runtime_error("DCUIDarkDat::fetchData(): " + e.getMessage()));
102  }
103 }
104 void DCUIDarkDat::writeArrayDB(const std::map<EcalLogicID, DCUIDarkDat>* data, DCUIOV* iov) noexcept(false) {
105  this->checkConnection();
106  this->checkPrepare();
107 
108  int iovID = iov->fetchID();
109  if (!iovID) {
110  throw(std::runtime_error("DCUIDarkDat::writeArrayDB: IOV not in DB"));
111  }
112 
113  int nrows = data->size();
114  int* ids = new int[nrows];
115  int* iovid_vec = new int[nrows];
116  float* xx = new float[nrows];
117 
118  ub2* ids_len = new ub2[nrows];
119  ub2* iov_len = new ub2[nrows];
120  ub2* x_len = new ub2[nrows];
121 
122  const EcalLogicID* channel;
123  const DCUIDarkDat* dataitem;
124  int count = 0;
125  typedef map<EcalLogicID, DCUIDarkDat>::const_iterator CI;
126  for (CI p = data->begin(); p != data->end(); ++p) {
127  channel = &(p->first);
128  int logicID = channel->getLogicID();
129  if (!logicID) {
130  throw(std::runtime_error("DCUIDarkDat::writeArrayDB: Bad EcalLogicID"));
131  }
132  ids[count] = logicID;
133  iovid_vec[count] = iovID;
134 
135  dataitem = &(p->second);
136  // dataIface.writeDB( channel, dataitem, iov);
137  float x = dataitem->getAPDIDark();
138 
139  xx[count] = x;
140 
141  ids_len[count] = sizeof(ids[count]);
142  iov_len[count] = sizeof(iovid_vec[count]);
143 
144  x_len[count] = sizeof(xx[count]);
145 
146  count++;
147  }
148 
149  try {
150  m_writeStmt->setDataBuffer(1, (dvoid*)iovid_vec, OCCIINT, sizeof(iovid_vec[0]), iov_len);
151  m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len);
152  m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIFLOAT, sizeof(xx[0]), x_len);
153 
154  m_writeStmt->executeArrayUpdate(nrows);
155 
156  delete[] ids;
157  delete[] iovid_vec;
158  delete[] xx;
159 
160  delete[] ids_len;
161  delete[] iov_len;
162  delete[] x_len;
163 
164  } catch (SQLException& e) {
165  throw(std::runtime_error("DCUIDarkDat::writeArrayDB(): " + e.getMessage()));
166  }
167 }
void setAPDIDark(float i)
Definition: DCUIDarkDat.h:21
Definition: DCUIOV.h:13
int getLogicID() const
Definition: EcalLogicID.cc:28
void writeArrayDB(const std::map< EcalLogicID, DCUIDarkDat > *data, DCUIOV *iov) noexcept(false)
Definition: DCUIDarkDat.cc:104
void writeDB(const EcalLogicID *ecid, const DCUIDarkDat *item, DCUIOV *iov) noexcept(false)
Definition: DCUIDarkDat.cc:38
float getAPDIDark() const
Definition: DCUIDarkDat.h:22
void fetchData(std::map< EcalLogicID, DCUIDarkDat > *fillVec, DCUIOV *iov) noexcept(false)
Definition: DCUIDarkDat.cc:64
void prepareWrite() noexcept(false) override
Definition: DCUIDarkDat.cc:23
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
~DCUIDarkDat() override
Definition: DCUIDarkDat.cc:21