CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ODTowersToByPassDat.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_tr = 0;
21  m_time = 0;
22  m_sta = 0;
23 
24 }
25 
26 
27 
29 {
30 }
31 
32 
33 
35  throw(std::runtime_error)
36 {
37  this->checkConnection();
38 
39  try {
40  m_writeStmt = m_conn->createStatement();
41  m_writeStmt->setSQL("INSERT INTO "+getTable()+" (rec_id, fed_id, tr_id, tt_id, time_corr, STATUS ) "
42  "VALUES (:1, :2, :3, :4, :5 , :6 )");
43  } catch (SQLException &e) {
44  throw(std::runtime_error("ODTowersToByPassDat::prepareWrite(): "+e.getMessage()));
45  }
46 }
47 
48 
49 
51  throw(std::runtime_error)
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->getTrId() );
59  m_writeStmt->setInt(4, item->getTTId() );
60  m_writeStmt->setInt(5, item->getTimeCorr() );
61  m_writeStmt->setInt(6, item->getStatus() );
62 
63  m_writeStmt->executeUpdate();
64  } catch (SQLException &e) {
65  throw(std::runtime_error("ODTowersToByPassDat::writeDB(): "+e.getMessage()));
66  }
67 }
68 
69 
70 
71 void ODTowersToByPassDat::fetchData(std::vector< ODTowersToByPassDat >* p, ODTowersToByPassInfo* iov)
72  throw(std::runtime_error)
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, tr_id, tt_id ");
85  m_readStmt->setInt(1, iovID);
86  ResultSet* rset = m_readStmt->executeQuery();
87 
88  // std::vector< ODTowersToByPassDat > p;
90  while(rset->next()) {
91  // dat.setId( rset->getInt(1) );
92  dat.setFedId( rset->getInt(2) );
93  dat.setTrId( rset->getInt(3) );
94  dat.setTTId( rset->getInt(4) );
95  dat.setTimeCorr( 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("ODTowersToByPassDat::fetchData(): "+e.getMessage()));
105  }
106 }
107 
108 // ************************************************************************ //
109 
110 void ODTowersToByPassDat::writeArrayDB(const std::vector< ODTowersToByPassDat >& data, ODTowersToByPassInfo* iov)
111  throw(std::runtime_error)
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  ODTowersToByPassDat 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.getTrId();
144  zz[count]=dataitem.getTTId();
145  ww[count]=dataitem.getTimeCorr();
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("ODTowersToByPassDat::writeArrayDB(): "+e.getMessage()));
188  }
189 }
void fetchData(std::vector< ODTowersToByPassDat > *fillMap, ODTowersToByPassInfo *iov)
#define NULL
Definition: scimark2.h:8
void writeArrayDB(const std::vector< ODTowersToByPassDat > &data, ODTowersToByPassInfo *iov)
tuple iov
Definition: o2o.py:307
void writeDB(const ODTowersToByPassDat *item, ODTowersToByPassInfo *iov)
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
tuple cout
Definition: gather_cfg.py:121