CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Attributes
cond::FileReader Class Reference

#include <FileUtils.h>

Public Member Functions

const std::string & content () const
 
 FileReader ()
 
bool read (const std::string &fileName)
 
virtual ~FileReader ()
 

Private Attributes

std::string m_content
 

Detailed Description

Definition at line 7 of file FileUtils.h.

Constructor & Destructor Documentation

cond::FileReader::FileReader ( )
inline

Definition at line 27 of file FileUtils.h.

27  :m_content(""){
28 }
std::string m_content
Definition: FileUtils.h:21
virtual cond::FileReader::~FileReader ( )
inlinevirtual

Definition at line 13 of file FileUtils.h.

13 {}

Member Function Documentation

const std::string & cond::FileReader::content ( ) const
inline

Definition at line 31 of file FileUtils.h.

Referenced by cond::XMLAuthenticationService::XMLAuthenticationService::processFile().

31  {
32  return m_content;
33 }
std::string m_content
Definition: FileUtils.h:21
bool cond::FileReader::read ( const std::string &  fileName)

struct stat st; if (stat(inputFileName.c_str(), &st) < 0){ seal::MessageStream log( this, this->name(),seal::Msg::Verbose ); log << seal::Msg::Error << "File \"" << inputFileName << "" not found." << seal::flush; return false; }

std::vector<char> buf(st.st_size, 0); int fd = open(inputFileName.c_str(), O_RDONLY); if (fd < 0){ seal::MessageStream log( this, this->name(),seal::Msg::Verbose ); log << seal::Msg::Error << "File \"" << inputFileName << "" cannot be open." << seal::flush; close(fd); return false; }

if (read(fd, &buf[0], st.st_size) != st.st_size){ seal::MessageStream log( this, this->name(),seal::Msg::Verbose ); log << seal::Msg::Error << "File \"" << inputFileName << "" cannot be open for reading." << seal::flush; close(fd); return false; } std::string content(&buf[0], &buf[0]+st.st_size);

Definition at line 6 of file FileUtils.cc.

References end, edm::hlt::Exception, recoMuon::in, analyzePatCleaning_cfg::inputFile, m_content, visualization-live-secondInstance_cfg::msg, and findQualityFiles::size.

Referenced by Vispa.Plugins.EdmBrowser.EdmDataAccessor.EdmDataAccessor::goto(), cond::XMLAuthenticationService::XMLAuthenticationService::processFile(), and Vispa.Plugins.EdmBrowser.EdmDataAccessor.EdmDataAccessor::setFilterBranches().

6  {
31  std::ifstream inputFile;
32  inputFile.open (fileName.c_str());
33  if(!inputFile.good()){
34  std::stringstream msg;
35  msg << "File \"" << fileName << "\" cannot be open.";
36  inputFile.close();
37  throw cond::Exception(msg.str());
38  }
39  // get pointer to associated buffer object
40  std::filebuf* pbuf=inputFile.rdbuf();
41  // get file size using buffer's members
42  long size=pbuf->pubseekoff (0,std::ios::end,std::ios::in);
43  pbuf->pubseekpos (0,std::ios::in);
44  // allocate memory to contain file data
45  char* buffer=new char[size+1];
46  // get file data
47  pbuf->sgetn (buffer,size);
48  inputFile.close();
49  buffer[size]=0;
50  m_content += buffer;
51  delete [] buffer;
52  return true;
53 }
std::string m_content
Definition: FileUtils.h:21
#define end
Definition: vmac.h:37
tuple size
Write out results.

Member Data Documentation

std::string cond::FileReader::m_content
private

Definition at line 21 of file FileUtils.h.

Referenced by read().