CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MultiFileBlob.cc
Go to the documentation of this file.
3 
4 #include <iostream>
5 #include <zlib.h>
6 
8  compressed(false), isize(0), expanded(false) {}
9 
11 
12 void MultiFileBlob::finalized(bool compress) {
13  if (!compress) return;
14  if (0==isize) return;
15  compressed=true;
16  expanded=false;
17  std::vector<unsigned char> out(isize);
18  uLongf destLen = compressBound(isize);
19  int zerr = compress2(&out.front(), &destLen,
20  &blob.front(), isize,
21  9);
22  if (zerr!=0) edm::LogError("MultiFileBlob")<< "Compression error " << zerr;
23  out.resize(destLen);
24  blob.swap(out);
25 }
26 
27 
28 void MultiFileBlob::read(const std::string& name, std::istream & is) {
29  Positions::const_iterator pos = positions.find(name);
30  if (pos!=positions.end()) {
31  edm::LogError("MultiFileBlob:")<< name << "already in this object";
32  return;
33  }
35  char c;
36  while (is.get(c))
37  blob.push_back( (unsigned char)c);
38  isize=blob.size();
39 }
40 
41 void MultiFileBlob::write(const std::string& name, std::ostream & os) const {
42  Range r = rawBlob(name);
43  os.write((const char *)(r.first),r.second-r.first);
44 
45 }
46 
48  const_cast<MultiFileBlob*>(this)->expand();
49  Positions::const_iterator pos = positions.find(name);
50  if (pos==positions.end()) {
51  edm::LogError("MultiFileBlob:")<< name << "not in this object";
52  return Range(0,0);
53  }
54  unsigned long long b = (*pos).second;
55  unsigned long long e = isize;
56  pos++;
57  if (pos!=positions.end()) e= (*pos).second;
58 
59  return Range(&blob[b],&blob[e]);
60 }
61 
62 
63 unsigned long long MultiFileBlob::size(const std::string& name) const {
64  Range r = rawBlob(name);
65  return r.second-r.first;
66 }
67 
69  if (expanded) return;
70  if (!compressed) {
71  expanded=true;
72  return;
73  }
74  std::vector<unsigned char> out(isize);
75  uLongf destLen = out.size();
76  int zerr = uncompress(&out.front(), &destLen,
77  &blob.front(), blob.size());
78  if (zerr!=0 || out.size()!=destLen)
79  edm::LogError("FileBlob")<< "uncompressing error " << zerr
80  << " original size was " << isize
81  << " new size is " << destLen;
82  blob.swap(out);
83  expanded=true;
84 }
85 
void write(const std::string &name, std::ostream &os) const
write to ostream
void zerr(int)
std::vector< unsigned char > blob
Definition: MultiFileBlob.h:52
void finalized(bool compress)
void read(const std::string &name, std::istream &is)
read from real file give it name name
unsigned long long size(const std::string &name) const
std::pair< unsigned char const *, unsigned char const * > Range
Definition: MultiFileBlob.h:12
tuple out
Definition: dbtoconf.py:99
unsigned long long isize
Definition: MultiFileBlob.h:56
Positions positions
Definition: MultiFileBlob.h:54
double b
Definition: hdecay.h:120
Range rawBlob(const std::string &name) const
volatile std::atomic< bool > shutdown_flag false