test
CMS 3D CMS Logo

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