CMS 3D CMS Logo

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