CMS 3D CMS Logo

ODDelaysDat.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_sm = 0;
17  m_fed = 0;
18  m_tt = 0;
19  m_t1 = 0;
20 }
21 
23 
24 void ODDelaysDat::prepareWrite() noexcept(false) {
25  this->checkConnection();
26 
27  try {
28  m_writeStmt = m_conn->createStatement();
29  m_writeStmt->setSQL("INSERT INTO " + getTable() +
30  " (rec_id, sm_id, fed_id, tt_id, time_offset ) "
31  "VALUES (:1, :2, :3, :4, :5 )");
32  } catch (SQLException& e) {
33  throw(std::runtime_error("ODDelaysDat::prepareWrite(): " + e.getMessage()));
34  }
35 }
36 
37 void ODDelaysDat::writeDB(const ODDelaysDat* item, ODFEDelaysInfo* iov) noexcept(false) {
38  this->checkConnection();
39 
40  try {
41  m_writeStmt->setInt(1, item->getId());
42  m_writeStmt->setInt(2, item->getSMId());
43  m_writeStmt->setInt(3, item->getFedId());
44  m_writeStmt->setInt(4, item->getTTId());
45  m_writeStmt->setInt(5, item->getTimeOffset());
46 
47  m_writeStmt->executeUpdate();
48  } catch (SQLException& e) {
49  throw(std::runtime_error("ODDelaysDat::writeDB(): " + e.getMessage()));
50  }
51 }
52 
53 void ODDelaysDat::fetchData(std::vector<ODDelaysDat>* p, ODFEDelaysInfo* iov) noexcept(false) {
54  iov->setConnection(m_env, m_conn);
55  int iovID = iov->fetchID();
56  fetchData(p, iovID);
57 }
58 
59 void ODDelaysDat::fetchData(std::vector<ODDelaysDat>* p, int iovID) noexcept(false) {
60  this->checkConnection();
61 
62  if (!iovID) {
63  // throw(std::runtime_error("ODDelaysDat::writeDB: IOV not in DB"));
64  return;
65  }
66 
67  try {
68  m_readStmt = m_conn->createStatement();
69  m_readStmt->setSQL("SELECT * FROM " + getTable() + " WHERE rec_id = :rec_id order by sm_id, fed_id, tt_id");
70  m_readStmt->setInt(1, iovID);
71  ResultSet* rset = m_readStmt->executeQuery();
72 
73  // std::vector< ODDelaysDat > p;
74  ODDelaysDat dat;
75  while (rset->next()) {
76  // dat.setId( rset->getInt(1) );
77  dat.setSMId(rset->getInt(2));
78  dat.setFedId(rset->getInt(3));
79  dat.setTTId(rset->getInt(4));
80  dat.setTimeOffset(rset->getInt(5));
81 
82  p->push_back(dat);
83  }
84  } catch (SQLException& e) {
85  throw(std::runtime_error("ODDelaysDat::fetchData(): " + e.getMessage()));
86  }
87 }
88 
89 // ************************************************************************ //
90 
91 void ODDelaysDat::writeArrayDB(const std::vector<ODDelaysDat>& data, ODFEDelaysInfo* 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* st = new int[nrows];
105 
106  ub2* ids_len = new ub2[nrows];
107  ub2* x_len = new ub2[nrows];
108  ub2* y_len = new ub2[nrows];
109  ub2* z_len = new ub2[nrows];
110  ub2* st_len = new ub2[nrows];
111 
112  ODDelaysDat dataitem;
113 
114  int n_data = (int)data.size();
115 
116  for (int count = 0; count < n_data; count++) {
117  dataitem = data[count];
118  ids[count] = iovID;
119  xx[count] = dataitem.getSMId();
120  yy[count] = dataitem.getFedId();
121  zz[count] = dataitem.getTTId();
122  st[count] = dataitem.getTimeOffset();
123 
124  ids_len[count] = sizeof(ids[count]);
125  x_len[count] = sizeof(xx[count]);
126  y_len[count] = sizeof(yy[count]);
127  z_len[count] = sizeof(zz[count]);
128  st_len[count] = sizeof(st[count]);
129  }
130 
131  try {
132  m_writeStmt->setDataBuffer(1, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len);
133  m_writeStmt->setDataBuffer(2, (dvoid*)xx, OCCIINT, sizeof(xx[0]), x_len);
134  m_writeStmt->setDataBuffer(3, (dvoid*)yy, OCCIINT, sizeof(yy[0]), y_len);
135  m_writeStmt->setDataBuffer(4, (dvoid*)zz, OCCIINT, sizeof(zz[0]), z_len);
136  m_writeStmt->setDataBuffer(5, (dvoid*)st, OCCIINT, sizeof(st[0]), st_len);
137 
138  m_writeStmt->executeArrayUpdate(nrows);
139 
140  delete[] ids;
141  delete[] xx;
142  delete[] yy;
143  delete[] zz;
144  delete[] st;
145 
146  delete[] ids_len;
147  delete[] x_len;
148  delete[] y_len;
149  delete[] z_len;
150  delete[] st_len;
151 
152  } catch (SQLException& e) {
153  throw(std::runtime_error("ODDelaysDat::writeArrayDB(): " + e.getMessage()));
154  }
155 }
void writeDB(const ODDelaysDat *item, ODFEDelaysInfo *iov) noexcept(false)
Definition: ODDelaysDat.cc:37
int getFedId() const
Definition: ODDelaysDat.h:26
void setTimeOffset(int dac)
Definition: ODDelaysDat.h:31
void setTTId(int dac)
Definition: ODDelaysDat.h:28
void fetchData(std::vector< ODDelaysDat > *fillMap, int id) noexcept(false)
Definition: ODDelaysDat.cc:59
~ODDelaysDat() override
Definition: ODDelaysDat.cc:22
int getTimeOffset() const
Definition: ODDelaysDat.h:32
int getTTId() const
Definition: ODDelaysDat.h:29
void prepareWrite() noexcept(false) override
Definition: ODDelaysDat.cc:24
int getSMId() const
Definition: ODDelaysDat.h:23
void writeArrayDB(const std::vector< ODDelaysDat > &data, ODFEDelaysInfo *iov) noexcept(false)
Definition: ODDelaysDat.cc:91
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
oracle::occi::SQLException SQLException
Definition: IODConfig.h:20
void setSMId(int dac)
Definition: ODDelaysDat.h:22
void setFedId(int dac)
Definition: ODDelaysDat.h:25