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() [1/3]

FileBlob::FileBlob ( )
inline

Definition at line 12 of file FileBlob.h.

12 {};

◆ FileBlob() [2/3]

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

constructor from file to read

Definition at line 9 of file FileBlob.cc.

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 }

References blob, compressed, computeFileSize(), alignmentValidation::fname, isize, read(), and ComparisonHelper::zip().

◆ FileBlob() [3/3]

FileBlob::FileBlob ( std::istream &  is,
bool  zip 
)

constructor from stream to read

Definition at line 22 of file FileBlob.cc.

22  : isize(0) {
23  compressed = zip;
24  if (isize == 0)
26  blob.reserve(isize);
27  read(is);
28 }

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

◆ ~FileBlob()

FileBlob::~FileBlob ( )
inline

Definition at line 18 of file FileBlob.h.

18 {};

Member Function Documentation

◆ computeFileSize()

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

Definition at line 117 of file FileBlob.cc.

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 }

References computeStreamSize(), alignmentValidation::fname, and compare_using_db::ifile.

Referenced by FileBlob().

◆ computeStreamSize()

unsigned int FileBlob::computeStreamSize ( std::istream &  is)
staticprivate

Definition at line 128 of file FileBlob.cc.

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 }

References HltBtagPostValidation_cff::c.

Referenced by computeFileSize(), and FileBlob().

◆ getUncompressedBlob() [1/2]

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.

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 }

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

Referenced by MillePedeFileExtractor::writeGzipped().

◆ getUncompressedBlob() [2/2]

void FileBlob::getUncompressedBlob ( std::vector< unsigned char > &  myblobcopy) const

Definition at line 89 of file FileBlob.cc.

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 }

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

◆ isCompressed()

bool FileBlob::isCompressed ( ) const
inline

Definition at line 30 of file FileBlob.h.

30 { return compressed; };

References compressed.

◆ read() [1/2]

void FileBlob::read ( const std::string &  fname)

read from real file

Definition at line 102 of file FileBlob.cc.

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 }

References alignmentValidation::fname, and compare_using_db::ifile.

Referenced by FileBlob(), and edmIntegrityCheck.PublishToFileSystem::get().

◆ read() [2/2]

void FileBlob::read ( std::istream &  is)

read from istream

Definition at line 30 of file FileBlob.cc.

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 }

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

Referenced by edmIntegrityCheck.PublishToFileSystem::get().

◆ serialize()

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

◆ size()

int FileBlob::size ( void  ) const
inline

Definition at line 32 of file FileBlob.h.

32 { return isize; };

References isize.

Referenced by ntupleDataFormat._Collection::__iter__(), and ntupleDataFormat._Collection::__len__().

◆ write() [1/2]

void FileBlob::write ( const std::string &  fname) const

write to real file

Definition at line 111 of file FileBlob.cc.

111  {
112  std::ofstream ofile(fname.c_str());
113  write(ofile);
114  ofile.close();
115 }

References alignmentValidation::fname, and indexGen::ofile.

Referenced by pkg.AbstractPkg::generate().

◆ write() [2/2]

void FileBlob::write ( std::ostream &  os) const

write to ostream

Definition at line 59 of file FileBlob.cc.

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 }

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

Referenced by pkg.AbstractPkg::generate().

Friends And Related Function Documentation

◆ boost::serialization::access

friend class boost::serialization::access
friend

Definition at line 47 of file FileBlob.h.

◆ cond::serialization::access

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

Definition at line 47 of file FileBlob.h.

Member Data Documentation

◆ blob

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

Definition at line 43 of file FileBlob.h.

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

◆ compressed

bool FileBlob::compressed
private

Definition at line 44 of file FileBlob.h.

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

◆ isize

unsigned int FileBlob::isize
private

Definition at line 45 of file FileBlob.h.

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

FileBlob::isize
unsigned int isize
Definition: FileBlob.h:45
indexGen.ofile
ofile
Definition: indexGen.py:102
FileBlob::computeFileSize
static unsigned int computeFileSize(const std::string &)
Definition: FileBlob.cc:117
compare_using_db.ifile
ifile
Definition: compare_using_db.py:251
FileBlob::blob
std::vector< unsigned char > blob
Definition: FileBlob.h:43
FileBlob::read
void read(const std::string &)
read from real file
Definition: FileBlob.cc:102
edm::LogError
Definition: MessageLogger.h:183
recoMuon::in
Definition: RecoMuonEnumerators.h:6
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
ComparisonHelper::zip
OutputIterator zip(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
Definition: L1TStage2CaloLayer1.h:38
alignmentValidation.fname
string fname
main script
Definition: alignmentValidation.py:959
FileBlob::computeStreamSize
static unsigned int computeStreamSize(std::istream &)
Definition: FileBlob.cc:128
FileBlob::write
void write(const std::string &) const
write to real file
Definition: FileBlob.cc:111
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
spu::zerr
void zerr(int)
Definition: SherpackUtilities.cc:129
FileBlob::compressed
bool compressed
Definition: FileBlob.h:44