CMS 3D CMS Logo

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