CMS 3D CMS Logo

MonShapeQualityDat.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_avgChi2 = 0;
19 }
20 
22 
24  this->checkConnection();
25 
26  try {
27  m_writeStmt = m_conn->createStatement();
28  m_writeStmt->setSQL(
29  "INSERT INTO mon_shape_quality_dat (iov_id, logic_id, "
30  "avg_chi2) "
31  "VALUES (:iov_id, :logic_id, "
32  ":avg_chi2)");
33  } catch (SQLException& e) {
34  throw(std::runtime_error("MonShapeQualityDat::prepareWrite(): " + e.getMessage()));
35  }
36 }
37 
39  const MonShapeQualityDat* item,
40  MonRunIOV* iov) noexcept(false) {
41  this->checkConnection();
42  this->checkPrepare();
43 
44  int iovID = iov->fetchID();
45  if (!iovID) {
46  throw(std::runtime_error("MonShapeQualityDat::writeDB: IOV not in DB"));
47  }
48 
49  int logicID = ecid->getLogicID();
50  if (!logicID) {
51  throw(std::runtime_error("MonShapeQualityDat::writeDB: Bad EcalLogicID"));
52  }
53 
54  try {
55  m_writeStmt->setInt(1, iovID);
56  m_writeStmt->setInt(2, logicID);
57 
58  m_writeStmt->setFloat(3, item->getAvgChi2());
59 
60  m_writeStmt->executeUpdate();
61  } catch (SQLException& e) {
62  throw(std::runtime_error("MonShapeQualityDat::writeDB(): " + e.getMessage()));
63  }
64 }
65 
66 void MonShapeQualityDat::fetchData(std::map<EcalLogicID, MonShapeQualityDat>* fillMap, MonRunIOV* iov) noexcept(false) {
67  this->checkConnection();
68  fillMap->clear();
69 
70  iov->setConnection(m_env, m_conn);
71  int iovID = iov->fetchID();
72  if (!iovID) {
73  // throw(std::runtime_error("MonShapeQualityDat::writeDB: IOV not in DB"));
74  return;
75  }
76 
77  try {
78  m_readStmt->setSQL(
79  "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
80  "d.avg_chi2 "
81  "FROM channelview cv JOIN mon_shape_quality_dat d "
82  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
83  "WHERE d.iov_id = :iov_id");
84  m_readStmt->setInt(1, iovID);
85  ResultSet* rset = m_readStmt->executeQuery();
86 
87  std::pair<EcalLogicID, MonShapeQualityDat> p;
89  while (rset->next()) {
90  p.first = EcalLogicID(rset->getString(1), // name
91  rset->getInt(2), // logic_id
92  rset->getInt(3), // id1
93  rset->getInt(4), // id2
94  rset->getInt(5), // id3
95  rset->getString(6)); // maps_to
96 
97  dat.setAvgChi2(rset->getFloat(7));
98 
99  p.second = dat;
100  fillMap->insert(p);
101  }
102  } catch (SQLException& e) {
103  throw(std::runtime_error("MonShapeQualityDat::fetchData(): " + e.getMessage()));
104  }
105 }
106 
107 void MonShapeQualityDat::writeArrayDB(const std::map<EcalLogicID, MonShapeQualityDat>* data,
108  MonRunIOV* iov) noexcept(false) {
109  this->checkConnection();
110  this->checkPrepare();
111 
112  int iovID = iov->fetchID();
113  if (!iovID) {
114  throw(std::runtime_error("MonShapeQualityDat::writeArrayDB: IOV not in DB"));
115  }
116 
117  int nrows = data->size();
118  int* ids = new int[nrows];
119  int* iovid_vec = new int[nrows];
120  float* xx = new float[nrows];
121 
122  ub2* ids_len = new ub2[nrows];
123  ub2* iov_len = new ub2[nrows];
124  ub2* x_len = new ub2[nrows];
125 
126  const EcalLogicID* channel;
127  const MonShapeQualityDat* dataitem;
128  int count = 0;
129  typedef map<EcalLogicID, MonShapeQualityDat>::const_iterator CI;
130  for (CI p = data->begin(); p != data->end(); ++p) {
131  channel = &(p->first);
132  int logicID = channel->getLogicID();
133  if (!logicID) {
134  throw(std::runtime_error("MonShapeQualityDat::writeArrayDB: Bad EcalLogicID"));
135  }
136  ids[count] = logicID;
137  iovid_vec[count] = iovID;
138 
139  dataitem = &(p->second);
140  // dataIface.writeDB( channel, dataitem, iov);
141  float x = dataitem->getAvgChi2();
142 
143  xx[count] = x;
144 
145  ids_len[count] = sizeof(ids[count]);
146  iov_len[count] = sizeof(iovid_vec[count]);
147 
148  x_len[count] = sizeof(xx[count]);
149 
150  count++;
151  }
152 
153  try {
154  m_writeStmt->setDataBuffer(1, (dvoid*)iovid_vec, OCCIINT, sizeof(iovid_vec[0]), iov_len);
155  m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len);
156  m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIFLOAT, sizeof(xx[0]), x_len);
157 
158  m_writeStmt->executeArrayUpdate(nrows);
159 
160  delete[] ids;
161  delete[] iovid_vec;
162  delete[] xx;
163 
164  delete[] ids_len;
165  delete[] iov_len;
166  delete[] x_len;
167 
168  } catch (SQLException& e) {
169  throw(std::runtime_error("MonPedestalsDat::writeArrayDB(): " + e.getMessage()));
170  }
171 }
MonShapeQualityDat::writeDB
void writeDB(const EcalLogicID *ecid, const MonShapeQualityDat *item, MonRunIOV *iov) noexcept(false)
Definition: MonShapeQualityDat.cc:38
funct::false
false
Definition: Factorize.h:29
MonShapeQualityDat::writeArrayDB
void writeArrayDB(const std::map< EcalLogicID, MonShapeQualityDat > *data, MonRunIOV *iov) noexcept(false)
Definition: MonShapeQualityDat.cc:107
RunIOV.h
MonShapeQualityDat::prepareWrite
void prepareWrite() noexcept(false) override
Definition: MonShapeQualityDat.cc:23
MonShapeQualityDat.h
MonShapeQualityDat::MonShapeQualityDat
MonShapeQualityDat()
Definition: MonShapeQualityDat.cc:12
MonShapeQualityDat
Definition: MonShapeQualityDat.h:12
DDAxes::x
EcalLogicID::getLogicID
int getLogicID() const
Definition: EcalLogicID.cc:28
oracle::occi
Definition: ConnectionManager.h:7
EcalLogicID
Definition: EcalLogicID.h:7
submitPVResolutionJobs.count
count
Definition: submitPVResolutionJobs.py:352
MonShapeQualityDat::fetchData
void fetchData(std::map< EcalLogicID, MonShapeQualityDat > *fillVec, MonRunIOV *iov) noexcept(false)
Definition: MonShapeQualityDat.cc:66
AlCaHLTBitMon_ParallelJobs.p
def p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
MonRunIOV
Definition: MonRunIOV.h:14
B2GTnPMonitor_cfi.item
item
Definition: B2GTnPMonitor_cfi.py:147
std
Definition: JetResolutionObject.h:76
MonShapeQualityDat::setAvgChi2
void setAvgChi2(float chi2)
Definition: MonShapeQualityDat.h:21
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
MonShapeQualityDat::getAvgChi2
float getAvgChi2() const
Definition: MonShapeQualityDat.h:22
Oracle.h
MonShapeQualityDat::~MonShapeQualityDat
~MonShapeQualityDat() override
Definition: MonShapeQualityDat.cc:21
RunTag.h
geometryCSVtoXML.xx
xx
Definition: geometryCSVtoXML.py:19
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37