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