CMS 3D CMS Logo

MonPedestalsOnlineDat.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 = nullptr;
15  m_conn = nullptr;
16  m_writeStmt = nullptr;
17  m_readStmt = nullptr;
18 
19  m_adcMeanG12 = 0;
20  m_adcRMSG12 = 0;
21  m_taskStatus = false;
22 }
23 
24 
25 
27 {
28 }
29 
30 
31 
34 {
35  this->checkConnection();
36 
37  try {
38  m_writeStmt = m_conn->createStatement();
39  m_writeStmt->setSQL("INSERT INTO mon_pedestals_online_dat (iov_id, logic_id, "
40  "adc_mean_g12, adc_rms_g12, task_status) "
41  "VALUES (:iov_id, :logic_id, "
42  ":adc_mean_g12, :adc_rms_g12, :task_status)");
43  } catch (SQLException &e) {
44  throw(std::runtime_error(std::string("MonPedestalsOnlineDat::prepareWrite(): ")+getOraMessage(&e)));
45  }
46 }
47 
48 
49 
51  noexcept(false)
52 {
53  this->checkConnection();
54  this->checkPrepare();
55 
56  int iovID = iov->fetchID();
57  if (!iovID) { throw(std::runtime_error("MonPedestalsOnlineDat::writeDB: IOV not in DB")); }
58 
59  int logicID = ecid->getLogicID();
60  if (!logicID) { throw(std::runtime_error("MonPedestalsOnlineDat::writeDB: Bad EcalLogicID")); }
61 
62  try {
63  m_writeStmt->setInt(1, iovID);
64  m_writeStmt->setInt(2, logicID);
65  m_writeStmt->setFloat(3, item->getADCMeanG12() );
66  m_writeStmt->setFloat(4, item->getADCRMSG12() );
67  m_writeStmt->setInt(5, item->getTaskStatus() );
68 
69  m_writeStmt->executeUpdate();
70  } catch (SQLException &e) {
71  throw(std::runtime_error(std::string("MonPedestalsOnlineDat::writeDB(): ")+getOraMessage(&e)));
72  }
73 }
74 
75 
76 
77 void MonPedestalsOnlineDat::fetchData(std::map< EcalLogicID, MonPedestalsOnlineDat >* fillMap, MonRunIOV* iov)
78  noexcept(false)
79 {
80  this->checkConnection();
81  fillMap->clear();
82 
83  iov->setConnection(m_env, m_conn);
84  int iovID = iov->fetchID();
85  if (!iovID) {
86  // throw(std::runtime_error("MonPedestalsOnlineDat::writeDB: IOV not in DB"));
87  return;
88  }
89 
90  try {
91 
92  m_readStmt->setSQL("SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
93  "d.adc_mean_g12, d.adc_rms_g12, d.task_status "
94  "FROM channelview cv JOIN mon_pedestals_online_dat d "
95  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
96  "WHERE d.iov_id = :iov_id");
97  m_readStmt->setInt(1, iovID);
98  ResultSet* rset = m_readStmt->executeQuery();
99 
100  std::pair< EcalLogicID, MonPedestalsOnlineDat > p;
102  while(rset->next()) {
103  p.first = EcalLogicID( getOraString(rset,1), // name
104  rset->getInt(2), // logic_id
105  rset->getInt(3), // id1
106  rset->getInt(4), // id2
107  rset->getInt(5), // id3
108  getOraString(rset,6)); // maps_to
109 
110  dat.setADCMeanG12( rset->getFloat(7) );
111  dat.setADCRMSG12( rset->getFloat(8) );
112  dat.setTaskStatus( rset->getInt(9) );
113 
114  p.second = dat;
115  fillMap->insert(p);
116  }
117  } catch (SQLException &e) {
118  throw(std::runtime_error(std::string("MonPedestalsOnlineDat::fetchData(): ")+getOraMessage(&e)));
119  }
120 }
121 
122 void MonPedestalsOnlineDat::writeArrayDB(const std::map< EcalLogicID, MonPedestalsOnlineDat >* data, MonRunIOV* iov)
123  noexcept(false)
124 {
125  this->checkConnection();
126  this->checkPrepare();
127 
128  int iovID = iov->fetchID();
129  if (!iovID) { throw(std::runtime_error("MonPedestalsOnlineDat::writeArrayDB: IOV not in DB")); }
130 
131 
132  int nrows=data->size();
133  int* ids= new int[nrows];
134  int* iovid_vec= new int[nrows];
135  float* xx= new float[nrows];
136  float* yy= new float[nrows];
137  int* st= new int[nrows];
138 
139  ub2* ids_len= new ub2[nrows];
140  ub2* iov_len= new ub2[nrows];
141  ub2* x_len= new ub2[nrows];
142  ub2* y_len= new ub2[nrows];
143  ub2* st_len= new ub2[nrows];
144 
145  const EcalLogicID* channel;
146  const MonPedestalsOnlineDat* dataitem;
147  int count=0;
148  typedef map< EcalLogicID, MonPedestalsOnlineDat >::const_iterator CI;
149  for (CI p = data->begin(); p != data->end(); ++p) {
150  channel = &(p->first);
151  int logicID = channel->getLogicID();
152  if (!logicID) { throw(std::runtime_error("MonPedestalsOnlineDat::writeArrayDB: Bad EcalLogicID")); }
153  ids[count]=logicID;
154  iovid_vec[count]=iovID;
155 
156  dataitem = &(p->second);
157  // dataIface.writeDB( channel, dataitem, iov);
158  float x=dataitem->getADCMeanG12();
159  float y=dataitem->getADCRMSG12();
160  int statu=dataitem->getTaskStatus();
161 
162 
163 
164  xx[count]=x;
165  yy[count]=y;
166  st[count]=statu;
167 
168 
169  ids_len[count]=sizeof(ids[count]);
170  iov_len[count]=sizeof(iovid_vec[count]);
171 
172  x_len[count]=sizeof(xx[count]);
173  y_len[count]=sizeof(yy[count]);
174  st_len[count]=sizeof(st[count]);
175 
176  count++;
177  }
178 
179 
180  try {
181  m_writeStmt->setDataBuffer(1, (dvoid*)iovid_vec, OCCIINT, sizeof(iovid_vec[0]),iov_len);
182  m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len );
183  m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIFLOAT , sizeof(xx[0]), x_len );
184  m_writeStmt->setDataBuffer(4, (dvoid*)yy, OCCIFLOAT , sizeof(yy[0]), y_len );
185  m_writeStmt->setDataBuffer(5, (dvoid*)st, OCCIINT , sizeof(st[0]), st_len );
186 
187 
188  m_writeStmt->executeArrayUpdate(nrows);
189 
190  delete [] ids;
191  delete [] iovid_vec;
192  delete [] xx;
193  delete [] yy;
194  delete [] st;
195 
196  delete [] ids_len;
197  delete [] iov_len;
198  delete [] x_len;
199  delete [] y_len;
200  delete [] st_len;
201 
202 
203 
204  } catch (SQLException &e) {
205  throw(std::runtime_error(std::string("MonPedestalsDat::writeArrayDB(): ")+getOraMessage(&e)));
206  }
207 }
#define noexcept
void setTaskStatus(bool status)
void prepareWrite() noexcept(false) override
int getLogicID() const
Definition: EcalLogicID.cc:41
void writeArrayDB(const std::map< EcalLogicID, MonPedestalsOnlineDat > *data, MonRunIOV *iov) noexcept(false)
void setADCMeanG12(float mean)
void fetchData(std::map< EcalLogicID, MonPedestalsOnlineDat > *fillMap, MonRunIOV *iov) noexcept(false)
void writeDB(const EcalLogicID *ecid, const MonPedestalsOnlineDat *item, MonRunIOV *iov) noexcept(false)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82