CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FEConfigFgrParamDat.cc
Go to the documentation of this file.
1 #include <stdexcept>
2 #include <string>
4 
7 
8 using namespace std;
9 using namespace oracle::occi;
10 
12 {
13  m_env = NULL;
14  m_conn = NULL;
15  m_writeStmt = NULL;
16  m_readStmt = NULL;
17 
18  m_fglowthresh = 0;
19  m_fghighthresh = 0;
20  m_lowratio = 0;
21  m_highratio = 0;
22 
23 }
24 
25 
26 
28 {
29 }
30 
31 
32 
34  throw(std::runtime_error)
35 {
36  this->checkConnection();
37 
38  try {
39  m_writeStmt = m_conn->createStatement();
40  m_writeStmt->setSQL("INSERT INTO "+ getTable()+" (fgr_conf_id, logic_id, "
41  " fg_lowthresh, fg_highthresh, fg_lowratio, fg_highratio ) "
42  "VALUES (:fgr_conf_id, :logic_id, "
43  " :fg_lowthresh, :fg_highthresh, :fg_lowratio, :fg_highratio )" );
44  } catch (SQLException &e) {
45  throw(std::runtime_error("FEConfigFgrParamDat::prepareWrite(): "+e.getMessage()));
46  }
47 }
48 
49 
50 
52  throw(std::runtime_error)
53 {
54  this->checkConnection();
55  this->checkPrepare();
56 
57  int iconfID = iconf->fetchID();
58  if (!iconfID) { throw(std::runtime_error("FEConfigFgrParamDat::writeDB: ICONF not in DB")); }
59 
60  int logicID = ecid->getLogicID();
61  if (!logicID) { throw(std::runtime_error("FEConfigFgrParamDat::writeDB: Bad EcalLogicID")); }
62 
63  try {
64  m_writeStmt->setInt(1, iconfID);
65  m_writeStmt->setInt(2, logicID);
66  m_writeStmt->setFloat(3, item->getFGlowthresh());
67  m_writeStmt->setFloat(4, item->getFGhighthresh());
68  m_writeStmt->setFloat(5, item->getFGlowratio());
69  m_writeStmt->setFloat(6, item->getFGhighratio());
70 
71  m_writeStmt->executeUpdate();
72  } catch (SQLException &e) {
73  throw(std::runtime_error("FEConfigFgrParamDat::writeDB(): "+e.getMessage()));
74  }
75 }
76 
77 
78 
79 void FEConfigFgrParamDat::fetchData(map< EcalLogicID, FEConfigFgrParamDat >* fillMap, FEConfigFgrInfo* iconf)
80  throw(std::runtime_error)
81 {
82  this->checkConnection();
83  fillMap->clear();
84 
85  iconf->setConnection(m_env, m_conn);
86  int iconfID = iconf->fetchID();
87  if (!iconfID) {
88  // throw(std::runtime_error("FEConfigFgrParamDat::writeDB: ICONF not in DB"));
89  return;
90  }
91 
92  try {
93 
94  m_readStmt->setSQL("SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
95  " d.fg_lowthresh, d.fg_highthresh, d.fg_lowratio, d.fg_highratio "
96  "FROM channelview cv JOIN "+ getTable() +" d "
97  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
98  "WHERE fgr_conf_id = :fgr_conf_id");
99  m_readStmt->setInt(1, iconfID);
100  ResultSet* rset = m_readStmt->executeQuery();
101 
102  std::pair< EcalLogicID, FEConfigFgrParamDat > p;
104  while(rset->next()) {
105  p.first = EcalLogicID( rset->getString(1), // name
106  rset->getInt(2), // logic_id
107  rset->getInt(3), // id1
108  rset->getInt(4), // id2
109  rset->getInt(5), // id3
110  rset->getString(6)); // maps_to
111 
112  dat.setFGlowthresh( rset->getFloat(7) );
113  dat.setFGhighthresh( rset->getFloat(8) );
114  dat.setFGlowratio( rset->getFloat(9) );
115  dat.setFGhighratio( rset->getFloat(10) );
116 
117  p.second = dat;
118  fillMap->insert(p);
119  }
120  } catch (SQLException &e) {
121  throw(std::runtime_error("FEConfigFgrParamDat::fetchData: "+e.getMessage()));
122  }
123 }
124 
125 void FEConfigFgrParamDat::writeArrayDB(const std::map< EcalLogicID, FEConfigFgrParamDat >* data, FEConfigFgrInfo* iconf)
126  throw(std::runtime_error)
127 {
128  this->checkConnection();
129  this->checkPrepare();
130 
131  int iconfID = iconf->fetchID();
132  if (!iconfID) { throw(std::runtime_error("FEConfigFgrParamDat::writeArrayDB: ICONF not in DB")); }
133 
134 
135  int nrows=data->size();
136  int* ids= new int[nrows];
137  int* iov_vec= new int[nrows];
138  float* ww= new float[nrows];
139  float* uu= new float[nrows];
140  float* tt= new float[nrows];
141  float* st= new float[nrows];
142 
143  ub2* ids_len= new ub2[nrows];
144  ub2* iov_len= new ub2[nrows];
145  ub2* w_len= new ub2[nrows];
146  ub2* u_len= new ub2[nrows];
147  ub2* t_len= new ub2[nrows];
148  ub2* st_len= new ub2[nrows];
149 
150  const EcalLogicID* channel;
151  const FEConfigFgrParamDat* dataitem;
152  int count=0;
153  typedef map< EcalLogicID, FEConfigFgrParamDat >::const_iterator CI;
154  for (CI p = data->begin(); p != data->end(); ++p) {
155  channel = &(p->first);
156  int logicID = channel->getLogicID();
157  if (!logicID) { throw(std::runtime_error("FEConfigFgrParamDat::writeArrayDB: Bad EcalLogicID")); }
158  ids[count]=logicID;
159  iov_vec[count]=iconfID;
160 
161  dataitem = &(p->second);
162  // dataIface.writeDB( channel, dataitem, conf);
163  float w=dataitem->getFGlowthresh();
164  float u=dataitem->getFGhighthresh();
165  float t=dataitem->getFGlowratio();
166  float r=dataitem->getFGhighratio();
167 
168  ww[count]=w;
169  uu[count]=u;
170  tt[count]=t;
171  st[count]=r;
172 
173 
174  ids_len[count]=sizeof(ids[count]);
175  iov_len[count]=sizeof(iov_vec[count]);
176 
177  w_len[count]=sizeof(ww[count]);
178  u_len[count]=sizeof(uu[count]);
179  t_len[count]=sizeof(tt[count]);
180  st_len[count]=sizeof(st[count]);
181 
182  count++;
183  }
184 
185 
186  try {
187  m_writeStmt->setDataBuffer(1, (dvoid*)iov_vec, OCCIINT, sizeof(iov_vec[0]),iov_len);
188  m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len );
189  m_writeStmt->setDataBuffer(3, (dvoid*)ww, OCCIFLOAT , sizeof(ww[0]), w_len );
190  m_writeStmt->setDataBuffer(4, (dvoid*)uu, OCCIFLOAT , sizeof(uu[0]), u_len );
191  m_writeStmt->setDataBuffer(5, (dvoid*)tt, OCCIFLOAT , sizeof(tt[0]), t_len );
192  m_writeStmt->setDataBuffer(6, (dvoid*)st, OCCIFLOAT , sizeof(st[0]), st_len );
193 
194 
195  m_writeStmt->executeArrayUpdate(nrows);
196 
197  delete [] ids;
198  delete [] iov_vec;
199  delete [] ww;
200  delete [] uu;
201  delete [] tt;
202  delete [] st;
203 
204  delete [] ids_len;
205  delete [] iov_len;
206  delete [] w_len;
207  delete [] u_len;
208  delete [] t_len;
209  delete [] st_len;
210 
211  } catch (SQLException &e) {
212  throw(std::runtime_error("FEConfigFgrParamDat::writeArrayDB(): "+e.getMessage()));
213  }
214 }
float getFGlowthresh() const
float getFGhighthresh() const
void setFGhighratio(float x)
void setFGlowthresh(float x)
float getFGhighratio() const
#define NULL
Definition: scimark2.h:8
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:27
void writeArrayDB(const std::map< EcalLogicID, FEConfigFgrParamDat > *data, FEConfigFgrInfo *iconf)
void fetchData(std::map< EcalLogicID, FEConfigFgrParamDat > *fillMap, FEConfigFgrInfo *iconf)
void writeDB(const EcalLogicID *ecid, const FEConfigFgrParamDat *item, FEConfigFgrInfo *iconf)
int getLogicID() const
Definition: EcalLogicID.cc:41
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:26
float getFGlowratio() const
void setFGlowratio(float x)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
T w() const
void setFGhighthresh(float x)