CMS 3D CMS Logo

MonPNIRedDat.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_adcMeanG16 = 0;
21  m_adcRMSG16 = 0;
22  m_pedMeanG1 = 0;
23  m_pedRMSG1 = 0;
24  m_pedMeanG16 = 0;
25  m_pedRMSG16 = 0;
26  m_taskStatus = false;
27 }
28 
30 
32  this->checkConnection();
33 
34  try {
35  m_writeStmt = m_conn->createStatement();
36  m_writeStmt->setSQL(
37  "INSERT INTO mon_pn_ired_dat (iov_id, logic_id, "
38  "adc_mean_g1, adc_rms_g1, adc_mean_g16, adc_rms_g16, ped_mean_g1, ped_rms_g1, ped_mean_g16, ped_rms_g16, "
39  "task_status) "
40  "VALUES (:iov_id, :logic_id, "
41  ":3, :4, :5, :6, :7, :8, :9, :10, :11)");
42  } catch (SQLException& e) {
43  throw(std::runtime_error("MonPNIRedDat::prepareWrite(): " + e.getMessage()));
44  }
45 }
46 
47 void MonPNIRedDat::writeDB(const EcalLogicID* ecid, const MonPNIRedDat* item, MonRunIOV* iov) noexcept(false) {
48  this->checkConnection();
49  this->checkPrepare();
50 
51  int iovID = iov->fetchID();
52  if (!iovID) {
53  throw(std::runtime_error("MonPNIRedDat::writeDB: IOV not in DB"));
54  }
55 
56  int logicID = ecid->getLogicID();
57  if (!logicID) {
58  throw(std::runtime_error("MonPNIRedDat::writeDB: Bad EcalLogicID"));
59  }
60 
61  try {
62  m_writeStmt->setInt(1, iovID);
63  m_writeStmt->setInt(2, logicID);
64 
65  m_writeStmt->setFloat(3, item->getADCMeanG1());
66  m_writeStmt->setFloat(4, item->getADCRMSG1());
67  m_writeStmt->setFloat(5, item->getADCMeanG16());
68  m_writeStmt->setFloat(6, item->getADCRMSG16());
69  m_writeStmt->setFloat(7, item->getPedMeanG1());
70  m_writeStmt->setFloat(8, item->getPedRMSG1());
71  m_writeStmt->setFloat(9, item->getPedMeanG16());
72  m_writeStmt->setFloat(10, item->getPedRMSG16());
73  m_writeStmt->setInt(11, item->getTaskStatus());
74 
75  m_writeStmt->executeUpdate();
76  } catch (SQLException& e) {
77  throw(std::runtime_error("MonPNIRedDat::writeDB(): " + e.getMessage()));
78  }
79 }
80 
81 void MonPNIRedDat::fetchData(std::map<EcalLogicID, MonPNIRedDat>* fillMap, MonRunIOV* iov) noexcept(false) {
82  this->checkConnection();
83  fillMap->clear();
84 
85  iov->setConnection(m_env, m_conn);
86  int iovID = iov->fetchID();
87  if (!iovID) {
88  // throw(std::runtime_error("MonPNIRedDat::writeDB: IOV not in DB"));
89  return;
90  }
91 
92  try {
93  m_readStmt->setSQL(
94  "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
95  "d.adc_mean_g1, d.adc_rms_g1, d.adc_mean_g16, d.adc_rms_g16, d.ped_mean_g1,d.ped_rms_g1, d.ped_mean_g16, "
96  "d.ped_rms_g16, d.task_status "
97  "FROM channelview cv JOIN mon_pn_ired_dat d "
98  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
99  "WHERE d.iov_id = :iov_id");
100  m_readStmt->setInt(1, iovID);
101  ResultSet* rset = m_readStmt->executeQuery();
102 
103  std::pair<EcalLogicID, MonPNIRedDat> p;
104  MonPNIRedDat dat;
105  while (rset->next()) {
106  p.first = EcalLogicID(rset->getString(1), // name
107  rset->getInt(2), // logic_id
108  rset->getInt(3), // id1
109  rset->getInt(4), // id2
110  rset->getInt(5), // id3
111  rset->getString(6)); // maps_to
112 
113  dat.setADCMeanG1(rset->getFloat(7));
114  dat.setADCRMSG1(rset->getFloat(8));
115  dat.setADCMeanG16(rset->getFloat(9));
116  dat.setADCRMSG16(rset->getFloat(10));
117  dat.setPedMeanG1(rset->getFloat(11));
118  dat.setPedRMSG1(rset->getFloat(12));
119  dat.setPedMeanG16(rset->getFloat(13));
120  dat.setPedRMSG16(rset->getFloat(14));
121  dat.setTaskStatus(rset->getInt(15));
122  p.second = dat;
123  fillMap->insert(p);
124  }
125  } catch (SQLException& e) {
126  throw(std::runtime_error("MonPNIRedDat::fetchData(): " + e.getMessage()));
127  }
128 }
129 void MonPNIRedDat::writeArrayDB(const std::map<EcalLogicID, MonPNIRedDat>* data, MonRunIOV* iov) noexcept(false) {
130  this->checkConnection();
131  this->checkPrepare();
132 
133  int iovID = iov->fetchID();
134  if (!iovID) {
135  throw(std::runtime_error("MonPNIRedDat::writeArrayDB: IOV not in DB"));
136  }
137 
138  int nrows = data->size();
139  int* ids = new int[nrows];
140  int* iovid_vec = new int[nrows];
141  float* xx = new float[nrows];
142  float* yy = new float[nrows];
143  float* zz = new float[nrows];
144  float* ww = new float[nrows];
145  float* uu = new float[nrows];
146  float* tt = new float[nrows];
147  float* rr = new float[nrows];
148  float* pp = new float[nrows];
149  int* st = new int[nrows];
150 
151  ub2* ids_len = new ub2[nrows];
152  ub2* iov_len = new ub2[nrows];
153  ub2* x_len = new ub2[nrows];
154  ub2* y_len = new ub2[nrows];
155  ub2* z_len = new ub2[nrows];
156  ub2* w_len = new ub2[nrows];
157  ub2* u_len = new ub2[nrows];
158  ub2* t_len = new ub2[nrows];
159  ub2* r_len = new ub2[nrows];
160  ub2* p_len = new ub2[nrows];
161  ub2* st_len = new ub2[nrows];
162 
163  const EcalLogicID* channel;
164  const MonPNIRedDat* dataitem;
165  int count = 0;
166  typedef map<EcalLogicID, MonPNIRedDat>::const_iterator CI;
167  for (CI p = data->begin(); p != data->end(); ++p) {
168  channel = &(p->first);
169  int logicID = channel->getLogicID();
170  if (!logicID) {
171  throw(std::runtime_error("MonPNIRedDat::writeArrayDB: Bad EcalLogicID"));
172  }
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->getADCMeanG16();
181  float w = dataitem->getADCRMSG16();
182  float u = dataitem->getPedMeanG1();
183  float t = dataitem->getPedRMSG1();
184  float r = dataitem->getPedMeanG16();
185  float pi = dataitem->getPedRMSG16();
186  int statu = dataitem->getTaskStatus();
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  rr[count] = r;
195  pp[count] = pi;
196  st[count] = statu;
197 
198  ids_len[count] = sizeof(ids[count]);
199  iov_len[count] = sizeof(iovid_vec[count]);
200 
201  x_len[count] = sizeof(xx[count]);
202  y_len[count] = sizeof(yy[count]);
203  z_len[count] = sizeof(zz[count]);
204  w_len[count] = sizeof(ww[count]);
205  u_len[count] = sizeof(uu[count]);
206  t_len[count] = sizeof(tt[count]);
207  r_len[count] = sizeof(rr[count]);
208  p_len[count] = sizeof(pp[count]);
209  st_len[count] = sizeof(st[count]);
210 
211  count++;
212  }
213 
214  try {
215  m_writeStmt->setDataBuffer(1, (dvoid*)iovid_vec, OCCIINT, sizeof(iovid_vec[0]), iov_len);
216  m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len);
217  m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIFLOAT, sizeof(xx[0]), x_len);
218  m_writeStmt->setDataBuffer(4, (dvoid*)yy, OCCIFLOAT, sizeof(yy[0]), y_len);
219  m_writeStmt->setDataBuffer(5, (dvoid*)zz, OCCIFLOAT, sizeof(zz[0]), z_len);
220  m_writeStmt->setDataBuffer(6, (dvoid*)ww, OCCIFLOAT, sizeof(ww[0]), w_len);
221  m_writeStmt->setDataBuffer(7, (dvoid*)uu, OCCIFLOAT, sizeof(uu[0]), u_len);
222  m_writeStmt->setDataBuffer(8, (dvoid*)tt, OCCIFLOAT, sizeof(tt[0]), t_len);
223  m_writeStmt->setDataBuffer(9, (dvoid*)rr, OCCIFLOAT, sizeof(rr[0]), r_len);
224  m_writeStmt->setDataBuffer(10, (dvoid*)pp, OCCIFLOAT, sizeof(pp[0]), p_len);
225  m_writeStmt->setDataBuffer(11, (dvoid*)st, OCCIINT, sizeof(st[0]), st_len);
226 
227  m_writeStmt->executeArrayUpdate(nrows);
228 
229  delete[] ids;
230  delete[] iovid_vec;
231  delete[] xx;
232  delete[] yy;
233  delete[] zz;
234  delete[] ww;
235  delete[] uu;
236  delete[] tt;
237  delete[] rr;
238  delete[] pp;
239  delete[] st;
240 
241  delete[] ids_len;
242  delete[] iov_len;
243  delete[] x_len;
244  delete[] y_len;
245  delete[] z_len;
246  delete[] w_len;
247  delete[] u_len;
248  delete[] t_len;
249  delete[] r_len;
250  delete[] p_len;
251  delete[] st_len;
252 
253  } catch (SQLException& e) {
254  throw(std::runtime_error("MonPNIRedDat::writeArrayDB(): " + e.getMessage()));
255  }
256 }
MonPNIRedDat::MonPNIRedDat
MonPNIRedDat()
Definition: MonPNIRedDat.cc:12
MonPNIRedDat::getADCRMSG16
float getADCRMSG16() const
Definition: MonPNIRedDat.h:31
DDAxes::y
geometryCSVtoXML.zz
zz
Definition: geometryCSVtoXML.py:19
funct::false
false
Definition: Factorize.h:29
groupFilesInBlocks.tt
int tt
Definition: groupFilesInBlocks.py:144
MonPNIRedDat.h
findQualityFiles.rr
string rr
Definition: findQualityFiles.py:185
MonPNIRedDat::getTaskStatus
bool getTaskStatus() const
Definition: MonPNIRedDat.h:46
RunIOV.h
MonPNIRedDat::getADCMeanG16
float getADCMeanG16() const
Definition: MonPNIRedDat.h:28
MonPNIRedDat::writeArrayDB
void writeArrayDB(const std::map< EcalLogicID, MonPNIRedDat > *data, MonRunIOV *iov) noexcept(false)
Definition: MonPNIRedDat.cc:129
MonPNIRedDat::getPedRMSG1
float getPedRMSG1() const
Definition: MonPNIRedDat.h:37
DDAxes::x
EcalLogicID::getLogicID
int getLogicID() const
Definition: EcalLogicID.cc:28
MonPNIRedDat::fetchData
void fetchData(std::map< EcalLogicID, MonPNIRedDat > *fillVec, MonRunIOV *iov) noexcept(false)
Definition: MonPNIRedDat.cc:81
MonPNIRedDat::setADCMeanG1
void setADCMeanG1(float mean)
Definition: MonPNIRedDat.h:21
MonPNIRedDat::setPedMeanG16
void setPedMeanG16(float mean)
Definition: MonPNIRedDat.h:39
MonPNIRedDat::setADCRMSG16
void setADCRMSG16(float mean)
Definition: MonPNIRedDat.h:30
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
MonPNIRedDat::setADCRMSG1
void setADCRMSG1(float mean)
Definition: MonPNIRedDat.h:24
MonPNIRedDat
Definition: MonPNIRedDat.h:12
MonPNIRedDat::getADCMeanG1
float getADCMeanG1() const
Definition: MonPNIRedDat.h:22
MonPNIRedDat::setADCMeanG16
void setADCMeanG16(float mean)
Definition: MonPNIRedDat.h:27
AlCaHLTBitMon_ParallelJobs.p
def p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
geometryCSVtoXML.yy
yy
Definition: geometryCSVtoXML.py:19
MonRunIOV
Definition: MonRunIOV.h:14
B2GTnPMonitor_cfi.item
item
Definition: B2GTnPMonitor_cfi.py:147
MonPNIRedDat::setPedMeanG1
void setPedMeanG1(float mean)
Definition: MonPNIRedDat.h:33
MonPNIRedDat::~MonPNIRedDat
~MonPNIRedDat() override
Definition: MonPNIRedDat.cc:29
alignCSCRings.r
r
Definition: alignCSCRings.py:93
MonPNIRedDat::writeDB
void writeDB(const EcalLogicID *ecid, const MonPNIRedDat *item, MonRunIOV *iov) noexcept(false)
Definition: MonPNIRedDat.cc:47
std
Definition: JetResolutionObject.h:76
MonPNIRedDat::getPedMeanG16
float getPedMeanG16() const
Definition: MonPNIRedDat.h:40
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
MonPNIRedDat::setTaskStatus
void setTaskStatus(bool status)
Definition: MonPNIRedDat.h:45
Oracle.h
pi
const Double_t pi
Definition: trackSplitPlot.h:36
RunTag.h
createTree.pp
pp
Definition: createTree.py:17
MonPNIRedDat::setPedRMSG1
void setPedRMSG1(float mean)
Definition: MonPNIRedDat.h:36
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
MonPNIRedDat::getPedRMSG16
float getPedRMSG16() const
Definition: MonPNIRedDat.h:43
geometryCSVtoXML.xx
xx
Definition: geometryCSVtoXML.py:19
MonPNIRedDat::prepareWrite
void prepareWrite() noexcept(false) override
Definition: MonPNIRedDat.cc:31
MonPNIRedDat::setPedRMSG16
void setPedRMSG16(float mean)
Definition: MonPNIRedDat.h:42
MonPNIRedDat::getPedMeanG1
float getPedMeanG1() const
Definition: MonPNIRedDat.h:34
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
MonPNIRedDat::getADCRMSG1
float getADCRMSG1() const
Definition: MonPNIRedDat.h:25