CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DCUCapsuleTempRawDat.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 = NULL;
15  m_conn = NULL;
16  m_writeStmt = NULL;
17  m_readStmt = NULL;
18 
19  m_capsuleTempADC = 0;
20  m_capsuleTempRMS = 0;
21 }
22 
23 
24 
26 {
27 }
28 
29 
30 
32  throw(std::runtime_error)
33 {
34  this->checkConnection();
35 
36  try {
37  m_writeStmt = m_conn->createStatement();
38  m_writeStmt->setSQL("INSERT INTO dcu_capsule_temp_raw_dat (iov_id, logic_id, "
39  "capsule_temp_adc, capsule_temp_rms) "
40  "VALUES (:iov_id, :logic_id, "
41  ":3, :4)");
42  } catch (SQLException &e) {
43  throw(std::runtime_error("DCUCapsuleTempRawDat::prepareWrite(): "+e.getMessage()));
44  }
45 }
46 
47 
48 
50  throw(std::runtime_error)
51 {
52  this->checkConnection();
53  this->checkPrepare();
54 
55  int iovID = iov->fetchID();
56  if (!iovID) { throw(std::runtime_error("DCUCapsuleTempRawDat::writeDB: IOV not in DB")); }
57 
58  int logicID = ecid->getLogicID();
59  if (!logicID) { throw(std::runtime_error("DCUCapsuleTempRawDat::writeDB: Bad EcalLogicID")); }
60 
61  try {
62  m_writeStmt->setInt(1, iovID);
63  m_writeStmt->setInt(2, logicID);
64 
65  m_writeStmt->setFloat(3, item->getCapsuleTempADC() );
66  m_writeStmt->setFloat(4, item->getCapsuleTempRMS() );
67 
68  m_writeStmt->executeUpdate();
69  } catch (SQLException &e) {
70  throw(std::runtime_error("DCUCapsuleTempRawDat::writeDB(): "+e.getMessage()));
71  }
72 }
73 
74 
75 
76 void DCUCapsuleTempRawDat::fetchData(std::map< EcalLogicID, DCUCapsuleTempRawDat >* fillMap, DCUIOV* iov)
77  throw(std::runtime_error)
78 {
79  this->checkConnection();
80  fillMap->clear();
81 
82  iov->setConnection(m_env, m_conn);
83  int iovID = iov->fetchID();
84  if (!iovID) {
85  // throw(std::runtime_error("DCUCapsuleTempRawDat::writeDB: IOV not in DB"));
86  return;
87  }
88 
89  try {
90 
91  m_readStmt->setSQL("SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
92  "d.capsule_temp_adc, d.capsule_temp_rms "
93  "FROM channelview cv JOIN dcu_capsule_temp_raw_dat d "
94  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
95  "WHERE d.iov_id = :iov_id");
96  m_readStmt->setInt(1, iovID);
97  ResultSet* rset = m_readStmt->executeQuery();
98 
99  std::pair< EcalLogicID, DCUCapsuleTempRawDat > p;
101  while(rset->next()) {
102  p.first = EcalLogicID( rset->getString(1), // name
103  rset->getInt(2), // logic_id
104  rset->getInt(3), // id1
105  rset->getInt(4), // id2
106  rset->getInt(5), // id3
107  rset->getString(6)); // maps_to
108 
109  dat.setCapsuleTempADC( rset->getFloat(7) );
110  dat.setCapsuleTempRMS( rset->getFloat(8) );
111 
112  p.second = dat;
113  fillMap->insert(p);
114  }
115  } catch (SQLException &e) {
116  throw(std::runtime_error("DCUCapsuleTempRawDat::fetchData(): "+e.getMessage()));
117  }
118 }
119 
120 void DCUCapsuleTempRawDat::writeArrayDB(const std::map< EcalLogicID, DCUCapsuleTempRawDat >* data, DCUIOV* iov)
121  throw(std::runtime_error)
122 {
123  this->checkConnection();
124  this->checkPrepare();
125 
126  int iovID = iov->fetchID();
127  if (!iovID) { throw(std::runtime_error("DCUCapsuleTempRawDat::writeArrayDB: IOV not in DB")); }
128 
129 
130  int nrows=data->size();
131  int* ids= new int[nrows];
132  int* iovid_vec= new int[nrows];
133  float* xx= new float[nrows];
134  float* yy= new float[nrows];
135 
136  ub2* ids_len= new ub2[nrows];
137  ub2* iov_len= new ub2[nrows];
138  ub2* x_len= new ub2[nrows];
139  ub2* y_len= new ub2[nrows];
140 
141 
142  const EcalLogicID* channel;
143  const DCUCapsuleTempRawDat* dataitem;
144  int count=0;
145  typedef map< EcalLogicID, DCUCapsuleTempRawDat >::const_iterator CI;
146  for (CI p = data->begin(); p != data->end(); ++p) {
147  channel = &(p->first);
148  int logicID = channel->getLogicID();
149  if (!logicID) { throw(std::runtime_error("DCUCapsuleTempRawDat::writeArrayDB: Bad EcalLogicID")); }
150  ids[count]=logicID;
151  iovid_vec[count]=iovID;
152 
153  dataitem = &(p->second);
154  // dataIface.writeDB( channel, dataitem, iov);
155  float x=dataitem->getCapsuleTempADC();
156  float y=dataitem->getCapsuleTempRMS();
157 
158  xx[count]=x;
159  yy[count]=y;
160 
161 
162  ids_len[count]=sizeof(ids[count]);
163  iov_len[count]=sizeof(iovid_vec[count]);
164 
165  x_len[count]=sizeof(xx[count]);
166  y_len[count]=sizeof(yy[count]);
167 
168  count++;
169  }
170 
171 
172  try {
173  m_writeStmt->setDataBuffer(1, (dvoid*)iovid_vec, OCCIINT, sizeof(iovid_vec[0]),iov_len);
174  m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len );
175  m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIFLOAT , sizeof(xx[0]), x_len );
176  m_writeStmt->setDataBuffer(4, (dvoid*)yy, OCCIFLOAT , sizeof(yy[0]), y_len );
177 
178 
179  m_writeStmt->executeArrayUpdate(nrows);
180 
181  delete [] ids;
182  delete [] iovid_vec;
183  delete [] xx;
184  delete [] yy;
185 
186  delete [] ids_len;
187  delete [] iov_len;
188  delete [] x_len;
189  delete [] y_len;
190 
191  } catch (SQLException &e) {
192  throw(std::runtime_error("DCUCapsuleTempRawDat::writeArrayDB(): "+e.getMessage()));
193  }
194 }
float getCapsuleTempADC() const
void writeDB(const EcalLogicID *ecid, const DCUCapsuleTempRawDat *item, DCUIOV *iov)
float getCapsuleTempRMS() const
#define NULL
Definition: scimark2.h:8
Definition: DCUIOV.h:13
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:27
void fetchData(std::map< EcalLogicID, DCUCapsuleTempRawDat > *fillVec, DCUIOV *iov)
tuple iov
Definition: o2o.py:307
int getLogicID() const
Definition: EcalLogicID.cc:41
void writeArrayDB(const std::map< EcalLogicID, DCUCapsuleTempRawDat > *data, DCUIOV *iov)
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:26
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
void setCapsuleTempADC(float adc)
void setCapsuleTempRMS(float rms)