CMS 3D CMS Logo

MonPedestalsDat.cc
Go to the documentation of this file.
1 #include <stdexcept>
2 #include <string>
4 
7 
8 using namespace std;
9 using namespace oracle::occi;
10 
12 {
13  m_env = nullptr;
14  m_conn = nullptr;
15  m_writeStmt = nullptr;
16  m_readStmt = nullptr;
17 
18  m_pedMeanG1 = 0;
19  m_pedMeanG6 = 0;
20  m_pedMeanG12 = 0;
21  m_pedRMSG1 = 0;
22  m_pedRMSG6 = 0;
23  m_pedRMSG12 = 0;
24  m_taskStatus = false;
25 }
26 
27 
28 
30 {
31 }
32 
33 
34 
37 {
38  this->checkConnection();
39 
40  try {
41  m_writeStmt = m_conn->createStatement();
42  m_writeStmt->setSQL("INSERT INTO mon_pedestals_dat (iov_id, logic_id, "
43  "ped_mean_g1, ped_mean_g6, ped_mean_g12, "
44  "ped_rms_g1, ped_rms_g6, ped_rms_g12, task_status) "
45  "VALUES (:iov_id, :logic_id, "
46  ":ped_mean_g1, :ped_mean_g6, :ped_mean_g12, "
47  ":ped_rms_g1, :ped_rms_g6, :ped_rms_g12, :task_status)");
48  } catch (SQLException &e) {
49  throw(std::runtime_error("MonPedestalsDat::prepareWrite(): "+e.getMessage()));
50  }
51 }
52 
53 
54 
55 void MonPedestalsDat::writeDB(const EcalLogicID* ecid, const MonPedestalsDat* item, MonRunIOV* iov)
56  noexcept(false)
57 {
58  this->checkConnection();
59  this->checkPrepare();
60 
61  int iovID = iov->fetchID();
62  if (!iovID) { throw(std::runtime_error("MonPedestalsDat::writeDB: IOV not in DB")); }
63 
64  int logicID = ecid->getLogicID();
65  if (!logicID) { throw(std::runtime_error("MonPedestalsDat::writeDB: Bad EcalLogicID")); }
66 
67  try {
68  m_writeStmt->setInt(1, iovID);
69  m_writeStmt->setInt(2, logicID);
70  m_writeStmt->setFloat(3, item->getPedMeanG1());
71  m_writeStmt->setFloat(4, item->getPedMeanG6());
72  m_writeStmt->setFloat(5, item->getPedMeanG12());
73  m_writeStmt->setFloat(6, item->getPedRMSG1());
74  m_writeStmt->setFloat(7, item->getPedRMSG6());
75  m_writeStmt->setFloat(8, item->getPedRMSG12());
76  m_writeStmt->setInt(9, item->getTaskStatus());
77 
78  m_writeStmt->executeUpdate();
79  } catch (SQLException &e) {
80  throw(std::runtime_error("MonPedestalsDat::writeDB(): "+e.getMessage()));
81  }
82 }
83 
84 
85 
86 void MonPedestalsDat::fetchData(map< EcalLogicID, MonPedestalsDat >* fillMap, MonRunIOV* iov)
87  noexcept(false)
88 {
89  this->checkConnection();
90  fillMap->clear();
91 
92  iov->setConnection(m_env, m_conn);
93  int iovID = iov->fetchID();
94  if (!iovID) {
95  // throw(std::runtime_error("MonPedestalsDat::writeDB: IOV not in DB"));
96  return;
97  }
98 
99  try {
100 
101  m_readStmt->setSQL("SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
102  "d.ped_mean_g1, d.ped_mean_g6, d.ped_mean_g12, "
103  "d.ped_rms_g1, d.ped_rms_g6, d.ped_rms_g12, d.task_status "
104  "FROM channelview cv JOIN mon_pedestals_dat d "
105  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
106  "WHERE iov_id = :iov_id");
107  m_readStmt->setInt(1, iovID);
108  ResultSet* rset = m_readStmt->executeQuery();
109 
110  std::pair< EcalLogicID, MonPedestalsDat > p;
111  MonPedestalsDat dat;
112  while(rset->next()) {
113  p.first = EcalLogicID( rset->getString(1), // name
114  rset->getInt(2), // logic_id
115  rset->getInt(3), // id1
116  rset->getInt(4), // id2
117  rset->getInt(5), // id3
118  rset->getString(6)); // maps_to
119 
120  dat.setPedMeanG1( rset->getFloat(7) );
121  dat.setPedMeanG6( rset->getFloat(8) );
122  dat.setPedMeanG12( rset->getFloat(9) );
123  dat.setPedRMSG1( rset->getFloat(10) );
124  dat.setPedRMSG6( rset->getFloat(11) );
125  dat.setPedRMSG12( rset->getFloat(12) );
126  dat.setTaskStatus( rset->getInt(13) );
127 
128  p.second = dat;
129  fillMap->insert(p);
130  }
131  } catch (SQLException &e) {
132  throw(std::runtime_error("MonPedestalsDat::fetchData: "+e.getMessage()));
133  }
134 }
135 
136 void MonPedestalsDat::writeArrayDB(const std::map< EcalLogicID, MonPedestalsDat >* data, MonRunIOV* iov)
137  noexcept(false)
138 {
139  this->checkConnection();
140  this->checkPrepare();
141 
142  int iovID = iov->fetchID();
143  if (!iovID) { throw(std::runtime_error("MonPedestalsDat::writeArrayDB: IOV not in DB")); }
144 
145 
146  int nrows=data->size();
147  int* ids= new int[nrows];
148  int* iovid_vec= new int[nrows];
149  float* xx= new float[nrows];
150  float* yy= new float[nrows];
151  float* zz= new float[nrows];
152  float* ww= new float[nrows];
153  float* uu= new float[nrows];
154  float* tt= new float[nrows];
155  int* st= new int[nrows];
156 
157  ub2* ids_len= new ub2[nrows];
158  ub2* iov_len= new ub2[nrows];
159  ub2* x_len= new ub2[nrows];
160  ub2* y_len= new ub2[nrows];
161  ub2* z_len= new ub2[nrows];
162  ub2* w_len= new ub2[nrows];
163  ub2* u_len= new ub2[nrows];
164  ub2* t_len= new ub2[nrows];
165  ub2* st_len= new ub2[nrows];
166 
167  const EcalLogicID* channel;
168  const MonPedestalsDat* dataitem;
169  int count=0;
170  typedef map< EcalLogicID, MonPedestalsDat >::const_iterator CI;
171  for (CI p = data->begin(); p != data->end(); ++p) {
172  channel = &(p->first);
173  int logicID = channel->getLogicID();
174  if (!logicID) { throw(std::runtime_error("MonPedestalsDat::writeArrayDB: Bad EcalLogicID")); }
175  ids[count]=logicID;
176  iovid_vec[count]=iovID;
177 
178  dataitem = &(p->second);
179  // dataIface.writeDB( channel, dataitem, iov);
180  float x=dataitem->getPedMeanG1();
181  float y=dataitem->getPedMeanG6();
182  float z=dataitem->getPedMeanG12();
183  float w=dataitem->getPedRMSG1();
184  float u=dataitem->getPedRMSG6();
185  float t=dataitem->getPedRMSG12();
186  int statu=dataitem->getTaskStatus();
187 
188 
189 
190  xx[count]=x;
191  yy[count]=y;
192  zz[count]=z;
193  ww[count]=w;
194  uu[count]=u;
195  tt[count]=t;
196  st[count]=statu;
197 
198 
199  ids_len[count]=sizeof(ids[count]);
200  iov_len[count]=sizeof(iovid_vec[count]);
201 
202  x_len[count]=sizeof(xx[count]);
203  y_len[count]=sizeof(yy[count]);
204  z_len[count]=sizeof(zz[count]);
205  w_len[count]=sizeof(ww[count]);
206  u_len[count]=sizeof(uu[count]);
207  t_len[count]=sizeof(tt[count]);
208  st_len[count]=sizeof(st[count]);
209 
210  count++;
211  }
212 
213 
214  try {
215  m_writeStmt->setDataBuffer(1, (dvoid*)iovid_vec, OCCIINT, sizeof(iovid_vec[0]),iov_len);
216  m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len );
217  m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIFLOAT , sizeof(xx[0]), x_len );
218  m_writeStmt->setDataBuffer(4, (dvoid*)yy, OCCIFLOAT , sizeof(yy[0]), y_len );
219  m_writeStmt->setDataBuffer(5, (dvoid*)zz, OCCIFLOAT , sizeof(zz[0]), z_len );
220  m_writeStmt->setDataBuffer(6, (dvoid*)ww, OCCIFLOAT , sizeof(ww[0]), w_len );
221  m_writeStmt->setDataBuffer(7, (dvoid*)uu, OCCIFLOAT , sizeof(uu[0]), u_len );
222  m_writeStmt->setDataBuffer(8, (dvoid*)tt, OCCIFLOAT , sizeof(tt[0]), t_len );
223  m_writeStmt->setDataBuffer(9, (dvoid*)st, OCCIINT , sizeof(st[0]), st_len );
224 
225 
226  m_writeStmt->executeArrayUpdate(nrows);
227 
228  delete [] ids;
229  delete [] iovid_vec;
230  delete [] xx;
231  delete [] yy;
232  delete [] zz;
233  delete [] ww;
234  delete [] uu;
235  delete [] tt;
236  delete [] st;
237 
238  delete [] ids_len;
239  delete [] iov_len;
240  delete [] x_len;
241  delete [] y_len;
242  delete [] z_len;
243  delete [] w_len;
244  delete [] u_len;
245  delete [] t_len;
246  delete [] st_len;
247 
248 
249 
250  } catch (SQLException &e) {
251  throw(std::runtime_error("MonPedestalsDat::writeArrayDB(): "+e.getMessage()));
252  }
253 }
void setPedMeanG1(float mean)
const double w
Definition: UKUtility.cc:23
float getPedRMSG1() const
void setPedRMSG6(float rms)
void setTaskStatus(bool status)
float getPedMeanG12() const
float getPedRMSG12() const
void prepareWrite() noexcept(false) override
void setPedMeanG6(float mean)
int getLogicID() const
Definition: EcalLogicID.cc:41
bool getTaskStatus() const
#define noexcept
void setPedRMSG1(float rms)
void fetchData(std::map< EcalLogicID, MonPedestalsDat > *fillMap, MonRunIOV *iov) noexcept(false)
float getPedMeanG1() const
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
float getPedMeanG6() const
void setPedMeanG12(float mean)
void writeDB(const EcalLogicID *ecid, const MonPedestalsDat *item, MonRunIOV *iov) noexcept(false)
void writeArrayDB(const std::map< EcalLogicID, MonPedestalsDat > *data, MonRunIOV *iov) noexcept(false)
float getPedRMSG6() const
~MonPedestalsDat() override
void setPedRMSG12(float rms)