CMS 3D CMS Logo

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