CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
MonH4TablePositionDat.cc
Go to the documentation of this file.
1 #include <stdexcept>
2 #include <string>
4 
6 
7 using namespace std;
8 using namespace oracle::occi;
9 
11  m_env = nullptr;
12  m_conn = nullptr;
13  m_writeStmt = nullptr;
14  m_readStmt = nullptr;
15 
16  m_tableX = 0;
17  m_tableY = 0;
18 }
19 
21 
23  this->checkConnection();
24 
25  try {
26  m_writeStmt = m_conn->createStatement();
27  m_writeStmt->setSQL(
28  "INSERT INTO mon_h4_table_position_dat (iov_id, logic_id, "
29  "table_x, table_y) "
30  "VALUES (:iov_id, :logic_id, "
31  ":3, :4)");
32  } catch (SQLException& e) {
33  throw(std::runtime_error("MonH4TablePositionDat::prepareWrite(): " + e.getMessage()));
34  }
35 }
36 
39  MonRunIOV* iov) noexcept(false) {
40  this->checkConnection();
41  this->checkPrepare();
42 
43  int iovID = iov->fetchID();
44  if (!iovID) {
45  throw(std::runtime_error("MonH4TablePositionDat::writeDB: IOV not in DB"));
46  }
47 
48  int logicID = ecid->getLogicID();
49  if (!logicID) {
50  throw(std::runtime_error("MonH4TablePositionDat::writeDB: Bad EcalLogicID"));
51  }
52 
53  try {
54  m_writeStmt->setInt(1, iovID);
55  m_writeStmt->setInt(2, logicID);
56 
57  m_writeStmt->setFloat(3, item->getTableX());
58  m_writeStmt->setFloat(4, item->getTableY());
59 
60  m_writeStmt->executeUpdate();
61  } catch (SQLException& e) {
62  throw(std::runtime_error("MonH4TablePositionDat::writeDB(): " + e.getMessage()));
63  }
64 }
65 
66 void MonH4TablePositionDat::fetchData(std::map<EcalLogicID, MonH4TablePositionDat>* fillMap,
67  MonRunIOV* iov) noexcept(false) {
68  this->checkConnection();
69  fillMap->clear();
70 
71  iov->setConnection(m_env, m_conn);
72  int iovID = iov->fetchID();
73  if (!iovID) {
74  // throw(std::runtime_error("MonH4TablePositionDat::writeDB: IOV 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.table_x, d.table_y "
82  "FROM channelview cv JOIN mon_h4_table_position_dat d "
83  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
84  "WHERE d.iov_id = :iov_id");
85  m_readStmt->setInt(1, iovID);
86  ResultSet* rset = m_readStmt->executeQuery();
87 
88  std::pair<EcalLogicID, MonH4TablePositionDat> p;
90  while (rset->next()) {
91  p.first = EcalLogicID(rset->getString(1), // name
92  rset->getInt(2), // logic_id
93  rset->getInt(3), // id1
94  rset->getInt(4), // id2
95  rset->getInt(5), // id3
96  rset->getString(6)); // maps_to
97 
98  dat.setTableX(rset->getFloat(7));
99  dat.setTableY(rset->getFloat(8));
100 
101  p.second = dat;
102  fillMap->insert(p);
103  }
104  } catch (SQLException& e) {
105  throw(std::runtime_error("MonH4TablePositionDat::fetchData(): " + e.getMessage()));
106  }
107 }
108 
109 void MonH4TablePositionDat::writeArrayDB(const std::map<EcalLogicID, MonH4TablePositionDat>* data,
110  MonRunIOV* iov) noexcept(false) {
111  this->checkConnection();
112  this->checkPrepare();
113 
114  int iovID = iov->fetchID();
115  if (!iovID) {
116  throw(std::runtime_error("MonH4TablePositionDat::writeArrayDB: IOV not in DB"));
117  }
118 
119  int nrows = data->size();
120  int* ids = new int[nrows];
121  int* iovid_vec = new int[nrows];
122  float* xx = new float[nrows];
123  float* yy = new float[nrows];
124 
125  ub2* ids_len = new ub2[nrows];
126  ub2* iov_len = new ub2[nrows];
127  ub2* x_len = new ub2[nrows];
128  ub2* y_len = new ub2[nrows];
129 
130  const EcalLogicID* channel;
131  const MonH4TablePositionDat* dataitem;
132  int count = 0;
133  typedef map<EcalLogicID, MonH4TablePositionDat>::const_iterator CI;
134  for (CI p = data->begin(); p != data->end(); ++p) {
135  channel = &(p->first);
136  int logicID = channel->getLogicID();
137  if (!logicID) {
138  throw(std::runtime_error("MonH4TablePositionDat::writeArrayDB: Bad EcalLogicID"));
139  }
140  ids[count] = logicID;
141  iovid_vec[count] = iovID;
142 
143  dataitem = &(p->second);
144  // dataIface.writeDB( channel, dataitem, iov);
145  float x = dataitem->getTableX();
146  float y = dataitem->getTableY();
147 
148  xx[count] = x;
149  yy[count] = y;
150 
151  ids_len[count] = sizeof(ids[count]);
152  iov_len[count] = sizeof(iovid_vec[count]);
153 
154  x_len[count] = sizeof(xx[count]);
155  y_len[count] = sizeof(yy[count]);
156 
157  count++;
158  }
159 
160  try {
161  m_writeStmt->setDataBuffer(1, (dvoid*)iovid_vec, OCCIINT, sizeof(iovid_vec[0]), iov_len);
162  m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len);
163  m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIFLOAT, sizeof(xx[0]), x_len);
164  m_writeStmt->setDataBuffer(4, (dvoid*)yy, OCCIFLOAT, sizeof(yy[0]), y_len);
165 
166  m_writeStmt->executeArrayUpdate(nrows);
167 
168  delete[] ids;
169  delete[] iovid_vec;
170  delete[] xx;
171  delete[] yy;
172 
173  delete[] ids_len;
174  delete[] iov_len;
175  delete[] x_len;
176  delete[] y_len;
177 
178  } catch (SQLException& e) {
179  throw(std::runtime_error("MonH4TablePositionDat::writeArrayDB(): " + e.getMessage()));
180  }
181 }
void writeArrayDB(const std::map< EcalLogicID, MonH4TablePositionDat > *data, MonRunIOV *iov) noexcept(false)
void prepareWrite() noexcept(false) override
void fetchData(std::map< EcalLogicID, MonH4TablePositionDat > *fillMap, MonRunIOV *iov) noexcept(false)
int getLogicID() const
Definition: EcalLogicID.cc:28
static std::vector< std::string > checklist dat
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
void writeDB(const EcalLogicID *ecid, const MonH4TablePositionDat *item, MonRunIOV *iov) noexcept(false)