CMS 3D CMS Logo

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