CMS 3D CMS Logo

ITimingDat.h
Go to the documentation of this file.
1 #ifndef ITIMINGDAT_H
2 #define ITIMINGDAT_H
3 
4 #include <map>
5 #include <stdexcept>
6 #include <string>
7 
14 
16 
17 class ITimingDat : public IDataItem {
18 public:
19  typedef oracle::occi::SQLException SQLException;
20  typedef oracle::occi::ResultSet ResultSet;
21  friend class EcalCondDBInterface;
22 
24  m_env = nullptr;
25  m_conn = nullptr;
26  m_writeStmt = nullptr;
27  m_readStmt = nullptr;
28 
29  m_timingMean = 0;
30  m_timingRMS = 0;
31  m_taskStatus = false;
32  };
33 
34  ~ITimingDat() override{};
35 
36  // User data methods
37  inline std::string getTable() override { return m_table_name; }
38  inline void setTable(std::string x) { m_table_name = x; }
39 
40  inline void setTimingMean(float mean) { m_timingMean = mean; }
41  inline float getTimingMean() const { return m_timingMean; }
42 
43  inline void setTimingRMS(float rms) { m_timingRMS = rms; }
44  inline float getTimingRMS() const { return m_timingRMS; }
45 
46  inline void setTaskStatus(bool status) { m_taskStatus = status; }
47  inline bool getTaskStatus() const { return m_taskStatus; }
48 
49 private:
50  void prepareWrite() noexcept(false) override {
51  this->checkConnection();
52 
53  try {
54  m_writeStmt = m_conn->createStatement();
55  m_writeStmt->setSQL("INSERT INTO " + getTable() +
56  " (iov_id, logic_id, "
57  "timing_mean, timing_rms , task_status ) "
58  "VALUES (:iov_id, :logic_id, "
59  ":timing_mean, :timing_rms, :task_status )");
60  } catch (SQLException& e) {
61  throw(std::runtime_error("ITimingDat::prepareWrite(): " + e.getMessage()));
62  }
63  }
64 
65  template <class DATT, class IOVT>
66  void writeDB(const EcalLogicID* ecid, const DATT* item, IOVT* iov) noexcept(false) {
67  this->checkConnection();
68  this->checkPrepare();
69 
70  int iovID = iov->fetchID();
71  if (!iovID) {
72  throw(std::runtime_error("ITimingDat::writeDB: IOV not in DB"));
73  }
74 
75  int logicID = ecid->getLogicID();
76  if (!logicID) {
77  throw(std::runtime_error("ITimingDat::writeDB: Bad EcalLogicID"));
78  }
79 
80  try {
81  m_writeStmt->setInt(1, iovID);
82  m_writeStmt->setInt(2, logicID);
83 
84  m_writeStmt->setFloat(3, item->getTimingMean());
85  m_writeStmt->setFloat(4, item->getTimingRMS());
86  m_writeStmt->setInt(5, item->getTaskStatus());
87 
88  m_writeStmt->executeUpdate();
89  } catch (SQLException& e) {
90  throw(std::runtime_error("ITimingDat::writeDB(): " + e.getMessage()));
91  }
92  }
93 
94  template <class DATT, class IOVT>
95  void writeArrayDB(const std::map<EcalLogicID, DATT>* data, IOVT* iov) noexcept(false) {
96  using oracle::occi::OCCIFLOAT;
97  using oracle::occi::OCCIINT;
98 
99  this->checkConnection();
100  this->checkPrepare();
101 
102  int iovID = iov->fetchID();
103  if (!iovID) {
104  throw(std::runtime_error("ITimingDat::writeArrayDB: IOV not in DB"));
105  }
106 
107  int nrows = data->size();
108  int* ids = new int[nrows];
109  int* iovid_vec = new int[nrows];
110  float* xx = new float[nrows];
111  float* yy = new float[nrows];
112  int* st = new int[nrows];
113 
114  ub2* ids_len = new ub2[nrows];
115  ub2* iov_len = new ub2[nrows];
116  ub2* x_len = new ub2[nrows];
117  ub2* y_len = new ub2[nrows];
118  ub2* st_len = new ub2[nrows];
119 
120  const EcalLogicID* channel;
121  const DATT* dataitem;
122  int count = 0;
123  // typedef std::map< EcalLogicID, DATT >::const_iterator CI;
124  typedef typename std::map<EcalLogicID, DATT>::const_iterator CI;
125  for (CI p = data->begin(); p != data->end(); ++p) {
126  channel = &(p->first);
127  int logicID = channel->getLogicID();
128  if (!logicID) {
129  throw(std::runtime_error("ITimingDat::writeArrayDB: Bad EcalLogicID"));
130  }
131  ids[count] = logicID;
132  iovid_vec[count] = iovID;
133 
134  dataitem = &(p->second);
135 
136  float x = dataitem->getTimingMean();
137  float y = dataitem->getTimingRMS();
138  int statu = dataitem->getTaskStatus();
139 
140  xx[count] = x;
141  yy[count] = y;
142  st[count] = statu;
143 
144  ids_len[count] = sizeof(ids[count]);
145  iov_len[count] = sizeof(iovid_vec[count]);
146 
147  x_len[count] = sizeof(xx[count]);
148  y_len[count] = sizeof(yy[count]);
149  st_len[count] = sizeof(st[count]);
150 
151  count++;
152  }
153 
154  try {
155  m_writeStmt->setDataBuffer(1, (dvoid*)iovid_vec, OCCIINT, sizeof(iovid_vec[0]), iov_len);
156  m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len);
157  m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIFLOAT, sizeof(xx[0]), x_len);
158  m_writeStmt->setDataBuffer(4, (dvoid*)yy, OCCIFLOAT, sizeof(yy[0]), y_len);
159  m_writeStmt->setDataBuffer(5, (dvoid*)st, OCCIINT, sizeof(st[0]), st_len);
160 
161  m_writeStmt->executeArrayUpdate(nrows);
162 
163  delete[] ids;
164  delete[] iovid_vec;
165  delete[] xx;
166  delete[] yy;
167  delete[] st;
168 
169  delete[] ids_len;
170  delete[] iov_len;
171  delete[] x_len;
172  delete[] y_len;
173  delete[] st_len;
174 
175  } catch (SQLException& e) {
176  throw(std::runtime_error("ITimingDat::writeArrayDB(): " + e.getMessage()));
177  }
178  }
179 
180  template <class DATT, class IOVT>
181  void fetchData(std::map<EcalLogicID, DATT>* fillMap, IOVT* iov) noexcept(false) {
182  this->checkConnection();
183  fillMap->clear();
184 
185  iov->setConnection(m_env, m_conn);
186  int iovID = iov->fetchID();
187  if (!iovID) {
188  // throw(std::runtime_error("ITimingDat::writeDB: IOV not in DB"));
189  return;
190  }
191 
192  try {
193  m_readStmt->setSQL(
194  "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
195  "d.timing_mean, d.timing_rms, d.task_status "
196  "FROM channelview cv JOIN " +
197  getTable() +
198  " d "
199  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
200  "WHERE d.iov_id = :iov_id");
201  m_readStmt->setInt(1, iovID);
202  ResultSet* rset = m_readStmt->executeQuery();
203 
204  std::pair<EcalLogicID, DATT> p;
205  DATT dat;
206  while (rset->next()) {
207  p.first = EcalLogicID(rset->getString(1), // name
208  rset->getInt(2), // logic_id
209  rset->getInt(3), // id1
210  rset->getInt(4), // id2
211  rset->getInt(5), // id3
212  rset->getString(6)); // maps_to
213 
214  dat.setTimingMean(rset->getFloat(7));
215  dat.setTimingRMS(rset->getFloat(8));
216  dat.setTaskStatus(rset->getInt(9));
217 
218  p.second = dat;
219  fillMap->insert(p);
220  }
221 
222  } catch (SQLException& e) {
223  throw(std::runtime_error("ITimingDat::fetchData(): " + e.getMessage()));
224  }
225  }
226 
227  // User data
229  float m_timingRMS;
232 };
233 
234 #endif
EcalCondDBInterface
Definition: EcalCondDBInterface.h:37
IDataItem.h
DDAxes::y
SiStripPI::mean
Definition: SiStripPayloadInspectorHelper.h:169
funct::false
false
Definition: Factorize.h:34
mps_update.status
status
Definition: mps_update.py:69
RunIOV.h
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
ITimingDat::SQLException
oracle::occi::SQLException SQLException
Definition: ITimingDat.h:19
ITimingDat::ITimingDat
ITimingDat()
Definition: ITimingDat.h:23
ITimingDat::getTimingRMS
float getTimingRMS() const
Definition: ITimingDat.h:44
IDataItem::checkPrepare
void checkPrepare() noexcept(false)
Definition: IDataItem.h:26
DDAxes::x
ITimingDat::setTimingRMS
void setTimingRMS(float rms)
Definition: ITimingDat.h:43
ITimingDat::m_timingRMS
float m_timingRMS
Definition: ITimingDat.h:229
EcalLogicID::getLogicID
int getLogicID() const
Definition: EcalLogicID.cc:28
IDataItem::m_readStmt
oracle::occi::Statement * m_readStmt
Definition: IDataItem.h:24
SiStripPI::rms
Definition: SiStripPayloadInspectorHelper.h:169
ITimingDat::getTimingMean
float getTimingMean() const
Definition: ITimingDat.h:41
ITimingDat::writeArrayDB
void writeArrayDB(const std::map< EcalLogicID, DATT > *data, IOVT *iov) noexcept(false)
Definition: ITimingDat.h:95
ITimingDat::setTaskStatus
void setTaskStatus(bool status)
Definition: ITimingDat.h:46
ITimingDat::ResultSet
oracle::occi::ResultSet ResultSet
Definition: ITimingDat.h:20
IDataItem::m_writeStmt
oracle::occi::Statement * m_writeStmt
Definition: IDataItem.h:23
IDBObject::m_conn
oracle::occi::Connection * m_conn
Definition: IDBObject.h:34
IDataItem
Definition: IDataItem.h:16
ITimingDat::m_table_name
std::string m_table_name
Definition: ITimingDat.h:231
ITimingDat::setTable
void setTable(std::string x)
Definition: ITimingDat.h:38
EcalLogicID
Definition: EcalLogicID.h:7
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
MonRunIOV.h
ITimingDat::~ITimingDat
~ITimingDat() override
Definition: ITimingDat.h:34
IDBObject::checkConnection
void checkConnection() const noexcept(false)
Definition: IDBObject.h:36
geometryCSVtoXML.yy
yy
Definition: geometryCSVtoXML.py:19
KineDebug3::count
void count()
Definition: KinematicConstrainedVertexUpdatorT.h:21
ITimingDat::m_timingMean
float m_timingMean
Definition: ITimingDat.h:228
ITimingDat
Definition: ITimingDat.h:17
ITimingDat::fetchData
void fetchData(std::map< EcalLogicID, DATT > *fillMap, IOVT *iov) noexcept(false)
Definition: ITimingDat.h:181
B2GTnPMonitor_cfi.item
item
Definition: B2GTnPMonitor_cfi.py:147
MonRunTag.h
EcalLogicID.h
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
ITimingDat::prepareWrite
void prepareWrite() noexcept(false) override
Definition: ITimingDat.h:50
Oracle.h
IDBObject::m_env
oracle::occi::Environment * m_env
Definition: IDBObject.h:33
ITimingDat::m_taskStatus
bool m_taskStatus
Definition: ITimingDat.h:230
RunTag.h
ITimingDat::writeDB
void writeDB(const EcalLogicID *ecid, const DATT *item, IOVT *iov) noexcept(false)
Definition: ITimingDat.h:66
ITimingDat::setTimingMean
void setTimingMean(float mean)
Definition: ITimingDat.h:40
geometryCSVtoXML.xx
xx
Definition: geometryCSVtoXML.py:19
ITimingDat::getTable
std::string getTable() override
Definition: ITimingDat.h:37
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
ITimingDat::getTaskStatus
bool getTaskStatus() const
Definition: ITimingDat.h:47