CMS 3D CMS Logo

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