CMS 3D CMS Logo

FEConfigBadStripDat.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  m_tcc = 0;
18  m_fed = 0;
19  m_tt = 0;
20  m_xt = 0;
21  m_t1 = 0;
22 
23 }
24 
25 
26 
28 {
29 }
30 
31 
32 
35 {
36  this->checkConnection();
37 
38  try {
39  m_writeStmt = m_conn->createStatement();
40  m_writeStmt->setSQL("INSERT INTO "+getTable()+" (rec_id, tcc_id,fed_id, tt_id, st_id, status ) "
41  "VALUES (:1, :2, :3, :4, :5 ,:6 )");
42  } catch (SQLException &e) {
43  throw(std::runtime_error("FEConfigBadStripDat::prepareWrite(): "+e.getMessage()));
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->getTCCId() );
57  m_writeStmt->setInt(3, item->getFedId());
58  m_writeStmt->setInt(4, item->getTTId() );
59  m_writeStmt->setInt(5, item->getStripId() );
60  m_writeStmt->setInt(6, item->getStatus() );
61 
62  m_writeStmt->executeUpdate();
63  } catch (SQLException &e) {
64  throw(std::runtime_error("FEConfigBadStripDat::writeDB(): "+e.getMessage()));
65  }
66 }
67 
68 
69 
70 void FEConfigBadStripDat::fetchData(std::vector< FEConfigBadStripDat >* p, FEConfigBadStripInfo* iov)
71  noexcept(false)
72 {
73  this->checkConnection();
74 
75  iov->setConnection(m_env, m_conn);
76  int iovID = iov->fetchID();
77  if (!iovID) {
78  // throw(std::runtime_error("FEConfigBadStripDat::writeDB: IOV not in DB"));
79  return;
80  }
81 
82  try {
83  m_readStmt->setSQL("SELECT * FROM " + getTable() + " WHERE rec_id = :rec_id order by tcc_id, fed_id, tt_id , st_id ");
84  m_readStmt->setInt(1, iovID);
85  ResultSet* rset = m_readStmt->executeQuery();
86 
87  // std::vector< FEConfigBadStripDat > p;
89  while(rset->next()) {
90  // dat.setId( rset->getInt(1) );
91  dat.setTCCId( rset->getInt(2) );
92  dat.setFedId( rset->getInt(3) );
93  dat.setTTId( rset->getInt(4) );
94  dat.setStripId( rset->getInt(5) );
95  dat.setStatus( rset->getInt(6) );
96 
97  p->push_back( dat);
98 
99  }
100  } catch (SQLException &e) {
101  throw(std::runtime_error("FEConfigBadStripDat::fetchData(): "+e.getMessage()));
102  }
103 }
104 
105 // ************************************************************************ //
106 
107 void FEConfigBadStripDat::writeArrayDB(const std::vector< FEConfigBadStripDat >& data, FEConfigBadStripInfo* iov)
108  noexcept(false)
109 {
110  this->checkConnection();
111 
112  int iovID = iov->fetchID();
113  if (!iovID) { throw(std::runtime_error("FEConfigDelays::writeArrayDB: FEConfigBadStripInfo not in DB")); }
114 
115 
116  int nrows=data.size();
117  int* ids= new int[nrows];
118  int* xx= new int[nrows];
119  int* yy= new int[nrows];
120  int* zz= new int[nrows];
121  int* z1= 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* z1_len= new ub2[nrows];
131  ub2* st_len= new ub2[nrows];
132 
133 
134  FEConfigBadStripDat dataitem;
135 
136 
137  for (size_t count = 0; count != data.size(); count++) {
138  dataitem=data[count];
139  ids[count]=iovID;
140  xx[count]=dataitem.getTCCId();
141  yy[count]=dataitem.getFedId();
142  zz[count]=dataitem.getTTId();
143  z1[count]=dataitem.getStripId();
144  st[count]=dataitem.getStatus();
145 
146 
147  ids_len[count]=sizeof(ids[count]);
148  x_len[count]=sizeof(xx[count]);
149  y_len[count]=sizeof(yy[count]);
150  z_len[count]=sizeof(zz[count]);
151  z1_len[count]=sizeof(z1[count]);
152  st_len[count]=sizeof(st[count]);
153 
154  }
155 
156 
157  try {
158  m_writeStmt->setDataBuffer(1, (dvoid*)ids, OCCIINT, sizeof(ids[0]),ids_len);
159  m_writeStmt->setDataBuffer(2, (dvoid*)xx, OCCIINT , sizeof(xx[0]), x_len );
160  m_writeStmt->setDataBuffer(3, (dvoid*)yy, OCCIINT , sizeof(yy[0]), y_len );
161  m_writeStmt->setDataBuffer(4, (dvoid*)zz, OCCIINT , sizeof(zz[0]), z_len );
162  m_writeStmt->setDataBuffer(5, (dvoid*)z1, OCCIINT , sizeof(z1[0]), z1_len );
163  m_writeStmt->setDataBuffer(6, (dvoid*)st, OCCIINT , sizeof(st[0]), st_len );
164 
165  m_writeStmt->executeArrayUpdate(nrows);
166 
167  delete [] ids;
168  delete [] xx;
169  delete [] yy;
170  delete [] zz;
171  delete [] z1;
172  delete [] st;
173 
174  delete [] ids_len;
175  delete [] x_len;
176  delete [] y_len;
177  delete [] z_len;
178  delete [] z1_len;
179  delete [] st_len;
180 
181  } catch (SQLException &e) {
182  throw(std::runtime_error("FEConfigBadStripDat::writeArrayDB(): "+e.getMessage()));
183  }
184 }
#define noexcept
#define NULL
Definition: scimark2.h:8
void writeArrayDB(const std::vector< FEConfigBadStripDat > &data, FEConfigBadStripInfo *iov) noexcept(false)
void writeDB(const FEConfigBadStripDat *item, FEConfigBadStripInfo *iov) noexcept(false)
void fetchData(std::vector< FEConfigBadStripDat > *fillMap, FEConfigBadStripInfo *iov) noexcept(false)
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:26
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
oracle::occi::SQLException SQLException
Definition: IODConfig.h:22
void prepareWrite() noexcept(false)