CMS 3D CMS Logo

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