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