CMS 3D CMS Logo

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