CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ODTowersToByPassDat.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_fed = 0;
17  m_tt = 0;
18  m_tr = 0;
19  m_time = 0;
20  m_sta = 0;
21 }
22 
24 
26  this->checkConnection();
27 
28  try {
29  m_writeStmt = m_conn->createStatement();
30  m_writeStmt->setSQL("INSERT INTO " + getTable() +
31  " (rec_id, fed_id, tr_id, tt_id, time_corr, STATUS ) "
32  "VALUES (:1, :2, :3, :4, :5 , :6 )");
33  } catch (SQLException& e) {
34  throw(std::runtime_error("ODTowersToByPassDat::prepareWrite(): " + e.getMessage()));
35  }
36 }
37 
39  this->checkConnection();
40 
41  try {
42  m_writeStmt->setInt(1, item->getId());
43  m_writeStmt->setInt(2, item->getFedId());
44  m_writeStmt->setInt(3, item->getTrId());
45  m_writeStmt->setInt(4, item->getTTId());
46  m_writeStmt->setInt(5, item->getTimeCorr());
47  m_writeStmt->setInt(6, item->getStatus());
48 
49  m_writeStmt->executeUpdate();
50  } catch (SQLException& e) {
51  throw(std::runtime_error("ODTowersToByPassDat::writeDB(): " + e.getMessage()));
52  }
53 }
54 
55 void ODTowersToByPassDat::fetchData(std::vector<ODTowersToByPassDat>* p, ODTowersToByPassInfo* iov) noexcept(false) {
56  this->checkConnection();
57 
58  iov->setConnection(m_env, m_conn);
59  int iovID = iov->fetchID();
60  if (!iovID) {
61  std::cout << "ID not in the DB" << endl;
62  return;
63  }
64 
65  try {
66  m_readStmt->setSQL("SELECT * FROM " + getTable() + " WHERE rec_id = :rec_id order by fed_id, tr_id, tt_id ");
67  m_readStmt->setInt(1, iovID);
68  ResultSet* rset = m_readStmt->executeQuery();
69 
70  // std::vector< ODTowersToByPassDat > p;
72  while (rset->next()) {
73  // dat.setId( rset->getInt(1) );
74  dat.setFedId(rset->getInt(2));
75  dat.setTrId(rset->getInt(3));
76  dat.setTTId(rset->getInt(4));
77  dat.setTimeCorr(rset->getInt(5));
78  dat.setStatus(rset->getInt(6));
79 
80  p->push_back(dat);
81  }
82 
83  } catch (SQLException& e) {
84  throw(std::runtime_error("ODTowersToByPassDat::fetchData(): " + e.getMessage()));
85  }
86 }
87 
88 // ************************************************************************ //
89 
90 void ODTowersToByPassDat::writeArrayDB(const std::vector<ODTowersToByPassDat>& data,
91  ODTowersToByPassInfo* iov) noexcept(false) {
92  this->checkConnection();
93 
94  int iovID = iov->fetchID();
95  if (!iovID) {
96  throw(std::runtime_error("ODDelays::writeArrayDB: ODFEDelaysInfo not in DB"));
97  }
98 
99  int nrows = data.size();
100  int* ids = new int[nrows];
101  int* xx = new int[nrows];
102  int* yy = new int[nrows];
103  int* zz = new int[nrows];
104  int* ww = new int[nrows];
105  int* st = new int[nrows];
106 
107  ub2* ids_len = new ub2[nrows];
108  ub2* x_len = new ub2[nrows];
109  ub2* y_len = new ub2[nrows];
110  ub2* z_len = new ub2[nrows];
111  ub2* w_len = new ub2[nrows];
112  ub2* st_len = new ub2[nrows];
113 
114  ODTowersToByPassDat dataitem;
115 
116  for (int count = 0; count != (int)data.size(); count++) {
117  dataitem = data[count];
118  ids[count] = iovID;
119  xx[count] = dataitem.getFedId();
120  yy[count] = dataitem.getTrId();
121  zz[count] = dataitem.getTTId();
122  ww[count] = dataitem.getTimeCorr();
123  st[count] = dataitem.getStatus();
124 
125  ids_len[count] = sizeof(ids[count]);
126  x_len[count] = sizeof(xx[count]);
127  y_len[count] = sizeof(yy[count]);
128  z_len[count] = sizeof(zz[count]);
129  w_len[count] = sizeof(ww[count]);
130  st_len[count] = sizeof(st[count]);
131  }
132 
133  try {
134  m_writeStmt->setDataBuffer(1, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len);
135  m_writeStmt->setDataBuffer(2, (dvoid*)xx, OCCIINT, sizeof(xx[0]), x_len);
136  m_writeStmt->setDataBuffer(3, (dvoid*)yy, OCCIINT, sizeof(yy[0]), y_len);
137  m_writeStmt->setDataBuffer(4, (dvoid*)zz, OCCIINT, sizeof(zz[0]), z_len);
138  m_writeStmt->setDataBuffer(5, (dvoid*)ww, OCCIINT, sizeof(ww[0]), w_len);
139  m_writeStmt->setDataBuffer(6, (dvoid*)st, OCCIINT, sizeof(st[0]), st_len);
140 
141  m_writeStmt->executeArrayUpdate(nrows);
142 
143  delete[] ids;
144  delete[] xx;
145  delete[] yy;
146  delete[] zz;
147  delete[] ww;
148  delete[] st;
149 
150  delete[] ids_len;
151  delete[] x_len;
152  delete[] y_len;
153  delete[] z_len;
154  delete[] w_len;
155  delete[] st_len;
156 
157  } catch (SQLException& e) {
158  throw(std::runtime_error("ODTowersToByPassDat::writeArrayDB(): " + e.getMessage()));
159  }
160 }
void prepareWrite() noexcept(false) override
void writeDB(const ODTowersToByPassDat *item, ODTowersToByPassInfo *iov) noexcept(false)
void fetchData(std::vector< ODTowersToByPassDat > *fillMap, ODTowersToByPassInfo *iov) noexcept(false)
void writeArrayDB(const std::vector< ODTowersToByPassDat > &data, ODTowersToByPassInfo *iov) noexcept(false)
static std::vector< std::string > checklist dat
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
oracle::occi::SQLException SQLException
Definition: IODConfig.h:20
tuple cout
Definition: gather_cfg.py:144