CMS 3D CMS Logo

DCUIDarkPedDat.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_ped = 0;
19 }
20 
22 
24  this->checkConnection();
25 
26  try {
27  m_writeStmt = m_conn->createStatement();
28  m_writeStmt->setSQL(
29  "INSERT INTO dcu_idark_ped_dat (iov_id, logic_id, "
30  "ped) "
31  "VALUES (:iov_id, :logic_id, "
32  ":ped)");
33  } catch (SQLException& e) {
34  throw(std::runtime_error("DCUIDarkPedDat::prepareWrite(): " + e.getMessage()));
35  }
36 }
37 
38 void DCUIDarkPedDat::writeDB(const EcalLogicID* ecid, const DCUIDarkPedDat* 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("DCUIDarkPedDat::writeDB: IOV not in DB"));
45  }
46 
47  int logicID = ecid->getLogicID();
48  if (!logicID) {
49  throw(std::runtime_error("DCUIDarkPedDat::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->getPed());
57 
58  m_writeStmt->executeUpdate();
59  } catch (SQLException& e) {
60  throw(std::runtime_error("DCUIDarkPedDat::writeDB(): " + e.getMessage()));
61  }
62 }
63 
64 void DCUIDarkPedDat::fetchData(std::map<EcalLogicID, DCUIDarkPedDat>* 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("DCUIDarkPedDat::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.ped "
79  "FROM channelview cv JOIN dcu_idark_ped_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, DCUIDarkPedDat> p;
86  DCUIDarkPedDat 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.setPed(rset->getFloat(7));
96 
97  p.second = dat;
98  fillMap->insert(p);
99  }
100  } catch (SQLException& e) {
101  throw(std::runtime_error("DCUIDarkPedDat::fetchData(): " + e.getMessage()));
102  }
103 }
104 void DCUIDarkPedDat::writeArrayDB(const std::map<EcalLogicID, DCUIDarkPedDat>* data, DCUIOV* iov) noexcept(false) {
105  this->checkConnection();
106  this->checkPrepare();
107 
108  int iovID = iov->fetchID();
109  if (!iovID) {
110  throw(std::runtime_error("DCUIDarkPedDat::writeArrayDB: IOV not in DB"));
111  }
112 
113  int nrows = data->size();
114  int* ids = new int[nrows];
115  int* iovid_vec = new int[nrows];
116  float* xx = new float[nrows];
117 
118  ub2* ids_len = new ub2[nrows];
119  ub2* iov_len = new ub2[nrows];
120  ub2* x_len = new ub2[nrows];
121 
122  const EcalLogicID* channel;
123  const DCUIDarkPedDat* dataitem;
124  int count = 0;
125  typedef map<EcalLogicID, DCUIDarkPedDat>::const_iterator CI;
126  for (CI p = data->begin(); p != data->end(); ++p) {
127  channel = &(p->first);
128  int logicID = channel->getLogicID();
129  if (!logicID) {
130  throw(std::runtime_error("DCUIDarkPedDat::writeArrayDB: Bad EcalLogicID"));
131  }
132  ids[count] = logicID;
133  iovid_vec[count] = iovID;
134 
135  dataitem = &(p->second);
136  // dataIface.writeDB( channel, dataitem, iov);
137  float x = dataitem->getPed();
138 
139  xx[count] = x;
140 
141  ids_len[count] = sizeof(ids[count]);
142  iov_len[count] = sizeof(iovid_vec[count]);
143 
144  x_len[count] = sizeof(xx[count]);
145 
146  count++;
147  }
148 
149  try {
150  m_writeStmt->setDataBuffer(1, (dvoid*)iovid_vec, OCCIINT, sizeof(iovid_vec[0]), iov_len);
151  m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len);
152  m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIFLOAT, sizeof(xx[0]), x_len);
153 
154  m_writeStmt->executeArrayUpdate(nrows);
155 
156  delete[] ids;
157  delete[] iovid_vec;
158  delete[] xx;
159 
160  delete[] ids_len;
161  delete[] iov_len;
162  delete[] x_len;
163 
164  } catch (SQLException& e) {
165  throw(std::runtime_error("DCUIDarkPedDat::writeArrayDB(): " + e.getMessage()));
166  }
167 }
DCUIDarkPedDat.h
funct::false
false
Definition: Factorize.h:34
DCUIDarkPedDat::prepareWrite
void prepareWrite() noexcept(false) override
Definition: DCUIDarkPedDat.cc:23
DCUIDarkPedDat::setPed
void setPed(float temp)
Definition: DCUIDarkPedDat.h:21
std::data
constexpr auto data(C &c) -> decltype(c.data())
Definition: cuda_cxx17.h:40
RunIOV.h
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
DCUIOV
Definition: DCUIOV.h:13
DCUIDarkPedDat::fetchData
void fetchData(std::map< EcalLogicID, DCUIDarkPedDat > *fillVec, DCUIOV *iov) noexcept(false)
Definition: DCUIDarkPedDat.cc:64
DDAxes::x
EcalLogicID::getLogicID
int getLogicID() const
Definition: EcalLogicID.cc:28
DCUIDarkPedDat
Definition: DCUIDarkPedDat.h:12
DCUIDarkPedDat::~DCUIDarkPedDat
~DCUIDarkPedDat() override
Definition: DCUIDarkPedDat.cc:21
DCUIDarkPedDat::getPed
float getPed() const
Definition: DCUIDarkPedDat.h:22
oracle::occi
Definition: ConnectionManager.h:7
DCUIDarkPedDat::writeArrayDB
void writeArrayDB(const std::map< EcalLogicID, DCUIDarkPedDat > *data, DCUIOV *iov) noexcept(false)
Definition: DCUIDarkPedDat.cc:104
EcalLogicID
Definition: EcalLogicID.h:7
KineDebug3::count
void count()
Definition: KinematicConstrainedVertexUpdatorT.h:21
B2GTnPMonitor_cfi.item
item
Definition: B2GTnPMonitor_cfi.py:147
DCUIDarkPedDat::DCUIDarkPedDat
DCUIDarkPedDat()
Definition: DCUIDarkPedDat.cc:12
std
Definition: JetResolutionObject.h:76
DCUIDarkPedDat::writeDB
void writeDB(const EcalLogicID *ecid, const DCUIDarkPedDat *item, DCUIOV *iov) noexcept(false)
Definition: DCUIDarkPedDat.cc:38
Oracle.h
RunTag.h
geometryCSVtoXML.xx
xx
Definition: geometryCSVtoXML.py:19
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37