File indexing completed on 2023-03-17 10:39:09
0001 #include "Alignment/Geners/interface/IOException.hh"
0002
0003 #include "Alignment/Geners/interface/CPP11_auto_ptr.hh"
0004 #include "Alignment/Geners/interface/CatalogEntry.hh"
0005 #include "Alignment/Geners/interface/binaryIO.hh"
0006
0007 namespace gs {
0008 CatalogEntry::CatalogEntry()
0009 : ItemDescriptor(), id_(0), len_(0), location_(ItemLocation(std::streampos(0), nullptr)) {}
0010
0011 CatalogEntry::CatalogEntry(const ItemDescriptor &r,
0012 const unsigned long long id,
0013 const unsigned compressionCod,
0014 const unsigned long long itemLength,
0015 const ItemLocation &location,
0016 const unsigned long long offset)
0017 : ItemDescriptor(r),
0018 id_(id),
0019 len_(itemLength),
0020 offset_(offset),
0021 compressionCode_(compressionCod),
0022 location_(location) {
0023 if (!id)
0024 throw gs::IOInvalidArgument("In CatalogEntry constructor: invalid item id");
0025 }
0026
0027 bool CatalogEntry::isEqual(const ItemDescriptor &other) const {
0028 if ((void *)this == (void *)(&other))
0029 return true;
0030 if (!ItemDescriptor::isEqual(other))
0031 return false;
0032 const CatalogEntry &r = static_cast<const CatalogEntry &>(other);
0033 return id_ == r.id_ && len_ == r.len_ && offset_ == r.offset_ && compressionCode_ == r.compressionCode_ &&
0034 location_ == r.location_;
0035 }
0036
0037 bool CatalogEntry::write(std::ostream &of) const {
0038 type().write(of);
0039 write_pod(of, ioPrototype());
0040 write_pod(of, name());
0041 write_pod(of, category());
0042 write_pod(of, id_);
0043 write_pod(of, len_);
0044 write_pod(of, compressionCode_);
0045
0046
0047 unsigned char hasOffset = offset_ > 0ULL;
0048 write_pod(of, hasOffset);
0049 if (hasOffset)
0050 write_pod(of, offset_);
0051
0052 location_.write(of);
0053
0054 return !of.fail();
0055 }
0056
0057 CatalogEntry *CatalogEntry::read(const ClassId &id, const ClassId &locId, std::istream &in) {
0058 static const ClassId current(ClassId::makeId<CatalogEntry>());
0059 current.ensureSameId(id);
0060
0061 ClassId itemClass(in, 1);
0062
0063 std::string ioPrototype, name, category;
0064 read_pod(in, &ioPrototype);
0065 read_pod(in, &name);
0066 read_pod(in, &category);
0067
0068 unsigned long long itemId = 0, itemLen = 0;
0069 read_pod(in, &itemId);
0070 read_pod(in, &itemLen);
0071
0072 unsigned coCode;
0073 read_pod(in, &coCode);
0074
0075 unsigned long long offset = 0;
0076 unsigned char hasOffset = 0;
0077 read_pod(in, &hasOffset);
0078 if (hasOffset)
0079 read_pod(in, &offset);
0080
0081 CatalogEntry *rec = nullptr;
0082 if (!in.fail()) {
0083 CPP11_auto_ptr<ItemLocation> loc(ItemLocation::read(locId, in));
0084 if (loc.get())
0085 rec = new CatalogEntry(ItemDescriptor(itemClass, ioPrototype.c_str(), name.c_str(), category.c_str()),
0086 itemId,
0087 coCode,
0088 itemLen,
0089 *loc,
0090 offset);
0091 }
0092 return rec;
0093 }
0094
0095 bool CatalogEntry::humanReadable(std::ostream &os) const {
0096 os << "Id: " << id_ << '\n'
0097 << "Class: " << type().id() << '\n'
0098 << "Name: " << name() << '\n'
0099 << "Category: " << category() << '\n'
0100 << "I/O prototype: " << ioPrototype() << '\n'
0101 << "URI: " << location().URI() << '\n'
0102 << "Cached: " << location().cachedItemURI() << '\n'
0103 << "Compression: " << compressionCode_ << '\n'
0104 << "Length: " << len_ << '\n'
0105 << "Streampos: " << location().streamPosition() << '\n'
0106 << "Offset: " << offset_ << std::endl;
0107 return !os.fail();
0108 }
0109 }