CMS 3D CMS Logo

ODTCCEEConfig.cc
Go to the documentation of this file.
1 #include <stdexcept>
2 #include <string>
3 #include <cstdlib>
4 
6 
8 
9 using namespace std;
10 using namespace oracle::occi;
11 
13  m_env = nullptr;
14  m_conn = nullptr;
15  m_writeStmt = nullptr;
16  m_readStmt = nullptr;
17  m_config_tag = "";
18 
19  m_ID = 0;
20  clear();
21  m_size = 0;
22 }
23 
25  m_tcc_ee_file = "";
26  m_lut_file = "";
27  m_slb_file = "";
28  m_test_url = "";
29  m_ntest = 0;
30 }
31 
33 
35  int result = 0;
36  try {
37  this->checkConnection();
38 
39  m_readStmt = m_conn->createStatement();
40  m_readStmt->setSQL("select ecal_tcc_ee_config_sq.NextVal from dual");
41  ResultSet* rset = m_readStmt->executeQuery();
42  while (rset->next()) {
43  result = rset->getInt(1);
44  }
45  m_conn->terminateStatement(m_readStmt);
46  return result;
47 
48  } catch (SQLException& e) {
49  throw(std::runtime_error(std::string("ODTCCEEConfig::fetchNextId(): ") + e.getMessage()));
50  }
51 }
52 
53 void ODTCCEEConfig::setParameters(const std::map<string, string>& my_keys_map) {
54  // parses the result of the XML parser that is a map of
55  // string string with variable name variable value
56 
57  for (std::map<std::string, std::string>::const_iterator ci = my_keys_map.begin(); ci != my_keys_map.end(); ci++) {
58  if (ci->first == "TCC_EE_CONFIGURATION_ID")
59  setConfigTag(ci->second);
60  if (ci->first == "N_TESTPATTERNS_TO_LOAD")
61  setNTestPatternsToLoad(atoi(ci->second.c_str()));
62  if (ci->first == "LUT_CONFIGURATION_FILE")
63  setLUTConfigurationFile(ci->second);
64  if (ci->first == "CONFIGURATION_FILE")
65  setTCCConfigurationFile(ci->second);
66  if (ci->first == "SLB_CONFIGURATION_FILE")
67  setSLBConfigurationFile(ci->second);
68  if (ci->first == "TESTPATTERNFILE_URL")
69  setTestPatternFileUrl(ci->second);
70 
71  if (ci->first == "SLB_LATENCY")
72  setSLBLatency(atoi(ci->second.c_str()));
73  if (ci->first == "SLBLATENCY")
74  setSLBLatency(atoi(ci->second.c_str()));
75 
76  if (ci->first == "TRIGGER_POS")
77  setTriggerPos(atoi(ci->second.c_str()));
78  }
79 }
80 
82  this->checkConnection();
83 
84  int next_id = fetchNextId();
85 
86  try {
87  m_writeStmt = m_conn->createStatement();
88  m_writeStmt->setSQL(
89  "INSERT INTO ECAL_TCC_EE_CONFIGURATION (tcc_ee_configuration_id, tcc_ee_tag, "
90  "Configuration_file, LUT_CONFIGURATION_FILE, SLB_CONFIGURATION_FILE, "
91  "TESTPATTERNFILE_URL , N_TESTPATTERNS_TO_LOAD, TRIGGER_POS, "
92  "tcc_configuration, lut_configuration, slb_configuration, slblatency ) "
93  "VALUES (:1, :2, :3, :4, :5, :6, :7, :8 , :9, :10, :11, :12)");
94  m_writeStmt->setInt(1, next_id);
95  m_writeStmt->setString(2, getConfigTag());
96  m_writeStmt->setString(3, getTCCConfigurationFile());
97  m_writeStmt->setString(4, getLUTConfigurationFile());
98  m_writeStmt->setString(5, getSLBConfigurationFile());
99  m_writeStmt->setString(6, getTestPatternFileUrl());
100  m_writeStmt->setInt(7, getNTestPatternsToLoad());
101  m_writeStmt->setInt(8, getTrigPos());
102  m_writeStmt->setInt(12, getSLBLatency());
103  // and now the clobs
104  oracle::occi::Clob clob1(m_conn);
105  clob1.setEmpty();
106  m_writeStmt->setClob(9, clob1);
107 
108  oracle::occi::Clob clob2(m_conn);
109  clob2.setEmpty();
110  m_writeStmt->setClob(10, clob2);
111 
112  oracle::occi::Clob clob3(m_conn);
113  clob3.setEmpty();
114  m_writeStmt->setClob(11, clob3);
115 
116  m_writeStmt->executeUpdate();
117  m_ID = next_id;
118 
119  m_conn->terminateStatement(m_writeStmt);
120  std::cout << "TCC 3 empty Clobs inserted into CONFIGURATION with id=" << next_id << std::endl;
121 
122  // now we read and update it
123  m_writeStmt = m_conn->createStatement();
124  m_writeStmt->setSQL(
125  "SELECT tcc_configuration, lut_configuration, slb_configuration FROM ECAL_TCC_EE_CONFIGURATION WHERE"
126  " tcc_ee_configuration_id=:1 FOR UPDATE");
127 
128  std::cout << "updating the clobs 0" << std::endl;
129 
130  } catch (SQLException& e) {
131  throw(std::runtime_error(std::string("ODTCCEEConfig::prepareWrite(): ") + e.getMessage()));
132  }
133 
134  std::cout << "updating the clob 1 " << std::endl;
135 }
136 
137 void ODTCCEEConfig::writeDB() noexcept(false) {
138  std::cout << "updating the clob 2" << std::endl;
139 
140  try {
141  m_writeStmt->setInt(1, m_ID);
142  ResultSet* rset = m_writeStmt->executeQuery();
143 
144  while (rset->next()) {
145  oracle::occi::Clob clob1 = rset->getClob(1);
146  oracle::occi::Clob clob2 = rset->getClob(2);
147  oracle::occi::Clob clob3 = rset->getClob(3);
148  cout << "Opening the clob in read write mode" << endl;
149  cout << "Populating the clobs" << endl;
150  populateClob(clob1, getTCCConfigurationFile(), m_size);
151  populateClob(clob2, getLUTConfigurationFile(), m_size);
152  populateClob(clob3, getSLBConfigurationFile(), m_size);
153  }
154 
155  m_writeStmt->executeUpdate();
156  m_writeStmt->closeResultSet(rset);
157 
158  } catch (SQLException& e) {
159  throw(std::runtime_error(std::string("ODTCCEEConfig::writeDB(): ") + e.getMessage()));
160  }
161  // Now get the ID
162  if (!this->fetchID()) {
163  throw(std::runtime_error("ODTCCEEConfig::writeDB: Failed to write"));
164  }
165 }
166 
168  this->checkConnection();
169  result->clear();
170  if (result->getId() == 0 && (result->getConfigTag().empty())) {
171  throw(std::runtime_error("ODTCCEEConfig::fetchData(): no Id defined for this ODTCCEEConfig "));
172  }
173 
174  try {
175  m_readStmt->setSQL(
176  "SELECT * "
177  "FROM ECAL_TCC_EE_CONFIGURATION d "
178  " where (tcc_ee_configuration_id = :1 or tcc_ee_tag=:2 )");
179  m_readStmt->setInt(1, result->getId());
180  m_readStmt->setString(2, result->getConfigTag());
181  ResultSet* rset = m_readStmt->executeQuery();
182 
183  rset->next();
184  // the first is the id
185  result->setId(rset->getInt(1));
186  result->setConfigTag(rset->getString(2));
187 
188  result->setTCCConfigurationFile(rset->getString(3));
189  result->setLUTConfigurationFile(rset->getString(4));
190  result->setSLBConfigurationFile(rset->getString(5));
191  result->setTestPatternFileUrl(rset->getString(6));
192  result->setNTestPatternsToLoad(rset->getInt(7));
193  result->setSLBLatency(rset->getInt(12));
194  //
195 
196  Clob clob1 = rset->getClob(8);
197  cout << "Opening the clob in Read only mode" << endl;
198  clob1.open(OCCI_LOB_READONLY);
199  int clobLength = clob1.length();
200  cout << "Length of the clob1 is: " << clobLength << endl;
201  unsigned char* buffer = readClob(clob1, clobLength);
202  clob1.close();
203  cout << "the clob buffer is:" << endl;
204  for (int i = 0; i < clobLength; ++i)
205  cout << (char)buffer[i];
206  cout << endl;
207  result->setTCCClob(buffer);
208 
209  Clob clob2 = rset->getClob(9);
210  cout << "Opening the clob in Read only mode" << endl;
211  clob2.open(OCCI_LOB_READONLY);
212  clobLength = clob2.length();
213  cout << "Length of the clob2 is: " << clobLength << endl;
214  unsigned char* buffer2 = readClob(clob2, clobLength);
215  clob2.close();
216  cout << "the clob buffer is:" << endl;
217  for (int i = 0; i < clobLength; ++i)
218  cout << (char)buffer2[i];
219  cout << endl;
220  result->setLUTClob(buffer2);
221 
222  Clob clob3 = rset->getClob(10);
223  cout << "Opening the clob in Read only mode" << endl;
224  clob3.open(OCCI_LOB_READONLY);
225  clobLength = clob3.length();
226  cout << "Length of the clob3 is: " << clobLength << endl;
227  unsigned char* buffer3 = readClob(clob3, clobLength);
228  clob3.close();
229  cout << "the clob buffer is:" << endl;
230  for (int i = 0; i < clobLength; ++i)
231  cout << (char)buffer3[i];
232  cout << endl;
233  result->setSLBClob(buffer3);
234 
235  } catch (SQLException& e) {
236  throw(std::runtime_error(std::string("ODTCCEEConfig::fetchData(): ") + e.getMessage()));
237  }
238 }
239 
240 int ODTCCEEConfig::fetchID() noexcept(false) {
241  if (m_ID != 0) {
242  return m_ID;
243  }
244 
245  this->checkConnection();
246 
247  try {
248  Statement* stmt = m_conn->createStatement();
249  stmt->setSQL(
250  "SELECT tcc_ee_configuration_id FROM ecal_tcc_ee_configuration "
251  "WHERE tcc_ee_tag=:tcc_ee_tag ");
252 
253  stmt->setString(1, getConfigTag());
254 
255  ResultSet* rset = stmt->executeQuery();
256 
257  if (rset->next()) {
258  m_ID = rset->getInt(1);
259  } else {
260  m_ID = 0;
261  }
262  m_conn->terminateStatement(stmt);
263  } catch (SQLException& e) {
264  throw(std::runtime_error(std::string("ODTCCEEConfig::fetchID: ") + e.getMessage()));
265  }
266 
267  return m_ID;
268 }
void writeDB() noexcept(false)
void fetchData(ODTCCEEConfig *result) noexcept(false)
int fetchNextId() noexcept(false)
void setParameters(const std::map< std::string, std::string > &my_keys_map)
oracle::occi::Statement Statement
Definition: IODConfig.h:21
oracle::occi::Clob Clob
Definition: IODConfig.h:23
~ODTCCEEConfig() override
int fetchID() noexcept(false)
oracle::occi::SQLException SQLException
Definition: IODConfig.h:20
void clear(EGIsoObj &c)
Definition: egamma.h:82
void prepareWrite() noexcept(false) override