CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ODWeightsDat.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_xt = 0;
21 
22 }
23 
24 
25 
27 {
28 }
29 
31  m_sm = 0;
32  m_fed = 0;
33  m_tt = 0;
34  m_xt = 0;
35  m_wei0 = 0;
36  m_wei1 = 0;
37  m_wei2 = 0;
38  m_wei3 = 0;
39  m_wei4 = 0;
40  m_wei5 = 0;
41 }
42 
43 
45  throw(std::runtime_error)
46 {
47  this->checkConnection();
48 
49  try {
50  m_writeStmt = m_conn->createStatement();
51  m_writeStmt->setSQL("INSERT INTO "+getTable()+" (rec_id, sm_id, fed_id, tt_id, cry_id, wei0, wei1, wei2, wei3, wei4, wei5 ) "
52  "VALUES (:1, :2, :3, :4, :5, :6, :7, :8 , :9, :10, :11 )");
53  } catch (SQLException &e) {
54  throw(std::runtime_error("ODWeightsDat::prepareWrite(): "+e.getMessage()));
55  }
56 }
57 
58 
59 
61  throw(std::runtime_error)
62 {
63  this->checkConnection();
64 
65  try {
66  m_writeStmt->setInt(1, item->getId());
67  m_writeStmt->setInt(2, item->getSMId());
68  m_writeStmt->setInt(3, item->getFedId() );
69  m_writeStmt->setInt(4, item->getTTId() );
70  m_writeStmt->setInt(5, item->getCrystalId() );
71 
72  m_writeStmt->setFloat(6, item->getWeight0() );
73  m_writeStmt->setFloat(7, item->getWeight1() );
74  m_writeStmt->setFloat(8, item->getWeight2() );
75  m_writeStmt->setFloat(9, item->getWeight3() );
76  m_writeStmt->setFloat(10, item->getWeight4() );
77  m_writeStmt->setFloat(11, item->getWeight5() );
78 
79  m_writeStmt->executeUpdate();
80  } catch (SQLException &e) {
81  throw(std::runtime_error("ODWeightsDat::writeDB(): "+e.getMessage()));
82  }
83 }
84 
85 
86 
87 void ODWeightsDat::fetchData(std::vector< ODWeightsDat >* p, ODFEWeightsInfo* iov)
88  throw(std::runtime_error)
89 {
90  this->checkConnection();
91 
92  iov->setConnection(m_env, m_conn);
93  int iovID = iov->fetchID();
94  if (!iovID) {
95  std::cout <<"ID not in the DB"<< endl;
96  return;
97  }
98 
99  try {
100  m_readStmt->setSQL("SELECT * FROM " + getTable() + " WHERE rec_id = :rec_id order by sm_id, fed_id, tt_id, cry_id");
101  m_readStmt->setInt(1, iovID);
102  ResultSet* rset = m_readStmt->executeQuery();
103 
104  // std::vector< ODWeightsDat > p;
105  ODWeightsDat dat;
106  while(rset->next()) {
107  // dat.setId( rset->getInt(1) );
108  dat.setSMId( rset->getInt(2) );
109  dat.setFedId( rset->getInt(3) );
110  dat.setTTId( rset->getInt(4) );
111  dat.setCrystalId( rset->getInt(5) );
112  /*
113  dat.setWeight0( rset->getFloat(6) );
114  dat.setWeight1( rset->getFloat(7) );
115  dat.setWeight2( rset->getFloat(8) );
116  dat.setWeight3( rset->getFloat(9) );
117  dat.setWeight4( rset->getFloat(10) );
118  dat.setWeight5( rset->getFloat(11) );
119  */
120  p->push_back( dat);
121  for(int iwei = 0; iwei < 6; iwei++) {
122  dat.setWeight(iwei, rset->getFloat(6 + iwei) );
123  }
124  std::vector<float> dccwei( m_wei, m_wei+6);
125  dccw.push_back(dccwei); // vector vector
126 
127  }
128 
129 
130  } catch (SQLException &e) {
131  throw(std::runtime_error("ODWeightsDat::fetchData(): "+e.getMessage()));
132  }
133 }
134 
136  throw(std::runtime_error)
137 {
138  this->checkConnection();
139 
140  try {
141  m_readStmt->setSQL("SELECT * FROM " + getTable() + " WHERE rec_id = :1 order by sm_id, fed_id, tt_id, cry_id");
142  m_readStmt->setInt(1, p->getId());
143  ResultSet* rset = m_readStmt->executeQuery();
144 
145  int row = 0;
146  while(rset->next()) {
147  row++;
148  p->setSMId( rset->getInt(2) );
149  p->setFedId( rset->getInt(3) );
150  p->setTTId( rset->getInt(4) );
151  p->setCrystalId( rset->getInt(5) );
152  for(int iwei = 0; iwei < 6; iwei++) {
153  p->setWeight(iwei, rset->getFloat(6 + iwei) );
154  }
155  std::vector<float> dccwei( m_wei, m_wei+6);
156  dccw.push_back(dccwei); // vector vector
157  } // loop on all rows in the table
158  std::cout << " table " << getTable() << " total nb of rows " << row << std::endl;
159 
160  } catch (SQLException &e) {
161  throw(std::runtime_error("ODWeightsDat::fetchData(): "+e.getMessage()));
162  }
163 }
164 
165 // ************************************************************************ //
166 
167 void ODWeightsDat::writeArrayDB(const std::vector< ODWeightsDat >& data, ODFEWeightsInfo* iov)
168  throw(std::runtime_error)
169 {
170  this->checkConnection();
171 
172  int iovID = iov->fetchID();
173  if (!iovID) { throw(std::runtime_error("ODDelays::writeArrayDB: ODFEDelaysInfo not in DB")); }
174 
175 
176  int nrows=data.size();
177  int* ids= new int[nrows];
178  int* xx= new int[nrows];
179  int* yy= new int[nrows];
180  int* zz= new int[nrows];
181  int* st= new int[nrows];
182  float* xx1= new float[nrows];
183  float* yy1= new float[nrows];
184  float* zz1= new float[nrows];
185  float* xx2= new float[nrows];
186  float* yy2= new float[nrows];
187  float* zz2= new float[nrows];
188 
189 
190  ub2* ids_len= new ub2[nrows];
191  ub2* x_len= new ub2[nrows];
192  ub2* y_len= new ub2[nrows];
193  ub2* z_len= new ub2[nrows];
194  ub2* st_len= new ub2[nrows];
195  ub2* x1_len= new ub2[nrows];
196  ub2* y1_len= new ub2[nrows];
197  ub2* z1_len= new ub2[nrows];
198  ub2* x2_len= new ub2[nrows];
199  ub2* y2_len= new ub2[nrows];
200  ub2* z2_len= new ub2[nrows];
201 
202  ODWeightsDat dataitem;
203 
204  int n_data= (int) data.size();
205  for (int count = 0; count <n_data ; count++) {
206  dataitem=data[count];
207  ids[count]=iovID;
208  xx[count]=dataitem.getSMId();
209  yy[count]=dataitem.getFedId();
210  zz[count]=dataitem.getTTId();
211  st[count]=dataitem.getCrystalId();
212  xx1[count]=dataitem.getWeight0();
213  yy1[count]=dataitem.getWeight1();
214  zz1[count]=dataitem.getWeight2();
215  xx2[count]=dataitem.getWeight3();
216  yy2[count]=dataitem.getWeight4();
217  zz2[count]=dataitem.getWeight5();
218 
219 
220  ids_len[count]=sizeof(ids[count]);
221  x_len[count]=sizeof(xx[count]);
222  y_len[count]=sizeof(yy[count]);
223  z_len[count]=sizeof(zz[count]);
224  st_len[count]=sizeof(st[count]);
225  x1_len[count]=sizeof(xx1[count]);
226  y1_len[count]=sizeof(yy1[count]);
227  z1_len[count]=sizeof(zz1[count]);
228  x2_len[count]=sizeof(xx2[count]);
229  y2_len[count]=sizeof(yy2[count]);
230  z2_len[count]=sizeof(zz2[count]);
231 
232  }
233 
234 
235  try {
236  m_writeStmt->setDataBuffer(1, (dvoid*)ids, OCCIINT, sizeof(ids[0]),ids_len);
237  m_writeStmt->setDataBuffer(2, (dvoid*)xx, OCCIINT , sizeof(xx[0]), x_len );
238  m_writeStmt->setDataBuffer(3, (dvoid*)yy, OCCIINT , sizeof(yy[0]), y_len );
239  m_writeStmt->setDataBuffer(4, (dvoid*)zz, OCCIINT , sizeof(zz[0]), z_len );
240  m_writeStmt->setDataBuffer(5, (dvoid*)st, OCCIINT , sizeof(st[0]), st_len );
241  m_writeStmt->setDataBuffer(6, (dvoid*)xx1, OCCIFLOAT , sizeof(xx1[0]), x1_len );
242  m_writeStmt->setDataBuffer(7, (dvoid*)yy1, OCCIFLOAT , sizeof(yy1[0]), y1_len );
243  m_writeStmt->setDataBuffer(8, (dvoid*)zz1, OCCIFLOAT , sizeof(zz1[0]), z1_len );
244  m_writeStmt->setDataBuffer(9, (dvoid*)xx2, OCCIFLOAT , sizeof(xx2[0]), x2_len );
245  m_writeStmt->setDataBuffer(10, (dvoid*)yy2, OCCIFLOAT , sizeof(yy2[0]), y2_len );
246  m_writeStmt->setDataBuffer(11, (dvoid*)zz2, OCCIFLOAT , sizeof(zz2[0]), z2_len );
247 
248 
249  m_writeStmt->executeArrayUpdate(nrows);
250 
251  delete [] ids;
252  delete [] xx;
253  delete [] yy;
254  delete [] zz;
255  delete [] st;
256  delete [] xx1;
257  delete [] yy1;
258  delete [] zz1;
259  delete [] xx2;
260  delete [] yy2;
261  delete [] zz2;
262 
263  delete [] ids_len;
264  delete [] x_len;
265  delete [] y_len;
266  delete [] z_len;
267  delete [] st_len;
268  delete [] x1_len;
269  delete [] y1_len;
270  delete [] z1_len;
271  delete [] x2_len;
272  delete [] y2_len;
273  delete [] z2_len;
274 
275  } catch (SQLException &e) {
276  throw(std::runtime_error("ODWeightsDat::writeArrayDB(): "+e.getMessage()));
277  }
278 }
float getWeight0() const
Definition: ODWeightsDat.h:45
void writeArrayDB(const std::vector< ODWeightsDat > &data, ODFEWeightsInfo *iov)
void writeDB(const ODWeightsDat *item, ODFEWeightsInfo *iov)
Definition: ODWeightsDat.cc:60
void fetchData(std::vector< ODWeightsDat > *fillMap, ODFEWeightsInfo *iov)
Definition: ODWeightsDat.cc:87
float getWeight5() const
Definition: ODWeightsDat.h:50
int getCrystalId() const
Definition: ODWeightsDat.h:34
void setSMId(int dac)
Definition: ODWeightsDat.h:24
void prepareWrite()
Definition: ODWeightsDat.cc:44
float getWeight3() const
Definition: ODWeightsDat.h:48
#define NULL
Definition: scimark2.h:8
void setWeight(int pos, float x)
Definition: ODWeightsDat.h:43
float getWeight4() const
Definition: ODWeightsDat.h:49
int getTTId() const
Definition: ODWeightsDat.h:31
float getWeight1() const
Definition: ODWeightsDat.h:46
tuple iov
Definition: o2o.py:307
void setTTId(int dac)
Definition: ODWeightsDat.h:30
void setCrystalId(int dac)
Definition: ODWeightsDat.h:33
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:26
float getWeight2() const
Definition: ODWeightsDat.h:47
int getSMId() const
Definition: ODWeightsDat.h:25
oracle::occi::SQLException SQLException
Definition: IODConfig.h:22
tuple cout
Definition: gather_cfg.py:121
void setFedId(int dac)
Definition: ODWeightsDat.h:27
int getFedId() const
Definition: ODWeightsDat.h:28