CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
WriteOnlyCatalog.cc
Go to the documentation of this file.
1 #include "Alignment/Geners/interface/CPP11_auto_ptr.hh"
2 #include "Alignment/Geners/interface/IOException.hh"
3 #include "Alignment/Geners/interface/WriteOnlyCatalog.hh"
4 #include "Alignment/Geners/interface/binaryIO.hh"
5 
6 #include <memory>
7 
8 namespace gs {
9  WriteOnlyCatalog::WriteOnlyCatalog(std::ostream &os, const unsigned long long firstId)
10  : AbsCatalog(), os_(os), count_(0), smallestId_(firstId ? firstId : 1ULL), largestId_(0) {}
11 
12  unsigned long long WriteOnlyCatalog::makeEntry(const ItemDescriptor &descriptor,
13  const unsigned compressionCode,
14  const unsigned long long itemLen,
15  const ItemLocation &loc,
16  const unsigned long long off) {
17  const unsigned long long id = count_ ? largestId_ + 1 : smallestId_;
18  lastEntry_ =
19  CPP11_auto_ptr<const CatalogEntry>(new CatalogEntry(descriptor, id, compressionCode, itemLen, loc, off));
20  if (lastEntry_->write(os_)) {
21  ++count_;
22  largestId_ = id;
23  return id;
24  } else {
25  lastEntry_ = nullptr;
26  return 0ULL;
27  }
28  }
29 
30  // Version 1 write function
31  // bool WriteOnlyCatalog::write(std::ostream& os) const
32  // {
33  // return ClassId::makeId<CatalogEntry>().write(os) &&
34  // ClassId::makeId<ItemLocation>().write(os);
35  // }
36 
37  bool WriteOnlyCatalog::write(std::ostream &os) const {
38  long long dummy = -1;
39  write_pod(os, dummy);
40  return !os.fail() && ClassId::makeId<CatalogEntry>().write(os) && ClassId::makeId<ItemLocation>().write(os);
41  }
42 
43  WriteOnlyCatalog *WriteOnlyCatalog::read(const ClassId &id, std::istream &in) {
44  static const ClassId current(ClassId::makeId<WriteOnlyCatalog>());
45  id.ensureSameName(current);
46  id.ensureVersionInRange(1, version());
47 
48  if (id.version() > 1) {
49  long long dummy;
50  read_pod(in, &dummy);
51  }
52 
53  ClassId rId(in, 1);
54  ClassId locId(in, 1);
55 
56  CPP11_auto_ptr<WriteOnlyCatalog> cat(new WriteOnlyCatalog(dynamic_cast<std::ostream &>(in)));
57  bool firstEntry = true;
58  for (in.peek(); !in.eof(); in.peek()) {
59  CatalogEntry *rec = CatalogEntry::read(rId, locId, in);
60  if (rec) {
61  bool ordered = true;
62  const unsigned long long id = rec->id();
63  if (firstEntry) {
64  cat->smallestId_ = id;
65  cat->count_ = 1;
66  cat->largestId_ = id;
67  firstEntry = false;
68  } else {
69  if (id < cat->smallestId_) {
70  cat->smallestId_ = id;
71  ++cat->count_;
72  } else if (id > cat->largestId_) {
73  cat->largestId_ = id;
74  ++cat->count_;
75  } else
76  ordered = false;
77  }
78  delete rec;
79  if (!ordered)
80  throw IOInvalidData(
81  "In gs::WriteOnlyCatalog::read: "
82  "entry out of order. Catalog is "
83  "likely to be corrupted.");
84  } else
85  throw IOInvalidData(
86  "In gs::WriteOnlyCatalog::read: "
87  "failed to read catalog entry");
88  }
89  return cat.release();
90  }
91 
92  std::shared_ptr<const CatalogEntry> WriteOnlyCatalog::retrieveEntry(unsigned long long) const {
93  throw IOReadFailure(
94  "In gs::WriteOnlyCatalog::retrieveEntry: "
95  "entries can not be retrieved "
96  "from a write-only catalog");
97  return std::shared_ptr<CatalogEntry>(reinterpret_cast<CatalogEntry *>(0));
98  }
99 
100  bool WriteOnlyCatalog::retrieveStreampos(unsigned long long /* id */,
101  unsigned * /* compressionCode */,
102  unsigned long long * /* length */,
103  std::streampos * /* pos */) const {
104  throw IOReadFailure(
105  "In gs::WriteOnlyCatalog::retrieveStreampos: "
106  "stream positions can not be retrieved "
107  "from a write-only catalog");
108  return false;
109  }
110 
111  void WriteOnlyCatalog::search(const SearchSpecifier &,
112  const SearchSpecifier &,
113  std::vector<unsigned long long> *) const {
114  throw IOReadFailure(
115  "In gs::WriteOnlyCatalog::search: "
116  "entries can not be searched "
117  "in a write-only catalog");
118  }
119 } // namespace gs
uint16_t *__restrict__ id
std::vector< T >::const_iterator search(const cond::Time_t &val, const std::vector< T > &container)
Definition: IOVProxy.cc:21
def cat
Definition: eostools.py:401