CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DCUIDarkPedDat.cc
Go to the documentation of this file.
1 #include <stdexcept>
2 #include <string>
4 
8 
9 using namespace std;
10 using namespace oracle::occi;
11 
13 {
14  m_env = NULL;
15  m_conn = NULL;
16  m_writeStmt = NULL;
17  m_readStmt = NULL;
18 
19  m_ped = 0;
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 dcu_idark_ped_dat (iov_id, logic_id, "
38  "ped) "
39  "VALUES (:iov_id, :logic_id, "
40  ":ped)");
41  } catch (SQLException &e) {
42  throw(std::runtime_error("DCUIDarkPedDat::prepareWrite(): "+e.getMessage()));
43  }
44 }
45 
46 
47 
49  throw(std::runtime_error)
50 {
51  this->checkConnection();
52  this->checkPrepare();
53 
54  int iovID = iov->fetchID();
55  if (!iovID) { throw(std::runtime_error("DCUIDarkPedDat::writeDB: IOV not in DB")); }
56 
57  int logicID = ecid->getLogicID();
58  if (!logicID) { throw(std::runtime_error("DCUIDarkPedDat::writeDB: Bad EcalLogicID")); }
59 
60  try {
61  m_writeStmt->setInt(1, iovID);
62  m_writeStmt->setInt(2, logicID);
63 
64  m_writeStmt->setFloat(3, item->getPed() );
65 
66  m_writeStmt->executeUpdate();
67  } catch (SQLException &e) {
68  throw(std::runtime_error("DCUIDarkPedDat::writeDB(): "+e.getMessage()));
69  }
70 }
71 
72 
73 
74 void DCUIDarkPedDat::fetchData(std::map< EcalLogicID, DCUIDarkPedDat >* fillMap, DCUIOV* iov)
75  throw(std::runtime_error)
76 {
77  this->checkConnection();
78  fillMap->clear();
79 
80  iov->setConnection(m_env, m_conn);
81  int iovID = iov->fetchID();
82  if (!iovID) {
83  // throw(std::runtime_error("DCUIDarkPedDat::writeDB: IOV not in DB"));
84  return;
85  }
86 
87  try {
88 
89  m_readStmt->setSQL("SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
90  "d.ped "
91  "FROM channelview cv JOIN dcu_idark_ped_dat d "
92  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
93  "WHERE d.iov_id = :iov_id");
94  m_readStmt->setInt(1, iovID);
95  ResultSet* rset = m_readStmt->executeQuery();
96 
97  std::pair< EcalLogicID, DCUIDarkPedDat > p;
98  DCUIDarkPedDat dat;
99  while(rset->next()) {
100  p.first = EcalLogicID( rset->getString(1), // name
101  rset->getInt(2), // logic_id
102  rset->getInt(3), // id1
103  rset->getInt(4), // id2
104  rset->getInt(5), // id3
105  rset->getString(6)); // maps_to
106 
107  dat.setPed( rset->getFloat(7) );
108 
109  p.second = dat;
110  fillMap->insert(p);
111  }
112  } catch (SQLException &e) {
113  throw(std::runtime_error("DCUIDarkPedDat::fetchData(): "+e.getMessage()));
114  }
115 }
116 void DCUIDarkPedDat::writeArrayDB(const std::map< EcalLogicID, DCUIDarkPedDat >* data, DCUIOV* iov)
117  throw(std::runtime_error)
118 {
119  this->checkConnection();
120  this->checkPrepare();
121 
122  int iovID = iov->fetchID();
123  if (!iovID) { throw(std::runtime_error("DCUIDarkPedDat::writeArrayDB: IOV not in DB")); }
124 
125 
126  int nrows=data->size();
127  int* ids= new int[nrows];
128  int* iovid_vec= new int[nrows];
129  float* xx= new float[nrows];
130 
131  ub2* ids_len= new ub2[nrows];
132  ub2* iov_len= new ub2[nrows];
133  ub2* x_len= new ub2[nrows];
134 
135  const EcalLogicID* channel;
136  const DCUIDarkPedDat* dataitem;
137  int count=0;
138  typedef map< EcalLogicID, DCUIDarkPedDat >::const_iterator CI;
139  for (CI p = data->begin(); p != data->end(); ++p) {
140  channel = &(p->first);
141  int logicID = channel->getLogicID();
142  if (!logicID) { throw(std::runtime_error("DCUIDarkPedDat::writeArrayDB: Bad EcalLogicID")); }
143  ids[count]=logicID;
144  iovid_vec[count]=iovID;
145 
146  dataitem = &(p->second);
147  // dataIface.writeDB( channel, dataitem, iov);
148  float x=dataitem->getPed();
149 
150  xx[count]=x;
151 
152 
153  ids_len[count]=sizeof(ids[count]);
154  iov_len[count]=sizeof(iovid_vec[count]);
155 
156  x_len[count]=sizeof(xx[count]);
157 
158 
159  count++;
160  }
161 
162 
163  try {
164  m_writeStmt->setDataBuffer(1, (dvoid*)iovid_vec, OCCIINT, sizeof(iovid_vec[0]),iov_len);
165  m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len );
166  m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIFLOAT , sizeof(xx[0]), x_len );
167 
168 
169  m_writeStmt->executeArrayUpdate(nrows);
170 
171  delete [] ids;
172  delete [] iovid_vec;
173  delete [] xx;
174 
175  delete [] ids_len;
176  delete [] iov_len;
177  delete [] x_len;
178 
179 
180  } catch (SQLException &e) {
181  throw(std::runtime_error("DCUIDarkPedDat::writeArrayDB(): "+e.getMessage()));
182  }
183 }
void fetchData(std::map< EcalLogicID, DCUIDarkPedDat > *fillVec, DCUIOV *iov)
#define NULL
Definition: scimark2.h:8
void writeArrayDB(const std::map< EcalLogicID, DCUIDarkPedDat > *data, DCUIOV *iov)
Definition: DCUIOV.h:13
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:22
tuple iov
Definition: o2o.py:307
void setPed(float temp)
void writeDB(const EcalLogicID *ecid, const DCUIDarkPedDat *item, DCUIOV *iov)
int getLogicID() const
Definition: EcalLogicID.cc:42
float getPed() const
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:21
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
void fillMap(Registry *reg, regmap_type &fillme)
Definition: Registry.cc:24
x
Definition: VDTMath.h:216