CMS 3D CMS Logo

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