CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MonLaserIRedDat.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_apdMean = 0;
18  m_apdRMS = 0;
19  m_apdOverPNMean = 0;
20  m_apdOverPNRMS = 0;
21  m_taskStatus = 0;
22 
23 }
24 
25 
26 
28 {
29 }
30 
31 
32 
34  throw(std::runtime_error)
35 {
36  this->checkConnection();
37 
38  try {
39  m_writeStmt = m_conn->createStatement();
40  m_writeStmt->setSQL("INSERT INTO mon_laser_ired_dat (iov_id, logic_id, "
41  "apd_mean, apd_rms, apd_over_pn_mean, apd_over_pn_rms, task_status) "
42  "VALUES (:iov_id, :logic_id, "
43  ":apd_mean, :apd_rms, :apd_over_pn_mean, :apd_over_pn_rms, :task_status)");
44  } catch (SQLException &e) {
45  throw(std::runtime_error("MonLaserIRedDat::prepareWrite(): "+e.getMessage()));
46  }
47 }
48 
49 
50 
52  throw(std::runtime_error)
53 {
54  this->checkConnection();
55  this->checkPrepare();
56 
57  int iovID = iov->fetchID();
58  if (!iovID) { throw(std::runtime_error("MonLaserIRedDat::writeDB: IOV not in DB")); }
59 
60  int logicID = ecid->getLogicID();
61  if (!logicID) { throw(std::runtime_error("MonLaserIRedDat::writeDB: Bad EcalLogicID")); }
62 
63  try {
64  m_writeStmt->setInt(1, iovID);
65  m_writeStmt->setInt(2, logicID);
66 
67  m_writeStmt->setFloat(3, item->getAPDMean() );
68  m_writeStmt->setFloat(4, item->getAPDRMS() );
69  m_writeStmt->setFloat(5, item->getAPDOverPNMean() );
70  m_writeStmt->setFloat(6, item->getAPDOverPNRMS() );
71  m_writeStmt->setInt(7, item->getTaskStatus() );
72 
73  m_writeStmt->executeUpdate();
74  } catch (SQLException &e) {
75  throw(std::runtime_error("MonLaserIRedDat::writeDB(): "+e.getMessage()));
76  }
77 }
78 
79 
80 
81 void MonLaserIRedDat::fetchData(std::map< EcalLogicID, MonLaserIRedDat >* fillMap, MonRunIOV* iov)
82  throw(std::runtime_error)
83 {
84  this->checkConnection();
85 
86  fillMap->clear();
87 
88  iov->setConnection(m_env, m_conn);
89  int iovID = iov->fetchID();
90  if (!iovID) {
91  // throw(std::runtime_error("MonLaserIRedDat::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.apd_mean, d.apd_rms, d.apd_over_pn_mean, d.apd_over_pn_rms, d.task_status "
99  "FROM channelview cv JOIN mon_laser_ired_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, MonLaserIRedDat > p;
106  MonLaserIRedDat 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.setAPDMean( rset->getFloat(7) );
116  dat.setAPDRMS( rset->getFloat(8) );
117  dat.setAPDOverPNMean( rset->getFloat(9) );
118  dat.setAPDOverPNRMS( rset->getFloat(10) );
119  dat.setTaskStatus( rset->getInt(11) );
120 
121 
122  p.second = dat;
123  fillMap->insert(p);
124  }
125  } catch (SQLException &e) {
126  throw(std::runtime_error("MonLaserIRedDat::fetchData(): "+e.getMessage()));
127  }
128 }
129 
130 void MonLaserIRedDat::writeArrayDB(const std::map< EcalLogicID, MonLaserIRedDat >* data, MonRunIOV* iov)
131  throw(std::runtime_error)
132 {
133  this->checkConnection();
134  this->checkPrepare();
135 
136  int iovID = iov->fetchID();
137  if (!iovID) { throw(std::runtime_error("MonLaserIRedDat::writeArrayDB: IOV not in DB")); }
138 
139 
140  int nrows=data->size();
141  int* ids= new int[nrows];
142  int* iovid_vec= new int[nrows];
143  float* xx= new float[nrows];
144  float* yy= new float[nrows];
145  float* zz= new float[nrows];
146  float* ww= new float[nrows];
147  int* st= new int[nrows];
148 
149  ub2* ids_len= new ub2[nrows];
150  ub2* iov_len= new ub2[nrows];
151  ub2* x_len= new ub2[nrows];
152  ub2* y_len= new ub2[nrows];
153  ub2* z_len= new ub2[nrows];
154  ub2* w_len= new ub2[nrows];
155  ub2* st_len= new ub2[nrows];
156 
157  const EcalLogicID* channel;
158  const MonLaserIRedDat* dataitem;
159  int count=0;
160  typedef map< EcalLogicID, MonLaserIRedDat >::const_iterator CI;
161  for (CI p = data->begin(); p != data->end(); ++p) {
162  channel = &(p->first);
163  int logicID = channel->getLogicID();
164  if (!logicID) { throw(std::runtime_error("MonLaserIRedDat::writeArrayDB: Bad EcalLogicID")); }
165  ids[count]=logicID;
166  iovid_vec[count]=iovID;
167 
168  dataitem = &(p->second);
169  // dataIface.writeDB( channel, dataitem, iov);
170  float x=dataitem->getAPDMean();
171  float y=dataitem->getAPDRMS();
172  float z=dataitem->getAPDOverPNMean();
173  float w=dataitem->getAPDOverPNRMS();
174  int statu=dataitem->getTaskStatus();
175 
176 
177 
178  xx[count]=x;
179  yy[count]=y;
180  zz[count]=z;
181  ww[count]=w;
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  st_len[count]=sizeof(st[count]);
193 
194  count++;
195  }
196 
197 
198  try {
199  m_writeStmt->setDataBuffer(1, (dvoid*)iovid_vec, OCCIINT, sizeof(iovid_vec[0]),iov_len);
200  m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len );
201  m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIFLOAT , sizeof(xx[0]), x_len );
202  m_writeStmt->setDataBuffer(4, (dvoid*)yy, OCCIFLOAT , sizeof(yy[0]), y_len );
203  m_writeStmt->setDataBuffer(5, (dvoid*)zz, OCCIFLOAT , sizeof(zz[0]), z_len );
204  m_writeStmt->setDataBuffer(6, (dvoid*)ww, OCCIFLOAT , sizeof(ww[0]), w_len );
205  m_writeStmt->setDataBuffer(7, (dvoid*)st, OCCIINT , sizeof(st[0]), st_len );
206 
207 
208  m_writeStmt->executeArrayUpdate(nrows);
209 
210  delete [] ids;
211  delete [] iovid_vec;
212  delete [] xx;
213  delete [] yy;
214  delete [] zz;
215  delete [] ww;
216  delete [] st;
217 
218  delete [] ids_len;
219  delete [] iov_len;
220  delete [] x_len;
221  delete [] y_len;
222  delete [] z_len;
223  delete [] w_len;
224  delete [] st_len;
225 
226 
227 
228  } catch (SQLException &e) {
229  throw(std::runtime_error("MonLaserIRedDat::writeArrayDB(): "+e.getMessage()));
230  }
231 }
float getAPDOverPNMean() const
bool getTaskStatus() const
float getAPDRMS() const
void setAPDMean(float mean)
#define NULL
Definition: scimark2.h:8
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:22
double double double z
tuple iov
Definition: o2o.py:307
void writeArrayDB(const std::map< EcalLogicID, MonLaserIRedDat > *data, MonRunIOV *iov)
int getLogicID() const
Definition: EcalLogicID.cc:42
void setTaskStatus(bool status)
void setAPDOverPNRMS(float rms)
float getAPDOverPNRMS() const
void writeDB(const EcalLogicID *ecid, const MonLaserIRedDat *item, MonRunIOV *iov)
void setAPDOverPNMean(float mean)
void fetchData(std::map< EcalLogicID, MonLaserIRedDat > *fillMap, MonRunIOV *iov)
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:21
void setAPDRMS(float rms)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
Definition: DDAxes.h:10
void fillMap(Registry *reg, regmap_type &fillme)
Definition: Registry.cc:24
float getAPDMean() const
T w() const