CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Member Functions | Private Attributes | Friends
MODCCSHFDat Class Reference

#include <MODCCSHFDat.h>

Inheritance diagram for MODCCSHFDat:
IDataItem IDBObject

Public Types

typedef oracle::occi::Clob Clob
 

Public Member Functions

unsigned char * getClob () const
 
std::string getFile () const
 
unsigned int getSize () const
 
std::string getTable ()
 
int getTest () const
 
 MODCCSHFDat ()
 
void setClob (unsigned char *x)
 
void setFile (std::string x)
 
void setSize (unsigned int id)
 
void setTest (int id)
 
 ~MODCCSHFDat ()
 
- Public Member Functions inherited from IDataItem
 IDataItem ()
 
- Public Member Functions inherited from IDBObject
oracle::occi::Connection * getConn () const
 
oracle::occi::Environment * getEnv () const
 
void setConnection (oracle::occi::Environment *env, oracle::occi::Connection *conn)
 
virtual ~IDBObject ()
 

Private Member Functions

void fetchData (std::map< EcalLogicID, MODCCSHFDat > *fillMap, MODRunIOV *iov) noexcept(false)
 
void populateClob (Clob &clob, std::string fname, unsigned int clob_size) noexcept(false)
 
void prepareWrite () noexcept(false)
 
unsigned char * readClob (Clob &clob, int size) noexcept(false)
 
void writeArrayDB (const std::map< EcalLogicID, MODCCSHFDat > *data, MODRunIOV *iov) noexcept(false)
 
void writeDB (const EcalLogicID *ecid, const MODCCSHFDat *item, MODRunIOV *iov) noexcept(false)
 

Private Attributes

unsigned char * m_clob
 
std::string m_file
 
unsigned int m_size
 
int testing
 

Friends

class EcalCondDBInterface
 

Additional Inherited Members

- Static Public Attributes inherited from IDBObject
static int const ECALDB_NROWS =1024
 
- Protected Member Functions inherited from IDataItem
void checkPrepare () noexcept(false)
 
void createReadStatement () noexcept(false)
 
void setPrefetchRowCount (int ncount) noexcept(false)
 
void terminateReadStatement () noexcept(false)
 
void terminateWriteStatement () noexcept(false)
 
- Protected Member Functions inherited from IDBObject
void checkConnection () const noexcept(false)
 
- Protected Attributes inherited from IDataItem
oracle::occi::Statement * m_readStmt
 
oracle::occi::Statement * m_writeStmt
 
- Protected Attributes inherited from IDBObject
oracle::occi::Connection * m_conn
 
oracle::occi::Environment * m_env
 

Detailed Description

Definition at line 19 of file MODCCSHFDat.h.

Member Typedef Documentation

typedef oracle::occi::Clob MODCCSHFDat::Clob

Definition at line 21 of file MODCCSHFDat.h.

Constructor & Destructor Documentation

MODCCSHFDat::MODCCSHFDat ( )

Definition at line 17 of file MODCCSHFDat.cc.

References NULL.

18 {
19  m_env = NULL;
20  m_conn = NULL;
21  m_writeStmt = NULL;
22  m_readStmt = NULL;
23 
24  // m_clob = 0;
25  m_size=0;
26  m_file="";
27 
28 }
oracle::occi::Environment * m_env
Definition: IDBObject.h:38
oracle::occi::Statement * m_writeStmt
Definition: IDataItem.h:28
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
#define NULL
Definition: scimark2.h:8
unsigned int m_size
Definition: MODCCSHFDat.h:56
std::string m_file
Definition: MODCCSHFDat.h:57
oracle::occi::Statement * m_readStmt
Definition: IDataItem.h:29
MODCCSHFDat::~MODCCSHFDat ( )

Definition at line 32 of file MODCCSHFDat.cc.

33 {
34 }

Member Function Documentation

void MODCCSHFDat::fetchData ( std::map< EcalLogicID, MODCCSHFDat > *  fillMap,
MODRunIOV iov 
)
privatenoexcept

