5 #include "Alignment/Geners/interface/IOException.hh"
7 #include "Alignment/Geners/interface/stringArchiveIO.hh"
8 #include "Alignment/Geners/interface/CompressedIO.hh"
9 #include "Alignment/Geners/interface/IOException.hh"
10 #include "Alignment/Geners/interface/Reference.hh"
15 static const char default_suffix[] =
".gssaz";
18 suffix = default_suffix;
19 const std::size_t lenSuffix = strlen(suffix);
20 const std::size_t len = strlen(filename);
21 bool suffixMatches = len >= lenSuffix;
22 for (std::size_t
i=0;
i<lenSuffix && suffixMatches; ++
i)
23 suffixMatches = suffix[
i] == filename[len-lenSuffix+
i];
34 std::ofstream of(filename, std::ios_base::binary);
37 const_cast<StringArchive&
>(ar).flush();
38 status = write_item(of, ar);
47 std::ifstream is(filename, std::ios_base::binary);
49 throw IOOpeningFailure(
"gs::readStringArchive", filename);
50 CPP11_auto_ptr<StringArchive> ar = read_item<StringArchive>(is);
55 const StringArchive& ar,
const char*
filename,
56 const unsigned inCompressionMode,
const int compressionLevel,
57 const unsigned minSizeToCompress,
const unsigned bufSize)
60 if (inCompressionMode > CStringStream::BZIP2)
61 throw gs::IOInvalidArgument(
62 "In gs::writeCompressedStringArchive: "
63 "compression mode argument out of range");
64 const CStringStream::CompressionMode
m =
65 static_cast<CStringStream::CompressionMode
>(inCompressionMode);
68 std::ofstream of(filename, std::ios_base::binary);
71 const_cast<StringArchive&
>(ar).flush();
72 status = write_compressed_item(of, ar, m, compressionLevel,
73 minSizeToCompress, bufSize);
82 std::ifstream is(filename, std::ios_base::binary);
84 throw IOOpeningFailure(
"gs::readCompressedStringArchive", filename);
85 CPP11_auto_ptr<StringArchive> ar =
86 read_compressed_item<StringArchive>(is);
91 const unsigned long long id)
93 Reference<StringArchive> ref(arch,
id);
96 std::ostringstream os;
97 os <<
"In gs::loadStringArchiveFromArchive: "
98 <<
"StringArchive item with id " <<
id <<
" not found";
99 throw gs::IOInvalidArgument(os.str());
101 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)