CMS 3D CMS Logo

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