CMS 3D CMS Logo

MonOccupancyDat.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  m_env = nullptr;
12  m_conn = nullptr;
13  m_writeStmt = nullptr;
14  m_readStmt = nullptr;
15 
16  m_eventsOverLowThreshold = 0;
17  m_eventsOverHighThreshold = 0;
18  m_avgEnergy = 0;
19 }
20 
22 
24  this->checkConnection();
25 
26  try {
27  m_writeStmt = m_conn->createStatement();
28  m_writeStmt->setSQL(
29  "INSERT INTO mon_occupancy_dat (iov_id, logic_id, "
30  "events_over_low_threshold, events_over_high_threshold, avg_energy) "
31  "VALUES (:iov_id, :logic_id, "
32  ":3, :4, :5)");
33  } catch (SQLException& e) {
34  throw(std::runtime_error("MonOccupancyDat::prepareWrite(): " + e.getMessage()));
35  }
36 }
37 
38 void MonOccupancyDat::writeDB(const EcalLogicID* ecid, const MonOccupancyDat* item, MonRunIOV* iov) noexcept(false) {
39  this->checkConnection();
40  this->checkPrepare();
41 
42  int iovID = iov->fetchID();
43  if (!iovID) {
44  throw(std::runtime_error("MonOccupancyDat::writeDB: IOV not in DB"));
45  }
46 
47  int logicID = ecid->getLogicID();
48  if (!logicID) {
49  throw(std::runtime_error("MonOccupancyDat::writeDB: Bad EcalLogicID"));
50  }
51 
52  try {
53  m_writeStmt->setInt(1, iovID);
54  m_writeStmt->setInt(2, logicID);
55 
56  m_writeStmt->setInt(3, item->getEventsOverLowThreshold());
57  m_writeStmt->setInt(4, item->getEventsOverHighThreshold());
58  m_writeStmt->setFloat(5, item->getAvgEnergy());
59 
60  m_writeStmt->executeUpdate();
61  } catch (SQLException& e) {
62  throw(std::runtime_error("MonOccupancyDat::writeDB(): " + e.getMessage()));
63  }
64 }
65 
66 void MonOccupancyDat::fetchData(std::map<EcalLogicID, MonOccupancyDat>* 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("MonOccupancyDat::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.events_over_low_threshold, d.events_over_high_threshold, d.avg_energy "
81  "FROM channelview cv JOIN mon_occupancy_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, MonOccupancyDat> p;
88  MonOccupancyDat dat;
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.setEventsOverLowThreshold(rset->getInt(7));
98  dat.setEventsOverHighThreshold(rset->getInt(8));
99  dat.setAvgEnergy(rset->getFloat(9));
100 
101  p.second = dat;
102  fillMap->insert(p);
103  }
104  } catch (SQLException& e) {
105  throw(std::runtime_error("MonOccupancyDat::fetchData(): " + e.getMessage()));
106  }
107 }
108 
109 void MonOccupancyDat::writeArrayDB(const std::map<EcalLogicID, MonOccupancyDat>* data, MonRunIOV* iov) noexcept(false) {
110  this->checkConnection();
111  this->checkPrepare();
112 
113  int iovID = iov->fetchID();
114  if (!iovID) {
115  throw(std::runtime_error("MonOccupancyDat::writeArrayDB: IOV not in DB"));
116  }
117 
118  int nrows = data->size();
119  int* ids = new int[nrows];
120  int* iovid_vec = new int[nrows];
121  int* xx = new int[nrows];
122  int* yy = new int[nrows];
123  float* zz = new float[nrows];
124 
125  ub2* ids_len = new ub2[nrows];
126  ub2* iov_len = new ub2[nrows];
127  ub2* x_len = new ub2[nrows];
128  ub2* y_len = new ub2[nrows];
129  ub2* z_len = new ub2[nrows];
130 
131  const EcalLogicID* channel;
132  const MonOccupancyDat* dataitem;
133  int count = 0;
134  typedef map<EcalLogicID, MonOccupancyDat>::const_iterator CI;
135  for (CI p = data->begin(); p != data->end(); ++p) {
136  channel = &(p->first);
137  int logicID = channel->getLogicID();
138  if (!logicID) {
139  throw(std::runtime_error("MonOccupancyDat::writeArrayDB: Bad EcalLogicID"));
140  }
141  ids[count] = logicID;
142  iovid_vec[count] = iovID;
143 
144  dataitem = &(p->second);
145  // dataIface.writeDB( channel, dataitem, iov);
146  int x = dataitem->getEventsOverLowThreshold();
147  int y = dataitem->getEventsOverHighThreshold();
148  float z = dataitem->getAvgEnergy();
149 
150  xx[count] = x;
151  yy[count] = y;
152  zz[count] = z;
153 
154  ids_len[count] = sizeof(ids[count]);
155  iov_len[count] = sizeof(iovid_vec[count]);
156 
157  x_len[count] = sizeof(xx[count]);
158  y_len[count] = sizeof(yy[count]);
159  z_len[count] = sizeof(zz[count]);
160 
161  count++;
162  }
163 
164  try {
165  m_writeStmt->setDataBuffer(1, (dvoid*)iovid_vec, OCCIINT, sizeof(iovid_vec[0]), iov_len);
166  m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len);
167  m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIINT, sizeof(xx[0]), x_len);
168  m_writeStmt->setDataBuffer(4, (dvoid*)yy, OCCIINT, sizeof(yy[0]), y_len);
169  m_writeStmt->setDataBuffer(5, (dvoid*)zz, OCCIFLOAT, sizeof(zz[0]), z_len);
170 
171  m_writeStmt->executeArrayUpdate(nrows);
172 
173  delete[] ids;
174  delete[] iovid_vec;
175  delete[] xx;
176  delete[] yy;
177  delete[] zz;
178 
179  delete[] ids_len;
180  delete[] iov_len;
181  delete[] x_len;
182  delete[] y_len;
183  delete[] z_len;
184 
185  } catch (SQLException& e) {
186  throw(std::runtime_error("MonOccupancyDat::writeArrayDB(): " + e.getMessage()));
187  }
188 }
DDAxes::y
geometryCSVtoXML.zz
zz
Definition: geometryCSVtoXML.py:19
funct::false
false
Definition: Factorize.h:29
MonOccupancyDat::fetchData
void fetchData(std::map< EcalLogicID, MonOccupancyDat > *fillVec, MonRunIOV *iov) noexcept(false)
Definition: MonOccupancyDat.cc:66
MonOccupancyDat.h
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
MonOccupancyDat::MonOccupancyDat
MonOccupancyDat()
Definition: MonOccupancyDat.cc:10
DDAxes::x
EcalLogicID::getLogicID
int getLogicID() const
Definition: EcalLogicID.cc:28
MonOccupancyDat::getEventsOverLowThreshold
int getEventsOverLowThreshold() const
Definition: MonOccupancyDat.h:22
oracle::occi
Definition: ConnectionManager.h:7
MonOccupancyDat::getAvgEnergy
float getAvgEnergy() const
Definition: MonOccupancyDat.h:28
MonOccupancyDat::getEventsOverHighThreshold
int getEventsOverHighThreshold() const
Definition: MonOccupancyDat.h:25
DDAxes::z
EcalLogicID
Definition: EcalLogicID.h:7
submitPVResolutionJobs.count
count
Definition: submitPVResolutionJobs.py:352
geometryCSVtoXML.yy
yy
Definition: geometryCSVtoXML.py:19
MonOccupancyDat::setAvgEnergy
void setAvgEnergy(float energy)
Definition: MonOccupancyDat.h:27
MonOccupancyDat::writeArrayDB
void writeArrayDB(const std::map< EcalLogicID, MonOccupancyDat > *data, MonRunIOV *iov) noexcept(false)
Definition: MonOccupancyDat.cc:109
MonRunIOV
Definition: MonRunIOV.h:14
B2GTnPMonitor_cfi.item
item
Definition: B2GTnPMonitor_cfi.py:147
MonOccupancyDat::prepareWrite
void prepareWrite() noexcept(false) override
Definition: MonOccupancyDat.cc:23
std
Definition: JetResolutionObject.h:76
MonOccupancyDat::~MonOccupancyDat
~MonOccupancyDat() override
Definition: MonOccupancyDat.cc:21
MonOccupancyDat::setEventsOverLowThreshold
void setEventsOverLowThreshold(int events)
Definition: MonOccupancyDat.h:21
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
MonOccupancyDat::writeDB
void writeDB(const EcalLogicID *ecid, const MonOccupancyDat *item, MonRunIOV *iov) noexcept(false)
Definition: MonOccupancyDat.cc:38
Oracle.h
MonOccupancyDat
Definition: MonOccupancyDat.h:12
MonOccupancyDat::setEventsOverHighThreshold
void setEventsOverHighThreshold(int events)
Definition: MonOccupancyDat.h:24
geometryCSVtoXML.xx
xx
Definition: geometryCSVtoXML.py:19
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37