CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CaliGainRatioDat.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 
18  m_g1_g12 = 0;
19  m_g6_g12 = 0;
20  m_taskStatus = false;
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 cali_gain_ratio_dat (iov_id, logic_id, "
39  "g1_g6, g6_g12, task_status) "
40  "VALUES (:iov_id, :logic_id, "
41  ":3, :4, :5)");
42  } catch (SQLException &e) {
43  throw(std::runtime_error("CaliGainRatioDat::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("CaliGainRatioDat::writeDB: IOV not in DB")); }
57 
58  int logicID = ecid->getLogicID();
59  if (!logicID) { throw(std::runtime_error("CaliGainRatioDat::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->getG1G12() );
66  m_writeStmt->setFloat(4, item->getG6G12() );
67  m_writeStmt->setInt(5, item->getTaskStatus() );
68 
69  m_writeStmt->executeUpdate();
70  } catch (SQLException &e) {
71  throw(std::runtime_error("CaliGainRatioDat::writeDB(): "+e.getMessage()));
72  }
73 }
74 
75 
76 
77 void CaliGainRatioDat::fetchData(std::map< EcalLogicID, CaliGainRatioDat >* fillMap, CaliIOV* iov)
78  throw(std::runtime_error)
79 {
80  this->checkConnection();
81  fillMap->clear();
82 
83  iov->setConnection(m_env, m_conn);
84  int iovID = iov->fetchID();
85  if (!iovID) {
86  // throw(std::runtime_error("CaliGainRatioDat::writeDB: IOV not in DB"));
87  return;
88  }
89 
90  try {
91 
92  m_readStmt->setSQL("SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
93  "d.g1_g6, d.g6_g12, d.task_status "
94  "FROM channelview cv JOIN cali_gain_ratio_dat d "
95  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
96  "WHERE d.iov_id = :iov_id");
97  m_readStmt->setInt(1, iovID);
98  ResultSet* rset = m_readStmt->executeQuery();
99 
100  std::pair< EcalLogicID, CaliGainRatioDat > p;
101  CaliGainRatioDat dat;
102  while(rset->next()) {
103  p.first = EcalLogicID( rset->getString(1), // name
104  rset->getInt(2), // logic_id
105  rset->getInt(3), // id1
106  rset->getInt(4), // id2
107  rset->getInt(5), // id3
108  rset->getString(6)); // maps_to
109 
110  dat.setG1G12( rset->getFloat(7) );
111  dat.setG6G12( rset->getFloat(8) );
112  dat.setTaskStatus( rset->getInt(9) );
113 
114  p.second = dat;
115  fillMap->insert(p);
116  }
117  } catch (SQLException &e) {
118  throw(std::runtime_error("CaliGainRatioDat::fetchData(): "+e.getMessage()));
119  }
120 }
121 
122 void CaliGainRatioDat::writeArrayDB(const std::map< EcalLogicID, CaliGainRatioDat >* data, CaliIOV* iov)
123  throw(std::runtime_error)
124 {
125  this->checkConnection();
126  this->checkPrepare();
127 
128  int iovID = iov->fetchID();
129  if (!iovID) { throw(std::runtime_error("CaliGainRatioDat::writeArrayDB: IOV not in DB")); }
130 
131 
132  int nrows=data->size();
133  int* ids= new int[nrows];
134  int* iovid_vec= new int[nrows];
135  float* xx= new float[nrows];
136  float* yy= new float[nrows];
137  int* st= new int[nrows];
138 
139  ub2* ids_len= new ub2[nrows];
140  ub2* iov_len= new ub2[nrows];
141  ub2* x_len= new ub2[nrows];
142  ub2* y_len= new ub2[nrows];
143  ub2* st_len= new ub2[nrows];
144 
145  const EcalLogicID* channel;
146  const CaliGainRatioDat* dataitem;
147  int count=0;
148  typedef map< EcalLogicID, CaliGainRatioDat >::const_iterator CI;
149  for (CI p = data->begin(); p != data->end(); ++p) {
150  channel = &(p->first);
151  int logicID = channel->getLogicID();
152  if (!logicID) { throw(std::runtime_error("CaliGainRatioDat::writeArrayDB: Bad EcalLogicID")); }
153  ids[count]=logicID;
154  iovid_vec[count]=iovID;
155 
156  dataitem = &(p->second);
157  // dataIface.writeDB( channel, dataitem, iov);
158  float x=dataitem->getG1G12();
159  float y=dataitem->getG6G12();
160  int statu=dataitem->getTaskStatus();
161 
162 
163 
164  xx[count]=x;
165  yy[count]=y;
166  st[count]=statu;
167 
168 
169  ids_len[count]=sizeof(ids[count]);
170  iov_len[count]=sizeof(iovid_vec[count]);
171 
172  x_len[count]=sizeof(xx[count]);
173  y_len[count]=sizeof(yy[count]);
174  st_len[count]=sizeof(st[count]);
175 
176  count++;
177  }
178 
179 
180  try {
181  m_writeStmt->setDataBuffer(1, (dvoid*)iovid_vec, OCCIINT, sizeof(iovid_vec[0]),iov_len);
182  m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len );
183  m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIFLOAT , sizeof(xx[0]), x_len );
184  m_writeStmt->setDataBuffer(4, (dvoid*)yy, OCCIFLOAT , sizeof(yy[0]), y_len );
185  m_writeStmt->setDataBuffer(5, (dvoid*)st, OCCIINT , sizeof(st[0]), st_len );
186 
187 
188  m_writeStmt->executeArrayUpdate(nrows);
189 
190  delete [] ids;
191  delete [] iovid_vec;
192  delete [] xx;
193  delete [] yy;
194  delete [] st;
195 
196  delete [] ids_len;
197  delete [] iov_len;
198  delete [] x_len;
199  delete [] y_len;
200  delete [] st_len;
201 
202 
203 
204  } catch (SQLException &e) {
205  throw(std::runtime_error("CaliGainRatio::writeArrayDB(): "+e.getMessage()));
206  }
207 }
void setG1G12(float c)
#define NULL
Definition: scimark2.h:8
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:27
void setTaskStatus(bool s)
tuple iov
Definition: o2o.py:307
float getG6G12() const
int getLogicID() const
Definition: EcalLogicID.cc:41
float getG1G12() const
void setG6G12(float c)
bool getTaskStatus() const
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:26
void writeDB(const EcalLogicID *ecid, const CaliGainRatioDat *item, CaliIOV *iov)
void writeArrayDB(const std::map< EcalLogicID, CaliGainRatioDat > *data, CaliIOV *iov)
void fetchData(std::map< EcalLogicID, CaliGainRatioDat > *fillVec, CaliIOV *iov)