CMS 3D CMS Logo

FEConfigOddWeightInfo.cc
Go to the documentation of this file.
1 #include <stdexcept>
2 #include <string>
3 #include <cstring>
5 #include <cstdlib>
9 
10 using namespace std;
11 using namespace oracle::occi;
12 
14  m_env = nullptr;
15  m_conn = nullptr;
16  m_writeStmt = nullptr;
17  m_readStmt = nullptr;
18  m_config_tag = "";
19  m_version = 0;
20  m_ID = 0;
21  clear();
22 }
23 
24 void FEConfigOddWeightInfo::clear() { m_ngr = 0; }
25 
27 
29  int result = 0;
30  try {
31  this->checkConnection();
32 
33  m_readStmt = m_conn->createStatement();
34  m_readStmt->setSQL("select FE_CONFIG_WEIGHT2GROUP_SQ.NextVal from DUAL ");
35  ResultSet* rset = m_readStmt->executeQuery();
36  while (rset->next()) {
37  result = rset->getInt(1);
38  }
39  result++;
40  m_conn->terminateStatement(m_readStmt);
41  return result;
42 
43  } catch (SQLException& e) {
44  throw(std::runtime_error(std::string("FEConfigOddWeightInfo::fetchNextId(): ") + e.getMessage()));
45  }
46 }
47 
49  this->checkConnection();
50 
51  int next_id = 0;
52  if (getId() == 0) {
53  next_id = fetchNextId();
54  }
55 
56  try {
57  m_writeStmt = m_conn->createStatement();
58  m_writeStmt->setSQL("INSERT INTO " + getTable() +
59  " ( wei2_conf_id, tag, number_of_groups) "
60  " VALUES ( :1, :2, :3 ) ");
61 
62  m_writeStmt->setInt(1, next_id);
63  m_ID = next_id;
64 
65  } catch (SQLException& e) {
66  throw(std::runtime_error(std::string("FEConfigOddWeightInfo::prepareWrite(): ") + e.getMessage()));
67  }
68 }
69 
70 void FEConfigOddWeightInfo::setParameters(const std::map<string, string>& my_keys_map) {
71  // parses the result of the XML parser that is a map of
72  // string string with variable name variable value
73 
74  for (std::map<std::string, std::string>::const_iterator ci = my_keys_map.begin(); ci != my_keys_map.end(); ci++) {
75  if (ci->first == "TAG")
76  setConfigTag(ci->second);
77  if (ci->first == "NUMBER_OF_GROUPS")
78  setNumberOfGroups(atoi(ci->second.c_str()));
79  }
80 }
81 
83  this->checkConnection();
84  this->checkPrepare();
85 
86  try {
87  // number 1 is the id
88  m_writeStmt->setString(2, this->getConfigTag());
89  m_writeStmt->setInt(3, this->getNumberOfGroups());
90 
91  m_writeStmt->executeUpdate();
92 
93  } catch (SQLException& e) {
94  throw(std::runtime_error(std::string("FEConfigOddWeightInfo::writeDB(): ") + e.getMessage()));
95  }
96  // Now get the ID
97  if (!this->fetchID()) {
98  throw(std::runtime_error("FEConfigOddWeightInfo::writeDB: Failed to write"));
99  }
100 }
101 
103  this->checkConnection();
104  result->clear();
105  if (result->getId() == 0 && (result->getConfigTag().empty())) {
106  throw(std::runtime_error("FEConfigOddWeightInfo::fetchData(): no Id defined for this FEConfigOddWeightInfo "));
107  }
108 
109  try {
110  DateHandler dh(m_env, m_conn);
111 
112  m_readStmt->setSQL("SELECT wei2_conf_id, tag, number_of_groups, db_timestamp FROM " + getTable() +
113  " where ( wei2_conf_id= :1 or (tag=:2 ) )");
114  m_readStmt->setInt(1, result->getId());
115  m_readStmt->setString(2, result->getConfigTag());
116  ResultSet* rset = m_readStmt->executeQuery();
117 
118  rset->next();
119 
120  // 1 is the id and 2 is the config tag and 3 is the version
121 
122  result->setId(rset->getInt(1));
123  result->setConfigTag(rset->getString(2));
124  result->setNumberOfGroups(rset->getInt(3));
125  Date dbdate = rset->getDate(4);
126  result->setDBTime(dh.dateToTm(dbdate));
127 
128  } catch (SQLException& e) {
129  throw(std::runtime_error(std::string("FEConfigOddWeightInfo::fetchData(): ") + e.getMessage()));
130  }
131 }
132 
134  this->checkConnection();
135  result->clear();
136  try {
137  DateHandler dh(m_env, m_conn);
138 
139  m_readStmt->setSQL("SELECT wei2_conf_id, tag, number_of_groups, db_timestamp FROM " + getTable() +
140  " where wei2_conf_id = ( select max( wei2_conf_id) from " + getTable() + " ) ");
141  ResultSet* rset = m_readStmt->executeQuery();
142 
143  rset->next();
144 
145  result->setId(rset->getInt(1));
146  result->setConfigTag(rset->getString(2));
147  result->setNumberOfGroups(rset->getInt(3));
148  Date dbdate = rset->getDate(4);
149  result->setDBTime(dh.dateToTm(dbdate));
150 
151  } catch (SQLException& e) {
152  throw(std::runtime_error(std::string("FEConfigOddWeightInfo::fetchData(): ") + e.getMessage()));
153  }
154 }
155 
157  // Return from memory if available
158  if (m_ID != 0) {
159  return m_ID;
160  }
161 
162  this->checkConnection();
163 
164  try {
165  Statement* stmt = m_conn->createStatement();
166  stmt->setSQL("SELECT wei2_conf_id FROM " + getTable() + " WHERE tag=:1 ");
167 
168  stmt->setString(1, getConfigTag());
169 
170  ResultSet* rset = stmt->executeQuery();
171 
172  if (rset->next()) {
173  m_ID = rset->getInt(1);
174  } else {
175  m_ID = 0;
176  }
177  m_conn->terminateStatement(stmt);
178  } catch (SQLException& e) {
179  throw(std::runtime_error(std::string("FEConfigOddWeightInfo::fetchID: ") + e.getMessage()));
180  }
181 
182  return m_ID;
183 }
184 
185 void FEConfigOddWeightInfo::setByID(int id) noexcept(false) {
186  this->checkConnection();
187 
188  DateHandler dh(m_env, m_conn);
189 
190  try {
191  Statement* stmt = m_conn->createStatement();
192 
193  stmt->setSQL("SELECT wei2_conf_id, tag, number_of_groups, db_timestamp FROM " + getTable() +
194  " WHERE wei2_conf_id = :1");
195  stmt->setInt(1, id);
196 
197  ResultSet* rset = stmt->executeQuery();
198  if (rset->next()) {
199  this->setId(rset->getInt(1));
200  this->setConfigTag(rset->getString(2));
201  this->setNumberOfGroups(rset->getInt(3));
202  Date dbdate = rset->getDate(4);
203  this->setDBTime(dh.dateToTm(dbdate));
204  } else {
205  throw(std::runtime_error("FEConfigOddWeightInfo::setByID: Given config_id is not in the database"));
206  }
207 
208  m_conn->terminateStatement(stmt);
209  } catch (SQLException& e) {
210  throw(std::runtime_error(std::string("FEConfigOddWeightInfo::setByID: ") + e.getMessage()));
211  }
212 }
FEConfigOddWeightInfo.h
funct::false
false
Definition: Factorize.h:29
FEConfigOddWeightInfo::fetchData
void fetchData(FEConfigOddWeightInfo *result) noexcept(false)
Definition: FEConfigOddWeightInfo.cc:102
IODConfig::Statement
oracle::occi::Statement Statement
Definition: IODConfig.h:21
FEConfigOddWeightInfo::fetchNextId
int fetchNextId() noexcept(false)
Definition: FEConfigOddWeightInfo.cc:28
FEConfigOddWeightInfo::~FEConfigOddWeightInfo
~FEConfigOddWeightInfo() override
Definition: FEConfigOddWeightInfo.cc:26
FEConfigOddWeightInfo
Definition: FEConfigOddWeightInfo.h:11
FEConfigOddWeightInfo::fetchID
int fetchID() noexcept(false)
Definition: FEConfigOddWeightInfo.cc:156
IODConfig::SQLException
oracle::occi::SQLException SQLException
Definition: IODConfig.h:20
FEConfigOddWeightInfo::setByID
void setByID(int id) noexcept(false)
Definition: FEConfigOddWeightInfo.cc:185
oracle::occi
Definition: ConnectionManager.h:7
FEConfigOddWeightInfo::FEConfigOddWeightInfo
FEConfigOddWeightInfo()
Definition: FEConfigOddWeightInfo.cc:13
FEConfigOddWeightInfo::fetchLastData
void fetchLastData(FEConfigOddWeightInfo *result) noexcept(false)
Definition: FEConfigOddWeightInfo.cc:133
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
clear
void clear(HadCaloObj &c)
Definition: data.h:124
Tm.h
FEConfigOddWeightInfo::setParameters
void setParameters(const std::map< std::string, std::string > &my_keys_map)
Definition: FEConfigOddWeightInfo.cc:70
std
Definition: JetResolutionObject.h:76
FEConfigOddWeightInfo::writeDB
void writeDB() noexcept(false)
Definition: FEConfigOddWeightInfo.cc:82
Oracle.h
DateHandler.h
mps_fire.result
result
Definition: mps_fire.py:311
FEConfigOddWeightInfo::prepareWrite
void prepareWrite() noexcept(false) override
Definition: FEConfigOddWeightInfo.cc:48
getId
static unsigned int getId()
Definition: DQMStoreStats.h:129
FEConfigOddWeightInfo::clear
void clear()
Definition: FEConfigOddWeightInfo.cc:24
DateHandler
Definition: DateHandler.h:7
cuy.dh
dh
Definition: cuy.py:355
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37