Definition at line 142 of file MODCCSHFDat.cc.

References MillePedeFileConverter_cfg::e, and AlCaHLTBitMon_ParallelJobs::p.

Referenced by getFile().

144 {
145  this->checkConnection();
146  fillMap->clear();
147 
148  iov->setConnection(m_env, m_conn);
149  int iovID = iov->fetchID();
150  if (!iovID) {
151  // throw(std::runtime_error("MODCCSHFDat::writeDB: IOV not in DB"));
152  return;
153  }
154 
155  try {
156 
157  m_readStmt->setSQL("SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
158  " d.ccs_log "
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();
164 
165  std::pair< EcalLogicID, MODCCSHFDat > p;
166  MODCCSHFDat dat;
167  while(rset->next()) {
168  p.first = EcalLogicID( rset->getString(1), // name
169  rset->getInt(2), // logic_id
170  rset->getInt(3), // id1
171  rset->getInt(4), // id2
172  rset->getInt(5), // id3
173  rset->getString(6)); // maps_to
174  // to be corrected
175  // dat.setClob( rset->getString(7) );
176 
177  p.second = dat;
178  fillMap->insert(p);
179  }
180  } catch (SQLException &e) {
181  throw(std::runtime_error("MODCCSHFDat::fetchData(): "+e.getMessage()));
182  }
183 }
oracle::occi::Environment * m_env
Definition: IDBObject.h:38
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
int fetchID() noexcept(false)
Definition: MODRunIOV.cc:101
void checkConnection() const noexcept(false)
Definition: IDBObject.h:41
oracle::occi::Statement * m_readStmt
Definition: IDataItem.h:29
void setConnection(oracle::occi::Environment *env, oracle::occi::Connection *conn)
Definition: IDBObject.h:23
unsigned char* MODCCSHFDat::getClob ( ) const
inline

Definition at line 30 of file MODCCSHFDat.h.

References m_clob.

30 { return m_clob; }
unsigned char * m_clob
Definition: MODCCSHFDat.h:55
std::string MODCCSHFDat::getFile ( ) const
inline

Definition at line 39 of file MODCCSHFDat.h.

References data, fetchData(), m_file, noexcept, prepareWrite(), writeArrayDB(), and writeDB().

39 { return m_file; }
std::string m_file
Definition: MODCCSHFDat.h:57
unsigned int MODCCSHFDat::getSize ( ) const
inline

Definition at line 33 of file MODCCSHFDat.h.

References m_size.

33 { return m_size; }
unsigned int m_size
Definition: MODCCSHFDat.h:56
std::string MODCCSHFDat::getTable ( )
inlinevirtual

Implements IDataItem.

Definition at line 27 of file MODCCSHFDat.h.

27 { return "OD_CCS_HF_DAT"; }
int MODCCSHFDat::getTest ( ) const
inline

Definition at line 36 of file MODCCSHFDat.h.

References setFile(), AlCaHLTBitMon_QueryRunRegistry::string, testing, and x.

36 { return testing; }
void MODCCSHFDat::populateClob ( Clob clob,
std::string  fname,
unsigned int  clob_size 
)
privatenoexcept

Definition at line 258 of file MODCCSHFDat.cc.

References edmScanValgrind::buffer, gather_cfg::cout, MillePedeFileConverter_cfg::e, end, FrontierConditions_GlobalTag_cff::file, alignmentValidation::fname, recoMuon::in, findQualityFiles::size, and AlCaHLTBitMon_QueryRunRegistry::string.

260 {
261 
262  try{
263  // Uses stream here
264  cout << "Populating the Clob using writeBuffer(Stream) method" << endl;
265  std::cout<<"we are here0"<<std::endl;
266 
267  char *file = (char *)fname.c_str();
268  std::cout<<"we are here0.5 file is:"<<fname<<std::endl;
269 
270  ifstream inFile;
271  inFile.open(file,ios::in);
272  if (!inFile)
273  {
274  cout << fname<<" file not found\n";
275  inFile.close();
276 
277  std::string fname2="/u1/fra/null_file.txt";
278  inFile.open((char*)fname2.c_str(),ios::in);
279 
280 
281 
282  }
283  if(clob_size==0){
284 
285 
286  inFile.seekg( 0,ios::end );
287  clob_size = inFile.tellg();
288  std::cout <<" bufsize ="<<clob_size<< std::endl;
289  // set file pointer to start again
290  inFile.seekg( 0,ios::beg );
291 
292  }
293 
294  char *buffer = new char[clob_size + 1];
295 
296 
297  std::cout<<"we are here1"<<std::endl;
298  unsigned int size;
299  Stream *strm=clob.getStream();
300  std::cout<<"we are here2"<<std::endl;
301  // while(inFile)
302  // {
303  int buf=0;
304  memset (buffer, buf, clob_size + 1);
305  inFile.read(buffer,clob_size);
306  std::cout<<"we are here2.5"<<std::endl;
307 
308  strm->writeBuffer(buffer,strlen(buffer));
309  std::cout<<"we are here2.6"<<std::endl;
310 
311  //}
312  std::cout<<"we are here3"<<std::endl;
313  strcpy(buffer," ");
314  size=strlen(buffer);
315  strm->writeLastBuffer(buffer,size);
316  clob.closeStream(strm);
317  inFile.close();
318  std::cout<<"we are here4"<<std::endl;
319  delete[] buffer;
320 
321 
322  }catch (SQLException &e) {
323  throw(std::runtime_error("populateClob(): "+e.getMessage()));
324  }
325 
326  cout << "Populating the Clob - Success" << endl;
327 }
size
Write out results.
#define end
Definition: vmac.h:37
string fname
main script
void MODCCSHFDat::prepareWrite ( )
privatevirtualnoexcept

Implements IDataItem.

Definition at line 61 of file MODCCSHFDat.cc.

References MillePedeFileConverter_cfg::e.

Referenced by getFile().

63 {
64  this->checkConnection();
65 
66  try {
67  m_writeStmt = m_conn->createStatement();
68  m_writeStmt->setSQL("INSERT INTO OD_CCS_HF_dat (iov_id, logic_id, "
69  "ccs_log) "
70  "VALUES (:iov_id, :logic_id, "
71  ":ccs_log )");
72 
73 
74  } catch (SQLException &e) {
75  throw(std::runtime_error("MODCCSHFDat::prepareWrite(): "+e.getMessage()));
76  }
77 }
oracle::occi::Statement * m_writeStmt
Definition: IDataItem.h:28
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
void checkConnection() const noexcept(false)
Definition: IDBObject.h:41
unsigned char * MODCCSHFDat::readClob ( Clob clob,
int  size 
)
privatenoexcept

Definition at line 330 of file MODCCSHFDat.cc.

References edmScanValgrind::buffer, gather_cfg::cout, MillePedeFileConverter_cfg::e, mps_fire::i, and findQualityFiles::size.

332 {
333 
334  try{
335  Stream *instream = clob.getStream (1,0);
336  unsigned char *buffer= new unsigned char[size];
337  int buf=0;
338  memset (buffer, buf, size);
339 
340  instream->readBuffer ((char*)buffer, size);
341  cout << "remember to delete the char* at the end of the program ";
342  for (int i = 0; i < size; ++i)
343  cout << (char) buffer[i];
344  cout << endl;
345 
346 
347  clob.closeStream (instream);
348 
349  return buffer;
350 
351  }catch (SQLException &e) {
352  throw(std::runtime_error("readClob(): "+e.getMessage()));
353  }
354 
355 }
size
Write out results.
void MODCCSHFDat::setClob ( unsigned char *  x)
inline

Definition at line 29 of file MODCCSHFDat.h.

References m_clob, and x.

29 { m_clob = x; }
unsigned char * m_clob
Definition: MODCCSHFDat.h:55
void MODCCSHFDat::setFile ( std::string  x)

Definition at line 37 of file MODCCSHFDat.cc.

References gather_cfg::cout, end, and x.

Referenced by getTest().

37  {
38  m_file=x;
39  //try {
40  std::cout<< "file is "<< m_file<<endl;
41  // }catch (Exception &e) {
42  //throw(std::runtime_error("MODCCSHFDat::setFile(): "+e.getMessage()));
43  //}
44  // here we must open the file and read the CCS Clob
45  std::cout << "Going to read CCS file: " << m_file << endl;
46  ifstream inpFile;
47  inpFile.open(m_file.c_str());
48  // tell me size of file
49  int bufsize = 0;
50  inpFile.seekg( 0,ios::end );
51  bufsize = inpFile.tellg();
52  std::cout <<" bufsize ="<<bufsize<< std::endl;
53  // set file pointer to start again
54  inpFile.seekg( 0,ios::beg );
55  m_size=bufsize;
56  inpFile.close();
57  std::cout << "Going to read CCS file: " << m_file << endl;
58 
59 }
#define end
Definition: vmac.h:37
unsigned int m_size
Definition: MODCCSHFDat.h:56
std::string m_file
Definition: MODCCSHFDat.h:57
void MODCCSHFDat::setSize ( unsigned int  id)
inline

Definition at line 32 of file MODCCSHFDat.h.

References triggerObjects_cff::id, and m_size.

32 { m_size = id; }
unsigned int m_size
Definition: MODCCSHFDat.h:56
void MODCCSHFDat::setTest ( int  id)
inline

Definition at line 35 of file MODCCSHFDat.h.

References triggerObjects_cff::id, and testing.

void MODCCSHFDat::writeArrayDB ( const std::map< EcalLogicID, MODCCSHFDat > *  data,
MODRunIOV iov 
)
privatenoexcept

Definition at line 185 of file MODCCSHFDat.cc.

References KineDebug3::count(), data, MillePedeFileConverter_cfg::e, EcalLogicID::getLogicID(), electrons_cff::ids, AlCaHLTBitMon_ParallelJobs::p, x, and geometryCSVtoXML::xx.

Referenced by getFile().

187 {
188  this->checkConnection();
189  this->checkPrepare();
190 
191  int iovID = iov->fetchID();
192  if (!iovID) { throw(std::runtime_error("MODCCSHFDat::writeArrayDB: IOV not in DB")); }
193 
194 
195  int nrows=data->size();
196  int* ids= new int[nrows];
197  int* iovid_vec= new int[nrows];
198  int* xx= new int[nrows];
199 
200  ub2* ids_len= new ub2[nrows];
201  ub2* iov_len= new ub2[nrows];
202  ub2* x_len= new ub2[nrows];
203 
204  const EcalLogicID* channel;
205  //const MODCCSHFDat* dataitem;
206  int count=0;
207  typedef map< EcalLogicID, MODCCSHFDat >::const_iterator CI;
208  for (CI p = data->begin(); p != data->end(); ++p) {
209  channel = &(p->first);
210  int logicID = channel->getLogicID();
211  if (!logicID) { throw(std::runtime_error("MODCCSHFDat::writeArrayDB: Bad EcalLogicID")); }
212  ids[count]=logicID;
213  iovid_vec[count]=iovID;
214 
215  // dataitem = &(p->second);
216  // dataIface.writeDB( channel, dataitem, iov);
217  // to be corrected
218 
219  int x=0;
220  //=dataitem->getWord();
221 
222  xx[count]=x;
223 
224  ids_len[count]=sizeof(ids[count]);
225  iov_len[count]=sizeof(iovid_vec[count]);
226 
227  x_len[count]=sizeof(xx[count]);
228 
229  count++;
230  }
231 
232 
233  try {
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 );
237 
238  m_writeStmt->executeArrayUpdate(nrows);
239 
240  delete [] ids;
241  delete [] iovid_vec;
242  delete [] xx;
243 
244 
245  delete [] ids_len;
246  delete [] iov_len;
247  delete [] x_len;
248 
249 
250 
251  } catch (SQLException &e) {
252  throw(std::runtime_error("MonPedestalsDat::writeArrayDB(): "+e.getMessage()));
253  }
254 }
oracle::occi::Statement * m_writeStmt
Definition: IDataItem.h:28
void checkPrepare() noexcept(false)
Definition: IDataItem.h:31
int fetchID() noexcept(false)
Definition: MODRunIOV.cc:101
void checkConnection() const noexcept(false)
Definition: IDBObject.h:41
int getLogicID() const
Definition: EcalLogicID.cc:41
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
void MODCCSHFDat::writeDB ( const EcalLogicID ecid,
const MODCCSHFDat item,
MODRunIOV iov 
)
privatenoexcept

