CMS 3D CMS Logo

FEConfigFgrEEStripDat.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_thresh = 0;
18  m_lut_fg = 0;
19 }
20 
22 
24  this->checkConnection();
25 
26  try {
27  m_writeStmt = m_conn->createStatement();
28  m_writeStmt->setSQL("INSERT INTO " + getTable() +
29  " (fgr_conf_id, logic_id, "
30  "threshold, lut_fg ) "
31  "VALUES (:fgr_conf_id, :logic_id, "
32  ":threshold, :lut_fg )");
33  } catch (SQLException& e) {
34  throw(std::runtime_error("FEConfigFgrEEStripDat::prepareWrite(): " + e.getMessage()));
35  }
36 }
37 
40  FEConfigFgrInfo* iconf) noexcept(false) {
41  this->checkConnection();
42  this->checkPrepare();
43 
44  int iconfID = iconf->fetchID();
45  if (!iconfID) {
46  throw(std::runtime_error("FEConfigFgrEEStripDat::writeDB: ICONF not in DB"));
47  }
48 
49  int logicID = ecid->getLogicID();
50  if (!logicID) {
51  throw(std::runtime_error("FEConfigFgrEEStripDat::writeDB: Bad EcalLogicID"));
52  }
53 
54  try {
55  m_writeStmt->setInt(1, iconfID);
56  m_writeStmt->setInt(2, logicID);
57  m_writeStmt->setUInt(3, item->getThreshold());
58  m_writeStmt->setUInt(4, item->getLutFg());
59 
60  m_writeStmt->executeUpdate();
61  } catch (SQLException& e) {
62  throw(std::runtime_error("FEConfigFgrEEStripDat::writeDB(): " + e.getMessage()));
63  }
64 }
65 
66 void FEConfigFgrEEStripDat::fetchData(map<EcalLogicID, FEConfigFgrEEStripDat>* fillMap,
67  FEConfigFgrInfo* iconf) noexcept(false) {
68  this->checkConnection();
69  fillMap->clear();
70 
71  iconf->setConnection(m_env, m_conn);
72  int iconfID = iconf->fetchID();
73  if (!iconfID) {
74  // throw(std::runtime_error("FEConfigFgrEEStripDat::writeDB: ICONF 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.threshold, d.lut_fg "
82  "FROM channelview cv JOIN " +
83  getTable() +
84  " d "
85  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
86  "WHERE fgr_conf_id = :fgr_conf_id");
87  m_readStmt->setInt(1, iconfID);
88  ResultSet* rset = m_readStmt->executeQuery();
89 
90  std::pair<EcalLogicID, FEConfigFgrEEStripDat> p;
92  while (rset->next()) {
93  p.first = EcalLogicID(rset->getString(1), // name
94  rset->getInt(2), // logic_id
95  rset->getInt(3), // id1
96  rset->getInt(4), // id2
97  rset->getInt(5), // id3
98  rset->getString(6)); // maps_to
99 
100  dat.setThreshold(rset->getUInt(7));
101  dat.setLutFg(rset->getUInt(8));
102 
103  p.second = dat;
104  fillMap->insert(p);
105  }
106  } catch (SQLException& e) {
107  throw(std::runtime_error("FEConfigFgrEEStripDat::fetchData: " + e.getMessage()));
108  }
109 }
110 
111 void FEConfigFgrEEStripDat::writeArrayDB(const std::map<EcalLogicID, FEConfigFgrEEStripDat>* data,
112  FEConfigFgrInfo* iconf) noexcept(false) {
113  this->checkConnection();
114  this->checkPrepare();
115 
116  int iconfID = iconf->fetchID();
117  if (!iconfID) {
118  throw(std::runtime_error("FEConfigFgrEEStripDat::writeArrayDB: ICONF not in DB"));
119  }
120 
121  int nrows = data->size();
122  int* ids = new int[nrows];
123  int* iconfid_vec = new int[nrows];
124  unsigned int* xx = new unsigned int[nrows];
125  unsigned int* yy = new unsigned int[nrows];
126 
127  ub2* ids_len = new ub2[nrows];
128  ub2* iconf_len = new ub2[nrows];
129  ub2* x_len = new ub2[nrows];
130  ub2* y_len = new ub2[nrows];
131 
132  const EcalLogicID* channel;
133  const FEConfigFgrEEStripDat* dataitem;
134  int count = 0;
135  typedef map<EcalLogicID, FEConfigFgrEEStripDat>::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("FEConfigFgrEEStripDat::writeArrayDB: Bad EcalLogicID"));
141  }
142  ids[count] = logicID;
143  iconfid_vec[count] = iconfID;
144 
145  dataitem = &(p->second);
146  // dataIface.writeDB( channel, dataitem, iconf);
147  unsigned int x = dataitem->getThreshold();
148  unsigned int y = dataitem->getLutFg();
149 
150  xx[count] = x;
151  yy[count] = y;
152 
153  ids_len[count] = sizeof(ids[count]);
154  iconf_len[count] = sizeof(iconfid_vec[count]);
155 
156  x_len[count] = sizeof(xx[count]);
157  y_len[count] = sizeof(yy[count]);
158 
159  count++;
160  }
161 
162  try {
163  m_writeStmt->setDataBuffer(1, (dvoid*)iconfid_vec, OCCIINT, sizeof(iconfid_vec[0]), iconf_len);
164  m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len);
165  m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIUNSIGNED_INT, sizeof(xx[0]), x_len);
166  m_writeStmt->setDataBuffer(4, (dvoid*)yy, OCCIUNSIGNED_INT, sizeof(yy[0]), y_len);
167 
168  m_writeStmt->executeArrayUpdate(nrows);
169 
170  delete[] ids;
171  delete[] iconfid_vec;
172  delete[] xx;
173  delete[] yy;
174 
175  delete[] ids_len;
176  delete[] iconf_len;
177  delete[] x_len;
178  delete[] y_len;
179 
180  } catch (SQLException& e) {
181  throw(std::runtime_error("FEConfigFgrEEStripDat::writeArrayDB(): " + e.getMessage()));
182  }
183 }
unsigned int getThreshold() const
void setThreshold(unsigned int mean)
int getLogicID() const
Definition: EcalLogicID.cc:28
void prepareWrite() noexcept(false) override
void setLutFg(unsigned int mean)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
unsigned int getLutFg() const
void writeDB(const EcalLogicID *ecid, const FEConfigFgrEEStripDat *item, FEConfigFgrInfo *iconf) noexcept(false)
void fetchData(std::map< EcalLogicID, FEConfigFgrEEStripDat > *fillMap, FEConfigFgrInfo *iconf) noexcept(false)
void writeArrayDB(const std::map< EcalLogicID, FEConfigFgrEEStripDat > *data, FEConfigFgrInfo *iconf) noexcept(false)