CMS 3D CMS Logo

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