CMS 3D CMS Logo

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