CMS 3D CMS Logo

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