CMS 3D CMS Logo

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