21 m_writeStmt =
nullptr;
45 std::cout <<
"Going to read CCS file: " << m_file << endl;
47 inpFile.open(m_file.c_str());
51 bufsize = inpFile.tellg();
52 std::cout <<
" bufsize ="<<bufsize<< std::endl;
54 inpFile.seekg( 0,ios::beg );
57 std::cout <<
"Going to read CCS file: " << m_file << endl;
64 this->checkConnection();
67 m_writeStmt = m_conn->createStatement();
68 m_writeStmt->setSQL(
"INSERT INTO OD_CCS_HF_dat (iov_id, logic_id, " 70 "VALUES (:iov_id, :logic_id, " 74 }
catch (SQLException &
e) {
75 throw(std::runtime_error(
std::string(
"MODCCSHFDat::prepareWrite(): ")+getOraMessage(&e)));
87 this->checkConnection();
90 int iovID = iov->fetchID();
91 if (!iovID) {
throw(std::runtime_error(
"MODCCSHFDat::writeDB: IOV not in DB")); }
93 int logicID = ecid->getLogicID();
94 if (!logicID) {
throw(std::runtime_error(
"MODCCSHFDat::writeDB: Bad EcalLogicID")); }
97 std::cout <<
"Going to read CCS file: " << fname << endl;
102 m_writeStmt->setInt(1, iovID);
103 m_writeStmt->setInt(2, logicID);
106 oracle::occi::Clob clob(m_conn);
108 m_writeStmt->setClob(3,clob);
109 m_writeStmt->executeUpdate ();
111 m_conn->terminateStatement(m_writeStmt);
112 std::cout<<
"empty CCS Clob inserted into DB" <<std::endl;
115 m_writeStmt = m_conn->createStatement();
116 m_writeStmt->setSQL (
"SELECT CCS_LOG FROM OD_CCS_HF_DAT WHERE" 117 " iov_ID=:1 and logic_ID=:2 FOR UPDATE");
118 m_writeStmt->setInt(1, iovID);
119 m_writeStmt->setInt(2, logicID);
120 ResultSet* rset = m_writeStmt->executeQuery();
122 oracle::occi::Clob clob2 = rset->getClob (1);
123 cout <<
"Opening the clob in read write mode" << endl;
125 unsigned int clob_size=item->getSize();
127 populateClob (clob2 , fname, clob_size);
129 int clobLength=clob2.length ();
130 cout <<
"Length of the clob is: " << clobLength << endl;
132 m_writeStmt->executeUpdate();
133 m_writeStmt->closeResultSet (rset);
135 }
catch (SQLException &
e) {
136 throw(std::runtime_error(
std::string(
"MODCCSHFDat::writeDB(): ")+getOraMessage(&e)));
145 this->checkConnection();
148 iov->setConnection(m_env, m_conn);
149 int iovID = iov->fetchID();
157 m_readStmt->setSQL(
"SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, " 159 "FROM channelview cv JOIN OD_CCS_HF_dat d " 160 "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to " 161 "WHERE d.iov_id = :iov_id");
162 m_readStmt->setInt(1, iovID);
163 ResultSet* rset = m_readStmt->executeQuery();
165 std::pair< EcalLogicID, MODCCSHFDat >
p;
167 while(rset->next()) {
173 getOraString(rset,6));
180 }
catch (SQLException &
e) {
181 throw(std::runtime_error(
std::string(
"MODCCSHFDat::fetchData(): ")+getOraMessage(&e)));
188 this->checkConnection();
189 this->checkPrepare();
191 int iovID = iov->fetchID();
192 if (!iovID) {
throw(std::runtime_error(
"MODCCSHFDat::writeArrayDB: IOV not in DB")); }
195 int nrows=
data->size();
196 int* ids=
new int[nrows];
197 int* iovid_vec=
new int[nrows];
198 int*
xx=
new int[nrows];
200 ub2* ids_len=
new ub2[nrows];
201 ub2* iov_len=
new ub2[nrows];
202 ub2* x_len=
new ub2[nrows];
207 typedef map< EcalLogicID, MODCCSHFDat >::const_iterator CI;
208 for (CI
p =
data->begin();
p !=
data->end(); ++
p) {
209 channel = &(
p->first);
211 if (!logicID) {
throw(std::runtime_error(
"MODCCSHFDat::writeArrayDB: Bad EcalLogicID")); }
213 iovid_vec[
count]=iovID;
234 m_writeStmt->setDataBuffer(1, (dvoid*)iovid_vec, OCCIINT,
sizeof(iovid_vec[0]),iov_len);
235 m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT,
sizeof(ids[0]), ids_len );
236 m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIINT ,
sizeof(xx[0]), x_len );
238 m_writeStmt->executeArrayUpdate(nrows);
251 }
catch (SQLException &
e) {
252 throw(std::runtime_error(
std::string(
"MonPedestalsDat::writeArrayDB(): ")+getOraMessage(&e)));
264 cout <<
"Populating the Clob using writeBuffer(Stream) method" << endl;
278 inFile.open((
char*)fname2.c_str(),
ios::in);
287 clob_size = inFile.tellg();
288 std::cout <<
" bufsize ="<<clob_size<< std::endl;
290 inFile.seekg( 0,ios::beg );
294 char *
buffer =
new char[clob_size + 1];
299 Stream *strm=clob.getStream();
304 memset (buffer, buf, clob_size + 1);
305 inFile.read(buffer,clob_size);
308 strm->writeBuffer(buffer,strlen(buffer));
315 strm->writeLastBuffer(buffer,size);
316 clob.closeStream(strm);
322 }
catch (SQLException &
e) {
323 throw(std::runtime_error(
std::string(
"populateClob(): ")+getOraMessage(&e)));
326 cout <<
"Populating the Clob - Success" << endl;
335 Stream *instream = clob.getStream (1,0);
336 unsigned char *
buffer=
new unsigned char[
size];
338 memset (buffer, buf,
size);
340 instream->readBuffer ((
char*)buffer,
size);
341 cout <<
"remember to delete the char* at the end of the program ";
343 cout << (
char) buffer[
i];
347 clob.closeStream (instream);
351 }
catch (SQLException &
e) {
352 throw(std::runtime_error(
std::string(
"readClob(): ")+getOraMessage(&e)));
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]