CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Friends
FileBlob Class Reference

#include <FileBlob.h>

Public Member Functions

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

Private Member Functions

template<class Archive >
void serialize (Archive &ar, const unsigned int version)
 

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
 

Friends

class boost::serialization::access
 
template<typename CondSerializationT , typename Enabled >
struct cond::serialization::access
 

Detailed Description

Definition at line 10 of file FileBlob.h.

Constructor & Destructor Documentation

FileBlob::FileBlob ( )
inline
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, read(), and ComparisonHelper::zip().

9  : isize(0) {
10  compressed = zip;
11  /*
12  std::cout << "isize = " << isize
13  << " zip = " << (zip? "true" : "false")
14  << std::endl;
15  */
16  if (isize == 0)
18  // std::cout << "isize = " << isize << std::endl;
19  blob.reserve(isize);
20  read(fname);
21 }
std::vector< unsigned char > blob
Definition: FileBlob.h:43
static unsigned int computeFileSize(const std::string &)
Definition: FileBlob.cc:117
OutputIterator zip(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
bool compressed
Definition: FileBlob.h:44
string fname
main script
unsigned int isize
Definition: FileBlob.h:45
void read(const std::string &)
read from real file
Definition: FileBlob.cc:102
FileBlob::FileBlob ( std::istream &  is,
bool  zip 
)

constructor from stream to read

Definition at line 22 of file FileBlob.cc.

References blob, compressed, computeStreamSize(), isize, read(), and ComparisonHelper::zip().

22  : isize(0) {
23  compressed = zip;
24  if (isize == 0)
26  blob.reserve(isize);
27  read(is);
28 }
std::vector< unsigned char > blob
Definition: FileBlob.h:43
OutputIterator zip(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
bool compressed
Definition: FileBlob.h:44
static unsigned int computeStreamSize(std::istream &)
Definition: FileBlob.cc:128
unsigned int isize
Definition: FileBlob.h:45
void read(const std::string &)
read from real file
Definition: FileBlob.cc:102
FileBlob::~FileBlob ( )
inline

Definition at line 18 of file FileBlob.h.

References read(), AlCaHLTBitMon_QueryRunRegistry::string, and write().

18 {};

Member Function Documentation

unsigned int FileBlob::computeFileSize ( const std::string &  fname)
staticprivate

Definition at line 117 of file FileBlob.cc.

References computeStreamSize(), and compare_using_db::ifile.

Referenced by FileBlob(), and size().

117  {
118  unsigned int is = 0;
119  std::ifstream ifile(fname.c_str());
120  if (!ifile) {
121  edm::LogError("FileBlob") << "file " << fname << " does not exist...";
122  } else
123  is = computeStreamSize(ifile);
124  ifile.close();
125  return is;
126 }
static unsigned int computeStreamSize(std::istream &)
Definition: FileBlob.cc:128
string fname
main script
unsigned int FileBlob::computeStreamSize ( std::istream &  is)
staticprivate

Definition at line 128 of file FileBlob.cc.

References HltBtagPostValidation_cff::c.

Referenced by computeFileSize(), FileBlob(), and size().

128  {
129  unsigned int rs = 0;
130  char c;
131  while (is.get(c))
132  rs++;
133  is.clear();
134  is.seekg(0);
135  return rs;
136 }
std::unique_ptr< std::vector< unsigned char > > FileBlob::getUncompressedBlob ( ) const

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

Definition at line 73 of file FileBlob.cc.

References blob, compressed, isize, and spu::zerr().

Referenced by size(), and MillePedeFileExtractor::writeGzipped().

73  {
74  std::unique_ptr<std::vector<unsigned char> > newblob;
75  if (compressed) {
76  newblob.reset(new std::vector<unsigned char>(isize));
77  uLongf destLen = newblob->size();
78  // std::cout<<"Store isize = "<<isize<<"; newblob->size() = "<<newblob->size()<<"; destLen = "<<destLen<<std::endl;
79  int zerr = uncompress(&*(newblob->begin()), &destLen, &*blob.begin(), blob.size());
80  if (zerr != 0 || newblob->size() != destLen)
81  edm::LogError("FileBlob") << "uncompressing error " << zerr << " original size was " << isize << " new size is "
82  << destLen;
83  } else {
84  newblob.reset(new std::vector<unsigned char>(blob));
85  }
86  return newblob;
87 }
void zerr(int)
std::vector< unsigned char > blob
Definition: FileBlob.h:43
bool compressed
Definition: FileBlob.h:44
unsigned int isize
Definition: FileBlob.h:45
void FileBlob::getUncompressedBlob ( std::vector< unsigned char > &  myblobcopy) const

Definition at line 89 of file FileBlob.cc.

References blob, compressed, isize, and spu::zerr().

89  {
90  if (compressed) {
91  myblobcopy.reserve(isize);
92  uLongf destLen = isize;
93  int zerr = uncompress(&*myblobcopy.begin(), &destLen, &*blob.begin(), blob.size());
94  if (zerr != 0 || myblobcopy.size() != destLen)
95  edm::LogError("FileBlob") << "uncompressing error " << zerr << " original size was " << isize << " new size is "
96  << destLen;
97  } else {
98  myblobcopy = blob;
99  }
100 }
void zerr(int)
std::vector< unsigned char > blob
Definition: FileBlob.h:43
bool compressed
Definition: FileBlob.h:44
unsigned int isize
Definition: FileBlob.h:45
bool FileBlob::isCompressed ( ) const
inline

Definition at line 30 of file FileBlob.h.

References compressed.

30 { return compressed; };
bool compressed
Definition: FileBlob.h:44
void FileBlob::read ( const std::string &  fname)

read from real file

Definition at line 102 of file FileBlob.cc.

References compare_using_db::ifile.

Referenced by FileBlob(), edmIntegrityCheck.PublishToFileSystem::get(), Vispa.Plugins.EdmBrowser.EdmDataAccessor.EdmDataAccessor::goto(), Vispa.Plugins.EdmBrowser.EdmDataAccessor.EdmDataAccessor::setFilterBranches(), and ~FileBlob().

102  {
103  std::ifstream ifile(fname.c_str());
104  if (!ifile) {
105  edm::LogError("FileBlob") << "file " << fname << " does not exist...";
106  } else
107  read(ifile);
108  ifile.close();
109 }
string fname
main script
void read(const std::string &)
read from real file
Definition: FileBlob.cc:102
void FileBlob::read ( std::istream &  is)

read from istream

Definition at line 30 of file FileBlob.cc.

References blob, HltBtagPostValidation_cff::c, compressed, recoMuon::in, isize, and spu::zerr().

Referenced by edmIntegrityCheck.PublishToFileSystem::get(), Vispa.Plugins.EdmBrowser.EdmDataAccessor.EdmDataAccessor::goto(), and Vispa.Plugins.EdmBrowser.EdmDataAccessor.EdmDataAccessor::setFilterBranches().

30  {
31  if (compressed) {
32  std::vector<unsigned char> in;
33  in.reserve(isize);
34  char c;
35  while (is.get(c))
36  in.push_back((unsigned char)c);
37  /*
38  for(int i=0;i<in.size();i++){
39  std::cout<<in[i];
40  }
41  std::cout<<std::endl;
42  */
43  blob.resize(isize);
44  uLongf destLen = compressBound(in.size());
45  int zerr = compress2(&*blob.begin(), &destLen, &*in.begin(), in.size(), 9);
46  if (zerr != 0)
47  edm::LogError("FileBlob") << "Compression error " << zerr;
48  blob.resize(destLen);
49  } else {
50  //std::cout << "reading uncompressed" << std::endl;
51  char c;
52  while (is.get(c))
53  blob.push_back((unsigned char)c);
54  blob.resize(blob.size());
55  isize = blob.size();
56  }
57 }
void zerr(int)
std::vector< unsigned char > blob
Definition: FileBlob.h:43
bool compressed
Definition: FileBlob.h:44
unsigned int isize
Definition: FileBlob.h:45
template<class Archive >
void FileBlob::serialize ( Archive &  ar,
const unsigned int  version 
)
private
int FileBlob::size ( void  ) const
inline
void FileBlob::write ( const std::string &  fname) const

write to real file

Definition at line 111 of file FileBlob.cc.

References indexGen::ofile.

Referenced by pkg.AbstractPkg::generate(), and ~FileBlob().

111  {
112  std::ofstream ofile(fname.c_str());
113  write(ofile);
114  ofile.close();
115 }
void write(const std::string &) const
write to real file
Definition: FileBlob.cc:111
string fname
main script
void FileBlob::write ( std::ostream &  os) const

write to ostream

Definition at line 59 of file FileBlob.cc.

References blob, compressed, isize, MillePedeFileConverter_cfg::out, and spu::zerr().

Referenced by pkg.AbstractPkg::generate().

59  {
60  if (compressed) {
61  std::vector<unsigned char> out(isize);
62  uLongf destLen = out.size();
63  int zerr = uncompress(&*out.begin(), &destLen, &*blob.begin(), blob.size());
64  if (zerr != 0 || out.size() != destLen)
65  edm::LogError("FileBlob") << "uncompressing error " << zerr << " original size was " << isize << " new size is "
66  << destLen;
67  os.write(reinterpret_cast<const char*>(&*out.begin()), out.size());
68  } else {
69  os.write(reinterpret_cast<const char*>(&*blob.begin()), blob.size());
70  }
71 }
void zerr(int)
std::vector< unsigned char > blob
Definition: FileBlob.h:43
bool compressed
Definition: FileBlob.h:44
unsigned int isize
Definition: FileBlob.h:45

Friends And Related Function Documentation

friend class boost::serialization::access
friend

Definition at line 47 of file FileBlob.h.

template<typename CondSerializationT , typename Enabled >
friend struct cond::serialization::access
friend

Definition at line 47 of file FileBlob.h.

Member Data Documentation

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

Definition at line 43 of file FileBlob.h.

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

bool FileBlob::compressed
private

Definition at line 44 of file FileBlob.h.

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

unsigned int FileBlob::isize
private

Definition at line 45 of file FileBlob.h.

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