CMS 3D CMS Logo

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