CMS 3D CMS Logo

ODDCCConfig.cc
Go to the documentation of this file.
1 #include <stdexcept>
2 #include <string>
3 #include <fstream>
4 #include <iostream>
5 #include <cstdio>
6 #include <cstdlib>
7 
9 
11 
12 using namespace std;
13 using namespace oracle::occi;
14 
16  m_env = nullptr;
17  m_conn = nullptr;
18  m_writeStmt = nullptr;
19  m_readStmt = nullptr;
20  m_size = 0;
21  m_config_tag = "";
22  m_ID = 0;
23  m_wei = "";
24  clear();
25 }
26 
28 
30  int result = 0;
31  try {
32  this->checkConnection();
33 
34  m_readStmt = m_conn->createStatement();
35  m_readStmt->setSQL("select ecal_dcc_config_sq.NextVal from dual");
36  ResultSet *rset = m_readStmt->executeQuery();
37  while (rset->next()) {
38  result = rset->getInt(1);
39  }
40  m_conn->terminateStatement(m_readStmt);
41  return result;
42 
43  } catch (SQLException &e) {
44  throw(std::runtime_error(std::string("ODDCCConfig::fetchNextId(): ") + e.getMessage()));
45  }
46 }
47 
48 void ODDCCConfig::prepareWrite() noexcept(false) {
49  this->checkConnection();
50 
51  int next_id = fetchNextId();
52 
53  try {
54  m_writeStmt = m_conn->createStatement();
55  m_writeStmt->setSQL(
56  "INSERT INTO ECAL_DCC_CONFIGURATION (dcc_configuration_id, dcc_tag, "
57  " DCC_CONFIGURATION_URL, TESTPATTERN_FILE_URL, "
58  " N_TESTPATTERNS_TO_LOAD , SM_HALF, weightsmode, "
59  " dcc_configuration) "
60  "VALUES (:1, :2, :3, :4, :5, :6 , :7 ,:8 )");
61  m_writeStmt->setInt(1, next_id);
62  m_writeStmt->setString(2, getConfigTag());
63  m_writeStmt->setString(3, getDCCConfigurationUrl());
64  m_writeStmt->setString(4, getTestPatternFileUrl());
65  m_writeStmt->setInt(5, getNTestPatternsToLoad());
66  m_writeStmt->setInt(6, getSMHalf());
67  m_writeStmt->setString(7, getDCCWeightsMode());
68 
69  // and now the clob
70  oracle::occi::Clob clob(m_conn);
71  clob.setEmpty();
72  m_writeStmt->setClob(8, clob);
73  m_writeStmt->executeUpdate();
74  m_ID = next_id;
75 
76  m_conn->terminateStatement(m_writeStmt);
77  std::cout << "DCC Clob inserted into CONFIGURATION with id=" << next_id << std::endl;
78 
79  // now we read and update it
80  m_writeStmt = m_conn->createStatement();
81  m_writeStmt->setSQL(
82  "SELECT dcc_configuration FROM ECAL_DCC_CONFIGURATION WHERE"
83  " dcc_configuration_id=:1 FOR UPDATE");
84 
85  std::cout << "updating the clob 0" << std::endl;
86 
87  } catch (SQLException &e) {
88  throw(std::runtime_error(std::string("ODDCCConfig::prepareWrite(): ") + e.getMessage()));
89  }
90 
91  std::cout << "updating the clob 1 " << std::endl;
92 }
93 
94 void ODDCCConfig::setParameters(const std::map<string, string> &my_keys_map) {
95  // parses the result of the XML parser that is a map of
96  // string string with variable name variable value
97 
98  for (std::map<std::string, std::string>::const_iterator ci = my_keys_map.begin(); ci != my_keys_map.end(); ci++) {
99  if (ci->first == "DCC_CONFIGURATION_ID")
100  setConfigTag(ci->second);
101  if (ci->first == "TESTPATTERN_FILE_URL")
102  setTestPatternFileUrl(ci->second);
103  if (ci->first == "N_TESTPATTERNS_TO_LOAD")
104  setNTestPatternsToLoad(atoi(ci->second.c_str()));
105  if (ci->first == "SM_HALF")
106  setSMHalf(atoi(ci->second.c_str()));
107  if (ci->first == "WEIGHTSMODE")
108  setDCCWeightsMode(ci->second);
109  if (ci->first == "DCC_CONFIGURATION_URL") {
110  std::string fname = ci->second;
111  setDCCConfigurationUrl(fname);
112 
113  // here we must open the file and read the DCC Clob
114  std::cout << "Going to read DCC file: " << fname << endl;
115 
116  ifstream inpFile;
117  inpFile.open(fname.c_str());
118 
119  // tell me size of file
120  int bufsize = 0;
121  inpFile.seekg(0, ios::end);
122  bufsize = inpFile.tellg();
123  std::cout << " bufsize =" << bufsize << std::endl;
124  // set file pointer to start again
125  inpFile.seekg(0, ios::beg);
126 
127  m_size = bufsize;
128 
129  inpFile.close();
130  }
131  }
132 }
133 
134 void ODDCCConfig::writeDB() noexcept(false) {
135  std::cout << "updating the clob " << std::endl;
136 
137  try {
138  m_writeStmt->setInt(1, m_ID);
139  ResultSet *rset = m_writeStmt->executeQuery();
140 
141  rset->next();
142  oracle::occi::Clob clob = rset->getClob(1);
143 
144  cout << "Opening the clob in read write mode" << endl;
145 
146  std::cout << "Populating the clob" << endl;
147 
148  populateClob(clob, getDCCConfigurationUrl(), m_size);
149  int clobLength = clob.length();
150  cout << "Length of the clob is: " << clobLength << endl;
151 
152  m_writeStmt->executeUpdate();
153 
154  m_writeStmt->closeResultSet(rset);
155 
156  } catch (SQLException &e) {
157  throw(std::runtime_error(std::string("ODDCCConfig::writeDB(): ") + e.getMessage()));
158  }
159  // Now get the ID
160  if (!this->fetchID()) {
161  throw(std::runtime_error("ODDCCConfig::writeDB: Failed to write"));
162  }
163 }
164 
166  m_dcc_url = "";
167  m_test_url = "";
168  m_ntest = 0;
169  m_sm_half = 0;
170  m_wei = "";
171 }
172 
173 void ODDCCConfig::fetchData(ODDCCConfig *result) noexcept(false) {
174  this->checkConnection();
175  // result->clear();
176  if (result->getId() == 0 && (result->getConfigTag().empty())) {
177  // throw(std::runtime_error("ODDCCConfig::fetchData(): no Id defined for this ODDCCConfig "));
178  result->fetchID();
179  }
180 
181  try {
182  m_readStmt->setSQL(
183  "SELECT * "
184  "FROM ECAL_DCC_CONFIGURATION "
185  " where dcc_configuration_id = :1 or dcc_tag=:2 ");
186  m_readStmt->setInt(1, result->getId());
187  m_readStmt->setString(2, result->getConfigTag());
188  ResultSet *rset = m_readStmt->executeQuery();
189 
190  rset->next();
191 
192  // 1 is the id and 2 is the config tag
193 
194  result->setId(rset->getInt(1));
195  result->setConfigTag(rset->getString(2));
196  result->setDCCConfigurationUrl(rset->getString(3));
197  result->setTestPatternFileUrl(rset->getString(4));
198  result->setNTestPatternsToLoad(rset->getInt(5));
199  result->setSMHalf(rset->getInt(6));
200 
201  Clob clob = rset->getClob(7);
202  m_size = clob.length();
203  Stream *instream = clob.getStream(1, 0);
204  unsigned char *buffer = new unsigned char[m_size];
205  memset(buffer, 0, m_size);
206  instream->readBuffer((char *)buffer, m_size);
207  /*
208  cout << "Opening the clob in Read only mode" << endl;
209  clob.open (OCCI_LOB_READONLY);
210  int clobLength=clob.length ();
211  cout << "Length of the clob is: " << clobLength << endl;
212  m_size=clobLength;
213  unsigned char* buffer = readClob (clob, m_size);
214  clob.close ();
215  cout<< "the clob buffer is:"<<endl;
216  for (int i = 0; i < clobLength; ++i)
217  cout << (char) buffer[i];
218  cout << endl;
219 
220 
221  */
222  result->setDCCClob(buffer);
223  result->setDCCWeightsMode(rset->getString(8));
224 
225  } catch (SQLException &e) {
226  throw(std::runtime_error(std::string("ODDCCConfig::fetchData(): ") + e.getMessage()));
227  }
228 }
229 
230 int ODDCCConfig::fetchID() noexcept(false) {
231  if (m_ID != 0) {
232  return m_ID;
233  }
234 
235  this->checkConnection();
236 
237  try {
238  Statement *stmt = m_conn->createStatement();
239  stmt->setSQL(
240  "SELECT DCC_configuration_id FROM ecal_dcc_configuration "
241  "WHERE dcc_tag=:dcc_tag ");
242 
243  stmt->setString(1, getConfigTag());
244 
245  ResultSet *rset = stmt->executeQuery();
246 
247  if (rset->next()) {
248  m_ID = rset->getInt(1);
249  } else {
250  m_ID = 0;
251  }
252  m_conn->terminateStatement(stmt);
253  } catch (SQLException &e) {
254  throw(std::runtime_error(std::string("ODDCCConfig::fetchID: ") + e.getMessage()));
255  }
256 
257  return m_ID;
258 }
ODDCCConfig.h
funct::false
false
Definition: Factorize.h:34
ODDCCConfig::prepareWrite
void prepareWrite() noexcept(false) override
Definition: ODDCCConfig.cc:48
IODConfig::Statement
oracle::occi::Statement Statement
Definition: IODConfig.h:21
gather_cfg.cout
cout
Definition: gather_cfg.py:144
ODDCCConfig::fetchID
int fetchID() noexcept(false)
Definition: ODDCCConfig.cc:230
ODDCCConfig
Definition: ODDCCConfig.h:15
ODDCCConfig::writeDB
void writeDB() noexcept(false)
Definition: ODDCCConfig.cc:134
ODDCCConfig::fetchData
void fetchData(ODDCCConfig *result) noexcept(false)
Definition: ODDCCConfig.cc:173
IODConfig::SQLException
oracle::occi::SQLException SQLException
Definition: IODConfig.h:20
end
#define end
Definition: vmac.h:39
edmScanValgrind.buffer
buffer
Definition: edmScanValgrind.py:171
IODConfig::Stream
oracle::occi::Stream Stream
Definition: IODConfig.h:22
oracle::occi
Definition: ConnectionManager.h:7
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
clear
void clear(HadCaloObj &c)
Definition: data.h:124
ODDCCConfig::fetchNextId
int fetchNextId() noexcept(false)
Definition: ODDCCConfig.cc:29
alignmentValidation.fname
string fname
main script
Definition: alignmentValidation.py:959
IODConfig::Clob
oracle::occi::Clob Clob
Definition: IODConfig.h:23
std
Definition: JetResolutionObject.h:76
ODDCCConfig::setParameters
void setParameters(const std::map< std::string, std::string > &my_keys_map)
Definition: ODDCCConfig.cc:94
ODDCCConfig::~ODDCCConfig
~ODDCCConfig() override
Definition: ODDCCConfig.cc:27
Oracle.h
mps_fire.result
result
Definition: mps_fire.py:303
ODDCCConfig::ODDCCConfig
ODDCCConfig()
Definition: ODDCCConfig.cc:15
ODDCCConfig::clear
void clear()
Definition: ODDCCConfig.cc:165
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37