CMS 3D CMS Logo

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