test
CMS 3D CMS Logo

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