test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CatalogEntry.cc
Go to the documentation of this file.
1 #include "Alignment/Geners/interface/IOException.hh"
2 
3 #include "Alignment/Geners/interface/CPP11_auto_ptr.hh"
4 #include "Alignment/Geners/interface/CatalogEntry.hh"
5 #include "Alignment/Geners/interface/binaryIO.hh"
6 
7 namespace gs {
8  CatalogEntry::CatalogEntry()
9  : ItemDescriptor(),
10  id_(0),
11  len_(0),
12  location_(ItemLocation(std::streampos(0), 0))
13  {
14  }
15 
16  CatalogEntry::CatalogEntry(const ItemDescriptor& r,
17  const unsigned long long id,
18  const unsigned compressionCod,
19  const unsigned long long itemLength,
20  const ItemLocation& location,
21  const unsigned long long offset)
22  : ItemDescriptor(r),
23  id_(id),
24  len_(itemLength),
25  offset_(offset),
26  compressionCode_(compressionCod),
27  location_(location)
28  {
29  if (!id) throw gs::IOInvalidArgument(
30  "In CatalogEntry constructor: invalid item id");
31  }
32 
33  bool CatalogEntry::isEqual(const ItemDescriptor& other) const
34  {
35  if ((void*)this == (void*)(&other))
36  return true;
37  if (!ItemDescriptor::isEqual(other))
38  return false;
39  const CatalogEntry& r = static_cast<const CatalogEntry&>(other);
40  return id_ == r.id_ && len_ == r.len_ &&
41  offset_ == r.offset_ &&
42  compressionCode_ == r.compressionCode_ &&
43  location_ == r.location_;
44  }
45 
46  bool CatalogEntry::write(std::ostream& of) const
47  {
48  type().write(of);
49  write_pod(of, ioPrototype());
50  write_pod(of, name());
51  write_pod(of, category());
52  write_pod(of, id_);
53  write_pod(of, len_);
54  write_pod(of, compressionCode_);
55 
56  // Most items will not have offsets
57  unsigned char hasOffset = offset_ > 0ULL;
58  write_pod(of, hasOffset);
59  if (hasOffset)
60  write_pod(of, offset_);
61 
62  location_.write(of);
63 
64  return !of.fail();
65  }
66 
67  CatalogEntry* CatalogEntry::read(const ClassId& id,
68  const ClassId& locId,
69  std::istream& in)
70  {
71  static const ClassId current(ClassId::makeId<CatalogEntry>());
72  current.ensureSameId(id);
73 
74  ClassId itemClass(in, 1);
75 
76  std::string ioPrototype, name, category;
77  read_pod(in, &ioPrototype);
78  read_pod(in, &name);
79  read_pod(in, &category);
80 
81  unsigned long long itemId = 0, itemLen = 0;
82  read_pod(in, &itemId);
83  read_pod(in, &itemLen);
84 
85  unsigned coCode;
86  read_pod(in, &coCode);
87 
88  unsigned long long offset = 0;
89  unsigned char hasOffset = 0;
90  read_pod(in, &hasOffset);
91  if (hasOffset)
92  read_pod(in, &offset);
93 
94  CatalogEntry* rec = 0;
95  if (!in.fail())
96  {
97  CPP11_auto_ptr<ItemLocation> loc(ItemLocation::read(locId, in));
98  if (loc.get())
99  rec = new CatalogEntry(
100  ItemDescriptor(itemClass, ioPrototype.c_str(),
101  name.c_str(), category.c_str()),
102  itemId, coCode, itemLen, *loc, offset);
103  }
104  return rec;
105  }
106 
107  bool CatalogEntry::humanReadable(std::ostream& os) const
108  {
109  os << "Id: " << id_ << '\n'
110  << "Class: " << type().id() << '\n'
111  << "Name: " << name() << '\n'
112  << "Category: " << category() << '\n'
113  << "I/O prototype: " << ioPrototype() << '\n'
114  << "URI: " << location().URI() << '\n'
115  << "Cached: " << location().cachedItemURI() << '\n'
116  << "Compression: " << compressionCode_ << '\n'
117  << "Length: " << len_ << '\n'
118  << "Streampos: " << location().streamPosition() << '\n'
119  << "Offset: " << offset_
120  << std::endl;
121  return !os.fail();
122  }
123 }
type
Definition: HCALResponse.h:21