test
CMS 3D CMS Logo

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