CMS 3D CMS Logo

FEConfigLinDat.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_multx12 = 0;
18  m_multx6 = 0;
19  m_multx1 = 0;
20  m_shift12 = 0;
21  m_shift6 = 0;
22  m_shift1 = 0;
23 }
24 
26 
28  this->checkConnection();
29 
30  try {
31  m_writeStmt = m_conn->createStatement();
32  m_writeStmt->setSQL(
33  "INSERT INTO fe_config_lin_dat (lin_conf_id, logic_id, "
34  " multx12, multx6, multx1, shift12, shift6, shift1 ) "
35  "VALUES (:lin_conf_id, :logic_id, "
36  ":multx12, :multx6, :multx1, :shift12, :shift6, :shift1 )");
37  } catch (SQLException& e) {
38  throw(std::runtime_error("FEConfigLinDat::prepareWrite(): " + e.getMessage()));
39  }
40 }
41 
43  const FEConfigLinDat* item,
44  FEConfigLinInfo* iconf) noexcept(false) {
45  this->checkConnection();
46  this->checkPrepare();
47 
48  int iconfID = iconf->fetchID();
49  if (!iconfID) {
50  throw(std::runtime_error("FEConfigLinDat::writeDB: ICONF not in DB"));
51  }
52 
53  int logicID = ecid->getLogicID();
54  if (!logicID) {
55  throw(std::runtime_error("FEConfigLinDat::writeDB: Bad EcalLogicID"));
56  }
57 
58  try {
59  m_writeStmt->setInt(1, iconfID);
60  m_writeStmt->setInt(2, logicID);
61  m_writeStmt->setInt(3, item->getMultX12());
62  m_writeStmt->setInt(4, item->getMultX6());
63  m_writeStmt->setInt(5, item->getMultX1());
64  m_writeStmt->setInt(6, item->getShift12());
65  m_writeStmt->setInt(7, item->getShift6());
66  m_writeStmt->setInt(8, item->getShift1());
67 
68  m_writeStmt->executeUpdate();
69  } catch (SQLException& e) {
70  throw(std::runtime_error("FEConfigLinDat::writeDB(): " + e.getMessage()));
71  }
72 }
73 
74 void FEConfigLinDat::fetchData(map<EcalLogicID, FEConfigLinDat>* fillMap, FEConfigLinInfo* iconf) noexcept(false) {
75  this->checkConnection();
76  fillMap->clear();
77 
78  iconf->setConnection(m_env, m_conn);
79  int iconfID = iconf->fetchID();
80  if (!iconfID) {
81  // throw(std::runtime_error("FEConfigLinDat::writeDB: ICONF not in DB"));
82  return;
83  }
84 
85  try {
86  m_readStmt->setSQL(
87  "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
88  "d.multx12, d.multx6, d.multx1, d.shift12, d.shift6, d.shift1 "
89  "FROM channelview cv JOIN fe_config_lin_dat d "
90  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
91  "WHERE lin_conf_id = :lin_conf_id");
92  m_readStmt->setInt(1, iconfID);
93  ResultSet* rset = m_readStmt->executeQuery();
94 
95  std::pair<EcalLogicID, FEConfigLinDat> p;
96  FEConfigLinDat dat;
97  while (rset->next()) {
98  p.first = EcalLogicID(rset->getString(1), // name
99  rset->getInt(2), // logic_id
100  rset->getInt(3), // id1
101  rset->getInt(4), // id2
102  rset->getInt(5), // id3
103  rset->getString(6)); // maps_to
104 
105  dat.setMultX12(rset->getInt(7));
106  dat.setMultX6(rset->getInt(8));
107  dat.setMultX1(rset->getInt(9));
108  dat.setShift12(rset->getInt(10));
109  dat.setShift6(rset->getInt(11));
110  dat.setShift1(rset->getInt(12));
111 
112  p.second = dat;
113  fillMap->insert(p);
114  }
115  } catch (SQLException& e) {
116  throw(std::runtime_error("FEConfigLinDat::fetchData: " + e.getMessage()));
117  }
118 }
119 
120 void FEConfigLinDat::writeArrayDB(const std::map<EcalLogicID, FEConfigLinDat>* data,
121  FEConfigLinInfo* iconf) noexcept(false) {
122  this->checkConnection();
123  this->checkPrepare();
124 
125  int iconfID = iconf->fetchID();
126  if (!iconfID) {
127  throw(std::runtime_error("FEConfigLinDat::writeArrayDB: ICONF not in DB"));
128  }
129 
130  int nrows = data->size();
131  int* ids = new int[nrows];
132  int* iconfid_vec = new int[nrows];
133  int* xx = new int[nrows];
134  int* yy = new int[nrows];
135  int* zz = new int[nrows];
136  int* ww = new int[nrows];
137  int* rr = new int[nrows];
138  int* ss = new int[nrows];
139 
140  ub2* ids_len = new ub2[nrows];
141  ub2* iconf_len = new ub2[nrows];
142  ub2* x_len = new ub2[nrows];
143  ub2* y_len = new ub2[nrows];
144  ub2* z_len = new ub2[nrows];
145  ub2* w_len = new ub2[nrows];
146  ub2* r_len = new ub2[nrows];
147  ub2* s_len = new ub2[nrows];
148 
149  const EcalLogicID* channel;
150  const FEConfigLinDat* dataitem;
151  int count = 0;
152  typedef map<EcalLogicID, FEConfigLinDat>::const_iterator CI;
153  for (CI p = data->begin(); p != data->end(); ++p) {
154  channel = &(p->first);
155  int logicID = channel->getLogicID();
156  if (!logicID) {
157  throw(std::runtime_error("FEConfigLinDat::writeArrayDB: Bad EcalLogicID"));
158  }
159  ids[count] = logicID;
160  iconfid_vec[count] = iconfID;
161 
162  dataitem = &(p->second);
163  // dataIface.writeDB( channel, dataitem, iconf);
164  int x = dataitem->getMultX12();
165  int y = dataitem->getMultX6();
166  int z = dataitem->getMultX1();
167  int w = dataitem->getShift12();
168  int r = dataitem->getShift6();
169  int s = dataitem->getShift1();
170 
171  xx[count] = x;
172  yy[count] = y;
173  zz[count] = z;
174  ww[count] = w;
175  rr[count] = r;
176  ss[count] = s;
177 
178  ids_len[count] = sizeof(ids[count]);
179  iconf_len[count] = sizeof(iconfid_vec[count]);
180 
181  x_len[count] = sizeof(xx[count]);
182  y_len[count] = sizeof(yy[count]);
183  z_len[count] = sizeof(zz[count]);
184  w_len[count] = sizeof(ww[count]);
185  r_len[count] = sizeof(rr[count]);
186  s_len[count] = sizeof(ss[count]);
187 
188  count++;
189  }
190 
191  try {
192  m_writeStmt->setDataBuffer(1, (dvoid*)iconfid_vec, OCCIINT, sizeof(iconfid_vec[0]), iconf_len);
193  m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len);
194  m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIINT, sizeof(xx[0]), x_len);
195  m_writeStmt->setDataBuffer(4, (dvoid*)yy, OCCIINT, sizeof(yy[0]), y_len);
196  m_writeStmt->setDataBuffer(5, (dvoid*)zz, OCCIINT, sizeof(zz[0]), z_len);
197  m_writeStmt->setDataBuffer(6, (dvoid*)ww, OCCIINT, sizeof(ww[0]), w_len);
198  m_writeStmt->setDataBuffer(7, (dvoid*)rr, OCCIINT, sizeof(rr[0]), r_len);
199  m_writeStmt->setDataBuffer(8, (dvoid*)ss, OCCIINT, sizeof(ss[0]), s_len);
200 
201  m_writeStmt->executeArrayUpdate(nrows);
202 
203  delete[] ids;
204  delete[] iconfid_vec;
205  delete[] xx;
206  delete[] yy;
207  delete[] zz;
208  delete[] ww;
209  delete[] rr;
210  delete[] ss;
211 
212  delete[] ids_len;
213  delete[] iconf_len;
214  delete[] x_len;
215  delete[] y_len;
216  delete[] z_len;
217  delete[] w_len;
218  delete[] r_len;
219  delete[] s_len;
220 
221  } catch (SQLException& e) {
222  throw(std::runtime_error("FEConfigLinDat::writeArrayDB(): " + e.getMessage()));
223  }
224 }
int getMultX1() const
T w() const
void setShift12(int x)
int getShift12() const
void setMultX1(int x)
void setShift6(int x)
void prepareWrite() noexcept(false) override
void setShift1(int x)
int getLogicID() const
Definition: EcalLogicID.cc:28
int getMultX12() const
~FEConfigLinDat() override
void writeDB(const EcalLogicID *ecid, const FEConfigLinDat *item, FEConfigLinInfo *iconf) noexcept(false)
int getShift1() const
void setMultX6(int x)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
void writeArrayDB(const std::map< EcalLogicID, FEConfigLinDat > *data, FEConfigLinInfo *iconf) noexcept(false)
void setMultX12(int x)
int getShift6() const
void fetchData(std::map< EcalLogicID, FEConfigLinDat > *fillMap, FEConfigLinInfo *iconf) noexcept(false)
int getMultX6() const