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