CMS 3D CMS Logo

ODTTCFConfig.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  m_ID = 0;
19  clear();
20  m_size = 0;
21 }
22 
24 
26 
28  int result = 0;
29  try {
30  this->checkConnection();
31  std::cout << "going to fetch new id for TTCF 1" << endl;
32  m_readStmt = m_conn->createStatement();
33  m_readStmt->setSQL("select ecal_ttcf_config_sq.NextVal from dual");
34  ResultSet* rset = m_readStmt->executeQuery();
35  while (rset->next()) {
36  result = rset->getInt(1);
37  }
38  std::cout << "id is : " << result << endl;
39 
40  m_conn->terminateStatement(m_readStmt);
41  return result;
42 
43  } catch (SQLException& e) {
44  throw(std::runtime_error(std::string("ODTTCFConfig::fetchNextId(): ") + e.getMessage()));
45  }
46 }
47 
49  this->checkConnection();
50  int next_id = fetchNextId();
51 
52  try {
53  m_writeStmt = m_conn->createStatement();
54  m_writeStmt->setSQL(
55  "INSERT INTO ECAL_TTCF_CONFIGURATION (ttcf_configuration_id, ttcf_tag, "
56  " rxbc0_delay, reg_30 , ttcf_configuration_file , ttcf_configuration ) "
57  "VALUES (:1, :2, :3 , :4, :5, :6)");
58  m_writeStmt->setInt(1, next_id);
59  m_writeStmt->setString(2, getConfigTag());
60 
61  m_writeStmt->setInt(3, getRxBC0Delay());
62  m_writeStmt->setInt(4, getReg30());
63 
64  m_writeStmt->setString(5, getTTCFConfigurationFile());
65 
66  oracle::occi::Clob clob(m_conn);
67  clob.setEmpty();
68  m_writeStmt->setClob(6, clob);
69  m_writeStmt->executeUpdate();
70  m_ID = next_id;
71 
72  m_conn->terminateStatement(m_writeStmt);
73  std::cout << "inserted into CONFIGURATION with id=" << next_id << std::endl;
74 
75  // now we read and update it
76  m_writeStmt = m_conn->createStatement();
77  m_writeStmt->setSQL(
78  "SELECT ttcf_configuration FROM ECAL_TTCF_CONFIGURATION WHERE"
79  " ttcf_configuration_id=:1 FOR UPDATE");
80 
81  std::cout << "updating the clob 0" << std::endl;
82 
83  } catch (SQLException& e) {
84  throw(std::runtime_error(std::string("ODTTCFConfig::prepareWrite(): ") + e.getMessage()));
85  }
86 
87  std::cout << "updating the clob 1 " << std::endl;
88 }
89 
90 void ODTTCFConfig::writeDB() noexcept(false) {
91  std::cout << "updating the clob 2" << std::endl;
92 
93  try {
94  m_writeStmt->setInt(1, m_ID);
95  ResultSet* rset = m_writeStmt->executeQuery();
96 
97  rset->next();
98 
99  oracle::occi::Clob clob = rset->getClob(1);
100  cout << "Opening the clob in read write mode" << endl;
101  populateClob(clob, getTTCFConfigurationFile(), m_size);
102  int clobLength = clob.length();
103  cout << "Length of the clob is: " << clobLength << endl;
104 
105  m_writeStmt->executeUpdate();
106  m_writeStmt->closeResultSet(rset);
107 
108  } catch (SQLException& e) {
109  throw(std::runtime_error(std::string("ODTTCFConfig::writeDB(): ") + e.getMessage()));
110  }
111  // Now get the ID
112  if (!this->fetchID()) {
113  throw(std::runtime_error("ODTTCFConfig::writeDB: Failed to write"));
114  }
115 }
116 
118  this->checkConnection();
119  result->clear();
120 
121  if (result->getId() == 0 && (result->getConfigTag().empty())) {
122  throw(std::runtime_error("ODTTCFConfig::fetchData(): no Id defined for this ODTTCFConfig "));
123  }
124 
125  try {
126  m_readStmt->setSQL(
127  "SELECT * "
128  "FROM ECAL_TTCF_CONFIGURATION "
129  " where (ttcf_configuration_id = :1 or ttcf_tag= :2) ");
130  m_readStmt->setInt(1, result->getId());
131  m_readStmt->setString(2, result->getConfigTag());
132  ResultSet* rset = m_readStmt->executeQuery();
133 
134  rset->next();
135 
136  result->setId(rset->getInt(1));
137  result->setConfigTag(rset->getString(2));
138  result->setTTCFConfigurationFile(rset->getString(3));
139  Clob clob = rset->getClob(4);
140  cout << "Opening the clob in Read only mode" << endl;
141  clob.open(OCCI_LOB_READONLY);
142  int clobLength = clob.length();
143  cout << "Length of the clob is: " << clobLength << endl;
144  m_size = clobLength;
145  unsigned char* buffer = readClob(clob, m_size);
146  clob.close();
147  result->setTTCFClob((unsigned char*)buffer);
148 
149  } catch (SQLException& e) {
150  throw(std::runtime_error(std::string("ODTTCFConfig::fetchData(): ") + e.getMessage()));
151  }
152 }
153 
154 int ODTTCFConfig::fetchID() noexcept(false) {
155  if (m_ID != 0) {
156  return m_ID;
157  }
158 
159  this->checkConnection();
160 
161  try {
162  Statement* stmt = m_conn->createStatement();
163  stmt->setSQL(
164  "SELECT ttcf_configuration_id FROM ecal_ttcf_configuration "
165  "WHERE ttcf_tag=:ttcf_tag ");
166 
167  stmt->setString(1, getConfigTag());
168 
169  ResultSet* rset = stmt->executeQuery();
170 
171  if (rset->next()) {
172  m_ID = rset->getInt(1);
173  } else {
174  m_ID = 0;
175  }
176  m_conn->terminateStatement(stmt);
177  } catch (SQLException& e) {
178  throw(std::runtime_error(std::string("ODTTCFConfig::fetchID: ") + e.getMessage()));
179  }
180 
181  return m_ID;
182 }
183 
184 void ODTTCFConfig::setParameters(const std::map<string, string>& my_keys_map) {
185  // parses the result of the XML parser that is a map of
186  // string string with variable name variable value
187 
188  for (std::map<std::string, std::string>::const_iterator ci = my_keys_map.begin(); ci != my_keys_map.end(); ci++) {
189  if (ci->first == "TTCF_CONFIGURATION_ID")
190  setConfigTag(ci->second);
191  if (ci->first == "Configuration") {
192  std::string fname = ci->second;
193  string str3;
194  size_t pos, pose;
195 
196  pos = fname.find('='); // position of "live" in str
197  pose = fname.size(); // position of "]" in str
198  str3 = fname.substr(pos + 1, pose - pos - 2);
199 
200  cout << "fname=" << fname << " and reduced is: " << str3 << endl;
201  setTTCFConfigurationFile(str3);
202 
203  // here we must open the file and read the LTC Clob
204  std::cout << "Going to read file: " << str3 << endl;
205 
206  ifstream inpFile;
207  inpFile.open(str3.c_str());
208 
209  // tell me size of file
210  int bufsize = 0;
211  inpFile.seekg(0, ios::end);
212  bufsize = inpFile.tellg();
213  std::cout << " bufsize =" << bufsize << std::endl;
214  // set file pointer to start again
215  inpFile.seekg(0, ios::beg);
216 
217  inpFile.close();
218  m_size = bufsize;
219 
220  } else if (ci->first == "RXBC0_DELAY") {
221  setRxBC0Delay(atoi(ci->second.c_str()));
222  } else if (ci->first == "REG_30") {
223  setReg30(atoi(ci->second.c_str()));
224  }
225  }
226 }
ODTTCFConfig::prepareWrite
void prepareWrite() noexcept(false) override
Definition: ODTTCFConfig.cc:48
ODTTCFConfig::fetchData
void fetchData(ODTTCFConfig *result) noexcept(false)
Definition: ODTTCFConfig.cc:117
funct::false
false
Definition: Factorize.h:29
IODConfig::Statement
oracle::occi::Statement Statement
Definition: IODConfig.h:21
gather_cfg.cout
cout
Definition: gather_cfg.py:144
pos
Definition: PixelAliasList.h:18
ODTTCFConfig::fetchID
int fetchID() noexcept(false)
Definition: ODTTCFConfig.cc:154
IODConfig::SQLException
oracle::occi::SQLException SQLException
Definition: IODConfig.h:20
edmScanValgrind.buffer
buffer
Definition: edmScanValgrind.py:171
ODTTCFConfig::fetchNextId
int fetchNextId() noexcept(false)
Definition: ODTTCFConfig.cc:27
ODTTCFConfig::~ODTTCFConfig
~ODTTCFConfig() override
Definition: ODTTCFConfig.cc:25
oracle::occi
Definition: ConnectionManager.h:7
mps_fire.end
end
Definition: mps_fire.py:242
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
ODTTCFConfig
Definition: ODTTCFConfig.h:15
clear
void clear(HadCaloObj &c)
Definition: data.h:124
ODTTCFConfig::ODTTCFConfig
ODTTCFConfig()
Definition: ODTTCFConfig.cc:12
ODTTCFConfig::setParameters
void setParameters(const std::map< std::string, std::string > &my_keys_map)
Definition: ODTTCFConfig.cc:184
ODTTCFConfig.h
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
ODTTCFConfig::clear
void clear()
Definition: ODTTCFConfig.cc:23
Oracle.h
mps_fire.result
result
Definition: mps_fire.py:311
ODTTCFConfig::writeDB
void writeDB() noexcept(false)
Definition: ODTTCFConfig.cc:90
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37