4 #include "Alignment/Geners/interface/AbsArchive.hh" 5 #include "Alignment/Geners/interface/IOException.hh" 7 #define GS_STREAM_COPY_BUFFER_SIZE 65536 14 bool in_fail = in.fail();
15 bool out_fail = out.fail();
16 while (count > bufsize && !in_fail && !out_fail) {
17 in.read(buffer, bufsize);
20 out.write(buffer, bufsize);
21 out_fail = out.fail();
25 if (!in_fail && !out_fail) {
26 in.read(buffer, count);
28 out.write(buffer, count);
34 class NotWritableRecord :
public gs::AbsRecord {
36 inline NotWritableRecord(
const gs::ClassId &classId,
const char *ioPrototype,
const char *
name,
const char *
category)
37 : gs::AbsRecord(classId, ioPrototype, name, category) {}
40 NotWritableRecord() =
delete;
41 inline bool writeData(std::ostream &)
const override {
return false; }
46 AbsArchive::AbsArchive(
const char *
name) : name_(name ? name :
""), lastItemId_(0), lastItemLength_(0) {}
48 void AbsArchive::addItemToReference(AbsReference &
r,
const unsigned long long id)
const { r.addItemId(
id); }
50 unsigned long long AbsArchive::copyItem(
const unsigned long long id,
53 const char *newCategory) {
55 throw gs::IOInvalidArgument(
56 "In gs::AbsArchive::copyItem: " 57 "origin archive is not readable");
59 if (
this == destination)
60 throw gs::IOInvalidArgument(
61 "In gs::AbsArchive::copyItem: " 62 "origin and destination archives are the same");
63 AbsArchive &ar(*destination);
65 throw gs::IOInvalidArgument(
66 "In gs::AbsArchive::copyItem: " 67 "destination archive is not writable");
68 CPP11_shared_ptr<const CatalogEntry>
entry(catalogEntry(
id));
70 throw gs::IOInvalidArgument(
71 "In gs::AbsArchive::copyItem: no item " 72 "in the archive with the given id");
76 std::istream &is = inputStream(
id, &sz);
80 std::ostream &os = ar.outputStream();
81 std::streampos
base = os.tellp();
82 std::ostream &compressed = ar.compressedStream(os);
85 unsigned long long len;
89 len = entry->itemLength();
93 "In gs::AbsArchive::copyItem: " 94 "input stream failure");
95 if (compressed.fail())
97 "In gs::AbsArchive::copyItem: " 98 "output stream failure");
99 const unsigned compressCode = ar.flushCompressedRecord(compressed);
101 throw IOWriteFailure(
102 "In gs::AbsArchive::copyItem: " 103 "failed to transfer compressed data");
106 std::streamoff off = os.tellp() -
base;
107 const long long delta = off;
108 assert(delta >= 0LL);
113 name = entry->name().c_str();
116 category = entry->category().c_str();
117 NotWritableRecord
record(entry->type(), entry->ioPrototype().c_str(),
name,
category);
120 const unsigned long long id2 = ar.addToCatalog(
record, compressCode, delta);
122 throw IOWriteFailure(
123 "In gs::AbsArchive::copyItem: " 124 "failed to add catalog entry");
125 ar.lastItemId_ =
id2;
126 ar.lastItemLength_ =
delta;
132 std::ostringstream err;
133 err <<
"In operator<<(gs::AbsArchive& ar, const gs::AbsRecord& record): " 134 <<
"failed to " << failedAction <<
" to the archive \"" << ar.name() <<
"\" for item with type \"" 135 << record.type().name() <<
"\", name \"" << record.name() <<
"\", and category \"" << record.category() <<
'"';
142 throw gs::IOInvalidArgument(
143 "In operator<<(gs::AbsArchive& ar, const gs::AbsRecord& record): " 144 "records can not be reused");
151 std::ostream &os = ar.outputStream();
152 std::streampos
base = os.tellp();
153 std::ostream &compressed = ar.compressedStream(os);
156 if (!record.writeData(compressed))
159 const unsigned compressCode = ar.flushCompressedRecord(compressed);
164 std::streamoff off = os.tellp() -
base;
165 const long long delta = off;
166 assert(delta >= 0LL);
169 const unsigned long long id = ar.addToCatalog(record, compressCode, delta);
175 record.itemLength_ =
delta;
179 ar.lastItemLength_ =
delta;
static void archive_stream_copy(std::istream &in, std::size_t count, std::ostream &out)
#define GS_STREAM_COPY_BUFFER_SIZE
gs::AbsArchive & operator<<(gs::AbsArchive &ar, const gs::AbsRecord &record)
base
Make Sure CMSSW is Setup ##.
static std::string local_error_message(gs::AbsArchive &ar, const gs::AbsRecord &record, const char *failedAction)