CMS 3D CMS Logo

stringArchiveIO.cc
Go to the documentation of this file.
1 #include "Alignment/Geners/interface/IOException.hh"
2 #include <cassert>
3 #include <cstring>
4 #include <fstream>
5 #include <sstream>
6 
7 #include "Alignment/Geners/interface/CompressedIO.hh"
8 #include "Alignment/Geners/interface/IOException.hh"
9 #include "Alignment/Geners/interface/Reference.hh"
10 #include "Alignment/Geners/interface/stringArchiveIO.hh"
11 
12 static bool suffix_matches(const char *filename, const char *suffix) {
13  static const char default_suffix[] = ".gssaz";
15  if (suffix == nullptr)
16  suffix = default_suffix;
17  const std::size_t lenSuffix = strlen(suffix);
18  const std::size_t len = strlen(filename);
19  bool suffixMatches = len >= lenSuffix;
20  for (std::size_t i = 0; i < lenSuffix && suffixMatches; ++i)
21  suffixMatches = suffix[i] == filename[len - lenSuffix + i];
22  return suffixMatches;
23 }
24 
25 namespace gs {
26  bool writeStringArchive(const StringArchive &ar, const char *filename) {
28  bool status = false;
29  {
30  std::ofstream of(filename, std::ios_base::binary);
31  if (of.is_open()) {
32  const_cast<StringArchive &>(ar).flush();
33  status = write_item(of, ar);
34  }
35  }
36  return status;
37  }
38 
39  StringArchive *readStringArchive(const char *filename) {
41  std::ifstream is(filename, std::ios_base::binary);
42  if (!is.is_open())
43  throw IOOpeningFailure("gs::readStringArchive", filename);
44  CPP11_auto_ptr<StringArchive> ar = read_item<StringArchive>(is);
45  return ar.release();
46  }
47 
48  bool writeCompressedStringArchive(const StringArchive &ar,
49  const char *filename,
50  const unsigned inCompressionMode,
51  const int compressionLevel,
52  const unsigned minSizeToCompress,
53  const unsigned bufSize) {
55  if (inCompressionMode > CStringStream::BZIP2)
56  throw gs::IOInvalidArgument(
57  "In gs::writeCompressedStringArchive: "
58  "compression mode argument out of range");
59  const CStringStream::CompressionMode m = static_cast<CStringStream::CompressionMode>(inCompressionMode);
60  bool status = false;
61  {
62  std::ofstream of(filename, std::ios_base::binary);
63  if (of.is_open()) {
64  const_cast<StringArchive &>(ar).flush();
65  status = write_compressed_item(of, ar, m, compressionLevel, minSizeToCompress, bufSize);
66  }
67  }
68  return status;
69  }
70 
71  StringArchive *readCompressedStringArchive(const char *filename) {
73  std::ifstream is(filename, std::ios_base::binary);
74  if (!is.is_open())
75  throw IOOpeningFailure("gs::readCompressedStringArchive", filename);
76  CPP11_auto_ptr<StringArchive> ar = read_compressed_item<StringArchive>(is);
77  return ar.release();
78  }
79 
80  StringArchive *loadStringArchiveFromArchive(AbsArchive &arch, const unsigned long long id) {
81  Reference<StringArchive> ref(arch, id);
82  if (!ref.unique()) {
83  std::ostringstream os;
84  os << "In gs::loadStringArchiveFromArchive: "
85  << "StringArchive item with id " << id << " not found";
86  throw gs::IOInvalidArgument(os.str());
87  }
88  CPP11_auto_ptr<StringArchive> p = ref.get(0);
89  return p.release();
90  }
91 
92  StringArchive *readCompressedStringArchiveExt(const char *filename, const char *suffix) {
95  else
97  }
98 
99  bool writeCompressedStringArchiveExt(const StringArchive &ar, const char *filename, const char *suffix) {
102  else
103  return writeStringArchive(ar, filename);
104  }
105 } // namespace gs
gs::writeStringArchive
bool writeStringArchive(const StringArchive &ar, const char *filename)
Definition: stringArchiveIO.cc:26
mps_fire.i
i
Definition: mps_fire.py:428
mps_update.status
status
Definition: mps_update.py:68
cms::cuda::assert
assert(be >=bs)
gs::readCompressedStringArchive
StringArchive * readCompressedStringArchive(const char *filename)
Definition: stringArchiveIO.cc:71
gs
Definition: AbsArchive.cc:46
createPayload.suffix
suffix
Definition: createPayload.py:281
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:79
corrVsCorr.filename
filename
Definition: corrVsCorr.py:123
gs::readStringArchive
StringArchive * readStringArchive(const char *filename)
Definition: stringArchiveIO.cc:39
AlCaHLTBitMon_ParallelJobs.p
def p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
gs::writeCompressedStringArchiveExt
bool writeCompressedStringArchiveExt(const StringArchive &ar, const char *filename, const char *suffix)
Definition: stringArchiveIO.cc:99
suffix_matches
static bool suffix_matches(const char *filename, const char *suffix)
Definition: stringArchiveIO.cc:12
gs::loadStringArchiveFromArchive
StringArchive * loadStringArchiveFromArchive(AbsArchive &arch, const unsigned long long id)
Definition: stringArchiveIO.cc:80
gs::readCompressedStringArchiveExt
StringArchive * readCompressedStringArchiveExt(const char *filename, const char *suffix)
Definition: stringArchiveIO.cc:92
gs::writeCompressedStringArchive
bool writeCompressedStringArchive(const StringArchive &ar, const char *filename, const unsigned inCompressionMode, const int compressionLevel, const unsigned minSizeToCompress, const unsigned bufSize)
Definition: stringArchiveIO.cc:48
NanoAODEDMEventContent_cff.compressionLevel
compressionLevel
Definition: NanoAODEDMEventContent_cff.py:15