test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FEConfigLUTParamDat.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_etsat = 0;
19  m_tthreshlow = 0;
20  m_tthreshhigh = 0;
21 
22 }
23 
24 
25 
27 {
28 }
29 
30 
31 
33  throw(std::runtime_error)
34 {
35  this->checkConnection();
36 
37  try {
38  m_writeStmt = m_conn->createStatement();
39  m_writeStmt->setSQL("INSERT INTO "+getTable()+" (lut_conf_id, logic_id, "
40  " etsat, ttthreshlow, ttthreshhigh ) "
41  "VALUES (:lut_conf_id, :logic_id, "
42  ":etsat, :ttthreshlow, :ttthreshhigh )" );
43  } catch (SQLException &e) {
44  throw(std::runtime_error("FEConfigLUTParamDat::prepareWrite(): "+e.getMessage()));
45  }
46 }
47 
48 
49 
51  throw(std::runtime_error)
52 {
53  this->checkConnection();
54  this->checkPrepare();
55 
56  int iconfID = iconf->fetchID();
57  if (!iconfID) { throw(std::runtime_error("FEConfigLUTParamDat::writeDB: ICONF not in DB")); }
58 
59  int logicID = ecid->getLogicID();
60  if (!logicID) { throw(std::runtime_error("FEConfigLUTParamDat::writeDB: Bad EcalLogicID")); }
61 
62  try {
63  m_writeStmt->setInt(1, iconfID);
64  m_writeStmt->setInt(2, logicID);
65  m_writeStmt->setFloat(3, item->getETSat());
66  m_writeStmt->setFloat(4, item->getTTThreshlow());
67  m_writeStmt->setFloat(5, item->getTTThreshhigh());
68 
69  m_writeStmt->executeUpdate();
70  } catch (SQLException &e) {
71  throw(std::runtime_error("FEConfigLUTParamDat::writeDB(): "+e.getMessage()));
72  }
73 }
74 
75 
76 
77 void FEConfigLUTParamDat::fetchData(map< EcalLogicID, FEConfigLUTParamDat >* fillMap, FEConfigLUTInfo* iconf)
78  throw(std::runtime_error)
79 {
80  this->checkConnection();
81  fillMap->clear();
82 
83  iconf->setConnection(m_env, m_conn);
84  int iconfID = iconf->fetchID();
85  if (!iconfID) {
86  // throw(std::runtime_error("FEConfigLUTParamDat::writeDB: ICONF 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.etsat, d.ttthreshlow, d.ttthreshhigh "
94  "FROM channelview cv JOIN "+getTable()+" d "
95  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
96  "WHERE lut_conf_id = :lut_conf_id");
97  m_readStmt->setInt(1, iconfID);
98  ResultSet* rset = m_readStmt->executeQuery();
99 
100  std::pair< EcalLogicID, FEConfigLUTParamDat > p;
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 
111 
112  dat.setETSat( rset->getFloat(7) );
113  dat.setTTThreshlow( rset->getFloat(8) );
114  dat.setTTThreshhigh( rset->getFloat(9) );
115 
116  p.second = dat;
117  fillMap->insert(p);
118  }
119  } catch (SQLException &e) {
120  throw(std::runtime_error("FEConfigLUTParamDat::fetchData: "+e.getMessage()));
121  }
122 }
123 
124 void FEConfigLUTParamDat::writeArrayDB(const std::map< EcalLogicID, FEConfigLUTParamDat >* data, FEConfigLUTInfo* iconf)
125  throw(std::runtime_error)
126 {
127  this->checkConnection();
128  this->checkPrepare();
129 
130  int iconfID = iconf->fetchID();
131  if (!iconfID) { throw(std::runtime_error("FEConfigLUTParamDat::writeArrayDB: ICONF not in DB")); }
132 
133 
134  int nrows=data->size();
135  int* ids= new int[nrows];
136  int* iov_vec= new int[nrows];
137  float* xx= new float[nrows];
138  float* yy= new float[nrows];
139  float* zz= new float[nrows];
140 
141 
142  ub2* ids_len= new ub2[nrows];
143  ub2* iov_len= new ub2[nrows];
144  ub2* x_len= new ub2[nrows];
145  ub2* y_len= new ub2[nrows];
146  ub2* z_len= new ub2[nrows];
147 
148 
149  const EcalLogicID* channel;
150  const FEConfigLUTParamDat* dataitem;
151  int count=0;
152  typedef map< EcalLogicID, FEConfigLUTParamDat >::const_iterator CI;
153  for (CI p = data->begin(); p != data->end(); ++p) {
154  channel = &(p->first);
155  int logicID = channel->getLogicID();
156  if (!logicID) { throw(std::runtime_error("FEConfigLUTParamDat::writeArrayDB: Bad EcalLogicID")); }
157  ids[count]=logicID;
158  iov_vec[count]=iconfID;
159 
160  dataitem = &(p->second);
161  // dataIface.writeDB( channel, dataitem, conf);
162  float x=dataitem->getETSat();
163  float y=dataitem->getTTThreshlow();
164  float z=dataitem->getTTThreshhigh();
165 
166  xx[count]=x;
167  yy[count]=y;
168  zz[count]=z;
169 
170 
171  ids_len[count]=sizeof(ids[count]);
172  iov_len[count]=sizeof(iov_vec[count]);
173 
174  x_len[count]=sizeof(xx[count]);
175  y_len[count]=sizeof(yy[count]);
176  z_len[count]=sizeof(zz[count]);
177 
178  count++;
179  }
180 
181 
182  try {
183  m_writeStmt->setDataBuffer(1, (dvoid*)iov_vec, OCCIINT, sizeof(iov_vec[0]),iov_len);
184  m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len );
185  m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIFLOAT , sizeof(xx[0]), x_len );
186  m_writeStmt->setDataBuffer(4, (dvoid*)yy, OCCIFLOAT , sizeof(yy[0]), y_len );
187  m_writeStmt->setDataBuffer(5, (dvoid*)zz, OCCIFLOAT , sizeof(zz[0]), z_len );
188 
189  m_writeStmt->executeArrayUpdate(nrows);
190 
191  delete [] ids;
192  delete [] iov_vec;
193  delete [] xx;
194  delete [] yy;
195  delete [] zz;
196 
197  delete [] ids_len;
198  delete [] iov_len;
199  delete [] x_len;
200  delete [] y_len;
201  delete [] z_len;
202 
203  } catch (SQLException &e) {
204  throw(std::runtime_error("FEConfigLUTParamDat::writeArrayDB(): "+e.getMessage()));
205  }
206 }
#define NULL
Definition: scimark2.h:8
float getTTThreshhigh() const
void fetchData(std::map< EcalLogicID, FEConfigLUTParamDat > *fillMap, FEConfigLUTInfo *iconf)
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:27
void writeArrayDB(const std::map< EcalLogicID, FEConfigLUTParamDat > *data, FEConfigLUTInfo *iconf)
float getTTThreshlow() const
int getLogicID() const
Definition: EcalLogicID.cc:41
void writeDB(const EcalLogicID *ecid, const FEConfigLUTParamDat *item, FEConfigLUTInfo *iconf)
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:26
void setTTThreshhigh(float x)
void setTTThreshlow(float x)