19 m_writeStmt =
nullptr;
32 std::cout <<
"file is " << m_file << endl;
37 std::cout <<
"Going to read CCS file: " << m_file << endl;
39 inpFile.open(m_file.c_str());
43 bufsize = inpFile.tellg();
44 std::cout <<
" bufsize =" << bufsize << std::endl;
46 inpFile.seekg(0, ios::beg);
49 std::cout <<
"Going to read CCS file: " << m_file << endl;
53 this->checkConnection();
56 m_writeStmt = m_conn->createStatement();
58 "INSERT INTO OD_CCS_HF_dat (iov_id, logic_id, " 60 "VALUES (:iov_id, :logic_id, " 63 }
catch (SQLException&
e) {
64 throw(std::runtime_error(
std::string(
"MODCCSHFDat::prepareWrite(): ") + e.getMessage()));
69 this->checkConnection();
72 int iovID = iov->fetchID();
74 throw(std::runtime_error(
"MODCCSHFDat::writeDB: IOV not in DB"));
77 int logicID = ecid->getLogicID();
79 throw(std::runtime_error(
"MODCCSHFDat::writeDB: Bad EcalLogicID"));
83 std::cout <<
"Going to read CCS file: " << fname << endl;
86 m_writeStmt->setInt(1, iovID);
87 m_writeStmt->setInt(2, logicID);
90 oracle::occi::Clob clob(m_conn);
92 m_writeStmt->setClob(3, clob);
93 m_writeStmt->executeUpdate();
95 m_conn->terminateStatement(m_writeStmt);
96 std::cout <<
"empty CCS Clob inserted into DB" << std::endl;
99 m_writeStmt = m_conn->createStatement();
101 "SELECT CCS_LOG FROM OD_CCS_HF_DAT WHERE" 102 " iov_ID=:1 and logic_ID=:2 FOR UPDATE");
103 m_writeStmt->setInt(1, iovID);
104 m_writeStmt->setInt(2, logicID);
105 ResultSet* rset = m_writeStmt->executeQuery();
107 oracle::occi::Clob clob2 = rset->getClob(1);
108 cout <<
"Opening the clob in read write mode" << endl;
110 unsigned int clob_size =
item->getSize();
112 populateClob(clob2, fname, clob_size);
114 int clobLength = clob2.length();
115 cout <<
"Length of the clob is: " << clobLength << endl;
117 m_writeStmt->executeUpdate();
118 m_writeStmt->closeResultSet(rset);
120 }
catch (SQLException&
e) {
121 throw(std::runtime_error(
std::string(
"MODCCSHFDat::writeDB(): ") + e.getMessage()));
126 this->checkConnection();
129 iov->setConnection(m_env, m_conn);
130 int iovID = iov->fetchID();
138 "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, " 140 "FROM channelview cv JOIN OD_CCS_HF_dat d " 141 "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to " 142 "WHERE d.iov_id = :iov_id");
143 m_readStmt->setInt(1, iovID);
144 ResultSet* rset = m_readStmt->executeQuery();
146 std::pair<EcalLogicID, MODCCSHFDat>
p;
148 while (rset->next()) {
161 }
catch (SQLException&
e) {
162 throw(std::runtime_error(
std::string(
"MODCCSHFDat::fetchData(): ") + e.getMessage()));
167 this->checkConnection();
168 this->checkPrepare();
170 int iovID = iov->fetchID();
172 throw(std::runtime_error(
"MODCCSHFDat::writeArrayDB: IOV not in DB"));
175 int nrows =
data->size();
176 int*
ids =
new int[nrows];
177 int* iovid_vec =
new int[nrows];
178 int*
xx =
new int[nrows];
180 ub2* ids_len =
new ub2[nrows];
181 ub2* iov_len =
new ub2[nrows];
182 ub2* x_len =
new ub2[nrows];
187 typedef map<EcalLogicID, MODCCSHFDat>::const_iterator CI;
188 for (CI
p =
data->begin();
p !=
data->end(); ++
p) {
189 channel = &(
p->first);
192 throw(std::runtime_error(
"MODCCSHFDat::writeArrayDB: Bad EcalLogicID"));
194 ids[
count] = logicID;
195 iovid_vec[
count] = iovID;
215 m_writeStmt->setDataBuffer(1, (dvoid*)iovid_vec, OCCIINT,
sizeof(iovid_vec[0]), iov_len);
216 m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT,
sizeof(ids[0]), ids_len);
217 m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIINT,
sizeof(xx[0]), x_len);
219 m_writeStmt->executeArrayUpdate(nrows);
229 }
catch (SQLException&
e) {
230 throw(std::runtime_error(
std::string(
"MonPedestalsDat::writeArrayDB(): ") + e.getMessage()));
237 cout <<
"Populating the Clob using writeBuffer(Stream) method" << endl;
238 std::cout <<
"we are here0" << std::endl;
249 inFile.open(fname2.c_str(),
ios::in);
251 if (clob_size == 0) {
253 clob_size = inFile.tellg();
254 std::cout <<
" bufsize =" << clob_size << std::endl;
256 inFile.seekg(0, ios::beg);
259 char*
buffer =
new char[clob_size + 1];
261 std::cout <<
"we are here1" << std::endl;
263 Stream* strm = clob.getStream();
264 std::cout <<
"we are here2" << std::endl;
268 memset(buffer, buf, clob_size + 1);
269 inFile.read(buffer, clob_size);
270 std::cout <<
"we are here2.5" << std::endl;
272 strm->writeBuffer(buffer, strlen(buffer));
273 std::cout <<
"we are here2.6" << std::endl;
276 std::cout <<
"we are here3" << std::endl;
278 size = strlen(buffer);
279 strm->writeLastBuffer(buffer, size);
280 clob.closeStream(strm);
282 std::cout <<
"we are here4" << std::endl;
285 }
catch (SQLException&
e) {
286 throw(std::runtime_error(
std::string(
"populateClob(): ") + e.getMessage()));
289 cout <<
"Populating the Clob - Success" << endl;
294 Stream* instream = clob.getStream(1, 0);
295 unsigned char*
buffer =
new unsigned char[
size];
297 memset(buffer, buf,
size);
299 instream->readBuffer((
char*)buffer,
size);
300 cout <<
"remember to delete the char* at the end of the program ";
302 cout << (
char)buffer[
i];
305 clob.closeStream(instream);
309 }
catch (SQLException&
e) {
310 throw(std::runtime_error(
std::string(
"readClob(): ") + e.getMessage()));
unsigned char * readClob(Clob &clob, int size) noexcept(false)
void prepareWrite() noexcept(false) override
void fetchData(std::map< EcalLogicID, MODCCSHFDat > *fillMap, MODRunIOV *iov) noexcept(false)
void writeDB(const EcalLogicID *ecid, const MODCCSHFDat *item, MODRunIOV *iov) noexcept(false)
void setFile(std::string x)
void writeArrayDB(const std::map< EcalLogicID, MODCCSHFDat > *data, MODRunIOV *iov) noexcept(false)
void populateClob(Clob &clob, std::string fname, unsigned int clob_size) noexcept(false)
char data[epos_bytes_allocation]