CMS 3D CMS Logo

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