CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FEConfigFgrGroupDat.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_group_id=0;
19  m_thresh_low = 0;
20  m_thresh_high = 0;
21  m_ratio_low = 0;
22  m_ratio_high = 0;
23  m_lut = 0;
24 
25 }
26 
27 
28 
30 {
31 }
32 
33 
34 
36  throw(std::runtime_error)
37 {
38  this->checkConnection();
39 
40  try {
41  m_writeStmt = m_conn->createStatement();
42  m_writeStmt->setSQL("INSERT INTO fe_fgr_per_group_dat (fgr_conf_id, group_id, "
43  " threshold_low, threshold_high, ratio_low, ratio_high, lut_value ) "
44  "VALUES (:fgr_conf_id, :group_id, "
45  ":3, :4, :5, :6, :7 )" );
46  } catch (SQLException &e) {
47  throw(std::runtime_error("FEConfigFgrGroupDat::prepareWrite(): "+e.getMessage()));
48  }
49 }
50 
51 
52 
54  throw(std::runtime_error)
55 {
56  this->checkConnection();
57  this->checkPrepare();
58 
59  int iconfID = iconf->fetchID();
60  if (!iconfID) { throw(std::runtime_error("FEConfigFgrGroupDat::writeDB: ICONF not in DB")); }
61  /* no need for the logic id in this table
62  int logicID = ecid->getLogicID();
63  if (!logicID) { throw(std::runtime_error("FEConfigFgrGroupDat::writeDB: Bad EcalLogicID")); }
64  */
65 
66  try {
67  m_writeStmt->setInt(1, iconfID);
68 
69  m_writeStmt->setInt(2, item->getFgrGroupId());
70  m_writeStmt->setFloat(3, item->getThreshLow());
71  m_writeStmt->setFloat(4, item->getThreshHigh());
72  m_writeStmt->setFloat(5, item->getRatioLow());
73  m_writeStmt->setFloat(6, item->getRatioHigh());
74  m_writeStmt->setInt(7, item->getLUTValue());
75 
76  m_writeStmt->executeUpdate();
77  } catch (SQLException &e) {
78  throw(std::runtime_error("FEConfigFgrGroupDat::writeDB(): "+e.getMessage()));
79  }
80 }
81 
82 
83 
84 void FEConfigFgrGroupDat::fetchData(map< EcalLogicID, FEConfigFgrGroupDat >* fillMap, FEConfigFgrInfo* iconf)
85  throw(std::runtime_error)
86 {
87  this->checkConnection();
88  fillMap->clear();
89 
90  iconf->setConnection(m_env, m_conn);
91  int iconfID = iconf->fetchID();
92  if (!iconfID) {
93  throw(std::runtime_error("FEConfigFgrGroupDat::fetchData: ICONF not in DB"));
94  return;
95  }
96 
97  try {
98 
99  m_readStmt->setSQL("SELECT d.group_id, d.threshold_low, d.threshold_high, d.ratio_low, d.ratio_high, d.lut_value "
100  "FROM fe_fgr_per_group_dat d "
101  "WHERE fgr_conf_id = :fgr_conf_id order by d.group_id ");
102  m_readStmt->setInt(1, iconfID);
103  ResultSet* rset = m_readStmt->executeQuery();
104 
105  std::pair< EcalLogicID, FEConfigFgrGroupDat > p;
107  int ig=-1;
108  while(rset->next()) {
109  ig++; // we create a dummy logic_id
110  p.first = EcalLogicID( "Group_id", // name
111  ig ); // logic_id
112 
113  dat.setFgrGroupId( rset->getInt(1) );
114  dat.setThreshLow( rset->getFloat(2) );
115  dat.setThreshHigh( rset->getFloat(3) );
116  dat.setRatioLow( rset->getFloat(4) );
117  dat.setRatioHigh( rset->getFloat(5) );
118  dat.setLUTValue( rset->getInt(6) );
119 
120  p.second = dat;
121  fillMap->insert(p);
122  }
123  } catch (SQLException &e) {
124  throw(std::runtime_error("FEConfigFgrGroupDat::fetchData: "+e.getMessage()));
125  }
126 }
127 
128 void FEConfigFgrGroupDat::writeArrayDB(const std::map< EcalLogicID, FEConfigFgrGroupDat >* data, FEConfigFgrInfo* iconf)
129  throw(std::runtime_error)
130 {
131  this->checkConnection();
132  this->checkPrepare();
133 
134  int iconfID = iconf->fetchID();
135  if (!iconfID) { throw(std::runtime_error("FEConfigFgrGroupDat::writeArrayDB: ICONF not in DB")); }
136 
137 
138  int nrows=data->size();
139  int* ids= new int[nrows];
140  int* iconfid_vec= new int[nrows];
141  int* xx= new int[nrows];
142  float* yy= new float[nrows];
143  float* zz= new float[nrows];
144  float* rr= new float[nrows];
145  float* ss= new float[nrows];
146  int* tt= new int[nrows];
147 
148 
149  ub2* ids_len= new ub2[nrows];
150  ub2* iconf_len= new ub2[nrows];
151  ub2* x_len= new ub2[nrows];
152  ub2* y_len= new ub2[nrows];
153  ub2* z_len= new ub2[nrows];
154  ub2* r_len= new ub2[nrows];
155  ub2* s_len= new ub2[nrows];
156  ub2* t_len= new ub2[nrows];
157 
158 
159  // const EcalLogicID* channel;
160  const FEConfigFgrGroupDat* dataitem;
161  int count=0;
162  typedef map< EcalLogicID, FEConfigFgrGroupDat >::const_iterator CI;
163  for (CI p = data->begin(); p != data->end(); ++p) {
164  //channel = &(p->first);
165  // int logicID = channel->getLogicID();
166  // if (!logicID) { throw(std::runtime_error("FEConfigFgrGroupDat::writeArrayDB: Bad EcalLogicID")); }
167  // ids[count]=logicID;
168  iconfid_vec[count]=iconfID;
169 
170  dataitem = &(p->second);
171  // dataIface.writeDB( channel, dataitem, iconf);
172  int x=dataitem->getFgrGroupId();
173  float y=dataitem->getThreshLow();
174  float z=dataitem->getThreshHigh();
175  float r=dataitem->getRatioLow();
176  float s=dataitem->getRatioHigh();
177  int t=dataitem->getLUTValue();
178 
179  xx[count]=x;
180  yy[count]=y;
181  zz[count]=z;
182  rr[count]=r;
183  ss[count]=s;
184  tt[count]=t;
185 
186  // ids_len[count]=sizeof(ids[count]);
187  iconf_len[count]=sizeof(iconfid_vec[count]);
188 
189  x_len[count]=sizeof(xx[count]);
190  y_len[count]=sizeof(yy[count]);
191  z_len[count]=sizeof(zz[count]);
192  r_len[count]=sizeof(rr[count]);
193  s_len[count]=sizeof(ss[count]);
194  t_len[count]=sizeof(tt[count]);
195 
196  count++;
197  }
198 
199 
200  try {
201  m_writeStmt->setDataBuffer(1, (dvoid*)iconfid_vec, OCCIINT, sizeof(iconfid_vec[0]),iconf_len);
202  m_writeStmt->setDataBuffer(2, (dvoid*)xx, OCCIINT, sizeof(xx[0]), x_len );
203  m_writeStmt->setDataBuffer(3, (dvoid*)yy, OCCIFLOAT , sizeof(yy[0]), y_len );
204  m_writeStmt->setDataBuffer(4, (dvoid*)zz, OCCIFLOAT , sizeof(zz[0]), z_len );
205  m_writeStmt->setDataBuffer(5, (dvoid*)rr, OCCIFLOAT , sizeof(rr[0]), r_len );
206  m_writeStmt->setDataBuffer(6, (dvoid*)ss, OCCIFLOAT , sizeof(ss[0]), s_len );
207  m_writeStmt->setDataBuffer(7, (dvoid*)tt, OCCIINT , sizeof(tt[0]), t_len );
208 
209  m_writeStmt->executeArrayUpdate(nrows);
210 
211  delete [] ids;
212  delete [] iconfid_vec;
213  delete [] xx;
214  delete [] yy;
215  delete [] zz;
216  delete [] rr;
217  delete [] ss;
218  delete [] tt;
219 
220  delete [] ids_len;
221  delete [] iconf_len;
222  delete [] x_len;
223  delete [] y_len;
224  delete [] z_len;
225  delete [] r_len;
226  delete [] s_len;
227  delete [] t_len;
228 
229  } catch (SQLException &e) {
230  throw(std::runtime_error("FEConfigFgrGroupDat::writeArrayDB(): "+e.getMessage()));
231  }
232 }
void setThreshLow(float x)
#define NULL
Definition: scimark2.h:8
void setRatioHigh(float x)
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:27
float float float z
void setThreshHigh(float x)
float getRatioLow() const
float getThreshLow() const
float getRatioHigh() const
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:26
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
void fetchData(std::map< EcalLogicID, FEConfigFgrGroupDat > *fillMap, FEConfigFgrInfo *iconf)
void writeDB(const EcalLogicID *ecid, const FEConfigFgrGroupDat *item, FEConfigFgrInfo *iconf)
void writeArrayDB(const std::map< EcalLogicID, FEConfigFgrGroupDat > *data, FEConfigFgrInfo *iconf)
float getThreshHigh() const
Definition: DDAxes.h:10