CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MonMemTTConsistencyDat.cc
Go to the documentation of this file.
1 #include <stdexcept>
2 #include <string>
4 
6 
7 using namespace std;
8 using namespace oracle::occi;
9 
11 {
12  m_env = NULL;
13  m_conn = NULL;
14  m_writeStmt = NULL;
15  m_readStmt = NULL;
16 
17  m_processedEvents = 0;
18  m_problematicEvents = 0;
19  m_problemsID = 0;
20  m_problemsSize = 0;
21  m_problemsLV1 = 0;
22  m_problemsBunchX = 0;
23  m_taskStatus = 0;
24 }
25 
26 
27 
29 {
30 }
31 
32 
33 
35  throw(std::runtime_error)
36 {
37  this->checkConnection();
38 
39  try {
40  m_writeStmt = m_conn->createStatement();
41  m_writeStmt->setSQL("INSERT INTO mon_mem_tt_consistency_dat (iov_id, logic_id, "
42  "processed_events, problematic_events, problems_id, problems_size, problems_LV1, problems_bunch_X, task_status) "
43  "VALUES (:iov_id, :logic_id, "
44  ":3, :4, :5, :6, :7, :8, :9)");
45  } catch (SQLException &e) {
46  throw(std::runtime_error("MonMemTTConsistencyDat::prepareWrite(): "+e.getMessage()));
47  }
48 }
49 
50 
51 
53  throw(std::runtime_error)
54 {
55  this->checkConnection();
56  this->checkPrepare();
57 
58  int iovID = iov->fetchID();
59  if (!iovID) { throw(std::runtime_error("MonMemTTConsistencyDat::writeDB: IOV not in DB")); }
60 
61  int logicID = ecid->getLogicID();
62  if (!logicID) { throw(std::runtime_error("MonMemTTConsistencyDat::writeDB: Bad EcalLogicID")); }
63 
64  try {
65  m_writeStmt->setInt(1, iovID);
66  m_writeStmt->setInt(2, logicID);
67 
68  m_writeStmt->setInt(3, item->getProcessedEvents() );
69  m_writeStmt->setInt(4, item->getProblematicEvents() );
70  m_writeStmt->setInt(5, item->getProblemsID() );
71  m_writeStmt->setInt(6, item->getProblemsSize() );
72  m_writeStmt->setInt(7, item->getProblemsLV1() );
73  m_writeStmt->setInt(8, item->getProblemsBunchX() );
74  m_writeStmt->setInt(9, item->getTaskStatus() );
75  m_writeStmt->executeUpdate();
76  } catch (SQLException &e) {
77  throw(std::runtime_error("MonMemTTConsistencyDat::writeDB(): "+e.getMessage()));
78  }
79 }
80 
81 
82 
83 void MonMemTTConsistencyDat::fetchData(std::map< EcalLogicID, MonMemTTConsistencyDat >* fillMap, MonRunIOV* iov)
84  throw(std::runtime_error)
85 {
86  this->checkConnection();
87  fillMap->clear();
88 
89  iov->setConnection(m_env, m_conn);
90  int iovID = iov->fetchID();
91  if (!iovID) {
92  // throw(std::runtime_error("MonMemTTConsistencyDat::writeDB: IOV not in DB"));
93  return;
94  }
95 
96  try {
97 
98  m_readStmt->setSQL("SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
99  "d.processed_events, d.problematic_events, d.problems_id, d.problems_size, d.problems_LV1, d.problems_bunch_X, d.task_status "
100  "FROM channelview cv JOIN mon_mem_tt_consistency_dat d "
101  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
102  "WHERE d.iov_id = :iov_id");
103  m_readStmt->setInt(1, iovID);
104  ResultSet* rset = m_readStmt->executeQuery();
105 
106  std::pair< EcalLogicID, MonMemTTConsistencyDat > p;
108  while(rset->next()) {
109  p.first = EcalLogicID( rset->getString(1), // name
110  rset->getInt(2), // logic_id
111  rset->getInt(3), // id1
112  rset->getInt(4), // id2
113  rset->getInt(5), // id3
114  rset->getString(6)); // maps_to
115 
116  dat.setProcessedEvents( rset->getInt(7) );
117  dat.setProblematicEvents( rset->getInt(8) );
118  dat.setProblemsID( rset->getInt(9) );
119  dat.setProblemsSize( rset->getInt(10) );
120  dat.setProblemsLV1( rset->getInt(11) );
121  dat.setProblemsBunchX( rset->getInt(12) );
122  dat.setTaskStatus( rset->getInt(13) );
123 
124  p.second = dat;
125  fillMap->insert(p);
126  }
127  } catch (SQLException &e) {
128  throw(std::runtime_error("MonMemTTConsistencyDat::fetchData(): "+e.getMessage()));
129  }
130 }
131 
132 void MonMemTTConsistencyDat::writeArrayDB(const std::map< EcalLogicID, MonMemTTConsistencyDat >* data, MonRunIOV* iov)
133  throw(std::runtime_error)
134 {
135  this->checkConnection();
136  this->checkPrepare();
137 
138  int iovID = iov->fetchID();
139  if (!iovID) { throw(std::runtime_error("MonMemTTConsistencyDat::writeArrayDB: IOV not in DB")); }
140 
141 
142  int nrows=data->size();
143  int* ids= new int[nrows];
144  int* iovid_vec= new int[nrows];
145  int* xx= new int[nrows];
146  int* yy= new int[nrows];
147  int* zz= new int[nrows];
148  int* ww= new int[nrows];
149  int* uu= new int[nrows];
150  int* tt= new int[nrows];
151  int* st= new int[nrows];
152 
153  ub2* ids_len= new ub2[nrows];
154  ub2* iov_len= new ub2[nrows];
155  ub2* x_len= new ub2[nrows];
156  ub2* y_len= new ub2[nrows];
157  ub2* z_len= new ub2[nrows];
158  ub2* w_len= new ub2[nrows];
159  ub2* u_len= new ub2[nrows];
160  ub2* t_len= new ub2[nrows];
161  ub2* st_len= new ub2[nrows];
162 
163  const EcalLogicID* channel;
164  const MonMemTTConsistencyDat* dataitem;
165  int count=0;
166  typedef map< EcalLogicID, MonMemTTConsistencyDat >::const_iterator CI;
167  for (CI p = data->begin(); p != data->end(); ++p) {
168  channel = &(p->first);
169  int logicID = channel->getLogicID();
170  if (!logicID) { throw(std::runtime_error("MonMemTTConsistencyDat::writeArrayDB: Bad EcalLogicID")); }
171  ids[count]=logicID;
172  iovid_vec[count]=iovID;
173 
174  dataitem = &(p->second);
175  // dataIface.writeDB( channel, dataitem, iov);
176  int x=dataitem->getProcessedEvents();
177  int y=dataitem->getProblematicEvents();
178  int z=dataitem->getProblemsID();
179  int w=dataitem->getProblemsSize();
180  int u=dataitem->getProblemsLV1();
181  int t=dataitem->getProblemsBunchX();
182  int statu=dataitem->getTaskStatus();
183 
184 
185 
186 
187  xx[count]=x;
188  yy[count]=y;
189  zz[count]=z;
190  ww[count]=w;
191  uu[count]=u;
192  tt[count]=t;
193  st[count]=statu;
194 
195 
196  ids_len[count]=sizeof(ids[count]);
197  iov_len[count]=sizeof(iovid_vec[count]);
198 
199  x_len[count]=sizeof(xx[count]);
200  y_len[count]=sizeof(yy[count]);
201  z_len[count]=sizeof(zz[count]);
202  w_len[count]=sizeof(ww[count]);
203  u_len[count]=sizeof(uu[count]);
204  t_len[count]=sizeof(tt[count]);
205  st_len[count]=sizeof(st[count]);
206 
207  count++;
208  }
209 
210 
211  try {
212  m_writeStmt->setDataBuffer(1, (dvoid*)iovid_vec, OCCIINT, sizeof(iovid_vec[0]),iov_len);
213  m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len );
214  m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIINT , sizeof(xx[0]), x_len );
215  m_writeStmt->setDataBuffer(4, (dvoid*)yy, OCCIINT , sizeof(yy[0]), y_len );
216  m_writeStmt->setDataBuffer(5, (dvoid*)zz, OCCIINT , sizeof(zz[0]), z_len );
217  m_writeStmt->setDataBuffer(6, (dvoid*)ww, OCCIINT , sizeof(ww[0]), w_len );
218  m_writeStmt->setDataBuffer(7, (dvoid*)uu, OCCIINT , sizeof(uu[0]), u_len );
219  m_writeStmt->setDataBuffer(8, (dvoid*)tt, OCCIINT , sizeof(tt[0]), t_len );
220  m_writeStmt->setDataBuffer(9, (dvoid*)st, OCCIINT , sizeof(st[0]), st_len );
221 
222 
223  m_writeStmt->executeArrayUpdate(nrows);
224 
225  delete [] ids;
226  delete [] iovid_vec;
227  delete [] xx;
228  delete [] yy;
229  delete [] zz;
230  delete [] ww;
231  delete [] uu;
232  delete [] tt;
233  delete [] st;
234 
235  delete [] ids_len;
236  delete [] iov_len;
237  delete [] x_len;
238  delete [] y_len;
239  delete [] z_len;
240  delete [] w_len;
241  delete [] u_len;
242  delete [] t_len;
243  delete [] st_len;
244 
245 
246 
247  } catch (SQLException &e) {
248  throw(std::runtime_error("MonMemTTConsistencyDat::writeArrayDB(): "+e.getMessage()));
249  }
250 }
const double w
Definition: UKUtility.cc:23
#define NULL
Definition: scimark2.h:8
void writeDB(const EcalLogicID *ecid, const MonMemTTConsistencyDat *item, MonRunIOV *iov)
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:27
float float float z
tuple iov
Definition: o2o.py:307
void setProblemsBunchX(int bunchX)
void fetchData(std::map< EcalLogicID, MonMemTTConsistencyDat > *fillVec, MonRunIOV *iov)
int getLogicID() const
Definition: EcalLogicID.cc:41
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:26
void setTaskStatus(bool status)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
Definition: DDAxes.h:10
void writeArrayDB(const std::map< EcalLogicID, MonMemTTConsistencyDat > *data, MonRunIOV *iov)