CMS 3D CMS Logo

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