CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CaliCrystalIntercalDat.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 
18  m_cali = 0;
19  m_caliRMS = 0;
20  m_numEvents = 0;
21  m_taskStatus = false;
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 cali_crystal_intercal_dat (iov_id, logic_id, "
40  "cali, cali_rms, num_events, task_status) "
41  "VALUES (:iov_id, :logic_id, "
42  ":3, :4, :5, :6)");
43  } catch (SQLException &e) {
44  throw(std::runtime_error("CaliCrystalIntercalDat::prepareWrite(): "+e.getMessage()));
45  }
46 }
47 
48 
49 
51  throw(std::runtime_error)
52 {
53  this->checkConnection();
54  this->checkPrepare();
55 
56  int iovID = iov->fetchID();
57  if (!iovID) { throw(std::runtime_error("CaliCrystalIntercalDat::writeDB: IOV not in DB")); }
58 
59  int logicID = ecid->getLogicID();
60  if (!logicID) { throw(std::runtime_error("CaliCrystalIntercalDat::writeDB: Bad EcalLogicID")); }
61 
62  try {
63  m_writeStmt->setInt(1, iovID);
64  m_writeStmt->setInt(2, logicID);
65 
66  m_writeStmt->setFloat(3, item->getCali() );
67  m_writeStmt->setFloat(4, item->getCaliRMS() );
68  m_writeStmt->setInt(5, item->getNumEvents() );
69  m_writeStmt->setInt(6, item->getTaskStatus() );
70 
71  m_writeStmt->executeUpdate();
72  } catch (SQLException &e) {
73  throw(std::runtime_error("CaliCrystalIntercalDat::writeDB(): "+e.getMessage()));
74  }
75 }
76 
77 
78 
79 void CaliCrystalIntercalDat::fetchData(std::map< EcalLogicID, CaliCrystalIntercalDat >* fillMap, CaliIOV* iov)
80  throw(std::runtime_error)
81 {
82  this->checkConnection();
83  fillMap->clear();
84 
85  iov->setConnection(m_env, m_conn);
86  int iovID = iov->fetchID();
87  if (!iovID) {
88  // throw(std::runtime_error("CaliCrystalIntercalDat::writeDB: IOV not in DB"));
89  return;
90  }
91 
92  try {
93 
94  m_readStmt->setSQL("SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
95  "d.cali, d.cali_rms, d.num_events, d.task_status "
96  "FROM channelview cv JOIN cali_crystal_intercal_dat d "
97  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
98  "WHERE d.iov_id = :iov_id");
99  m_readStmt->setInt(1, iovID);
100  ResultSet* rset = m_readStmt->executeQuery();
101 
102  std::pair< EcalLogicID, CaliCrystalIntercalDat > p;
104  while(rset->next()) {
105  p.first = EcalLogicID( rset->getString(1), // name
106  rset->getInt(2), // logic_id
107  rset->getInt(3), // id1
108  rset->getInt(4), // id2
109  rset->getInt(5), // id3
110  rset->getString(6)); // maps_to
111 
112  dat.setCali( rset->getFloat(7) );
113  dat.setCaliRMS( rset->getFloat(8) );
114  dat.setNumEvents( rset->getInt(9) );
115  dat.setTaskStatus( rset->getInt(10) );
116 
117  p.second = dat;
118  fillMap->insert(p);
119  }
120  } catch (SQLException &e) {
121  throw(std::runtime_error("CaliCrystalIntercalDat::fetchData(): "+e.getMessage()));
122  }
123 }
124 
125 void CaliCrystalIntercalDat::writeArrayDB(const std::map< EcalLogicID, CaliCrystalIntercalDat >* data, CaliIOV* iov)
126  throw(std::runtime_error)
127 {
128  this->checkConnection();
129  this->checkPrepare();
130 
131  int iovID = iov->fetchID();
132  if (!iovID) { throw(std::runtime_error("CaliCrystalIntercalDat::writeArrayDB: IOV not in DB")); }
133 
134 
135  int nrows=data->size();
136  int* ids= new int[nrows];
137  int* iovid_vec= new int[nrows];
138  float* xx= new float[nrows];
139  float* yy= new float[nrows];
140  int* tt= new int[nrows];
141  int* st= new int[nrows];
142 
143  ub2* ids_len= new ub2[nrows];
144  ub2* iov_len= new ub2[nrows];
145  ub2* x_len= new ub2[nrows];
146  ub2* y_len= new ub2[nrows];
147  ub2* tt_len= new ub2[nrows];
148  ub2* st_len= new ub2[nrows];
149 
150  const EcalLogicID* channel;
151  const CaliCrystalIntercalDat* dataitem;
152  int count=0;
153  typedef map< EcalLogicID, CaliCrystalIntercalDat >::const_iterator CI;
154  for (CI p = data->begin(); p != data->end(); ++p) {
155  channel = &(p->first);
156  int logicID = channel->getLogicID();
157  if (!logicID) { throw(std::runtime_error("CaliCrystalIntercalDat::writeArrayDB: Bad EcalLogicID")); }
158  ids[count]=logicID;
159  iovid_vec[count]=iovID;
160 
161  dataitem = &(p->second);
162  // dataIface.writeDB( channel, dataitem, iov);
163  float x=dataitem->getCali();
164  float y=dataitem->getCaliRMS();
165  int xtt=dataitem->getNumEvents();
166  int statu=dataitem->getTaskStatus();
167 
168 
169 
170  xx[count]=x;
171  yy[count]=y;
172  tt[count]=xtt;
173  st[count]=statu;
174 
175 
176  ids_len[count]=sizeof(ids[count]);
177  iov_len[count]=sizeof(iovid_vec[count]);
178 
179  x_len[count]=sizeof(xx[count]);
180  y_len[count]=sizeof(yy[count]);
181  tt_len[count]=sizeof(tt[count]);
182  st_len[count]=sizeof(st[count]);
183 
184  count++;
185  }
186 
187 
188  try {
189  m_writeStmt->setDataBuffer(1, (dvoid*)iovid_vec, OCCIINT, sizeof(iovid_vec[0]),iov_len);
190  m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len );
191  m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIFLOAT , sizeof(xx[0]), x_len );
192  m_writeStmt->setDataBuffer(4, (dvoid*)yy, OCCIFLOAT , sizeof(yy[0]), y_len );
193  m_writeStmt->setDataBuffer(5, (dvoid*)tt, OCCIINT , sizeof(tt[0]), tt_len );
194  m_writeStmt->setDataBuffer(6, (dvoid*)st, OCCIINT , sizeof(st[0]), st_len );
195 
196 
197  m_writeStmt->executeArrayUpdate(nrows);
198 
199  delete [] ids;
200  delete [] iovid_vec;
201  delete [] xx;
202  delete [] yy;
203  delete [] st;
204  delete [] tt;
205 
206  delete [] ids_len;
207  delete [] iov_len;
208  delete [] x_len;
209  delete [] y_len;
210  delete [] tt_len;
211  delete [] st_len;
212 
213 
214 
215  } catch (SQLException &e) {
216  throw(std::runtime_error("MonPedestalsDat::writeArrayDB(): "+e.getMessage()));
217  }
218 }
void fetchData(std::map< EcalLogicID, CaliCrystalIntercalDat > *fillVec, CaliIOV *iov)
#define NULL
Definition: scimark2.h:8
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:22
tuple iov
Definition: o2o.py:307
int getLogicID() const
Definition: EcalLogicID.cc:42
void writeArrayDB(const std::map< EcalLogicID, CaliCrystalIntercalDat > *data, CaliIOV *iov)
void writeDB(const EcalLogicID *ecid, const CaliCrystalIntercalDat *item, CaliIOV *iov)
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:21
Definition: DDAxes.h:10
void fillMap(Registry *reg, regmap_type &fillme)
Definition: Registry.cc:24