CMS 3D CMS Logo

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