CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Static Private Member Functions | Private Attributes
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 ()
 

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
 
 COND_SERIALIZABLE
 
unsigned int isize
 

Detailed Description

Definition at line 10 of file FileBlob.h.

Constructor & Destructor Documentation

FileBlob::FileBlob ( )
inline

Definition at line 13 of file FileBlob.h.

13 {};
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 archive::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) isize= computeFileSize(fname);
17  // std::cout << "isize = " << isize << std::endl;
18  blob.reserve(isize);
19  read(fname);
20 }
tuple zip
Definition: archive.py:476
std::vector< unsigned char > blob
Definition: FileBlob.h:44
static unsigned int computeFileSize(const std::string &)
Definition: FileBlob.cc:123
bool compressed
Definition: FileBlob.h:45
string fname
main script
unsigned int isize
Definition: FileBlob.h:46
void read(const std::string &)
read from real file
Definition: FileBlob.cc:110
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, read(), and archive::zip.

21  :isize(0) {
22  compressed = zip;
23  if (isize==0) isize= computeStreamSize(is);
24  blob.reserve(isize);
25  read(is);
26 }
tuple zip
Definition: archive.py:476
std::vector< unsigned char > blob
Definition: FileBlob.h:44
bool compressed
Definition: FileBlob.h:45
static unsigned int computeStreamSize(std::istream &)
Definition: FileBlob.cc:132
unsigned int isize
Definition: FileBlob.h:46
void read(const std::string &)
read from real file
Definition: FileBlob.cc:110
FileBlob::~FileBlob ( )
inline

Definition at line 19 of file FileBlob.h.

19 {};

Member Function Documentation

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

Definition at line 123 of file FileBlob.cc.

References computeStreamSize(), and compare_using_db::ifile.

Referenced by FileBlob().

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

Definition at line 132 of file FileBlob.cc.

References trackerHits::c.

Referenced by computeFileSize(), and FileBlob().

132  {
133  unsigned int rs=0;
134  char c;
135  while (is.get(c)) rs++;
136  is.clear();
137  is.seekg(0);
138  return rs;
139 }
std::unique_ptr< 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, isize, and spu::zerr().

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

Definition at line 93 of file FileBlob.cc.

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

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

Definition at line 31 of file FileBlob.h.

References compressed.

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

read from real file

Definition at line 110 of file FileBlob.cc.

References compare_using_db::ifile.

Referenced by FileBlob(), Vispa.Plugins.EdmBrowser.EdmDataAccessor.EdmDataAccessor::goto(), and Vispa.Plugins.EdmBrowser.EdmDataAccessor.EdmDataAccessor::setFilterBranches().

110  {
111  std::ifstream ifile(fname.c_str());
112  if (!ifile) { edm::LogError("FileBlob")<< "file " << fname << " does not exist...";}
113  else read(ifile);
114  ifile.close();
115 }
string fname
main script
void read(const std::string &)
read from real file
Definition: FileBlob.cc:110
void FileBlob::read ( std::istream &  is)

read from istream

Definition at line 28 of file FileBlob.cc.

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

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

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

Definition at line 33 of file FileBlob.h.

References isize.

Referenced by popcon::DQMReferenceHistogramRootFileSourceHandler::getNewObjects(), and popcon::DQMXMLFileSourceHandler::getNewObjects().

33 {return isize;};
unsigned int isize
Definition: FileBlob.h:46
void FileBlob::write ( const std::string &  fname) const

write to real file

Definition at line 117 of file FileBlob.cc.

References checklumidiff::ofile.

Referenced by pkg.AbstractPkg::generate().

117  {
118  std::ofstream ofile(fname.c_str());
119  write(ofile);
120  ofile.close();
121 }
void write(const std::string &) const
write to real file
Definition: FileBlob.cc:117
string fname
main script
void FileBlob::write ( std::ostream &  os) const

write to ostream

Definition at line 58 of file FileBlob.cc.

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

Referenced by pkg.AbstractPkg::generate().

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

Member Data Documentation

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

Definition at line 44 of file FileBlob.h.

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

bool FileBlob::compressed
private

Definition at line 45 of file FileBlob.h.

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

FileBlob::COND_SERIALIZABLE
private

Definition at line 48 of file FileBlob.h.

unsigned int FileBlob::isize
private

Definition at line 46 of file FileBlob.h.

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