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