CMS 3D CMS Logo

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