CMS 3D CMS Logo

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