CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FEConfigFgrEEStripDat.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_thresh = 0;
19  m_lut_fg = 0;
20 
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 "+getTable()+" (fgr_conf_id, logic_id, "
39  "threshold, lut_fg ) "
40  "VALUES (:fgr_conf_id, :logic_id, "
41  ":threshold, :lut_fg )" );
42  } catch (SQLException &e) {
43  throw(std::runtime_error("FEConfigFgrEEStripDat::prepareWrite(): "+e.getMessage()));
44  }
45 }
46 
47 
48 
50  throw(std::runtime_error)
51 {
52  this->checkConnection();
53  this->checkPrepare();
54 
55  int iconfID = iconf->fetchID();
56  if (!iconfID) { throw(std::runtime_error("FEConfigFgrEEStripDat::writeDB: ICONF not in DB")); }
57 
58  int logicID = ecid->getLogicID();
59  if (!logicID) { throw(std::runtime_error("FEConfigFgrEEStripDat::writeDB: Bad EcalLogicID")); }
60 
61  try {
62  m_writeStmt->setInt(1, iconfID);
63  m_writeStmt->setInt(2, logicID);
64  m_writeStmt->setUInt(3, item->getThreshold());
65  m_writeStmt->setUInt(4, item->getLutFg());
66 
67  m_writeStmt->executeUpdate();
68  } catch (SQLException &e) {
69  throw(std::runtime_error("FEConfigFgrEEStripDat::writeDB(): "+e.getMessage()));
70  }
71 }
72 
73 
74 
75 void FEConfigFgrEEStripDat::fetchData(map< EcalLogicID, FEConfigFgrEEStripDat >* fillMap, FEConfigFgrInfo* iconf)
76  throw(std::runtime_error)
77 {
78  this->checkConnection();
79  fillMap->clear();
80 
81  iconf->setConnection(m_env, m_conn);
82  int iconfID = iconf->fetchID();
83  if (!iconfID) {
84  // throw(std::runtime_error("FEConfigFgrEEStripDat::writeDB: ICONF not in DB"));
85  return;
86  }
87 
88  try {
89 
90  m_readStmt->setSQL("SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
91  "d.threshold, d.lut_fg "
92  "FROM channelview cv JOIN "+getTable()+" d "
93  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
94  "WHERE fgr_conf_id = :fgr_conf_id");
95  m_readStmt->setInt(1, iconfID);
96  ResultSet* rset = m_readStmt->executeQuery();
97 
98  std::pair< EcalLogicID, FEConfigFgrEEStripDat > p;
100  while(rset->next()) {
101  p.first = EcalLogicID( rset->getString(1), // name
102  rset->getInt(2), // logic_id
103  rset->getInt(3), // id1
104  rset->getInt(4), // id2
105  rset->getInt(5), // id3
106  rset->getString(6)); // maps_to
107 
108  dat.setThreshold( rset->getUInt(7) );
109  dat.setLutFg( rset->getUInt(8) );
110 
111  p.second = dat;
112  fillMap->insert(p);
113  }
114  } catch (SQLException &e) {
115  throw(std::runtime_error("FEConfigFgrEEStripDat::fetchData: "+e.getMessage()));
116  }
117 }
118 
119 void FEConfigFgrEEStripDat::writeArrayDB(const std::map< EcalLogicID, FEConfigFgrEEStripDat >* data, FEConfigFgrInfo* iconf)
120  throw(std::runtime_error)
121 {
122  this->checkConnection();
123  this->checkPrepare();
124 
125  int iconfID = iconf->fetchID();
126  if (!iconfID) { throw(std::runtime_error("FEConfigFgrEEStripDat::writeArrayDB: ICONF not in DB")); }
127 
128 
129  int nrows=data->size();
130  int* ids= new int[nrows];
131  int* iconfid_vec= new int[nrows];
132  unsigned int* xx= new unsigned int[nrows];
133  unsigned int* yy= new unsigned int[nrows];
134 
135 
136  ub2* ids_len= new ub2[nrows];
137  ub2* iconf_len= new ub2[nrows];
138  ub2* x_len= new ub2[nrows];
139  ub2* y_len= new ub2[nrows];
140 
141 
142  const EcalLogicID* channel;
143  const FEConfigFgrEEStripDat* dataitem;
144  int count=0;
145  typedef map< EcalLogicID, FEConfigFgrEEStripDat >::const_iterator CI;
146  for (CI p = data->begin(); p != data->end(); ++p) {
147  channel = &(p->first);
148  int logicID = channel->getLogicID();
149  if (!logicID) { throw(std::runtime_error("FEConfigFgrEEStripDat::writeArrayDB: Bad EcalLogicID")); }
150  ids[count]=logicID;
151  iconfid_vec[count]=iconfID;
152 
153  dataitem = &(p->second);
154  // dataIface.writeDB( channel, dataitem, iconf);
155  unsigned int x=dataitem->getThreshold();
156  unsigned int y=dataitem->getLutFg();
157 
158  xx[count]=x;
159  yy[count]=y;
160 
161 
162  ids_len[count]=sizeof(ids[count]);
163  iconf_len[count]=sizeof(iconfid_vec[count]);
164 
165  x_len[count]=sizeof(xx[count]);
166  y_len[count]=sizeof(yy[count]);
167 
168  count++;
169  }
170 
171 
172  try {
173  m_writeStmt->setDataBuffer(1, (dvoid*)iconfid_vec, OCCIINT, sizeof(iconfid_vec[0]),iconf_len);
174  m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len );
175  m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIUNSIGNED_INT , sizeof(xx[0]), x_len );
176  m_writeStmt->setDataBuffer(4, (dvoid*)yy, OCCIUNSIGNED_INT , sizeof(yy[0]), y_len );
177 
178  m_writeStmt->executeArrayUpdate(nrows);
179 
180  delete [] ids;
181  delete [] iconfid_vec;
182  delete [] xx;
183  delete [] yy;
184 
185  delete [] ids_len;
186  delete [] iconf_len;
187  delete [] x_len;
188  delete [] y_len;
189 
190  } catch (SQLException &e) {
191  throw(std::runtime_error("FEConfigFgrEEStripDat::writeArrayDB(): "+e.getMessage()));
192  }
193 }
#define NULL
Definition: scimark2.h:8
unsigned int getThreshold() const
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:22
void setThreshold(unsigned int mean)
void writeArrayDB(const std::map< EcalLogicID, FEConfigFgrEEStripDat > *data, FEConfigFgrInfo *iconf)
void fetchData(std::map< EcalLogicID, FEConfigFgrEEStripDat > *fillMap, FEConfigFgrInfo *iconf)
void setLutFg(unsigned int mean)
int getLogicID() const
Definition: EcalLogicID.cc:42
unsigned int getLutFg() const
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:21
void writeDB(const EcalLogicID *ecid, const FEConfigFgrEEStripDat *item, FEConfigFgrInfo *iconf)
void fillMap(Registry *reg, regmap_type &fillme)
Definition: Registry.cc:24