CMS 3D CMS Logo

FEConfigLUTParamDat.cc
Go to the documentation of this file.
1 #include <stdexcept>
2 #include <string>
4 
7 
8 using namespace std;
9 using namespace oracle::occi;
10 
12  m_env = nullptr;
13  m_conn = nullptr;
14  m_writeStmt = nullptr;
15  m_readStmt = nullptr;
16 
17  m_etsat = 0;
18  m_tthreshlow = 0;
19  m_tthreshhigh = 0;
20 }
21 
23 
25  this->checkConnection();
26 
27  try {
28  m_writeStmt = m_conn->createStatement();
29  m_writeStmt->setSQL("INSERT INTO " + getTable() +
30  " (lut_conf_id, logic_id, "
31  " etsat, ttthreshlow, ttthreshhigh ) "
32  "VALUES (:lut_conf_id, :logic_id, "
33  ":etsat, :ttthreshlow, :ttthreshhigh )");
34  } catch (SQLException& e) {
35  throw(std::runtime_error("FEConfigLUTParamDat::prepareWrite(): " + e.getMessage()));
36  }
37 }
38 
41  FEConfigLUTInfo* iconf) noexcept(false) {
42  this->checkConnection();
43  this->checkPrepare();
44 
45  int iconfID = iconf->fetchID();
46  if (!iconfID) {
47  throw(std::runtime_error("FEConfigLUTParamDat::writeDB: ICONF not in DB"));
48  }
49 
50  int logicID = ecid->getLogicID();
51  if (!logicID) {
52  throw(std::runtime_error("FEConfigLUTParamDat::writeDB: Bad EcalLogicID"));
53  }
54 
55  try {
56  m_writeStmt->setInt(1, iconfID);
57  m_writeStmt->setInt(2, logicID);
58  m_writeStmt->setFloat(3, item->getETSat());
59  m_writeStmt->setFloat(4, item->getTTThreshlow());
60  m_writeStmt->setFloat(5, item->getTTThreshhigh());
61 
62  m_writeStmt->executeUpdate();
63  } catch (SQLException& e) {
64  throw(std::runtime_error("FEConfigLUTParamDat::writeDB(): " + e.getMessage()));
65  }
66 }
67 
68 void FEConfigLUTParamDat::fetchData(map<EcalLogicID, FEConfigLUTParamDat>* fillMap,
69  FEConfigLUTInfo* iconf) noexcept(false) {
70  this->checkConnection();
71  fillMap->clear();
72 
73  iconf->setConnection(m_env, m_conn);
74  int iconfID = iconf->fetchID();
75  if (!iconfID) {
76  // throw(std::runtime_error("FEConfigLUTParamDat::writeDB: ICONF 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.etsat, d.ttthreshlow, d.ttthreshhigh "
84  "FROM channelview cv JOIN " +
85  getTable() +
86  " d "
87  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
88  "WHERE lut_conf_id = :lut_conf_id");
89  m_readStmt->setInt(1, iconfID);
90  ResultSet* rset = m_readStmt->executeQuery();
91 
92  std::pair<EcalLogicID, FEConfigLUTParamDat> p;
94  while (rset->next()) {
95  p.first = EcalLogicID(rset->getString(1), // name
96  rset->getInt(2), // logic_id
97  rset->getInt(3), // id1
98  rset->getInt(4), // id2
99  rset->getInt(5), // id3
100  rset->getString(6)); // maps_to
101 
102  dat.setETSat(rset->getFloat(7));
103  dat.setTTThreshlow(rset->getFloat(8));
104  dat.setTTThreshhigh(rset->getFloat(9));
105 
106  p.second = dat;
107  fillMap->insert(p);
108  }
109  } catch (SQLException& e) {
110  throw(std::runtime_error("FEConfigLUTParamDat::fetchData: " + e.getMessage()));
111  }
112 }
113 
114 void FEConfigLUTParamDat::writeArrayDB(const std::map<EcalLogicID, FEConfigLUTParamDat>* data,
115  FEConfigLUTInfo* iconf) noexcept(false) {
116  this->checkConnection();
117  this->checkPrepare();
118 
119  int iconfID = iconf->fetchID();
120  if (!iconfID) {
121  throw(std::runtime_error("FEConfigLUTParamDat::writeArrayDB: ICONF not in DB"));
122  }
123 
124  int nrows = data->size();
125  int* ids = new int[nrows];
126  int* iov_vec = new int[nrows];
127  float* xx = new float[nrows];
128  float* yy = new float[nrows];
129  float* zz = new float[nrows];
130 
131  ub2* ids_len = new ub2[nrows];
132  ub2* iov_len = new ub2[nrows];
133  ub2* x_len = new ub2[nrows];
134  ub2* y_len = new ub2[nrows];
135  ub2* z_len = new ub2[nrows];
136 
137  const EcalLogicID* channel;
138  const FEConfigLUTParamDat* dataitem;
139  int count = 0;
140  typedef map<EcalLogicID, FEConfigLUTParamDat>::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("FEConfigLUTParamDat::writeArrayDB: Bad EcalLogicID"));
146  }
147  ids[count] = logicID;
148  iov_vec[count] = iconfID;
149 
150  dataitem = &(p->second);
151  // dataIface.writeDB( channel, dataitem, conf);
152  float x = dataitem->getETSat();
153  float y = dataitem->getTTThreshlow();
154  float z = dataitem->getTTThreshhigh();
155 
156  xx[count] = x;
157  yy[count] = y;
158  zz[count] = z;
159 
160  ids_len[count] = sizeof(ids[count]);
161  iov_len[count] = sizeof(iov_vec[count]);
162 
163  x_len[count] = sizeof(xx[count]);
164  y_len[count] = sizeof(yy[count]);
165  z_len[count] = sizeof(zz[count]);
166 
167  count++;
168  }
169 
170  try {
171  m_writeStmt->setDataBuffer(1, (dvoid*)iov_vec, OCCIINT, sizeof(iov_vec[0]), iov_len);
172  m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len);
173  m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIFLOAT, sizeof(xx[0]), x_len);
174  m_writeStmt->setDataBuffer(4, (dvoid*)yy, OCCIFLOAT, sizeof(yy[0]), y_len);
175  m_writeStmt->setDataBuffer(5, (dvoid*)zz, OCCIFLOAT, sizeof(zz[0]), z_len);
176 
177  m_writeStmt->executeArrayUpdate(nrows);
178 
179  delete[] ids;
180  delete[] iov_vec;
181  delete[] xx;
182  delete[] yy;
183  delete[] zz;
184 
185  delete[] ids_len;
186  delete[] iov_len;
187  delete[] x_len;
188  delete[] y_len;
189  delete[] z_len;
190 
191  } catch (SQLException& e) {
192  throw(std::runtime_error("FEConfigLUTParamDat::writeArrayDB(): " + e.getMessage()));
193  }
194 }
float getTTThreshlow() const
void prepareWrite() noexcept(false) override
float getTTThreshhigh() const
void writeDB(const EcalLogicID *ecid, const FEConfigLUTParamDat *item, FEConfigLUTInfo *iconf) noexcept(false)
int getLogicID() const
Definition: EcalLogicID.cc:28
void fetchData(std::map< EcalLogicID, FEConfigLUTParamDat > *fillMap, FEConfigLUTInfo *iconf) noexcept(false)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
void setTTThreshhigh(float x)
void writeArrayDB(const std::map< EcalLogicID, FEConfigLUTParamDat > *data, FEConfigLUTInfo *iconf) noexcept(false)
void setTTThreshlow(float x)