1 #include "Alignment/Geners/interface/CPP11_auto_ptr.hh"
2 #include "Alignment/Geners/interface/CPP11_shared_ptr.hh"
3 #include "Alignment/Geners/interface/WriteOnlyCatalog.hh"
4 #include "Alignment/Geners/interface/binaryIO.hh"
5 #include "Alignment/Geners/interface/IOException.hh"
8 WriteOnlyCatalog::WriteOnlyCatalog(std::ostream& os,
9 const unsigned long long firstId)
13 smallestId_(firstId ? firstId : 1ULL),
18 unsigned long long WriteOnlyCatalog::makeEntry(
19 const ItemDescriptor& descriptor,
20 const unsigned compressionCode,
21 const unsigned long long itemLen,
22 const ItemLocation& loc,
23 const unsigned long long off)
25 const unsigned long long id = count_ ? largestId_ + 1 : smallestId_;
26 lastEntry_ = CPP11_auto_ptr<const CatalogEntry>(
new CatalogEntry(
27 descriptor,
id, compressionCode, itemLen, loc, off));
28 if (lastEntry_->write(os_))
36 delete lastEntry_.release();
52 return !os.fail() && ClassId::makeId<CatalogEntry>().
write(os) &&
53 ClassId::makeId<ItemLocation>().
write(os);
59 static const ClassId
current(ClassId::makeId<WriteOnlyCatalog>());
61 id.ensureVersionInRange(1,
version());
72 CPP11_auto_ptr<WriteOnlyCatalog>
cat(
new WriteOnlyCatalog(
73 dynamic_cast<std::ostream&>(in)));
74 bool firstEntry =
true;
75 for (in.peek(); !in.eof(); in.peek())
81 const unsigned long long id = rec->id();
84 cat->smallestId_ = id;
91 if (id < cat->smallestId_)
93 cat->smallestId_ = id;
96 else if (
id >
cat->largestId_)
106 throw IOInvalidData(
"In gs::WriteOnlyCatalog::read: "
107 "entry out of order. Catalog is "
108 "likely to be corrupted.");
111 throw IOInvalidData(
"In gs::WriteOnlyCatalog::read: "
112 "failed to read catalog entry");
114 return cat.release();
117 CPP11_shared_ptr<const CatalogEntry> WriteOnlyCatalog::retrieveEntry(
118 unsigned long long)
const
120 throw IOReadFailure(
"In gs::WriteOnlyCatalog::retrieveEntry: "
121 "entries can not be retrieved "
122 "from a write-only catalog");
123 return CPP11_shared_ptr<CatalogEntry>(
124 reinterpret_cast<CatalogEntry*
>(0));
127 bool WriteOnlyCatalog::retrieveStreampos(
128 unsigned long long ,
unsigned* ,
129 unsigned long long* , std::streampos* )
const
131 throw IOReadFailure(
"In gs::WriteOnlyCatalog::retrieveStreampos: "
132 "stream positions can not be retrieved "
133 "from a write-only catalog");
138 const SearchSpecifier&,
139 std::vector<unsigned long long>*)
const
141 throw IOReadFailure(
"In gs::WriteOnlyCatalog::search: "
142 "entries can not be searched "
143 "in a write-only catalog");
std::vector< T >::const_iterator search(const cond::Time_t &val, const std::vector< T > &container)