CMS 3D CMS Logo

Public Member Functions | Static Private Member Functions | Private Attributes

FileBlob Class Reference

#include <FileBlob.h>

List of all members.

Public Member Functions

 FileBlob ()
 FileBlob (const std::string &fname, bool zip)
 constructor from file to read
 FileBlob (std::istream &is, bool zip)
 constructor from stream to read
std::vector< unsigned char > * getUncompressedBlob () const
 i didn't want to do two copies ... hope this works.
void getUncompressedBlob (std::vector< unsigned char > &myblobcopy) const
bool isCompressed () const
void read (const std::string &)
 read from real file
void read (std::istream &)
 read from istream
int size () const
void write (std::ostream &) const
 write to ostream
void write (const std::string &) const
 write to real file
 ~FileBlob ()

Static Private Member Functions

static unsigned int computeFileSize (const std::string &)
static unsigned int computeStreamSize (std::istream &)

Private Attributes

std::vector< unsigned char > blob
bool compressed
unsigned int isize

Detailed Description

Definition at line 8 of file FileBlob.h.


Constructor & Destructor Documentation

FileBlob::FileBlob ( ) [inline]

Definition at line 11 of file FileBlob.h.

{};
FileBlob::FileBlob ( const std::string &  fname,
bool  zip 
)

constructor from file to read

Definition at line 9 of file FileBlob.cc.

References blob, compressed, computeFileSize(), isize, and read().

                                                   :isize(0){
  compressed = zip;
  /*  
  std::cout << "isize = " << isize 
            << "  zip = " << (zip? "true" : "false")
            << std::endl;
  */
  if (isize==0) isize= computeFileSize(fname);
  // std::cout << "isize = " << isize << std::endl;
  blob.reserve(isize);
  read(fname);
}
FileBlob::FileBlob ( std::istream &  is,
bool  zip 
)

constructor from stream to read

Definition at line 21 of file FileBlob.cc.

References blob, compressed, computeStreamSize(), isize, and read().

                                          :isize(0) {
  compressed = zip;
  if (isize==0) isize= computeStreamSize(is);
  blob.reserve(isize);
  read(is);
}
FileBlob::~FileBlob ( ) [inline]

Definition at line 17 of file FileBlob.h.

{};

Member Function Documentation

unsigned int FileBlob::computeFileSize ( const std::string &  fname) [static, private]

Definition at line 123 of file FileBlob.cc.

References computeStreamSize(), and indexGen::ifile.

Referenced by FileBlob().

                                                              {
  unsigned int is=0;
  std::ifstream ifile(fname.c_str());
  if (!ifile) { edm::LogError("FileBlob")<< "file " << fname << " does not exist...";}
  else is = computeStreamSize(ifile);
  ifile.close();
  return is;
}
unsigned int FileBlob::computeStreamSize ( std::istream &  is) [static, private]

Definition at line 132 of file FileBlob.cc.

References trackerHits::c.

Referenced by computeFileSize(), and FileBlob().

                                                        {
  unsigned int rs=0;
  char c;
  while (is.get(c)) rs++;
  is.clear();
  is.seekg(0);
  return rs;
}
void FileBlob::getUncompressedBlob ( std::vector< unsigned char > &  myblobcopy) const

Definition at line 93 of file FileBlob.cc.

References blob, compressed, and isize.

                                                                               {
  if(compressed)
  {
    myblobcopy.reserve(isize);
    uLongf destLen = isize;
    int zerr =  uncompress(&*myblobcopy.begin(),  &destLen,
                           &*blob.begin(), blob.size());
    if (zerr!=0 || myblobcopy.size()!=destLen) 
      edm::LogError("FileBlob")<< "uncompressing error " << zerr
                                   << " original size was " << isize
                                   << " new size is " << destLen;
  }else{
    myblobcopy = blob;
  }
  
}
std::vector< unsigned char > * FileBlob::getUncompressedBlob ( ) const

i didn't want to do two copies ... hope this works.

Definition at line 74 of file FileBlob.cc.

