CMS 3D CMS Logo

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