Definition at line 81 of file MODCCSHFDat.cc.

References gather_cfg::cout, MillePedeFileConverter_cfg::e, alignmentValidation::fname, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by getFile().

83 {
84 
85 
86 
87  this->checkConnection();
88  this->checkPrepare();
89 
90  int iovID = iov->fetchID();
91  if (!iovID) { throw(std::runtime_error("MODCCSHFDat::writeDB: IOV not in DB")); }
92 
93  int logicID = ecid->getLogicID();
94  if (!logicID) { throw(std::runtime_error("MODCCSHFDat::writeDB: Bad EcalLogicID")); }
95 
96  std::string fname=item->getFile();
97  std::cout << "Going to read CCS file: " << fname << endl;
98 
99 
100  try {
101 
102  m_writeStmt->setInt(1, iovID);
103  m_writeStmt->setInt(2, logicID);
104 
105  // and now the clob
106  oracle::occi::Clob clob(m_conn);
107  clob.setEmpty();
108  m_writeStmt->setClob(3,clob);
109  m_writeStmt->executeUpdate ();
110 
111  m_conn->terminateStatement(m_writeStmt);
112  std::cout<<"empty CCS Clob inserted into DB" <<std::endl;
113 
114  // now we read and update it
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();
121  rset->next ();
122  oracle::occi::Clob clob2 = rset->getClob (1);
123  cout << "Opening the clob in read write mode" << endl;
124 
125  unsigned int clob_size=item->getSize();
126 
127  populateClob (clob2 , fname, clob_size);
128 
129  int clobLength=clob2.length ();
130  cout << "Length of the clob is: " << clobLength << endl;
131 
132  m_writeStmt->executeUpdate();
133  m_writeStmt->closeResultSet (rset);
134 
135  } catch (SQLException &e) {
136  throw(std::runtime_error("MODCCSHFDat::writeDB(): "+e.getMessage()));
137  }
138 }
std::string getFile() const
Definition: MODCCSHFDat.h:39
oracle::occi::Statement * m_writeStmt
Definition: IDataItem.h:28
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
void checkPrepare() noexcept(false)
Definition: IDataItem.h:31
int fetchID() noexcept(false)
Definition: MODRunIOV.cc:101
void checkConnection() const noexcept(false)
Definition: IDBObject.h:41
int getLogicID() const
Definition: EcalLogicID.cc:41
void populateClob(Clob &clob, std::string fname, unsigned int clob_size) noexcept(false)
Definition: MODCCSHFDat.cc:258
string fname
main script
unsigned int getSize() const
Definition: MODCCSHFDat.h:33

Friends And Related Function Documentation

friend class EcalCondDBInterface
friend

Definition at line 22 of file MODCCSHFDat.h.

Member Data Documentation

unsigned char* MODCCSHFDat::m_clob
private

Definition at line 55 of file MODCCSHFDat.h.

Referenced by getClob(), and setClob().

std::string MODCCSHFDat::m_file
private

Definition at line 57 of file MODCCSHFDat.h.

Referenced by getFile().

unsigned int MODCCSHFDat::m_size
private

Definition at line 56 of file MODCCSHFDat.h.

Referenced by getSize(), and setSize().

int MODCCSHFDat::testing
private

Definition at line 58 of file MODCCSHFDat.h.

Referenced by getTest(), and setTest().