References blob, compressed, and isize.

                                                              { 
  std::vector<unsigned char>*  newblob;
  if(compressed)
  {
    newblob = new std::vector<unsigned char>(isize);
    uLongf destLen = newblob->size();
    //    std::cout<<"Store isize = "<<isize<<"; newblob->size() = "<<newblob->size()<<"; destLen = "<<destLen<<std::endl;
    int zerr =  uncompress(&*(newblob->begin()),  &destLen,
                           &*blob.begin(), blob.size());
    if (zerr!=0 || newblob->size()!=destLen) 
      edm::LogError("FileBlob")<< "uncompressing error " << zerr
                                   << " original size was " << isize
                                   << " new size is " << destLen;
  }else{
    newblob = new std::vector<unsigned char>(blob);
  }
  return newblob;
 }
bool FileBlob::isCompressed ( ) const [inline]

Definition at line 29 of file FileBlob.h.

References compressed.

{return compressed;};
void FileBlob::read ( const std::string &  fname)

read from real file

Definition at line 110 of file FileBlob.cc.

References indexGen::ifile.

Referenced by FileBlob().

                                           {
     std::ifstream ifile(fname.c_str());
     if (!ifile) { edm::LogError("FileBlob")<< "file " << fname << " does not exist...";}
     else read(ifile);
     ifile.close();
}
void FileBlob::read ( std::istream &  is)

read from istream

Definition at line 28 of file FileBlob.cc.

References blob, trackerHits::c, compressed, recoMuon::in, and isize.

                                   {
  if(compressed){
    std::vector<unsigned char> in;
    in.reserve(isize);
    char c;
    while (is.get(c))
      in.push_back((unsigned char)c);
    /*
    for(int i=0;i<in.size();i++){
      std::cout<<in[i];
    }
    std::cout<<std::endl;
    */
    blob.resize(isize);
    uLongf destLen = compressBound(in.size());
    int zerr =  compress2(&*blob.begin(), &destLen,
                          &*in.begin(), in.size(),
                          9);
    if (zerr!=0) edm::LogError("FileBlob")<< "Compression error " << zerr;
    blob.resize(destLen);  
  }else{
    //std::cout << "reading uncompressed" << std::endl;
    char c;
    while (is.get(c))
      blob.push_back( (unsigned char)c);
    blob.resize(blob.size());
    isize=blob.size();
  }
}
int FileBlob::size ( void  ) const [inline]
void FileBlob::write ( const std::string &  fname) const

write to real file

Definition at line 117 of file FileBlob.cc.

References summaryLumi::ofile.

                                                  {
  std::ofstream ofile(fname.c_str());
  write(ofile);
  ofile.close();
}
void FileBlob::write ( std::ostream &  os) const

write to ostream

Definition at line 58 of file FileBlob.cc.

References blob, compressed, isize, and dbtoconf::out.

                                          {
  if(compressed){
    std::vector<unsigned char> out(isize);
    uLongf destLen = out.size();
    int zerr =  uncompress(&*out.begin(),  &destLen,
                           &*blob.begin(), blob.size());
    if (zerr!=0 || out.size()!=destLen) 
      edm::LogError("FileBlob")<< "uncompressing error " << zerr
                                   << " original size was " << isize
                                   << " new size is " << destLen;
    os.write((const char *)(&*out.begin()),out.size());
  }else{
    os.write((char *)&*blob.begin(),blob.size());
  }
}

Member Data Documentation

std::vector<unsigned char> FileBlob::blob [private]

Definition at line 40 of file FileBlob.h.

Referenced by FileBlob(), getUncompressedBlob(), read(), and write().

bool FileBlob::compressed [private]

Definition at line 41 of file FileBlob.h.

Referenced by FileBlob(), getUncompressedBlob(), isCompressed(), read(), and write().

unsigned int FileBlob::isize [private]

Definition at line 42 of file FileBlob.h.

Referenced by FileBlob(), getUncompressedBlob(), read(), size(), and write().