CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ODEcalCycle.cc
Go to the documentation of this file.
1 #include <stdexcept>
2 #include <string>
5 
21 
22 using namespace std;
23 using namespace oracle::occi;
24 
26 {
27  m_env = NULL;
28  m_conn = NULL;
29  m_writeStmt = NULL;
30  m_readStmt = NULL;
31 
32  m_ID=0;
33  clear();
34 }
35 
36 
37 
39 {
40 }
41 
42 
43 
45  throw(std::runtime_error)
46 {
47 
48  std::cout<< "ODEcalCycle::prepareWrite(): this is a view writing specific tables "<< endl;
49 
50 }
51 
52 
53 
55  throw(std::runtime_error)
56 {
57 
59  cyc.setTag(this->getCycleTag());
60  cyc.setDescription(this->getCycleDescription());
61  cyc.setCycleNumber(this->getCycleNum());
62  cyc.setSequenceID(this->getSequenceId());
63  // here we insert the cycle and get back the id
64  cyc.setConnection(m_env, m_conn);
65  cyc.insertConfig();
66  int cyc_id=cyc.getId();
67  cout << "Cycle inserted with ID "<< cyc_id<< endl;
68  m_ID=cyc_id;
69 
70  if(getCCSId()!=0){
71  ODCCSCycle ccs_cycle;
72  ccs_cycle.setId(cyc_id);
73  ccs_cycle.setCCSConfigurationID(getCCSId());
74  ccs_cycle.setConnection(m_env, m_conn);
75  ccs_cycle.insertConfig();
76  cout << "Inserting CCS-cycle in DB..." << flush;
77  }
78  if(getDCCId()!=0){
79  ODDCCCycle dcc_cycle;
80  dcc_cycle.setId(cyc_id);
81  dcc_cycle.setDCCConfigurationID(getDCCId());
82  dcc_cycle.setConnection(m_env, m_conn);
83  dcc_cycle.insertConfig();
84  cout << "Inserting DCC-cycle in DB..." << flush;
85  }
86  if(getLaserId()!=0){
87  ODLaserCycle laser_cycle;
88  laser_cycle.setId(cyc_id);
89  laser_cycle.setLaserConfigurationID(getLaserId());
90  laser_cycle.setConnection(m_env, m_conn);
91  laser_cycle.insertConfig();
92  cout << "Inserting LASER-cycle in DB..." << flush;
93  }
94  if(getLTCId()!=0){
95  ODLTCCycle ltc_cycle;
96  ltc_cycle.setId(cyc_id);
97  ltc_cycle.setLTCConfigurationID(getLTCId());
98  ltc_cycle.setConnection(m_env, m_conn);
99  ltc_cycle.insertConfig();
100  cout << "Inserting LTC-cycle in DB..." << flush;
101  }
102  if(getLTSId()!=0){
103  ODLTSCycle lts_cycle;
104  lts_cycle.setId(cyc_id);
105  lts_cycle.setLTSConfigurationID(getLTSId());
106  lts_cycle.setConnection(m_env, m_conn);
107  lts_cycle.insertConfig();
108  cout << "Inserting LTS-cycle in DB..." << flush;
109  }
110  if(getDCUId()!=0){
111  ODDCUCycle dcu_cycle;
112  dcu_cycle.setId(cyc_id);
113  dcu_cycle.setDCUConfigurationID(getDCUId());
114  dcu_cycle.setConnection(m_env, m_conn);
115  dcu_cycle.insertConfig();
116  cout << "Inserting DCU-cycle in DB..." << flush;
117  }
118  if(getTCCId()!=0){
119  ODTCCCycle tcc_cycle;
120  tcc_cycle.setId(cyc_id);
121  tcc_cycle.setTCCConfigurationID(getTCCId());
122  tcc_cycle.setConnection(m_env, m_conn);
123  tcc_cycle.insertConfig();
124  cout << "Inserting TCC-cycle in DB..." << flush;
125  }
126  if(getTCCEEId()!=0){
127  ODTCCEECycle tcc_ee_cycle;
128  tcc_ee_cycle.setId(cyc_id);
129  tcc_ee_cycle.setTCCConfigurationID(getTCCEEId());
130  tcc_ee_cycle.setConnection(m_env, m_conn);
131  tcc_ee_cycle.insertConfig();
132  cout << "Inserting TCCEE-cycle in DB..." << flush;
133  }
134  if(getTTCCIId()!=0){
135  ODTTCciCycle ttcci_cycle;
136  ttcci_cycle.setId(cyc_id);
137  ttcci_cycle.setTTCciConfigurationID(getTTCCIId());
138  ttcci_cycle.setConnection(m_env, m_conn);
139  ttcci_cycle.insertConfig();
140  cout << "Inserting TTCCI-cycle in DB..." << flush;
141  }
142  if(getTTCFId()!=0){
143  ODTTCFCycle ttcf_cycle;
144  ttcf_cycle.setId(cyc_id);
145  ttcf_cycle.setTTCFConfigurationID(getTTCFId());
146  ttcf_cycle.setConnection(m_env, m_conn);
147  ttcf_cycle.insertConfig();
148  cout << "Inserting TTCF-cycle in DB..." << flush;
149  }
150  if(getSRPId()!=0){
151  ODSRPCycle srp_cycle;
152  srp_cycle.setId(cyc_id);
153  srp_cycle.setSRPConfigurationID(getSRPId());
154  srp_cycle.setConnection(m_env, m_conn);
155  srp_cycle.insertConfig();
156  cout << "Inserting SRP-cycle in DB..." << flush;
157  }
158  if(getJBH4Id()!=0){
159  ODJBH4Cycle jbh4_cycle;
160  jbh4_cycle.setId(cyc_id);
161  jbh4_cycle.setJBH4ConfigurationID(getJBH4Id());
162  jbh4_cycle.setConnection(m_env, m_conn);
163  jbh4_cycle.insertConfig();
164  cout << "Inserting JBH4-cycle in DB..." << flush;
165  }
166  if(getScanId()!=0){
167  ODScanCycle scan_cycle;
168  scan_cycle.setId(cyc_id);
169  scan_cycle.setScanConfigurationID(getScanId());
170  scan_cycle.setConnection(m_env, m_conn);
171  scan_cycle.insertConfig();
172  cout << "Inserting SCAN-cycle in DB..." << flush;
173  }
174 
175 
176 }
177 
178 
180  m_tag="";
181  m_version=0;
182  m_seq_num=0;
183  m_cycle_num=0;
184  m_cycle_tag="";
185  m_cycle_description="";
186  m_ccs=0;
187  m_dcc=0;
188  m_laser=0;
189  m_ltc=0;
190  m_lts=0;
191  m_dcu=0;
192  m_tcc=0;
193  m_tcc_ee=0;
194  m_ttcci=0;
195  m_jbh4=0;
196  m_scan=0;
197  // m_seq_id=0;
198  m_ttcf=0;
199  m_srp=0;
200 }
201 
203  throw(std::runtime_error)
204 {
205  // Return from memory if available
206  if (m_ID>0) {
207  return m_ID;
208  }
209 
210  this->checkConnection();
211 
212 
213  DateHandler dh(m_env, m_conn);
214 
215  try {
216  Statement* stmt = m_conn->createStatement();
217  stmt->setSQL("SELECT cycle_id from ECAL_CYCLE_DAT "
218  "WHERE sequence_id = :1 ");
219  stmt->setInt(1, m_seq_id);
220 
221  ResultSet* rset = stmt->executeQuery();
222 
223  if (rset->next()) {
224  m_ID = rset->getInt(1);
225  } else {
226  m_ID = 0;
227  }
228  m_conn->terminateStatement(stmt);
229  } catch (SQLException &e) {
230  throw(std::runtime_error("ODEcalCycle::fetchID: "+e.getMessage()));
231  }
232  setByID(m_ID);
233  return m_ID;
234 }
235 
237  throw(std::runtime_error)
238 {
239  this->checkConnection();
240 
241  DateHandler dh(m_env, m_conn);
242 
243  try {
244  Statement* stmt = m_conn->createStatement();
245 
246  stmt->setSQL("SELECT tag, version, sequence_num, cycle_num, cycle_tag, description, "
247  "ccs_configuration_id, dcc_configuration_id, laser_configuration_id, "
248  "ltc_configuration_id, lts_configuration_id, tcc_configuration_id, "
249  "\"TTCci_CONFIGURATION_ID\", jbh4_configuration_id, scan_id, TTCF_configuration_id, "
250  "srp_configuration_id, dcu_configuration_id, tcc_ee_configuration_id "
251  "FROM ECAL_CYCLE where cycle_id = :1 " );
252  stmt->setInt(1, id);
253 
254  ResultSet* rset = stmt->executeQuery();
255  if (rset->next()) {
256  m_tag = rset->getString(1);
257  m_version = rset->getInt(2);
258  m_seq_num = rset->getInt(3);
259  m_cycle_num = rset->getInt(4);
260  m_cycle_tag = rset->getString(5);
261  m_cycle_description = rset->getString(6);
262  m_ccs = rset->getInt(7);
263  m_dcc = rset->getInt(8);
264  m_laser = rset->getInt(9);
265  m_ltc = rset->getInt(10);
266  m_lts = rset->getInt(11);
267  m_tcc = rset->getInt(12);
268  m_ttcci = rset->getInt(13);
269  m_jbh4 = rset->getInt(14);
270  m_scan = rset->getInt(15);
271  m_ttcf = rset->getInt(16);
272  m_srp = rset->getInt(17);
273  m_dcu = rset->getInt(18);
274  m_tcc_ee = rset->getInt(19);
275 
276  } else {
277  throw(std::runtime_error("ODEcalCycle::setByID: Given config_id is not in the database"));
278  }
279  m_conn->terminateStatement(stmt);
280  } catch (SQLException &e) {
281  throw(std::runtime_error("ODEcalCycle::setByID: "+e.getMessage()));
282  }
283 }
284 
285 
287 
288  std::cout << "**** ODEcalCycle ****"<< std::endl;
289  std::cout << "**** id: "<< m_ID << std::endl;
290  std::cout << "**** tag: "<< m_tag << std::endl;
291  std::cout << "**** version: "<< m_version << std::endl;
292  std::cout << "**** seq_num: "<< m_seq_num << std::endl;
293  std::cout << "**** cycle num: "<< m_cycle_num << std::endl;
294  std::cout << "**** cycle tag: "<< m_cycle_tag << std::endl;
295  std::cout << "**** cycle description: "<< m_cycle_description<< std::endl;
296  std::cout << "**** ccs_id: "<< m_ccs <<std::endl;
297  std::cout << "**** dcc_id: "<< m_dcc <<std::endl;
298  std::cout << "**** laser: "<< m_laser << std::endl;
299  std::cout << "**** ttcf_id: "<< m_ttcf << std::endl;
300  std::cout << "**** srp_id: "<< m_srp << std::endl;
301  std::cout << "**** scan_id: "<< m_scan << std::endl;
302  std::cout << "**** ODEcalCycle ****"<< std::endl;
303 
304 
305 }
306 
307 
309  throw(std::runtime_error)
310 {
311  this->checkConnection();
312  // result->clear();
313  if(result->getId()==0){
314  // throw(std::runtime_error("ODEcalCycle::fetchData(): no Id defined for this ODEcalCycle "));
315  result->fetchID();
316  }
317 
318  try {
319 
320  m_readStmt->setSQL("SELECT tag, version, sequence_num, cycle_num, cycle_tag, description, "
321  "ccs_configuration_id, dcc_configuration_id, laser_configuration_id, "
322  "ltc_configuration_id, lts_configuration_id, tcc_configuration_id, "
323  "\"TTCci_CONFIGURATION_ID\", jbh4_configuration_id, scan_id, TTCF_configuration_id, "
324  "srp_configuration_id, dcu_configuration_id, tcc_ee_configuration_id "
325  "FROM ECAL_CYCLE where cycle_id = :1 " );
326  m_readStmt->setInt(1, result->getId());
327  ResultSet* rset = m_readStmt->executeQuery();
328 
329  rset->next();
330 
331  result->setTag( rset->getString(1) );
332  result->setVersion( rset->getInt(2) );
333  result->setSeqNum( rset->getInt(3) );
334  result->setCycleNum( rset->getInt(4) );
335  result->setCycleTag( rset->getString(5) );
336  result->setCycleDescription( rset->getString(6) );
337  result->setCCSId( rset->getInt(7) );
338  result->setDCCId( rset->getInt(8) );
339  result->setLaserId( rset->getInt(9) );
340  result->setLTCId( rset->getInt(10) );
341  result->setLTSId( rset->getInt(11) );
342  result->setTCCId( rset->getInt(12) );
343  result->setTTCCIId( rset->getInt(13) );
344 
345 
346  result->setJBH4Id( rset->getInt(14) );
347  result->setScanId( rset->getInt(15) );
348 
349  result->setTTCFId( rset->getInt(16) );
350  result->setSRPId( rset->getInt(17) );
351  result->setDCUId( rset->getInt(18) );
352  result->setTCCEEId( rset->getInt(19) );
353 
354  } catch (SQLException &e) {
355  throw(std::runtime_error("ODEcalCycle::fetchData(): "+e.getMessage()));
356  }
357 }
358 
void insertConfig()
void insertConfig()
Definition: ODTTCFCycle.cc:158
void insertConfig()
Definition: ODTCCCycle.cc:158
void prepareWrite()
Definition: ODEcalCycle.cc:44
void insertConfig()
Definition: ODDCUCycle.cc:158
void setId(int id)
Definition: ODTCCEECycle.h:21
void setId(int id)
Definition: ODTTCFCycle.h:21
void setId(int id)
Definition: ODLaserCycle.h:21
void clear()
Definition: ODEcalCycle.cc:179
void fetchData(ODEcalCycle *result)
Definition: ODEcalCycle.cc:308
void setDescription(std::string x)
void setJBH4ConfigurationID(int x)
Definition: ODJBH4Cycle.h:25
void printout()
Definition: ODEcalCycle.cc:286
void setId(int id)
Definition: ODDCUCycle.h:21
void insertConfig()
Definition: ODScanCycle.cc:158
void setId(int id)
Definition: ODLTSCycle.h:21
#define NULL
Definition: scimark2.h:8
void setLTCConfigurationID(int x)
Definition: ODLTCCycle.h:26
void setId(int id)
Definition: ODCCSCycle.h:21
void setId(int id)
Definition: ODScanCycle.h:22
void writeDB()
Definition: ODEcalCycle.cc:54
void insertConfig()
Definition: ODJBH4Cycle.cc:158
void setDCCConfigurationID(int x)
Definition: ODDCCCycle.h:25
void setTCCConfigurationID(int x)
Definition: ODTCCEECycle.h:25
void setId(int id)
Definition: ODTTCciCycle.h:21
void clear(CLHEP::HepGenMatrix &m)
Helper function: Reset all elements of a matrix to 0.
Definition: matutil.cc:167
tuple result
Definition: query.py:137
void setId(int id)
Definition: ODTCCCycle.h:21
void setTTCFConfigurationID(int x)
Definition: ODTTCFCycle.h:25
void setTCCConfigurationID(int x)
Definition: ODTCCCycle.h:25
oracle::occi::Statement Statement
Definition: IODConfig.h:23
void setTag(std::string x)
void insertConfig()
Definition: ODLTCCycle.cc:158
void setId(int id)
Definition: ODSRPCycle.h:21
void insertConfig()
Definition: ODCCSCycle.cc:158
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:26
void setDCUConfigurationID(int x)
Definition: ODDCUCycle.h:25
void setLTSConfigurationID(int x)
Definition: ODLTSCycle.h:25
oracle::occi::SQLException SQLException
Definition: IODConfig.h:22
void setSRPConfigurationID(int x)
Definition: ODSRPCycle.h:25
void setCCSConfigurationID(int x)
Definition: ODCCSCycle.h:25
tuple cout
Definition: gather_cfg.py:121
void insertConfig()
void setByID(int id)
Definition: ODEcalCycle.cc:236
void setConnection(oracle::occi::Environment *env, oracle::occi::Connection *conn)
Definition: IDBObject.h:23
void setId(int id)
Definition: ODLTCCycle.h:22
void setId(int id)
Definition: ODDCCCycle.h:21
void setScanConfigurationID(int x)
Definition: ODScanCycle.h:26
void setTTCciConfigurationID(int x)
Definition: ODTTCciCycle.h:25
void setId(int id)
Definition: ODJBH4Cycle.h:21
void insertConfig()
Definition: ODLTSCycle.cc:158
void setLaserConfigurationID(int x)
Definition: ODLaserCycle.h:25
void insertConfig()
Definition: ODSRPCycle.cc:158
void insertConfig()
void insertConfig()
Definition: ODDCCCycle.cc:158
tuple dh
Definition: cuy.py:353