CMS 3D CMS Logo

ODRunConfigSeqInfo.cc
Go to the documentation of this file.
1 #include <stdexcept>
3 
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_ID = 0;
18  //
19  m_ecal_config_id = 0;
20  m_seq_num = 0;
21  m_cycles = 0;
22  m_run_seq = RunSeqDef();
23  m_description = "";
24 }
25 
27 
28 //
29 RunSeqDef ODRunConfigSeqInfo::getRunSeqDef() const { return m_run_seq; }
31  if (run_seq != m_run_seq) {
32  m_run_seq = run_seq;
33  }
34 }
35 //
36 
38  // Return from memory if available
39  if (m_ID > 0) {
40  return m_ID;
41  }
42 
43  this->checkConnection();
44 
45  DateHandler dh(m_env, m_conn);
46 
47  try {
48  Statement* stmt = m_conn->createStatement();
49  stmt->setSQL(
50  "SELECT sequence_id from ECAL_sequence_DAT "
51  "WHERE ecal_config_id = :id1 "
52  " and sequence_num = :id2 ");
53  stmt->setInt(1, m_ecal_config_id);
54  stmt->setInt(2, m_seq_num);
55 
56  ResultSet* rset = stmt->executeQuery();
57 
58  if (rset->next()) {
59  m_ID = rset->getInt(1);
60  } else {
61  m_ID = 0;
62  }
63  m_conn->terminateStatement(stmt);
64  } catch (SQLException& e) {
65  throw(std::runtime_error("ODRunConfigSeqInfo::fetchID: " + e.getMessage()));
66  }
67  setByID(m_ID);
68  return m_ID;
69 }
70 
72  this->checkConnection();
73 
74  DateHandler dh(m_env, m_conn);
75 
76  try {
77  Statement* stmt = m_conn->createStatement();
78  stmt->setSQL("SELECT max(sequence_id) FROM ecal_sequence_dat ");
79  ResultSet* rset = stmt->executeQuery();
80 
81  if (rset->next()) {
82  m_ID = rset->getInt(1);
83  } else {
84  m_ID = 0;
85  }
86  m_conn->terminateStatement(stmt);
87  } catch (SQLException& e) {
88  throw(std::runtime_error("ODRunConfigSeqInfo::fetchIDLast: " + e.getMessage()));
89  }
90 
91  setByID(m_ID);
92  return m_ID;
93 }
94 
95 void ODRunConfigSeqInfo::setByID(int id) noexcept(false) {
96  this->checkConnection();
97 
98  DateHandler dh(m_env, m_conn);
99 
100  cout << "ODRunConfigSeqInfo::setByID called for id " << id << endl;
101 
102  try {
103  Statement* stmt = m_conn->createStatement();
104 
105  stmt->setSQL(
106  "SELECT ecal_config_id, sequence_num, num_of_cycles, sequence_type_def_id, description FROM ECAL_sequence_DAT "
107  "WHERE sequence_id = :1 ");
108  stmt->setInt(1, id);
109 
110  ResultSet* rset = stmt->executeQuery();
111  if (rset->next()) {
112  m_ecal_config_id = rset->getInt(1);
113  m_seq_num = rset->getInt(2);
114  m_cycles = rset->getInt(3);
115  int seq_def_id = rset->getInt(4);
116  m_description = rset->getString(5);
117  m_ID = id;
118  m_run_seq.setConnection(m_env, m_conn);
119  m_run_seq.setByID(seq_def_id);
120  } else {
121  throw(std::runtime_error("ODRunConfigSeqInfo::setByID: Given config_id is not in the database"));
122  }
123  m_conn->terminateStatement(stmt);
124  } catch (SQLException& e) {
125  throw(std::runtime_error("ODRunConfigSeqInfo::setByID: " + e.getMessage()));
126  }
127 }
128 
130  this->checkConnection();
131 
132  try {
133  m_writeStmt = m_conn->createStatement();
134  m_writeStmt->setSQL(
135  "INSERT INTO ECAL_SEQUENCE_DAT ( ecal_config_id, "
136  "sequence_num, num_of_cycles, sequence_type_def_id, description ) "
137  "VALUES (:1, :2, :3 , :4, :5 )");
138  } catch (SQLException& e) {
139  throw(std::runtime_error("ODRunConfigSeqInfo::prepareWrite(): " + e.getMessage()));
140  }
141 }
143  this->checkConnection();
144  this->checkPrepare();
145 
146  // Validate the data, use infinity-till convention
147  DateHandler dh(m_env, m_conn);
148 
149  try {
150  // get the run mode
151 
152  m_run_seq.setConnection(m_env, m_conn);
153  int seq_def_id = m_run_seq.writeDB();
154 
155  m_writeStmt->setInt(1, this->getEcalConfigId());
156  m_writeStmt->setInt(2, this->getSequenceNumber());
157  m_writeStmt->setInt(3, this->getNumberOfCycles());
158  m_writeStmt->setInt(4, seq_def_id);
159  m_writeStmt->setString(5, this->getDescription());
160 
161  m_writeStmt->executeUpdate();
162 
163  } catch (SQLException& e) {
164  throw(std::runtime_error("ODRunConfigSeqInfo::writeDB(): " + e.getMessage()));
165  }
166  if (!this->fetchID()) {
167  throw(std::runtime_error("ODRunConfigSeqInfo::writeDB: Failed to write"));
168  }
169  cout << "ODRunConfigSeqInfo::writeDB>> done inserting ODRunConfigSeqInfo with id=" << m_ID << endl;
170 }
171 
173  // m_ecal_config_id =0;
174  // m_seq_num =0;
175  m_ID = 0;
176  m_cycles = 0;
177  m_run_seq = RunSeqDef();
178  m_description = "";
179 }
180 
182  this->checkConnection();
183  // result->clear();
184  if (result->getId() == 0) {
185  // throw(std::runtime_error("ODRunConfigSeqInfo::fetchData(): no Id defined for this record "));
186  result->fetchID();
187  }
188 
189  try {
190  m_readStmt->setSQL(
191  "SELECT ecal_config_id, sequence_num, num_of_cycles, "
192  "sequence_type_def_id, description FROM ECAL_sequence_DAT WHERE sequence_id = :1 ");
193 
194  m_readStmt->setInt(1, result->getId());
195  ResultSet* rset = m_readStmt->executeQuery();
196 
197  rset->next();
198 
199  result->setEcalConfigId(rset->getInt(1));
200  result->setSequenceNumber(rset->getInt(2));
201  result->setNumberOfCycles(rset->getInt(3));
202  int seq_def_id = rset->getInt(4);
203 
204  m_run_seq.setConnection(m_env, m_conn);
205  m_run_seq.setByID(seq_def_id);
206  result->setDescription(rset->getString(5));
207 
208  } catch (SQLException& e) {
209  throw(std::runtime_error("ODRunConfigSeqInfo::fetchData(): " + e.getMessage()));
210  }
211 }
funct::false
false
Definition: Factorize.h:29
ODRunConfigSeqInfo::fetchData
void fetchData(ODRunConfigSeqInfo *result) noexcept(false)
Definition: ODRunConfigSeqInfo.cc:181
ODRunConfigSeqInfo::prepareWrite
void prepareWrite() noexcept(false) override
Definition: ODRunConfigSeqInfo.cc:129
IODConfig::Statement
oracle::occi::Statement Statement
Definition: IODConfig.h:21
gather_cfg.cout
cout
Definition: gather_cfg.py:144
ODRunConfigSeqInfo::clear
void clear()
Definition: ODRunConfigSeqInfo.cc:172
ODRunConfigSeqInfo::getRunSeqDef
RunSeqDef getRunSeqDef() const
Definition: ODRunConfigSeqInfo.cc:29
IODConfig::SQLException
oracle::occi::SQLException SQLException
Definition: IODConfig.h:20
ODRunConfigSeqInfo::setRunSeqDef
void setRunSeqDef(const RunSeqDef &runSeqDef)
Definition: ODRunConfigSeqInfo.cc:30
ODRunConfigSeqInfo::fetchIDLast
int fetchIDLast() noexcept(false)
Definition: ODRunConfigSeqInfo.cc:71
oracle::occi
Definition: ConnectionManager.h:7
RunSeqDef
Definition: RunSeqDef.h:13
Tm.h
ODRunConfigSeqInfo::ODRunConfigSeqInfo
ODRunConfigSeqInfo()
Definition: ODRunConfigSeqInfo.cc:11
ODRunConfigSeqInfo.h
std
Definition: JetResolutionObject.h:76
ODRunConfigSeqInfo::writeDB
void writeDB() noexcept(false)
Definition: ODRunConfigSeqInfo.cc:142
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:31
ODRunConfigSeqInfo::setByID
void setByID(int id) noexcept(false)
Definition: ODRunConfigSeqInfo.cc:95
ODRunConfigSeqInfo::fetchID
int fetchID() noexcept(false)
Definition: ODRunConfigSeqInfo.cc:37
Oracle.h
DateHandler.h
mps_fire.result
result
Definition: mps_fire.py:311
DateHandler
Definition: DateHandler.h:7
cuy.dh
dh
Definition: cuy.py:355
ODRunConfigSeqInfo::~ODRunConfigSeqInfo
~ODRunConfigSeqInfo() override
Definition: ODRunConfigSeqInfo.cc:26
ODRunConfigSeqInfo
Definition: ODRunConfigSeqInfo.h:15
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37