CMS 3D CMS Logo

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  m_env = nullptr;
13  m_conn = nullptr;
14  m_writeStmt = nullptr;
15  m_readStmt = nullptr;
16  m_ID = 0;
17  m_pedMeanG1 = 0;
18  m_pedMeanG6 = 0;
19  m_pedMeanG12 = 0;
20 }
21 
23 
25  this->checkConnection();
26 
27  try {
28  m_writeStmt = m_conn->createStatement();
29 
30  m_writeStmt->setSQL("INSERT INTO " + getTable() +
31  " (ped_conf_id, logic_id, "
32  "mean_12, mean_6, mean_1 ) "
33  "VALUES (:ped_conf_id, :logic_id, "
34  ":ped_mean_g12, :ped_mean_g6, :ped_mean_g1 )");
35  } catch (SQLException& e) {
36  throw(std::runtime_error("FEConfigPedDat::prepareWrite(): " + e.getMessage()));
37  }
38 }
39 
41  const FEConfigPedDat* item,
42  FEConfigPedInfo* iconf) noexcept(false) {
43  this->checkConnection();
44 
45  int iconfID = iconf->fetchID();
46  if (!iconfID) {
47  throw(std::runtime_error("FEConfigPedDat::writeDB: ICONF not in DB"));
48  }
49 
50  int logicID = ecid->getLogicID();
51  if (!logicID) {
52  throw(std::runtime_error("FEConfigPedDat::writeDB: Bad EcalLogicID"));
53  }
54 
55  try {
56  m_writeStmt->setInt(1, iconfID);
57  m_writeStmt->setInt(2, logicID);
58  m_writeStmt->setFloat(3, item->getPedMeanG12());
59  m_writeStmt->setFloat(4, item->getPedMeanG6());
60  m_writeStmt->setFloat(5, item->getPedMeanG1());
61 
62  m_writeStmt->executeUpdate();
63  } catch (SQLException& e) {
64  throw(std::runtime_error("FEConfigPedDat::writeDB(): " + e.getMessage()));
65  }
66 }
67 
68 void FEConfigPedDat::fetchData(map<EcalLogicID, FEConfigPedDat>* fillMap, FEConfigPedInfo* iconf) noexcept(false) {
69  this->checkConnection();
70  fillMap->clear();
71 
72  iconf->setConnection(m_env, m_conn);
73  int iconfID = iconf->fetchID();
74  if (!iconfID) {
75  // throw(std::runtime_error("FEConfigPedDat::writeDB: ICONF not in DB"));
76  return;
77  }
78 
79  try {
80  m_readStmt->setSQL(
81  "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
82  "d.mean_12, d.mean_6, d.mean_1 "
83  "FROM channelview cv JOIN fe_config_ped_dat d "
84  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
85  "WHERE ped_conf_id = :ped_conf_id");
86  m_readStmt->setInt(1, iconfID);
87  ResultSet* rset = m_readStmt->executeQuery();
88 
89  std::pair<EcalLogicID, FEConfigPedDat> p;
90  FEConfigPedDat dat;
91  while (rset->next()) {
92  p.first = EcalLogicID(rset->getString(1), // name
93  rset->getInt(2), // logic_id
94  rset->getInt(3), // id1
95  rset->getInt(4), // id2
96  rset->getInt(5), // id3
97  rset->getString(6)); // maps_to
98 
99  dat.setPedMeanG12(rset->getFloat(7));
100  dat.setPedMeanG6(rset->getFloat(8));
101  dat.setPedMeanG1(rset->getFloat(9));
102 
103  p.second = dat;
104  fillMap->insert(p);
105  }
106  } catch (SQLException& e) {
107  throw(std::runtime_error("FEConfigPedDat::fetchData: " + e.getMessage()));
108  }
109 }
110 
111 void FEConfigPedDat::writeArrayDB(const std::map<EcalLogicID, FEConfigPedDat>* data,
112  FEConfigPedInfo* iconf) noexcept(false) {
113  this->checkConnection();
114  this->checkPrepare();
115 
116  int iconfID = iconf->fetchID();
117  if (!iconfID) {
118  throw(std::runtime_error("FEConfigPedDat::writeArrayDB: ICONF not in DB"));
119  }
120 
121  int nrows = data->size();
122  int* ids = new int[nrows];
123  int* iconfid_vec = new int[nrows];
124  float* xx = new float[nrows];
125  float* yy = new float[nrows];
126  float* zz = new float[nrows];
127 
128  ub2* ids_len = new ub2[nrows];
129  ub2* iconf_len = new ub2[nrows];
130  ub2* x_len = new ub2[nrows];
131  ub2* y_len = new ub2[nrows];
132  ub2* z_len = new ub2[nrows];
133 
134  const EcalLogicID* channel;
135  const FEConfigPedDat* dataitem;
136  int count = 0;
137  typedef map<EcalLogicID, FEConfigPedDat>::const_iterator CI;
138  for (CI p = data->begin(); p != data->end(); ++p) {
139  channel = &(p->first);
140  int logicID = channel->getLogicID();
141  if (!logicID) {
142  throw(std::runtime_error("FEConfigPedDat::writeArrayDB: Bad EcalLogicID"));
143  }
144  ids[count] = logicID;
145  iconfid_vec[count] = iconfID;
146 
147  dataitem = &(p->second);
148  // dataIface.writeDB( channel, dataitem, iconf);
149  float x = dataitem->getPedMeanG12();
150  float y = dataitem->getPedMeanG6();
151  float z = dataitem->getPedMeanG1();
152 
153  xx[count] = x;
154  yy[count] = y;
155  zz[count] = z;
156 
157  ids_len[count] = sizeof(ids[count]);
158  iconf_len[count] = sizeof(iconfid_vec[count]);
159 
160  x_len[count] = sizeof(xx[count]);
161  y_len[count] = sizeof(yy[count]);
162  z_len[count] = sizeof(zz[count]);
163 
164  count++;
165  }
166 
167  try {
168  m_writeStmt->setDataBuffer(1, (dvoid*)iconfid_vec, OCCIINT, sizeof(iconfid_vec[0]), iconf_len);
169  m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len);
170  m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIFLOAT, sizeof(xx[0]), x_len);
171  m_writeStmt->setDataBuffer(4, (dvoid*)yy, OCCIFLOAT, sizeof(yy[0]), y_len);
172  m_writeStmt->setDataBuffer(5, (dvoid*)zz, OCCIFLOAT, sizeof(zz[0]), z_len);
173 
174  m_writeStmt->executeArrayUpdate(nrows);
175 
176  delete[] ids;
177  delete[] iconfid_vec;
178  delete[] xx;
179  delete[] yy;
180  delete[] zz;
181 
182  delete[] ids_len;
183  delete[] iconf_len;
184  delete[] x_len;
185  delete[] y_len;
186  delete[] z_len;
187 
188  } catch (SQLException& e) {
189  throw(std::runtime_error("FEConfigPedDat::writeArrayDB(): " + e.getMessage()));
190  }
191 }
DDAxes::y
geometryCSVtoXML.zz
zz
Definition: geometryCSVtoXML.py:19
funct::false
false
Definition: Factorize.h:29
FEConfigPedDat::setPedMeanG6
void setPedMeanG6(float mean)
Definition: FEConfigPedDat.h:26
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
FEConfigPedDat::writeDB
void writeDB(const EcalLogicID *ecid, const FEConfigPedDat *item, FEConfigPedInfo *iconf) noexcept(false)
Definition: FEConfigPedDat.cc:40
FEConfigPedDat::getPedMeanG12
float getPedMeanG12() const
Definition: FEConfigPedDat.h:30
FEConfigPedInfo.h
DDAxes::x
FEConfigPedDat::setPedMeanG1
void setPedMeanG1(float mean)
Definition: FEConfigPedDat.h:23
FEConfigPedDat.h
EcalLogicID::getLogicID
int getLogicID() const
Definition: EcalLogicID.cc:28
FEConfigPedDat::~FEConfigPedDat
~FEConfigPedDat() override
Definition: FEConfigPedDat.cc:22
oracle::occi
Definition: ConnectionManager.h:7
FEConfigPedDat::getPedMeanG1
float getPedMeanG1() const
Definition: FEConfigPedDat.h:24
DDAxes::z
EcalLogicID
Definition: EcalLogicID.h:7
submitPVResolutionJobs.count
count
Definition: submitPVResolutionJobs.py:352
FEConfigPedDat::getPedMeanG6
float getPedMeanG6() const
Definition: FEConfigPedDat.h:27
FEConfigPedDat::fetchData
void fetchData(std::map< EcalLogicID, FEConfigPedDat > *fillMap, FEConfigPedInfo *iconf) noexcept(false)
Definition: FEConfigPedDat.cc:68
geometryCSVtoXML.yy
yy
Definition: geometryCSVtoXML.py:19
FEConfigPedDat
Definition: FEConfigPedDat.h:11
B2GTnPMonitor_cfi.item
item
Definition: B2GTnPMonitor_cfi.py:147
FEConfigPedDat::writeArrayDB
void writeArrayDB(const std::map< EcalLogicID, FEConfigPedDat > *data, FEConfigPedInfo *iconf) noexcept(false)
Definition: FEConfigPedDat.cc:111
std
Definition: JetResolutionObject.h:76
FEConfigPedDat::prepareWrite
void prepareWrite() noexcept(false) override
Definition: FEConfigPedDat.cc:24
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
Oracle.h
FEConfigPedDat::setPedMeanG12
void setPedMeanG12(float mean)
Definition: FEConfigPedDat.h:29
FEConfigPedInfo
Definition: FEConfigPedInfo.h:11
FEConfigPedDat::FEConfigPedDat
FEConfigPedDat()
Definition: FEConfigPedDat.cc:11
geometryCSVtoXML.xx
xx
Definition: geometryCSVtoXML.py:19
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37