CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MonTestPulseDat.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_adcMeanG1 = 0;
20  m_adcRMSG1 = 0;
21  m_adcMeanG6 = 0;
22  m_adcRMSG6 = 0;
23  m_adcMeanG12 = 0;
24  m_adcRMSG12 = 0;
25  m_taskStatus = 0;
26 }
27 
28 
29 
31 {
32 }
33 
34 
35 
37  throw(std::runtime_error)
38 {
39  this->checkConnection();
40 
41  try {
42  m_writeStmt = m_conn->createStatement();
43  m_writeStmt->setSQL("INSERT INTO mon_test_pulse_dat (iov_id, logic_id, "
44  "adc_mean_g1, adc_rms_g1, adc_mean_g6, adc_rms_g6, adc_mean_g12, adc_rms_g12, task_status) "
45  "VALUES (:iov_id, :logic_id, "
46  ":adc_mean_g1, :adc_rms_g1, :adc_rms_g6, :adc_rms_g6, :adc_mean_g12, :adc_rms_g12, :task_status)");
47  } catch (SQLException &e) {
48  throw(std::runtime_error("MonTestPulseDat::prepareWrite(): "+e.getMessage()));
49  }
50 }
51 
52 
53 
55  throw(std::runtime_error)
56 {
57  this->checkConnection();
58  this->checkPrepare();
59 
60  int iovID = iov->fetchID();
61  if (!iovID) { throw(std::runtime_error("MonTestPulseDat::writeDB: IOV not in DB")); }
62 
63  int logicID = ecid->getLogicID();
64  if (!logicID) { throw(std::runtime_error("MonTestPulseDat::writeDB: Bad EcalLogicID")); }
65 
66  try {
67  m_writeStmt->setInt(1, iovID);
68  m_writeStmt->setInt(2, logicID);
69  m_writeStmt->setFloat(3, item->getADCMeanG1() );
70  m_writeStmt->setFloat(4, item->getADCRMSG1() );
71  m_writeStmt->setFloat(5, item->getADCMeanG6() );
72  m_writeStmt->setFloat(6, item->getADCRMSG6() );
73  m_writeStmt->setFloat(7, item->getADCMeanG12() );
74  m_writeStmt->setFloat(8, item->getADCRMSG12() );
75  m_writeStmt->setInt(9, item->getTaskStatus() );
76 
77  m_writeStmt->executeUpdate();
78  } catch (SQLException &e) {
79  throw(std::runtime_error("MonTestPulseDat::writeDB(): "+e.getMessage()));
80  }
81 }
82 
83 
84 
85 void MonTestPulseDat::fetchData(std::map< EcalLogicID, MonTestPulseDat >* fillMap, MonRunIOV* iov)
86  throw(std::runtime_error)
87 {
88  this->checkConnection();
89  fillMap->clear();
90 
91  iov->setConnection(m_env, m_conn);
92  int iovID = iov->fetchID();
93  if (!iovID) {
94  // throw(std::runtime_error("MonTestPulseDat::writeDB: IOV not in DB"));
95  return;
96  }
97 
98  try {
99 
100  m_readStmt->setSQL("SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
101  "d.adc_mean_g1, d.adc_rms_g1, d.adc_mean_g6, d.adc_rms_g6, d.adc_mean_g12, d.adc_rms_g12, d.task_status "
102  "FROM channelview cv JOIN mon_test_pulse_dat d "
103  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
104  "WHERE d.iov_id = :iov_id");
105  m_readStmt->setInt(1, iovID);
106  ResultSet* rset = m_readStmt->executeQuery();
107 
108  std::pair< EcalLogicID, MonTestPulseDat > p;
109  MonTestPulseDat dat;
110  while(rset->next()) {
111  p.first = EcalLogicID( rset->getString(1), // name
112  rset->getInt(2), // logic_id
113  rset->getInt(3), // id1
114  rset->getInt(4), // id2
115  rset->getInt(5), // id3
116  rset->getString(6)); // maps_to
117 
118  dat.setADCMeanG1( rset->getFloat(7) );
119  dat.setADCRMSG1( rset->getFloat(8) );
120  dat.setADCMeanG6( rset->getFloat(9) );
121  dat.setADCRMSG6( rset->getFloat(10) );
122  dat.setADCMeanG12( rset->getFloat(11) );
123  dat.setADCRMSG12( rset->getFloat(12) );
124  dat.setTaskStatus( rset->getInt(13) );
125 
126  p.second = dat;
127  fillMap->insert(p);
128  }
129  } catch (SQLException &e) {
130  throw(std::runtime_error("MonTestPulseDat::fetchData(): "+e.getMessage()));
131  }
132 }
133 
134 void MonTestPulseDat::writeArrayDB(const std::map< EcalLogicID, MonTestPulseDat >* data, MonRunIOV* iov)
135  throw(std::runtime_error)
136 {
137  this->checkConnection();
138  this->checkPrepare();
139 
140  int iovID = iov->fetchID();
141  if (!iovID) { throw(std::runtime_error("MonTestPulseDat::writeArrayDB: IOV not in DB")); }
142 
143 
144  int nrows=data->size();
145  int* ids= new int[nrows];
146  int* iovid_vec= new int[nrows];
147  float* xx= new float[nrows];
148  float* yy= new float[nrows];
149  float* zz= new float[nrows];
150  float* ww= new float[nrows];
151  float* uu= new float[nrows];
152  float* tt= new float[nrows];
153  int* st= new int[nrows];
154 
155  ub2* ids_len= new ub2[nrows];
156  ub2* iov_len= new ub2[nrows];
157  ub2* x_len= new ub2[nrows];
158  ub2* y_len= new ub2[nrows];
159  ub2* z_len= new ub2[nrows];
160  ub2* w_len= new ub2[nrows];
161  ub2* u_len= new ub2[nrows];
162  ub2* t_len= new ub2[nrows];
163  ub2* st_len= new ub2[nrows];
164 
165  const EcalLogicID* channel;
166  const MonTestPulseDat* dataitem;
167  int count=0;
168  typedef map< EcalLogicID, MonTestPulseDat >::const_iterator CI;
169  for (CI p = data->begin(); p != data->end(); ++p) {
170  channel = &(p->first);
171  int logicID = channel->getLogicID();
172  if (!logicID) { throw(std::runtime_error("MonTestPulseDat::writeArrayDB: Bad EcalLogicID")); }
173  ids[count]=logicID;
174  iovid_vec[count]=iovID;
175 
176  dataitem = &(p->second);
177  // dataIface.writeDB( channel, dataitem, iov);
178  float x=dataitem->getADCMeanG1();
179  float y=dataitem->getADCRMSG1();
180  float z=dataitem->getADCMeanG6();
181  float w=dataitem->getADCRMSG6();
182  float u=dataitem->getADCMeanG12();
183  float t=dataitem->getADCRMSG12();
184  int statu=dataitem->getTaskStatus();
185 
186 
187 
188  xx[count]=x;
189  yy[count]=y;
190  zz[count]=z;
191  ww[count]=w;
192  uu[count]=u;
193  tt[count]=t;
194  st[count]=statu;
195 
196 
197  ids_len[count]=sizeof(ids[count]);
198  iov_len[count]=sizeof(iovid_vec[count]);
199 
200  x_len[count]=sizeof(xx[count]);
201  y_len[count]=sizeof(yy[count]);
202  z_len[count]=sizeof(zz[count]);
203  w_len[count]=sizeof(ww[count]);
204  u_len[count]=sizeof(uu[count]);
205  t_len[count]=sizeof(tt[count]);
206  st_len[count]=sizeof(st[count]);
207 
208  count++;
209  }
210 
211 
212  try {
213  m_writeStmt->setDataBuffer(1, (dvoid*)iovid_vec, OCCIINT, sizeof(iovid_vec[0]),iov_len);
214  m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len );
215  m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIFLOAT , sizeof(xx[0]), x_len );
216  m_writeStmt->setDataBuffer(4, (dvoid*)yy, OCCIFLOAT , sizeof(yy[0]), y_len );
217  m_writeStmt->setDataBuffer(5, (dvoid*)zz, OCCIFLOAT , sizeof(zz[0]), z_len );
218  m_writeStmt->setDataBuffer(6, (dvoid*)ww, OCCIFLOAT , sizeof(ww[0]), w_len );
219  m_writeStmt->setDataBuffer(7, (dvoid*)uu, OCCIFLOAT , sizeof(uu[0]), u_len );
220  m_writeStmt->setDataBuffer(8, (dvoid*)tt, OCCIFLOAT , sizeof(tt[0]), t_len );
221  m_writeStmt->setDataBuffer(9, (dvoid*)st, OCCIINT , sizeof(st[0]), st_len );
222 
223 
224  m_writeStmt->executeArrayUpdate(nrows);
225 
226  delete [] ids;
227  delete [] iovid_vec;
228  delete [] xx;
229  delete [] yy;
230  delete [] zz;
231  delete [] ww;
232  delete [] uu;
233  delete [] tt;
234  delete [] st;
235 
236  delete [] ids_len;
237  delete [] iov_len;
238  delete [] x_len;
239  delete [] y_len;
240  delete [] z_len;
241  delete [] w_len;
242  delete [] u_len;
243  delete [] t_len;
244  delete [] st_len;
245 
246 
247 
248  } catch (SQLException &e) {
249  throw(std::runtime_error("MonTestPulseDat::writeArrayDB(): "+e.getMessage()));
250  }
251 }
void setADCRMSG1(float rms)
float getADCMeanG6() const
void setADCMeanG1(float mean)
#define NULL
Definition: scimark2.h:8
float getADCRMSG12() const
void setADCMeanG6(float mean)
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:22
double double double z
void writeArrayDB(const std::map< EcalLogicID, MonTestPulseDat > *data, MonRunIOV *iov)
void setADCMeanG12(float mean)
void fetchData(std::map< EcalLogicID, MonTestPulseDat > *fillMap, MonRunIOV *iov)
tuple iov
Definition: o2o.py:307
void setTaskStatus(bool status)
float getADCRMSG1() const
void setADCRMSG12(float rms)
int getLogicID() const
Definition: EcalLogicID.cc:42
float getADCMeanG12() const
bool getTaskStatus() const
void setADCRMSG6(float rms)
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:21
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
void writeDB(const EcalLogicID *ecid, const MonTestPulseDat *item, MonRunIOV *iov)
float getADCRMSG6() const
void fillMap(Registry *reg, regmap_type &fillme)
Definition: Registry.cc:24
x
Definition: VDTMath.h:216
float getADCMeanG1() const
T w() const