1 #include "Alignment/Geners/interface/IOException.hh" 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" 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];
30 std::ofstream of(filename, std::ios_base::binary);
32 const_cast<StringArchive &
>(ar).flush();
33 status = write_item(of, ar);
41 std::ifstream is(filename, std::ios_base::binary);
43 throw IOOpeningFailure(
"gs::readStringArchive", filename);
44 CPP11_auto_ptr<StringArchive> ar = read_item<StringArchive>(is);
50 const unsigned inCompressionMode,
52 const unsigned minSizeToCompress,
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);
62 std::ofstream of(filename, std::ios_base::binary);
64 const_cast<StringArchive &
>(ar).flush();
65 status = write_compressed_item(of, ar, m, compressionLevel, minSizeToCompress, bufSize);
73 std::ifstream is(filename, std::ios_base::binary);
75 throw IOOpeningFailure(
"gs::readCompressedStringArchive", filename);
76 CPP11_auto_ptr<StringArchive> ar = read_compressed_item<StringArchive>(is);
81 Reference<StringArchive> ref(arch,
id);
83 std::ostringstream os;
84 os <<
"In gs::loadStringArchiveFromArchive: " 85 <<
"StringArchive item with id " <<
id <<
" not found";
86 throw gs::IOInvalidArgument(os.str());
88 CPP11_auto_ptr<StringArchive>
p = ref.get(0);
bool writeCompressedStringArchiveExt(const StringArchive &ar, const char *filename, const char *suffix)
StringArchive * loadStringArchiveFromArchive(AbsArchive &arch, const unsigned long long id)
static bool suffix_matches(const char *filename, const char *suffix)
StringArchive * readCompressedStringArchive(const char *filename)
bool writeCompressedStringArchive(const StringArchive &ar, const char *filename, const unsigned inCompressionMode, const int compressionLevel, const unsigned minSizeToCompress, const unsigned bufSize)
StringArchive * readCompressedStringArchiveExt(const char *filename, const char *suffix)
StringArchive * readStringArchive(const char *filename)
bool writeStringArchive(const StringArchive &ar, const char *filename)