test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FEConfigLinDat.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_multx12 = 0;
19  m_multx6 = 0;
20  m_multx1 = 0;
21  m_shift12 = 0;
22  m_shift6 = 0;
23  m_shift1 = 0;
24 
25 
26 }
27 
28 
29 
31 {
32 }
33 
34 
35 
37  throw(std::runtime_error)
38 {
39  this->checkConnection();
40 
41  try {
42  m_writeStmt = m_conn->createStatement();
43  m_writeStmt->setSQL("INSERT INTO fe_config_lin_dat (lin_conf_id, logic_id, "
44  " multx12, multx6, multx1, shift12, shift6, shift1 ) "
45  "VALUES (:lin_conf_id, :logic_id, "
46  ":multx12, :multx6, :multx1, :shift12, :shift6, :shift1 )" );
47  } catch (SQLException &e) {
48  throw(std::runtime_error("FEConfigLinDat::prepareWrite(): "+e.getMessage()));
49  }
50 }
51 
52 
53 
54 void FEConfigLinDat::writeDB(const EcalLogicID* ecid, const FEConfigLinDat* item, FEConfigLinInfo* iconf)
55  throw(std::runtime_error)
56 {
57  this->checkConnection();
58  this->checkPrepare();
59 
60  int iconfID = iconf->fetchID();
61  if (!iconfID) { throw(std::runtime_error("FEConfigLinDat::writeDB: ICONF not in DB")); }
62 
63  int logicID = ecid->getLogicID();
64  if (!logicID) { throw(std::runtime_error("FEConfigLinDat::writeDB: Bad EcalLogicID")); }
65 
66  try {
67  m_writeStmt->setInt(1, iconfID);
68  m_writeStmt->setInt(2, logicID);
69  m_writeStmt->setInt(3, item->getMultX12());
70  m_writeStmt->setInt(4, item->getMultX6());
71  m_writeStmt->setInt(5, item->getMultX1());
72  m_writeStmt->setInt(6, item->getShift12());
73  m_writeStmt->setInt(7, item->getShift6());
74  m_writeStmt->setInt(8, item->getShift1());
75 
76  m_writeStmt->executeUpdate();
77  } catch (SQLException &e) {
78  throw(std::runtime_error("FEConfigLinDat::writeDB(): "+e.getMessage()));
79  }
80 }
81 
82 
83 
84 void FEConfigLinDat::fetchData(map< EcalLogicID, FEConfigLinDat >* fillMap, FEConfigLinInfo* 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("FEConfigLinDat::writeDB: ICONF not in DB"));
94  return;
95  }
96 
97  try {
98 
99  m_readStmt->setSQL("SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
100  "d.multx12, d.multx6, d.multx1, d.shift12, d.shift6, d.shift1 "
101  "FROM channelview cv JOIN fe_config_lin_dat d "
102  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
103  "WHERE lin_conf_id = :lin_conf_id");
104  m_readStmt->setInt(1, iconfID);
105  ResultSet* rset = m_readStmt->executeQuery();
106 
107  std::pair< EcalLogicID, FEConfigLinDat > p;
108  FEConfigLinDat dat;
109  while(rset->next()) {
110  p.first = EcalLogicID( rset->getString(1), // name
111  rset->getInt(2), // logic_id
112  rset->getInt(3), // id1
113  rset->getInt(4), // id2
114  rset->getInt(5), // id3
115  rset->getString(6)); // maps_to
116 
117  dat.setMultX12( rset->getInt(7) );
118  dat.setMultX6( rset->getInt(8) );
119  dat.setMultX1( rset->getInt(9) );
120  dat.setShift12( rset->getInt(10) );
121  dat.setShift6( rset->getInt(11) );
122  dat.setShift1( rset->getInt(12) );
123 
124  p.second = dat;
125  fillMap->insert(p);
126  }
127  } catch (SQLException &e) {
128  throw(std::runtime_error("FEConfigLinDat::fetchData: "+e.getMessage()));
129  }
130 }
131 
132 void FEConfigLinDat::writeArrayDB(const std::map< EcalLogicID, FEConfigLinDat >* data, FEConfigLinInfo* iconf)
133  throw(std::runtime_error)
134 {
135  this->checkConnection();
136  this->checkPrepare();
137 
138  int iconfID = iconf->fetchID();
139  if (!iconfID) { throw(std::runtime_error("FEConfigLinDat::writeArrayDB: ICONF not in DB")); }
140 
141 
142  int nrows=data->size();
143  int* ids= new int[nrows];
144  int* iconfid_vec= new int[nrows];
145  int* xx= new int[nrows];
146  int* yy= new int[nrows];
147  int* zz= new int[nrows];
148  int* ww= new int[nrows];
149  int* rr= new int[nrows];
150  int* ss= new int[nrows];
151 
152  ub2* ids_len= new ub2[nrows];
153  ub2* iconf_len= new ub2[nrows];
154  ub2* x_len= new ub2[nrows];
155  ub2* y_len= new ub2[nrows];
156  ub2* z_len= new ub2[nrows];
157  ub2* w_len= new ub2[nrows];
158  ub2* r_len= new ub2[nrows];
159  ub2* s_len= new ub2[nrows];
160 
161 
162  const EcalLogicID* channel;
163  const FEConfigLinDat* dataitem;
164  int count=0;
165  typedef map< EcalLogicID, FEConfigLinDat >::const_iterator CI;
166  for (CI p = data->begin(); p != data->end(); ++p) {
167  channel = &(p->first);
168  int logicID = channel->getLogicID();
169  if (!logicID) { throw(std::runtime_error("FEConfigLinDat::writeArrayDB: Bad EcalLogicID")); }
170  ids[count]=logicID;
171  iconfid_vec[count]=iconfID;
172 
173  dataitem = &(p->second);
174  // dataIface.writeDB( channel, dataitem, iconf);
175  int x=dataitem->getMultX12();
176  int y=dataitem->getMultX6();
177  int z=dataitem->getMultX1();
178  int w=dataitem->getShift12();
179  int r=dataitem->getShift6();
180  int s=dataitem->getShift1();
181 
182  xx[count]=x;
183  yy[count]=y;
184  zz[count]=z;
185  ww[count]=w;
186  rr[count]=r;
187  ss[count]=s;
188 
189  ids_len[count]=sizeof(ids[count]);
190  iconf_len[count]=sizeof(iconfid_vec[count]);
191 
192  x_len[count]=sizeof(xx[count]);
193  y_len[count]=sizeof(yy[count]);
194  z_len[count]=sizeof(zz[count]);
195  w_len[count]=sizeof(ww[count]);
196  r_len[count]=sizeof(rr[count]);
197  s_len[count]=sizeof(ss[count]);
198 
199  count++;
200  }
201 
202 
203  try {
204  m_writeStmt->setDataBuffer(1, (dvoid*)iconfid_vec, OCCIINT, sizeof(iconfid_vec[0]),iconf_len);
205  m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len );
206  m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIINT , sizeof(xx[0]), x_len );
207  m_writeStmt->setDataBuffer(4, (dvoid*)yy, OCCIINT , sizeof(yy[0]), y_len );
208  m_writeStmt->setDataBuffer(5, (dvoid*)zz, OCCIINT , sizeof(zz[0]), z_len );
209  m_writeStmt->setDataBuffer(6, (dvoid*)ww, OCCIINT , sizeof(ww[0]), w_len );
210  m_writeStmt->setDataBuffer(7, (dvoid*)rr, OCCIINT , sizeof(rr[0]), r_len );
211  m_writeStmt->setDataBuffer(8, (dvoid*)ss, OCCIINT , sizeof(ss[0]), s_len );
212 
213  m_writeStmt->executeArrayUpdate(nrows);
214 
215  delete [] ids;
216  delete [] iconfid_vec;
217  delete [] xx;
218  delete [] yy;
219  delete [] zz;
220  delete [] ww;
221  delete [] rr;
222  delete [] ss;
223 
224  delete [] ids_len;
225  delete [] iconf_len;
226  delete [] x_len;
227  delete [] y_len;
228  delete [] z_len;
229  delete [] w_len;
230  delete [] r_len;
231  delete [] s_len;
232 
233  } catch (SQLException &e) {
234  throw(std::runtime_error("FEConfigLinDat::writeArrayDB(): "+e.getMessage()));
235  }
236 }
const double w
Definition: UKUtility.cc:23
void writeArrayDB(const std::map< EcalLogicID, FEConfigLinDat > *data, FEConfigLinInfo *iconf)
void setShift12(int x)
void setMultX1(int x)
void fetchData(std::map< EcalLogicID, FEConfigLinDat > *fillMap, FEConfigLinInfo *iconf)
#define NULL
Definition: scimark2.h:8
int getMultX12() const
void setShift6(int x)
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:27
void setShift1(int x)
int getMultX1() const
int getShift6() const
int getShift12() const
int getMultX6() const
int getLogicID() const
Definition: EcalLogicID.cc:41
void writeDB(const EcalLogicID *ecid, const FEConfigLinDat *item, FEConfigLinInfo *iconf)
void setMultX6(int x)
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:26
void setMultX12(int x)
int getShift1() const