CMS 3D CMS Logo

RunModeDef.cc
Go to the documentation of this file.
1 #include <string>
3 
5 
6 using namespace std;
7 using namespace oracle::occi;
8 
10  m_env = nullptr;
11  m_conn = nullptr;
12  m_ID = 0;
13  m_runMode = "";
14 }
15 
17 
18 string RunModeDef::getRunMode() const { return m_runMode; }
19 
21  if (runmode != m_runMode) {
22  m_ID = 0;
23  m_runMode = runmode;
24  }
25 }
26 
27 int RunModeDef::fetchID() noexcept(false) {
28  // Return def from memory if available
29  if (m_ID) {
30  return m_ID;
31  }
32 
33  this->checkConnection();
34 
35  try {
36  Statement* stmt = m_conn->createStatement();
37  stmt->setSQL(
38  "SELECT def_id FROM ecal_run_mode_def WHERE "
39  "run_mode_string = :1");
40  stmt->setString(1, m_runMode);
41 
42  ResultSet* rset = stmt->executeQuery();
43 
44  if (rset->next()) {
45  m_ID = rset->getInt(1);
46  } else {
47  m_ID = 0;
48  }
49  m_conn->terminateStatement(stmt);
50  } catch (SQLException& e) {
51  throw(std::runtime_error("RunModeDef::fetchID: " + e.getMessage()));
52  }
53 
54  return m_ID;
55 }
56 
57 void RunModeDef::setByID(int id) noexcept(false) {
58  this->checkConnection();
59 
60  try {
61  Statement* stmt = m_conn->createStatement();
62 
63  stmt->setSQL("SELECT run_mode_string FROM ecal_run_mode_def WHERE def_id = :1");
64  stmt->setInt(1, id);
65 
66  ResultSet* rset = stmt->executeQuery();
67  if (rset->next()) {
68  m_runMode = rset->getString(1);
69  } else {
70  throw(std::runtime_error("RunModeDef::setByID: Given def_id is not in the database"));
71  }
72 
73  m_conn->terminateStatement(stmt);
74  } catch (SQLException& e) {
75  throw(std::runtime_error("RunModeDef::setByID: " + e.getMessage()));
76  }
77 }
78 
79 void RunModeDef::fetchAllDefs(std::vector<RunModeDef>* fillVec) noexcept(false) {
80  this->checkConnection();
81  try {
82  Statement* stmt = m_conn->createStatement();
83  stmt->setSQL("SELECT def_id FROM ecal_run_mode_def ORDER BY def_id");
84  ResultSet* rset = stmt->executeQuery();
85 
86  RunModeDef runModeDef;
87  runModeDef.setConnection(m_env, m_conn);
88 
89  while (rset->next()) {
90  runModeDef.setByID(rset->getInt(1));
91  fillVec->push_back(runModeDef);
92  }
93  } catch (SQLException& e) {
94  throw(std::runtime_error("RunModeDef::fetchAllDefs: " + e.getMessage()));
95  }
96 }
funct::false
false
Definition: Factorize.h:29
RunModeDef
Definition: RunModeDef.h:12
RunModeDef::fetchID
int fetchID() noexcept(false) override
Definition: RunModeDef.cc:27
RunModeDef::fetchAllDefs
void fetchAllDefs(std::vector< RunModeDef > *fillVec) noexcept(false)
Definition: RunModeDef.cc:79
RunModeDef::RunModeDef
RunModeDef()
Definition: RunModeDef.cc:9
oracle::occi
Definition: ConnectionManager.h:7
RunModeDef::setByID
void setByID(int id) noexcept(false) override
Definition: RunModeDef.cc:57
RunModeDef.h
RunModeDef::setRunMode
void setRunMode(std::string runmode)
Definition: RunModeDef.cc:20
SiStripCommissioningClient_cfg.runmode
runmode
Definition: SiStripCommissioningClient_cfg.py:8
std
Definition: JetResolutionObject.h:76
IDBObject::setConnection
void setConnection(oracle::occi::Environment *env, oracle::occi::Connection *conn)
Definition: IDBObject.h:23
RunModeDef::getRunMode
std::string getRunMode() const
Definition: RunModeDef.cc:18
Oracle.h
RunModeDef::~RunModeDef
~RunModeDef() override
Definition: RunModeDef.cc:16
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37