CMS 3D CMS Logo

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