CMS 3D CMS Logo

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