CMS 3D CMS Logo

ODRunConfigInfo.cc
Go to the documentation of this file.
1 #include <stdexcept>
3 
7 
8 using namespace std;
9 using namespace oracle::occi;
10 
11 
13 {
14  m_env = nullptr;
15  m_conn = nullptr;
16  m_ID = 0;
17  //
18  m_tag ="";
19  m_version=0;
20  m_num_seq=0;
21  m_runTypeDef = RunTypeDef();
22  m_runModeDef = RunModeDef();
23  m_defaults=0;
24  m_trigger_mode="";
25  m_num_events=0;
26 }
27 
28 
29 
31 
32 
33 
34 //
35 RunTypeDef ODRunConfigInfo::getRunTypeDef() const { return m_runTypeDef;}
37 {
38  if (runTypeDef != m_runTypeDef) {
39  m_ID = 0;
40  m_runTypeDef = runTypeDef;
41  }
42 }
43 //
44 RunModeDef ODRunConfigInfo::getRunModeDef() const { return m_runModeDef;}
46 {
47  if (runModeDef != m_runModeDef) {
48  m_ID = 0;
49  m_runModeDef = runModeDef;
50  }
51 }
52 //
53 
55 
56  int result=0;
57  try {
58  this->checkConnection();
59 
60  m_readStmt = m_conn->createStatement();
61  m_readStmt->setSQL("select ecal_run_sq.NextVal from dual");
62  ResultSet* rset = m_readStmt->executeQuery();
63  while (rset->next ()){
64  result= rset->getInt(1);
65  }
66  m_conn->terminateStatement(m_readStmt);
67  return result;
68 
69  } catch (SQLException &e) {
70  throw(std::runtime_error(std::string("ODDCCConfig::fetchNextId(): ")+getOraMessage(&e)));
71  }
72 
73 }
74 
77 {
78  // Return from memory if available
79  if (m_ID>0) {
80  return m_ID;
81  }
82 
83  this->checkConnection();
84 
85 
86  DateHandler dh(m_env, m_conn);
87 
88  try {
89  Statement* stmt = m_conn->createStatement();
90  stmt->setSQL("SELECT config_id from ECAL_RUN_CONFIGURATION_DAT "
91  "WHERE tag = :tag "
92  " and version = :version " );
93  stmt->setString(1, m_tag);
94  stmt->setInt(2, m_version);
95 
96  ResultSet* rset = stmt->executeQuery();
97  if (rset->next()) {
98  m_ID = rset->getInt(1);
99  } else {
100  m_ID = 0;
101  }
102  m_conn->terminateStatement(stmt);
103  } catch (SQLException &e) {
104  throw(std::runtime_error(std::string("ODRunConfigInfo::fetchID: ")+getOraMessage(&e)));
105  }
106  setByID(m_ID);
107  return m_ID;
108 }
109 
110 
111 
113  noexcept(false)
114 {
115 
116  this->checkConnection();
117 
118  DateHandler dh(m_env, m_conn);
119 
120  try {
121  Statement* stmt = m_conn->createStatement();
122  stmt->setSQL("SELECT max(config_id) FROM ecal_run_configuration_dat " );
123  ResultSet* rset = stmt->executeQuery();
124 
125  if (rset->next()) {
126  m_ID = rset->getInt(1);
127  } else {
128  m_ID = 0;
129  }
130  m_conn->terminateStatement(stmt);
131  } catch (SQLException &e) {
132  throw(std::runtime_error(std::string("ODRunConfigInfo::fetchIDLast: ")+getOraMessage(&e)));
133  }
134 
135  setByID(m_ID);
136  return m_ID;
137 }
138 
139 //
141  noexcept(false)
142 {
143  fetchID();
144  return m_ID;
145 }
146 
147 
148 
150  noexcept(false)
151 {
152  this->checkConnection();
153 
154  DateHandler dh(m_env, m_conn);
155 
156  try {
157  Statement* stmt = m_conn->createStatement();
158 
159  stmt->setSQL("SELECT tag, version, run_type_def_id, run_mode_def_id, num_of_sequences, description, defaults,"
160  " trg_mode,num_of_events, db_timestamp, usage_status"
161  " FROM ECAL_RUN_CONFIGURATION_DAT WHERE config_id = :1");
162  stmt->setInt(1, id);
163 
164  ResultSet* rset = stmt->executeQuery();
165  if (rset->next()) {
166  m_tag= getOraString(rset,1);
167  m_version= rset->getInt(2);
168  int run_type_id=rset->getInt(3);
169  int run_mode_id=rset->getInt(4);
170  m_num_seq=rset->getInt(5);
171  m_description= getOraString(rset,6);
172  m_defaults= rset->getInt(7);
173  m_trigger_mode= getOraString(rset,8);
174  m_num_events= rset->getInt(9);
175  Date dbdate = rset->getDate(10);
176  m_db_time = dh.dateToTm( dbdate );
177  m_ID = id;
178  m_runModeDef.setConnection(m_env, m_conn);
179  m_runModeDef.setByID(run_mode_id);
180  m_runTypeDef.setConnection(m_env, m_conn);
181  m_runTypeDef.setByID(run_type_id);
182  m_usage_status=getOraString(rset,11);
183  } else {
184  throw(std::runtime_error("ODRunConfigInfo::setByID: Given config_id is not in the database"));
185  }
186  m_conn->terminateStatement(stmt);
187  } catch (SQLException &e) {
188  throw(std::runtime_error(std::string("ODRunConfigInfo::setByID: ")+getOraMessage(&e)));
189  }
190 }
191 
193  noexcept(false)
194 {
195  this->checkConnection();
196 
197  int next_id=fetchNextId();
198 
199 
200 
201 
202  try {
203  m_writeStmt = m_conn->createStatement();
204  m_writeStmt->setSQL("INSERT INTO ECAL_RUN_CONFIGURATION_DAT (CONFIG_ID, tag, version, run_type_def_id, "
205  " run_mode_def_id, num_of_sequences, defaults, trg_mode, num_of_events, description, usage_status ) "
206  " VALUES (:1, :2, :3 , :4, :5, :6 ,:7, :8, :9, :10 , :11)");
207 
208  m_writeStmt->setInt(1, next_id);
209  m_ID=next_id;
210 
211  } catch (SQLException &e) {
212  throw(std::runtime_error(std::string("ODRunConfigInfo::prepareWrite(): ")+getOraMessage(&e)));
213  }
214 }
215 
216 
218  noexcept(false)
219 {
220  this->checkConnection();
221  this->checkPrepare();
222 
223  // Validate the data, use infinity-till convention
224  DateHandler dh(m_env, m_conn);
225 
226  try {
227 
228  // get the run mode
229  m_runModeDef.setConnection(m_env, m_conn);
230  int run_mode_id = m_runModeDef.fetchID();
231 
232  // get the run type
233  m_runTypeDef.setConnection(m_env, m_conn);
234  int run_type_id = m_runTypeDef.fetchID();
235 
236  // now insert
237 
238  m_writeStmt->setString(2, this->getTag());
239  m_writeStmt->setInt(3, this->getVersion());
240  m_writeStmt->setInt(4, run_type_id);
241  m_writeStmt->setInt(5, run_mode_id);
242  m_writeStmt->setInt(6, this->getNumberOfSequences());
243  m_writeStmt->setInt(7, this->getDefaults());
244  m_writeStmt->setString(8, this->getTriggerMode());
245  m_writeStmt->setInt(9, this->getNumberOfEvents());
246  m_writeStmt->setString(10, this->getDescription());
247  m_writeStmt->setString(11, this->getUsageStatus());
248 
249  m_writeStmt->executeUpdate();
250 
251  } catch (SQLException &e) {
252  throw(std::runtime_error(std::string("ODRunConfigInfo::writeDB: ")+getOraMessage(&e)));
253  }
254  // Now get the ID
255  if (!this->fetchID()) {
256  throw(std::runtime_error("ODRunConfigInfo::writeDB Failed to write"));
257  }
258 
259  this->setByID(m_ID);
260 
261  cout<< "ODRunConfigInfo::writeDB>> done inserting ODRunConfigInfo with id="<<m_ID<<endl;
262 }
263 
264 
266  noexcept(false)
267 {
268  this->checkConnection();
269 
270  // Check if this has already been written
271  if(!this->fetchID()){
272  this->writeDB();
273  }
274 
275 
276  try {
277  Statement* stmt = m_conn->createStatement();
278 
279  stmt->setSQL("UPDATE ecal_run_configuration_dat set defaults=:1 where config_id=:2 " );
280 
281  stmt->setInt(1, m_defaults);
282  stmt->setInt(2, m_ID);
283 
284  stmt->executeUpdate();
285 
286  m_conn->terminateStatement(stmt);
287  } catch (SQLException &e) {
288  throw(std::runtime_error(std::string("ODRunConfigInfo::writeDB: ")+getOraMessage(&e)));
289  }
290 
291  return m_ID;
292 }
293 
295  m_num_seq = 0;
296  m_runTypeDef = RunTypeDef();
297  m_runModeDef = RunModeDef();
298  m_defaults = 0;
299  m_trigger_mode = "";
300  m_num_events = 0;
301 }
302 
304  noexcept(false)
305 {
306  this->checkConnection();
307  DateHandler dh(m_env, m_conn);
308  // result->clear();
309 
310  if(result->getId()==0){
311  //throw(std::runtime_error("FEConfigMainInfo::fetchData(): no Id defined for this FEConfigMainInfo "));
312  result->fetchID();
313  }
314  try {
315  m_readStmt->setSQL("SELECT config_id, tag, version, run_type_def_id, run_mode_def_id, \
316  num_of_sequences, description, defaults, trg_mode, num_of_events, db_timestamp, usage_status \
317  FROM ECAL_RUN_CONFIGURATION_DAT WHERE config_id = :1 ");
318  m_readStmt->setInt(1, result->getId());
319 
320  ResultSet* rset = m_readStmt->executeQuery();
321  rset->next();
322 
323  result->setId( rset->getInt(1) );
324  result->setTag( getOraString(rset,2) );
325  result->setVersion( rset->getInt(3) );
326  // RunTypeDef myRunType = rset->getInt(4);
327  // result->setRunTypeDef( myRunType );
328  // RunModeDef myRunMode = rset->getInt(5);
329  // result->setRunModeDef( myRunMode );
330  result->setNumberOfSequences(rset->getInt(6) );
331  result->setDescription( getOraString(rset,7) );
332  result->setDefaults( rset->getInt(8) );
333  result->setTriggerMode( getOraString(rset,9) );
334  result->setNumberOfEvents( rset->getInt(10) );
335  Date dbdate = rset->getDate(11);
336  result->setDBTime(dh.dateToTm( dbdate ));
337  result->setUsageStatus( getOraString(rset,12) );
338 
339  } catch (SQLException &e) {
340  cout << " ODRunConfigInfo::fetchData(): " << getOraMessage(&e) << endl;
341  throw(std::runtime_error(std::string("ODRunConfigInfo::fetchData(): ")+getOraMessage(&e)));
342  }
343 }
int fetchIDLast() noexcept(false)
RunModeDef getRunModeDef() const
int fetchIDFromTagAndVersion() noexcept(false)
void writeDB() noexcept(false)
#define noexcept
int fetchID() noexcept(false)
void setRunModeDef(const RunModeDef &runModeDef)
void setRunTypeDef(const RunTypeDef &runTypeDef)
int fetchNextId() noexcept(false)
~ODRunConfigInfo() override
int updateDefaultCycle() noexcept(false)
void setByID(int id) noexcept(false)
oracle::occi::Statement Statement
Definition: IODConfig.h:23
RunTypeDef getRunTypeDef() const
void fetchData(ODRunConfigInfo *result) noexcept(false)
oracle::occi::SQLException SQLException
Definition: IODConfig.h:22
void prepareWrite() noexcept(false) override
dh
Definition: cuy.py:353
Tm dateToTm(oracle::occi::Date &date) const
Definition: DateHandler.cc:31