CMS 3D CMS Logo

RunSeqDef.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_runSeq = "";
14  m_runType = RunTypeDef();
15 }
16 
18 
19 string RunSeqDef::getRunSeq() const { return m_runSeq; }
20 
21 void RunSeqDef::setRunSeq(string runseq) { m_runSeq = runseq; }
22 
23 RunTypeDef RunSeqDef::getRunTypeDef() const { return m_runType; }
24 
25 void RunSeqDef::setRunTypeDef(const RunTypeDef& runTypeDef) { m_runType = runTypeDef; }
26 
27 int RunSeqDef::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  // get the run type
36  m_runType.setConnection(m_env, m_conn);
37  int run_type_id = m_runType.fetchID();
38 
39  try {
40  Statement* stmt = m_conn->createStatement();
41  stmt->setSQL(
42  "SELECT def_id FROM ecal_sequence_type_def WHERE "
43  " run_type_def_id = :1 and sequence_type_string = :2 ");
44 
45  stmt->setInt(1, run_type_id);
46  stmt->setString(2, m_runSeq);
47 
48  ResultSet* rset = stmt->executeQuery();
49 
50  if (rset->next()) {
51  m_ID = rset->getInt(1);
52  } else {
53  m_ID = 0;
54  }
55  m_conn->terminateStatement(stmt);
56  } catch (SQLException& e) {
57  throw(std::runtime_error("RunSeqDef::fetchID: " + e.getMessage()));
58  }
59 
60  return m_ID;
61 }
62 
63 void RunSeqDef::setByID(int id) noexcept(false) {
64  this->checkConnection();
65 
66  try {
67  Statement* stmt = m_conn->createStatement();
68 
69  stmt->setSQL("SELECT run_type_def_id, sequence_type_string FROM ecal_sequence_type_def WHERE def_id = :1");
70  stmt->setInt(1, id);
71 
72  int idruntype = 0;
73  ResultSet* rset = stmt->executeQuery();
74  if (rset->next()) {
75  idruntype = rset->getInt(1);
76  m_runSeq = rset->getString(2);
77  } else {
78  throw(std::runtime_error("RunSeqDef::setByID: Given def_id is not in the database"));
79  }
80 
81  m_conn->terminateStatement(stmt);
82 
83  m_runType.setConnection(m_env, m_conn);
84  m_runType.setByID(idruntype);
85 
86  } catch (SQLException& e) {
87  throw(std::runtime_error("RunSeqDef::setByID: " + e.getMessage()));
88  }
89 }
90 
91 void RunSeqDef::fetchAllDefs(std::vector<RunSeqDef>* fillVec) noexcept(false) {
92  this->checkConnection();
93  try {
94  Statement* stmt = m_conn->createStatement();
95  stmt->setSQL("SELECT def_id FROM ecal_sequence_type_def ORDER BY def_id");
96  ResultSet* rset = stmt->executeQuery();
97 
98  RunSeqDef runSeqDef;
99  runSeqDef.setConnection(m_env, m_conn);
100 
101  while (rset->next()) {
102  runSeqDef.setByID(rset->getInt(1));
103  fillVec->push_back(runSeqDef);
104  }
105  } catch (SQLException& e) {
106  throw(std::runtime_error("RunSeqDef::fetchAllDefs: " + e.getMessage()));
107  }
108 }
109 
110 int RunSeqDef::writeDB() noexcept(false) {
111  // see if this data is already in the DB
112  try {
113  if (this->fetchID()) {
114  return m_ID;
115  }
116  } catch (SQLException& e) {
117  // it does not exist yet
118  }
119 
120  // check the connectioin
121  this->checkConnection();
122 
123  // get the run type
124  m_runType.setConnection(m_env, m_conn);
125  int run_type_id = m_runType.fetchID();
126 
127  // write new seq def to the DB
128  try {
129  Statement* stmt = m_conn->createStatement();
130 
131  stmt->setSQL(
132  "insert into ecal_sequence_type_def(RUN_TYPE_DEF_ID, SEQUENCE_TYPE_STRING) values "
133  " ( :1, :2 )");
134  stmt->setInt(1, run_type_id);
135  stmt->setString(2, m_runSeq);
136 
137  stmt->executeUpdate();
138 
139  m_conn->terminateStatement(stmt);
140  } catch (SQLException& e) {
141  throw(std::runtime_error("RunSeqDef::writeDB: " + e.getMessage()));
142  }
143 
144  // now get the tag_id
145  if (!this->fetchID()) {
146  throw(std::runtime_error("RunSeqDef::writeDB: Failed to write"));
147  }
148 
149  return m_ID;
150 }
funct::false
false
Definition: Factorize.h:34
RunSeqDef::setByID
void setByID(int id) noexcept(false) override
Definition: RunSeqDef.cc:63
RunSeqDef::setRunTypeDef
void setRunTypeDef(const RunTypeDef &runTypeDef)
Definition: RunSeqDef.cc:25
RunSeqDef::fetchAllDefs
void fetchAllDefs(std::vector< RunSeqDef > *fillVec) noexcept(false)
Definition: RunSeqDef.cc:91
RunSeqDef::setRunSeq
void setRunSeq(std::string runseq)
Definition: RunSeqDef.cc:21
oracle::occi
Definition: ConnectionManager.h:7
RunSeqDef::getRunTypeDef
RunTypeDef getRunTypeDef() const
Definition: RunSeqDef.cc:23
RunSeqDef::writeDB
int writeDB() noexcept(false)
Definition: RunSeqDef.cc:110
RunSeqDef::getRunSeq
std::string getRunSeq() const
Definition: RunSeqDef.cc:19
RunSeqDef
Definition: RunSeqDef.h:13
RunTypeDef
Definition: RunTypeDef.h:12
RunSeqDef::~RunSeqDef
~RunSeqDef() override
Definition: RunSeqDef.cc:17
RunSeqDef.h
std
Definition: JetResolutionObject.h:76
IDBObject::setConnection
void setConnection(oracle::occi::Environment *env, oracle::occi::Connection *conn)
Definition: IDBObject.h:23
RunSeqDef::fetchID
int fetchID() noexcept(false) override
Definition: RunSeqDef.cc:27
RunSeqDef::RunSeqDef
RunSeqDef()
Definition: RunSeqDef.cc:9
Oracle.h
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37