CMS 3D CMS Logo

MonPedestalOffsetsDat.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_dacG1 = 0;
19  m_dacG6 = 0;
20  m_dacG12 = 0;
21  m_taskStatus = false;
22 }
23 
25 
27  this->checkConnection();
28 
29  try {
30  m_writeStmt = m_conn->createStatement();
31  m_writeStmt->setSQL(
32  "INSERT INTO mon_pedestal_offsets_dat (iov_id, logic_id, "
33  "dac_g1, dac_g6, dac_g12, task_status) "
34  "VALUES (:iov_id, :logic_id, "
35  ":dac_g1, :dac_g6, :dac_g12, :task_status)");
36  } catch (SQLException& e) {
37  throw(std::runtime_error("MonPedestalOffsetsDat::prepareWrite(): " + e.getMessage()));
38  }
39 }
40 
43  MonRunIOV* iov) noexcept(false) {
44  this->checkConnection();
45  this->checkPrepare();
46 
47  int iovID = iov->fetchID();
48  if (!iovID) {
49  throw(std::runtime_error("MonPedestalOffsetsDat::writeDB: IOV not in DB"));
50  }
51 
52  int logicID = ecid->getLogicID();
53  if (!logicID) {
54  throw(std::runtime_error("MonPedestalOffsetsDat::writeDB: Bad EcalLogicID"));
55  }
56 
57  try {
58  m_writeStmt->setInt(1, iovID);
59  m_writeStmt->setInt(2, logicID);
60  m_writeStmt->setInt(3, item->getDACG1());
61  m_writeStmt->setInt(4, item->getDACG6());
62  m_writeStmt->setInt(5, item->getDACG12());
63  m_writeStmt->setInt(6, item->getTaskStatus());
64 
65  m_writeStmt->executeUpdate();
66  } catch (SQLException& e) {
67  throw(std::runtime_error("MonPedestalOffsetsDat::writeDB(): " + e.getMessage()));
68  }
69 }
70 
71 void MonPedestalOffsetsDat::fetchData(std::map<EcalLogicID, MonPedestalOffsetsDat>* fillMap,
72  MonRunIOV* iov,
73  std::string mappa) noexcept(false) {
74  this->checkConnection();
75  fillMap->clear();
76 
77  iov->setConnection(m_env, m_conn);
78  int iovID = iov->fetchID();
79  if (!iovID) {
80  // throw(std::runtime_error("MonPedestalOffsetsDat::writeDB: IOV not in DB"));
81  return;
82  }
83 
84  try {
85  m_readStmt->setSQL(
86  "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
87  "d.dac_g1, d.dac_g6, d.dac_g12, d.task_status "
88  "FROM channelview cv JOIN mon_pedestal_offsets_dat d "
89  "ON cv.logic_id = d.logic_id AND cv.name = " +
90  mappa + " WHERE d.iov_id = :iov_id");
91  m_readStmt->setInt(1, iovID);
92  ResultSet* rset = m_readStmt->executeQuery();
93 
94  std::pair<EcalLogicID, MonPedestalOffsetsDat> p;
96  while (rset->next()) {
97  p.first = EcalLogicID(rset->getString(1), // name
98  rset->getInt(2), // logic_id
99  rset->getInt(3), // id1
100  rset->getInt(4), // id2
101  rset->getInt(5), // id3
102  rset->getString(6)); // maps_to
103 
104  dat.setDACG1(rset->getInt(7));
105  dat.setDACG6(rset->getInt(8));
106  dat.setDACG12(rset->getInt(9));
107  dat.setTaskStatus(rset->getInt(10));
108 
109  p.second = dat;
110  fillMap->insert(p);
111  }
112  } catch (SQLException& e) {
113  throw(std::runtime_error("MonPedestalOffsetsDat::fetchData(): " + e.getMessage()));
114  }
115 }
116 
117 void MonPedestalOffsetsDat::writeArrayDB(const std::map<EcalLogicID, MonPedestalOffsetsDat>* data,
118  MonRunIOV* iov) noexcept(false) {
119  this->checkConnection();
120  this->checkPrepare();
121 
122  int iovID = iov->fetchID();
123  if (!iovID) {
124  throw(std::runtime_error("MonPedestalOffsetsDat::writeArrayDB: IOV not in DB"));
125  }
126 
127  int nrows = data->size();
128  int* ids = new int[nrows];
129  int* iovid_vec = new int[nrows];
130  float* xx = new float[nrows];
131  float* yy = new float[nrows];
132  float* zz = new float[nrows];
133  int* st = new int[nrows];
134 
135  ub2* ids_len = new ub2[nrows];
136  ub2* iov_len = new ub2[nrows];
137  ub2* x_len = new ub2[nrows];
138  ub2* y_len = new ub2[nrows];
139  ub2* z_len = new ub2[nrows];
140  ub2* st_len = new ub2[nrows];
141 
142  const EcalLogicID* channel;
143  const MonPedestalOffsetsDat* dataitem;
144  int count = 0;
145  typedef map<EcalLogicID, MonPedestalOffsetsDat>::const_iterator CI;
146  for (CI p = data->begin(); p != data->end(); ++p) {
147  channel = &(p->first);
148  int logicID = channel->getLogicID();
149  if (!logicID) {
150  throw(std::runtime_error("MonPedestalOffsetsDat::writeArrayDB: Bad EcalLogicID"));
151  }
152  ids[count] = logicID;
153  iovid_vec[count] = iovID;
154 
155  dataitem = &(p->second);
156  // dataIface.writeDB( channel, dataitem, iov);
157  float x = dataitem->getDACG1();
158  float y = dataitem->getDACG6();
159  float z = dataitem->getDACG12();
160  int statu = dataitem->getTaskStatus();
161 
162  xx[count] = x;
163  yy[count] = y;
164  zz[count] = z;
165  st[count] = statu;
166 
167  ids_len[count] = sizeof(ids[count]);
168  iov_len[count] = sizeof(iovid_vec[count]);
169 
170  x_len[count] = sizeof(xx[count]);
171  y_len[count] = sizeof(yy[count]);
172  z_len[count] = sizeof(zz[count]);
173  st_len[count] = sizeof(st[count]);
174 
175  count++;
176  }
177 
178  try {
179  m_writeStmt->setDataBuffer(1, (dvoid*)iovid_vec, OCCIINT, sizeof(iovid_vec[0]), iov_len);
180  m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len);
181  m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIFLOAT, sizeof(xx[0]), x_len);
182  m_writeStmt->setDataBuffer(4, (dvoid*)yy, OCCIFLOAT, sizeof(yy[0]), y_len);
183  m_writeStmt->setDataBuffer(5, (dvoid*)zz, OCCIFLOAT, sizeof(zz[0]), z_len);
184  m_writeStmt->setDataBuffer(6, (dvoid*)st, OCCIINT, sizeof(st[0]), st_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  delete[] st;
194 
195  delete[] ids_len;
196  delete[] iov_len;
197  delete[] x_len;
198  delete[] y_len;
199  delete[] z_len;
200  delete[] st_len;
201 
202  } catch (SQLException& e) {
203  throw(std::runtime_error("MonPedestalOffsetsDat::writeArrayDB(): " + e.getMessage()));
204  }
205 }
MonPedestalOffsetsDat::~MonPedestalOffsetsDat
~MonPedestalOffsetsDat() override
Definition: MonPedestalOffsetsDat.cc:24
DDAxes::y
geometryCSVtoXML.zz
zz
Definition: geometryCSVtoXML.py:19
funct::false
false
Definition: Factorize.h:34
MonPedestalOffsetsDat::setDACG1
void setDACG1(int dac)
Definition: MonPedestalOffsetsDat.h:21
std::data
constexpr auto data(C &c) -> decltype(c.data())
Definition: cuda_cxx17.h:40
MonPedestalOffsetsDat::getDACG12
int getDACG12() const
Definition: MonPedestalOffsetsDat.h:28
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
DDAxes::x
EcalLogicID::getLogicID
int getLogicID() const
Definition: EcalLogicID.cc:28
MonPedestalOffsetsDat::prepareWrite
void prepareWrite() noexcept(false) override
Definition: MonPedestalOffsetsDat.cc:26
oracle::occi
Definition: ConnectionManager.h:7
MonPedestalOffsetsDat::setDACG6
void setDACG6(int dac)
Definition: MonPedestalOffsetsDat.h:24
DDAxes::z
EcalLogicID
Definition: EcalLogicID.h:7
MonPedestalOffsetsDat::getDACG6
int getDACG6() const
Definition: MonPedestalOffsetsDat.h:25
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
MonRunIOV.h
MonPedestalOffsetsDat::writeArrayDB
void writeArrayDB(const std::map< EcalLogicID, MonPedestalOffsetsDat > *data, MonRunIOV *iov) noexcept(false)
Definition: MonPedestalOffsetsDat.cc:117
MonPedestalOffsetsDat::fetchData
void fetchData(std::map< EcalLogicID, MonPedestalOffsetsDat > *fillMap, MonRunIOV *iov, std::string mappa=" cv.maps_to ") noexcept(false)
Definition: MonPedestalOffsetsDat.cc:71
geometryCSVtoXML.yy
yy
Definition: geometryCSVtoXML.py:19
MonPedestalOffsetsDat::getDACG1
int getDACG1() const
Definition: MonPedestalOffsetsDat.h:22
KineDebug3::count
void count()
Definition: KinematicConstrainedVertexUpdatorT.h:21
MonPedestalOffsetsDat::setDACG12
void setDACG12(int dac)
Definition: MonPedestalOffsetsDat.h:27
MonRunIOV
Definition: MonRunIOV.h:14
B2GTnPMonitor_cfi.item
item
Definition: B2GTnPMonitor_cfi.py:147
MonPedestalOffsetsDat.h
MonRunTag.h
MonPedestalOffsetsDat::writeDB
void writeDB(const EcalLogicID *ecid, const MonPedestalOffsetsDat *item, MonRunIOV *iov) noexcept(false)
Definition: MonPedestalOffsetsDat.cc:41
MonPedestalOffsetsDat::setTaskStatus
void setTaskStatus(bool status)
Definition: MonPedestalOffsetsDat.h:30
std
Definition: JetResolutionObject.h:76
MonPedestalOffsetsDat
Definition: MonPedestalOffsetsDat.h:12
Oracle.h
MonPedestalOffsetsDat::MonPedestalOffsetsDat
MonPedestalOffsetsDat()
Definition: MonPedestalOffsetsDat.cc:12
geometryCSVtoXML.xx
xx
Definition: geometryCSVtoXML.py:19
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
MonPedestalOffsetsDat::getTaskStatus
bool getTaskStatus() const
Definition: MonPedestalOffsetsDat.h:31