CMS 3D CMS Logo

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