CMS 3D CMS Logo

FEConfigFgrParamDat.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_fglowthresh = 0;
18  m_fghighthresh = 0;
19  m_lowratio = 0;
20  m_highratio = 0;
21 }
22 
24 
26  this->checkConnection();
27 
28  try {
29  m_writeStmt = m_conn->createStatement();
30  m_writeStmt->setSQL("INSERT INTO " + getTable() +
31  " (fgr_conf_id, logic_id, "
32  " fg_lowthresh, fg_highthresh, fg_lowratio, fg_highratio ) "
33  "VALUES (:fgr_conf_id, :logic_id, "
34  " :fg_lowthresh, :fg_highthresh, :fg_lowratio, :fg_highratio )");
35  } catch (SQLException& e) {
36  throw(std::runtime_error("FEConfigFgrParamDat::prepareWrite(): " + e.getMessage()));
37  }
38 }
39 
42  FEConfigFgrInfo* iconf) noexcept(false) {
43  this->checkConnection();
44  this->checkPrepare();
45 
46  int iconfID = iconf->fetchID();
47  if (!iconfID) {
48  throw(std::runtime_error("FEConfigFgrParamDat::writeDB: ICONF not in DB"));
49  }
50 
51  int logicID = ecid->getLogicID();
52  if (!logicID) {
53  throw(std::runtime_error("FEConfigFgrParamDat::writeDB: Bad EcalLogicID"));
54  }
55 
56  try {
57  m_writeStmt->setInt(1, iconfID);
58  m_writeStmt->setInt(2, logicID);
59  m_writeStmt->setFloat(3, item->getFGlowthresh());
60  m_writeStmt->setFloat(4, item->getFGhighthresh());
61  m_writeStmt->setFloat(5, item->getFGlowratio());
62  m_writeStmt->setFloat(6, item->getFGhighratio());
63 
64  m_writeStmt->executeUpdate();
65  } catch (SQLException& e) {
66  throw(std::runtime_error("FEConfigFgrParamDat::writeDB(): " + e.getMessage()));
67  }
68 }
69 
70 void FEConfigFgrParamDat::fetchData(map<EcalLogicID, FEConfigFgrParamDat>* fillMap,
71  FEConfigFgrInfo* iconf) noexcept(false) {
72  this->checkConnection();
73  fillMap->clear();
74 
75  iconf->setConnection(m_env, m_conn);
76  int iconfID = iconf->fetchID();
77  if (!iconfID) {
78  // throw(std::runtime_error("FEConfigFgrParamDat::writeDB: ICONF not in DB"));
79  return;
80  }
81 
82  try {
83  m_readStmt->setSQL(
84  "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
85  " d.fg_lowthresh, d.fg_highthresh, d.fg_lowratio, d.fg_highratio "
86  "FROM channelview cv JOIN " +
87  getTable() +
88  " d "
89  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
90  "WHERE fgr_conf_id = :fgr_conf_id");
91  m_readStmt->setInt(1, iconfID);
92  ResultSet* rset = m_readStmt->executeQuery();
93 
94  std::pair<EcalLogicID, FEConfigFgrParamDat> p;
96  while (rset->next()) {
97  p.first = EcalLogicID(rset->getString(1), // name
98  rset->getInt(2), // logic_id
99  rset->getInt(3), // id1
100  rset->getInt(4), // id2
101  rset->getInt(5), // id3
102  rset->getString(6)); // maps_to
103 
104  dat.setFGlowthresh(rset->getFloat(7));
105  dat.setFGhighthresh(rset->getFloat(8));
106  dat.setFGlowratio(rset->getFloat(9));
107  dat.setFGhighratio(rset->getFloat(10));
108 
109  p.second = dat;
110  fillMap->insert(p);
111  }
112  } catch (SQLException& e) {
113  throw(std::runtime_error("FEConfigFgrParamDat::fetchData: " + e.getMessage()));
114  }
115 }
116 
117 void FEConfigFgrParamDat::writeArrayDB(const std::map<EcalLogicID, FEConfigFgrParamDat>* data,
118  FEConfigFgrInfo* iconf) noexcept(false) {
119  this->checkConnection();
120  this->checkPrepare();
121 
122  int iconfID = iconf->fetchID();
123  if (!iconfID) {
124  throw(std::runtime_error("FEConfigFgrParamDat::writeArrayDB: ICONF not in DB"));
125  }
126 
127  int nrows = data->size();
128  int* ids = new int[nrows];
129  int* iov_vec = new int[nrows];
130  float* ww = new float[nrows];
131  float* uu = new float[nrows];
132  float* tt = new float[nrows];
133  float* st = new float[nrows];
134 
135  ub2* ids_len = new ub2[nrows];
136  ub2* iov_len = new ub2[nrows];
137  ub2* w_len = new ub2[nrows];
138  ub2* u_len = new ub2[nrows];
139  ub2* t_len = new ub2[nrows];
140  ub2* st_len = new ub2[nrows];
141 
142  const EcalLogicID* channel;
143  const FEConfigFgrParamDat* dataitem;
144  int count = 0;
145  typedef map<EcalLogicID, FEConfigFgrParamDat>::const_iterator CI;
146  for (CI p = data->begin(); p != data->end(); ++p) {
147  channel = &(p->first);
148  int logicID = channel->getLogicID();
149  if (!logicID) {
150  throw(std::runtime_error("FEConfigFgrParamDat::writeArrayDB: Bad EcalLogicID"));
151  }
152  ids[count] = logicID;
153  iov_vec[count] = iconfID;
154 
155  dataitem = &(p->second);
156  // dataIface.writeDB( channel, dataitem, conf);
157  float w = dataitem->getFGlowthresh();
158  float u = dataitem->getFGhighthresh();
159  float t = dataitem->getFGlowratio();
160  float r = dataitem->getFGhighratio();
161 
162  ww[count] = w;
163  uu[count] = u;
164  tt[count] = t;
165  st[count] = r;
166 
167  ids_len[count] = sizeof(ids[count]);
168  iov_len[count] = sizeof(iov_vec[count]);
169 
170  w_len[count] = sizeof(ww[count]);
171  u_len[count] = sizeof(uu[count]);
172  t_len[count] = sizeof(tt[count]);
173  st_len[count] = sizeof(st[count]);
174 
175  count++;
176  }
177 
178  try {
179  m_writeStmt->setDataBuffer(1, (dvoid*)iov_vec, OCCIINT, sizeof(iov_vec[0]), iov_len);
180  m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len);
181  m_writeStmt->setDataBuffer(3, (dvoid*)ww, OCCIFLOAT, sizeof(ww[0]), w_len);
182  m_writeStmt->setDataBuffer(4, (dvoid*)uu, OCCIFLOAT, sizeof(uu[0]), u_len);
183  m_writeStmt->setDataBuffer(5, (dvoid*)tt, OCCIFLOAT, sizeof(tt[0]), t_len);
184  m_writeStmt->setDataBuffer(6, (dvoid*)st, OCCIFLOAT, sizeof(st[0]), st_len);
185 
186  m_writeStmt->executeArrayUpdate(nrows);
187 
188  delete[] ids;
189  delete[] iov_vec;
190  delete[] ww;
191  delete[] uu;
192  delete[] tt;
193  delete[] st;
194 
195  delete[] ids_len;
196  delete[] iov_len;
197  delete[] w_len;
198  delete[] u_len;
199  delete[] t_len;
200  delete[] st_len;
201 
202  } catch (SQLException& e) {
203  throw(std::runtime_error("FEConfigFgrParamDat::writeArrayDB(): " + e.getMessage()));
204  }
205 }
void fetchData(std::map< EcalLogicID, FEConfigFgrParamDat > *fillMap, FEConfigFgrInfo *iconf) noexcept(false)
void setFGhighratio(float x)
T w() const
void setFGlowthresh(float x)
void writeDB(const EcalLogicID *ecid, const FEConfigFgrParamDat *item, FEConfigFgrInfo *iconf) noexcept(false)
void writeArrayDB(const std::map< EcalLogicID, FEConfigFgrParamDat > *data, FEConfigFgrInfo *iconf) noexcept(false)
float getFGhighratio() const
int getLogicID() const
Definition: EcalLogicID.cc:28
void prepareWrite() noexcept(false) override
void setFGlowratio(float x)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
float getFGlowthresh() const
float getFGlowratio() const
void setFGhighthresh(float x)
float getFGhighthresh() const