1 #include "Alignment/Geners/interface/CPP11_auto_ptr.hh" 2 #include "Alignment/Geners/interface/CPP11_shared_ptr.hh" 3 #include "Alignment/Geners/interface/IOException.hh" 4 #include "Alignment/Geners/interface/WriteOnlyCatalog.hh" 5 #include "Alignment/Geners/interface/binaryIO.hh" 8 WriteOnlyCatalog::WriteOnlyCatalog(std::ostream &os,
const unsigned long long firstId)
9 : AbsCatalog(), os_(os), count_(0), smallestId_(firstId ? firstId : 1ULL), largestId_(0) {}
11 unsigned long long WriteOnlyCatalog::makeEntry(
const ItemDescriptor &descriptor,
12 const unsigned compressionCode,
13 const unsigned long long itemLen,
14 const ItemLocation &
loc,
15 const unsigned long long off) {
16 const unsigned long long id = count_ ? largestId_ + 1 : smallestId_;
18 CPP11_auto_ptr<const CatalogEntry>(
new CatalogEntry(descriptor,
id, compressionCode, itemLen, loc, off));
19 if (lastEntry_->write(os_)) {
39 return !os.fail() && ClassId::makeId<CatalogEntry>().
write(os) && ClassId::makeId<ItemLocation>().
write(os);
42 WriteOnlyCatalog *WriteOnlyCatalog::read(
const ClassId &
id, std::istream &
in) {
43 static const ClassId current(ClassId::makeId<WriteOnlyCatalog>());
44 id.ensureSameName(current);
45 id.ensureVersionInRange(1,
version());
55 CPP11_auto_ptr<WriteOnlyCatalog>
cat(
new WriteOnlyCatalog(dynamic_cast<std::ostream &>(in)));
56 bool firstEntry =
true;
57 for (in.peek(); !in.eof(); in.peek()) {
58 CatalogEntry *rec = CatalogEntry::read(rId, locId, in);
61 const unsigned long long id = rec->id();
63 cat->smallestId_ =
id;
68 if (id < cat->smallestId_) {
69 cat->smallestId_ =
id;
71 }
else if (
id >
cat->largestId_) {
80 "In gs::WriteOnlyCatalog::read: " 81 "entry out of order. Catalog is " 82 "likely to be corrupted.");
85 "In gs::WriteOnlyCatalog::read: " 86 "failed to read catalog entry");
91 CPP11_shared_ptr<const CatalogEntry> WriteOnlyCatalog::retrieveEntry(
unsigned long long)
const {
93 "In gs::WriteOnlyCatalog::retrieveEntry: " 94 "entries can not be retrieved " 95 "from a write-only catalog");
96 return CPP11_shared_ptr<CatalogEntry>(
reinterpret_cast<CatalogEntry *
>(0));
99 bool WriteOnlyCatalog::retrieveStreampos(
unsigned long long ,
101 unsigned long long * ,
102 std::streampos * )
const {
104 "In gs::WriteOnlyCatalog::retrieveStreampos: " 105 "stream positions can not be retrieved " 106 "from a write-only catalog");
111 const SearchSpecifier &,
112 std::vector<unsigned long long> *)
const {
114 "In gs::WriteOnlyCatalog::search: " 115 "entries can not be searched " 116 "in a write-only catalog");
std::vector< T >::const_iterator search(const cond::Time_t &val, const std::vector< T > &container)