CMS 3D CMS Logo

FEConfigWeightInfo.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 FEConfigWeightInfo::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_WEIGHT_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("FEConfigWeightInfo::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  " ( wei_conf_id, tag, version, number_of_groups) "
60  " VALUES ( :1, :2, :3 , :4) ");
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("FEConfigWeightInfo::prepareWrite(): ") + e.getMessage()));
67  }
68 }
69 
70 void FEConfigWeightInfo::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 == "VERSION")
76  setVersion(atoi(ci->second.c_str()));
77  if (ci->first == "TAG")
78  setConfigTag(ci->second);
79  if (ci->first == "NUMBER_OF_GROUPS")
80  setNumberOfGroups(atoi(ci->second.c_str()));
81  }
82 }
83 
85  this->checkConnection();
86  this->checkPrepare();
87 
88  try {
89  // number 1 is the id
90  m_writeStmt->setString(2, this->getConfigTag());
91  m_writeStmt->setInt(3, this->getVersion());
92  m_writeStmt->setInt(4, this->getNumberOfGroups());
93 
94  m_writeStmt->executeUpdate();
95 
96  } catch (SQLException& e) {
97  throw(std::runtime_error(std::string("FEConfigWeightInfo::writeDB(): ") + e.getMessage()));
98  }
99  // Now get the ID
100  if (!this->fetchID()) {
101  throw(std::runtime_error("FEConfigWeightInfo::writeDB: Failed to write"));
102  }
103 }
104 
106  this->checkConnection();
107  result->clear();
108  if (result->getId() == 0 && (result->getConfigTag().empty())) {
109  throw(std::runtime_error("FEConfigWeightInfo::fetchData(): no Id defined for this FEConfigWeightInfo "));
110  }
111 
112  try {
113  DateHandler dh(m_env, m_conn);
114 
115  m_readStmt->setSQL("SELECT * FROM " + getTable() + " where ( wei_conf_id= :1 or (tag=:2 AND version=:3 ) )");
116  m_readStmt->setInt(1, result->getId());
117  m_readStmt->setString(2, result->getConfigTag());
118  m_readStmt->setInt(3, result->getVersion());
119  ResultSet* rset = m_readStmt->executeQuery();
120 
121  rset->next();
122 
123  // 1 is the id and 2 is the config tag and 3 is the version
124 
125  result->setId(rset->getInt(1));
126  result->setConfigTag(rset->getString(2));
127  result->setVersion(rset->getInt(3));
128  result->setNumberOfGroups(rset->getInt(4));
129  Date dbdate = rset->getDate(5);
130  result->setDBTime(dh.dateToTm(dbdate));
131 
132  } catch (SQLException& e) {
133  throw(std::runtime_error(std::string("FEConfigWeightInfo::fetchData(): ") + e.getMessage()));
134  }
135 }
136 
138  this->checkConnection();
139  result->clear();
140  try {
141  DateHandler dh(m_env, m_conn);
142 
143  m_readStmt->setSQL("SELECT * FROM " + getTable() + " where wei_conf_id = ( select max( wei_conf_id) from " +
144  getTable() + " ) ");
145  ResultSet* rset = m_readStmt->executeQuery();
146 
147  rset->next();
148 
149  result->setId(rset->getInt(1));
150  result->setConfigTag(rset->getString(2));
151  result->setVersion(rset->getInt(3));
152  result->setNumberOfGroups(rset->getInt(4));
153  Date dbdate = rset->getDate(5);
154  result->setDBTime(dh.dateToTm(dbdate));
155 
156  } catch (SQLException& e) {
157  throw(std::runtime_error(std::string("FEConfigWeightInfo::fetchData(): ") + e.getMessage()));
158  }
159 }
160 
162  // Return from memory if available
163  if (m_ID != 0) {
164  return m_ID;
165  }
166 
167  this->checkConnection();
168 
169  try {
170  Statement* stmt = m_conn->createStatement();
171  stmt->setSQL("SELECT wei_conf_id FROM " + getTable() + " WHERE tag=:1 and version=:2 ");
172 
173  stmt->setString(1, getConfigTag());
174  stmt->setInt(2, getVersion());
175 
176  ResultSet* rset = stmt->executeQuery();
177 
178  if (rset->next()) {
179  m_ID = rset->getInt(1);
180  } else {
181  m_ID = 0;
182  }
183  m_conn->terminateStatement(stmt);
184  } catch (SQLException& e) {
185  throw(std::runtime_error(std::string("FEConfigWeightInfo::fetchID: ") + e.getMessage()));
186  }
187 
188  return m_ID;
189 }
190 
191 void FEConfigWeightInfo::setByID(int id) noexcept(false) {
192  this->checkConnection();
193 
194  DateHandler dh(m_env, m_conn);
195 
196  try {
197  Statement* stmt = m_conn->createStatement();
198 
199  stmt->setSQL("SELECT * FROM fe_config_weight_info WHERE wei_conf_id = :1");
200  stmt->setInt(1, id);
201 
202  ResultSet* rset = stmt->executeQuery();
203  if (rset->next()) {
204  this->setId(rset->getInt(1));
205  this->setConfigTag(rset->getString(2));
206  this->setVersion(rset->getInt(3));
207  this->setNumberOfGroups(rset->getInt(4));
208  Date dbdate = rset->getDate(5);
209  this->setDBTime(dh.dateToTm(dbdate));
210  } else {
211  throw(std::runtime_error("FEConfigWeightInfo::setByID: Given config_id is not in the database"));
212  }
213 
214  m_conn->terminateStatement(stmt);
215  } catch (SQLException& e) {
216  throw(std::runtime_error(std::string("FEConfigWeightInfo::setByID: ") + e.getMessage()));
217  }
218 }
FEConfigWeightInfo::setByID
void setByID(int id) noexcept(false)
Definition: FEConfigWeightInfo.cc:191
funct::false
false
Definition: Factorize.h:34
IODConfig::Statement
oracle::occi::Statement Statement
Definition: IODConfig.h:21
FEConfigWeightInfo::FEConfigWeightInfo
FEConfigWeightInfo()
Definition: FEConfigWeightInfo.cc:13
FEConfigWeightInfo::setParameters
void setParameters(const std::map< std::string, std::string > &my_keys_map)
Definition: FEConfigWeightInfo.cc:70
IODConfig::SQLException
oracle::occi::SQLException SQLException
Definition: IODConfig.h:20
FEConfigWeightInfo::~FEConfigWeightInfo
~FEConfigWeightInfo() override
Definition: FEConfigWeightInfo.cc:26
oracle::occi
Definition: ConnectionManager.h:7
FEConfigWeightInfo
Definition: FEConfigWeightInfo.h:11
FEConfigWeightInfo::prepareWrite
void prepareWrite() noexcept(false) override
Definition: FEConfigWeightInfo.cc:48
FEConfigWeightInfo::fetchLastData
void fetchLastData(FEConfigWeightInfo *result) noexcept(false)
Definition: FEConfigWeightInfo.cc:137
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
clear
void clear(HadCaloObj &c)
Definition: data.h:124
Tm.h
FEConfigWeightInfo::fetchNextId
int fetchNextId() noexcept(false)
Definition: FEConfigWeightInfo.cc:28
std
Definition: JetResolutionObject.h:76
FEConfigWeightInfo::fetchID
int fetchID() noexcept(false)
Definition: FEConfigWeightInfo.cc:161
FEConfigWeightInfo.h
FEConfigWeightInfo::clear
void clear()
Definition: FEConfigWeightInfo.cc:24
Oracle.h
DateHandler.h
mps_fire.result
result
Definition: mps_fire.py:303
FEConfigWeightInfo::fetchData
void fetchData(FEConfigWeightInfo *result) noexcept(false)
Definition: FEConfigWeightInfo.cc:105
FEConfigWeightInfo::writeDB
void writeDB() noexcept(false)
Definition: FEConfigWeightInfo.cc:84
getId
static unsigned int getId()
Definition: DQMStoreStats.h:129
DateHandler
Definition: DateHandler.h:7
cuy.dh
dh
Definition: cuy.py:355
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37