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 {
12  m_env = nullptr;
13  m_conn = nullptr;
14  m_writeStmt = nullptr;
15  m_readStmt = nullptr;
16 
17  m_eventsOverLowThreshold = 0;
18  m_eventsOverHighThreshold = 0;
19  m_avgEnergy = 0;
20 }
21 
22 
23 
25 {
26 }
27 
28 
29 
32 {
33  this->checkConnection();
34 
35  try {
36  m_writeStmt = m_conn->createStatement();
37  m_writeStmt->setSQL("INSERT INTO mon_occupancy_dat (iov_id, logic_id, "
38  "events_over_low_threshold, events_over_high_threshold, avg_energy) "
39  "VALUES (:iov_id, :logic_id, "
40  ":3, :4, :5)");
41  } catch (SQLException &e) {
42  throw(std::runtime_error("MonOccupancyDat::prepareWrite(): "+e.getMessage()));
43  }
44 }
45 
46 
47 
48 void MonOccupancyDat::writeDB(const EcalLogicID* ecid, const MonOccupancyDat* item, MonRunIOV* iov)
49  noexcept(false)
50 {
51  this->checkConnection();
52  this->checkPrepare();
53 
54  int iovID = iov->fetchID();
55  if (!iovID) { throw(std::runtime_error("MonOccupancyDat::writeDB: IOV not in DB")); }
56 
57  int logicID = ecid->getLogicID();
58  if (!logicID) { throw(std::runtime_error("MonOccupancyDat::writeDB: Bad EcalLogicID")); }
59 
60  try {
61  m_writeStmt->setInt(1, iovID);
62  m_writeStmt->setInt(2, logicID);
63 
64  m_writeStmt->setInt(3, item->getEventsOverLowThreshold() );
65  m_writeStmt->setInt(4, item->getEventsOverHighThreshold() );
66  m_writeStmt->setFloat(5, item->getAvgEnergy() );
67 
68  m_writeStmt->executeUpdate();
69  } catch (SQLException &e) {
70  throw(std::runtime_error("MonOccupancyDat::writeDB(): "+e.getMessage()));
71  }
72 }
73 
74 
75 
76 void MonOccupancyDat::fetchData(std::map< EcalLogicID, MonOccupancyDat >* fillMap, MonRunIOV* iov)
77  noexcept(false)
78 {
79  this->checkConnection();
80  fillMap->clear();
81 
82  iov->setConnection(m_env, m_conn);
83  int iovID = iov->fetchID();
84  if (!iovID) {
85  // throw(std::runtime_error("MonOccupancyDat::writeDB: IOV not in DB"));
86  return;
87  }
88 
89  try {
90 
91  m_readStmt->setSQL("SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
92  "d.events_over_low_threshold, d.events_over_high_threshold, d.avg_energy "
93  "FROM channelview cv JOIN mon_occupancy_dat d "
94  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
95  "WHERE d.iov_id = :iov_id");
96  m_readStmt->setInt(1, iovID);
97  ResultSet* rset = m_readStmt->executeQuery();
98 
99  std::pair< EcalLogicID, MonOccupancyDat > p;
100  MonOccupancyDat dat;
101  while(rset->next()) {
102  p.first = EcalLogicID( rset->getString(1), // name
103  rset->getInt(2), // logic_id
104  rset->getInt(3), // id1
105  rset->getInt(4), // id2
106  rset->getInt(5), // id3
107  rset->getString(6)); // maps_to
108 
109  dat.setEventsOverLowThreshold( rset->getInt(7) );
110  dat.setEventsOverHighThreshold( rset->getInt(8) );
111  dat.setAvgEnergy( rset->getFloat(9) );
112 
113  p.second = dat;
114  fillMap->insert(p);
115  }
116  } catch (SQLException &e) {
117  throw(std::runtime_error("MonOccupancyDat::fetchData(): "+e.getMessage()));
118  }
119 }
120 
121 void MonOccupancyDat::writeArrayDB(const std::map< EcalLogicID, MonOccupancyDat >* data, MonRunIOV* iov)
122  noexcept(false)
123 {
124  this->checkConnection();
125  this->checkPrepare();
126 
127  int iovID = iov->fetchID();
128  if (!iovID) { throw(std::runtime_error("MonOccupancyDat::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  int* xx= new int[nrows];
135  int* yy= new int[nrows];
136  float* zz= new float[nrows];
137 
138  ub2* ids_len= new ub2[nrows];
139  ub2* iov_len= new ub2[nrows];
140  ub2* x_len= new ub2[nrows];
141  ub2* y_len= new ub2[nrows];
142  ub2* z_len= new ub2[nrows];
143 
144 
145  const EcalLogicID* channel;
146  const MonOccupancyDat* dataitem;
147  int count=0;
148  typedef map< EcalLogicID, MonOccupancyDat >::const_iterator CI;
149  for (CI p = data->begin(); p != data->end(); ++p) {
150  channel = &(p->first);
151  int logicID = channel->getLogicID();
152  if (!logicID) { throw(std::runtime_error("MonOccupancyDat::writeArrayDB: Bad EcalLogicID")); }
153  ids[count]=logicID;
154  iovid_vec[count]=iovID;
155 
156  dataitem = &(p->second);
157  // dataIface.writeDB( channel, dataitem, iov);
158  int x=dataitem->getEventsOverLowThreshold();
159  int y=dataitem->getEventsOverHighThreshold();
160  float z=dataitem->getAvgEnergy();
161 
162 
163 
164  xx[count]=x;
165  yy[count]=y;
166  zz[count]=z;
167 
168  ids_len[count]=sizeof(ids[count]);
169  iov_len[count]=sizeof(iovid_vec[count]);
170 
171  x_len[count]=sizeof(xx[count]);
172  y_len[count]=sizeof(yy[count]);
173  z_len[count]=sizeof(zz[count]);
174 
175  count++;
176  }
177 
178 
179  try {
180  m_writeStmt->setDataBuffer(1, (dvoid*)iovid_vec, OCCIINT, sizeof(iovid_vec[0]),iov_len);
181  m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len );
182  m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIINT , sizeof(xx[0]), x_len );
183  m_writeStmt->setDataBuffer(4, (dvoid*)yy, OCCIINT , sizeof(yy[0]), y_len );
184  m_writeStmt->setDataBuffer(5, (dvoid*)zz, OCCIFLOAT , sizeof(zz[0]), z_len );
185 
186  m_writeStmt->executeArrayUpdate(nrows);
187 
188  delete [] ids;
189  delete [] iovid_vec;
190  delete [] xx;
191  delete [] yy;
192  delete [] zz;
193 
194  delete [] ids_len;
195  delete [] iov_len;
196  delete [] x_len;
197  delete [] y_len;
198  delete [] z_len;
199 
200 
201  } catch (SQLException &e) {
202  throw(std::runtime_error("MonOccupancyDat::writeArrayDB(): "+e.getMessage()));
203  }
204 }
void setAvgEnergy(float energy)
void writeArrayDB(const std::map< EcalLogicID, MonOccupancyDat > *data, MonRunIOV *iov) noexcept(false)
void setEventsOverLowThreshold(int events)
int getEventsOverHighThreshold() const
float getAvgEnergy() const
int getEventsOverLowThreshold() const
int getLogicID() const
Definition: EcalLogicID.cc:41
void fetchData(std::map< EcalLogicID, MonOccupancyDat > *fillVec, MonRunIOV *iov) noexcept(false)
#define noexcept
~MonOccupancyDat() override
void writeDB(const EcalLogicID *ecid, const MonOccupancyDat *item, MonRunIOV *iov) noexcept(false)
void setEventsOverHighThreshold(int events)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
void prepareWrite() noexcept(false) override