CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FEConfigBadTTDat.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_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, tcc_id, fed_id, tt_id, status ) "
40  "VALUES (:1, :2, :3, :4, :5 )");
41  } catch (SQLException &e) {
42  throw(std::runtime_error("FEConfigBadTTDat::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->getTCCId() );
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("FEConfigBadTTDat::writeDB(): "+e.getMessage()));
63  }
64 }
65 
66 
67 
68 void FEConfigBadTTDat::fetchData(std::vector< FEConfigBadTTDat >* p, FEConfigBadTTInfo* 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("FEConfigBadTTDat::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 tcc_id, fed_id, tt_id ");
82  m_readStmt->setInt(1, iovID);
83  ResultSet* rset = m_readStmt->executeQuery();
84 
85  // std::vector< FEConfigBadTTDat > p;
86  FEConfigBadTTDat dat;
87  while(rset->next()) {
88  // dat.setId( rset->getInt(1) );
89  dat.setTCCId( 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("FEConfigBadTTDat::fetchData(): "+e.getMessage()));
99  }
100 }
101 
102 // ************************************************************************ //
103 
104 void FEConfigBadTTDat::writeArrayDB(const std::vector< FEConfigBadTTDat >& data, FEConfigBadTTInfo* iov)
105  throw(std::runtime_error)
106 {
107  this->checkConnection();
108 
109  int iovID = iov->fetchID();
110  if (!iovID) { throw(std::runtime_error("FEConfigDelays::writeArrayDB: FEConfigBadTTInfo 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  FEConfigBadTTDat 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.getTCCId();
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("FEConfigBadTTDat::writeArrayDB(): "+e.getMessage()));
173  }
174 }
void setTCCId(int dac)
#define NULL
Definition: scimark2.h:8
void setFedId(int x)
void fetchData(std::vector< FEConfigBadTTDat > *fillMap, FEConfigBadTTInfo *iov)
void writeArrayDB(const std::vector< FEConfigBadTTDat > &data, FEConfigBadTTInfo *iov)
void setStatus(int dac)
void writeDB(const FEConfigBadTTDat *item, FEConfigBadTTInfo *iov)
tuple iov
Definition: o2o.py:307
int getTTId() const
void setTTId(int dac)
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:26
oracle::occi::SQLException SQLException
Definition: IODConfig.h:22
int getFedId() const
int getStatus() const
int getTCCId() const