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 11 of file FileBlob.h.

Constructor & Destructor Documentation

◆ FileBlob() [1/3]

FileBlob::FileBlob ( )
inline

Definition at line 13 of file FileBlob.h.

References compressed, and isize.

13  {
14  compressed = false;
15  isize = 0;
16  };
bool compressed
Definition: FileBlob.h:48
unsigned int isize
Definition: FileBlob.h:49

◆ FileBlob() [2/3]

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

constructor from file to read

Definition at line 11 of file FileBlob.cc.

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

11  : isize(0) {
12  compressed = zip;
13  /*
14  std::cout << "isize = " << isize
15  << " zip = " << (zip? "true" : "false")
16  << std::endl;
17  */
18  if (isize == 0)
20  // std::cout << "isize = " << isize << std::endl;
21  blob.reserve(isize);
22  read(fname);
23 }
ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE constexpr float zip(ConstView const &tracks, int32_t i)
Definition: TracksSoA.h:90
std::vector< unsigned char > blob
Definition: FileBlob.h:47
static unsigned int computeFileSize(const std::string &)
Definition: FileBlob.cc:119
bool compressed
Definition: FileBlob.h:48
string fname
main script
unsigned int isize
Definition: FileBlob.h:49
void read(const std::string &)
read from real file
Definition: FileBlob.cc:104

◆ FileBlob() [3/3]

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

constructor from stream to read

Definition at line 24 of file FileBlob.cc.

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

24  : isize(0) {
25  compressed = zip;
26  if (isize == 0)
28  blob.reserve(isize);
29  read(is);
30 }
ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE constexpr float zip(ConstView const &tracks, int32_t i)
Definition: TracksSoA.h:90
std::vector< unsigned char > blob
Definition: FileBlob.h:47
bool compressed
Definition: FileBlob.h:48
static unsigned int computeStreamSize(std::istream &)
Definition: FileBlob.cc:130
unsigned int isize
Definition: FileBlob.h:49
void read(const std::string &)
read from real file
Definition: FileBlob.cc:104

◆ ~FileBlob()

FileBlob::~FileBlob ( )
inline

Definition at line 22 of file FileBlob.h.

22 {}

Member Function Documentation

◆ computeFileSize()

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

Definition at line 119 of file FileBlob.cc.

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

Referenced by FileBlob().

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

◆ computeStreamSize()

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

Definition at line 130 of file FileBlob.cc.

References DummyCfis::c.

Referenced by computeFileSize(), and FileBlob().

130  {
131  unsigned int rs = 0;
132  char c;
133  while (is.get(c))
134  rs++;
135  is.clear();
136  is.seekg(0);
137  return rs;
138 }

◆ 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 75 of file FileBlob.cc.

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

Referenced by MillePedeFileExtractor::writeGzipped().

75  {
76  std::unique_ptr<std::vector<unsigned char>> newblob;
77  if (compressed) {
78  newblob = std::make_unique<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, &*blob.begin(), blob.size());
82  if (zerr != 0 || newblob->size() != destLen)
83  edm::LogError("FileBlob") << "uncompressing error " << zerr << " original size was " << isize << " new size is "
84  << destLen;
85  } else {
86  newblob = std::make_unique<std::vector<unsigned char>>(blob);
87  }
88  return newblob;
89 }
void zerr(int)
std::vector< unsigned char > blob
Definition: FileBlob.h:47
bool compressed
Definition: FileBlob.h:48
unsigned int isize
Definition: FileBlob.h:49

◆ getUncompressedBlob() [2/2]

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

Definition at line 91 of file FileBlob.cc.

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

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

◆ isCompressed()

bool FileBlob::isCompressed ( ) const
inline

Definition at line 34 of file FileBlob.h.

References compressed.

34 { return compressed; };
bool compressed
Definition: FileBlob.h:48

◆ read() [1/2]

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

read from real file

Definition at line 104 of file FileBlob.cc.

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

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

104  {
105  std::ifstream ifile(fname.c_str());
106  if (!ifile) {
107  edm::LogError("FileBlob") << "file " << fname << " does not exist...";
108  } else
109  read(ifile);
110  ifile.close();
111 }
Log< level::Error, false > LogError
string fname
main script
void read(const std::string &)
read from real file
Definition: FileBlob.cc:104

◆ read() [2/2]

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

read from istream

Definition at line 32 of file FileBlob.cc.

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

Referenced by edmIntegrityCheck.PublishToFileSystem::get().

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

◆ serialize()

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

◆ size()

int FileBlob::size ( void  ) const
inline

Definition at line 36 of file FileBlob.h.

References isize.

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

36 { return isize; };
unsigned int isize
Definition: FileBlob.h:49

◆ write() [1/2]

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

write to real file

Definition at line 113 of file FileBlob.cc.

References alignmentValidation::fname.

Referenced by pkg.AbstractPkg::generate().

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

◆ write() [2/2]

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

write to ostream

Definition at line 61 of file FileBlob.cc.

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

Referenced by pkg.AbstractPkg::generate().

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

Friends And Related Function Documentation

◆ boost::serialization::access

friend class boost::serialization::access
friend

Definition at line 51 of file FileBlob.h.

◆ cond::serialization::access

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

Definition at line 51 of file FileBlob.h.

Member Data Documentation

◆ blob

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

Definition at line 47 of file FileBlob.h.

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

◆ compressed

bool FileBlob::compressed
private

Definition at line 48 of file FileBlob.h.

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

◆ isize

unsigned int FileBlob::isize
private

Definition at line 49 of file FileBlob.h.

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