CMS 3D CMS Logo

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