CMS 3D CMS Logo

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(), id_(0), len_(0), location_(ItemLocation(std::streampos(0), nullptr)) {}
10 
11  CatalogEntry::CatalogEntry(const ItemDescriptor &r,
12  const unsigned long long id,
13  const unsigned compressionCod,
14  const unsigned long long itemLength,
15  const ItemLocation &location,
16  const unsigned long long offset)
17  : ItemDescriptor(r),
18  id_(id),
19  len_(itemLength),
20  offset_(offset),
21  compressionCode_(compressionCod),
22  location_(location) {
23  if (!id)
24  throw gs::IOInvalidArgument("In CatalogEntry constructor: invalid item id");
25  }
26 
27  bool CatalogEntry::isEqual(const ItemDescriptor &other) const {
28  if ((void *)this == (void *)(&other))
29  return true;
30  if (!ItemDescriptor::isEqual(other))
31  return false;
32  const CatalogEntry &r = static_cast<const CatalogEntry &>(other);
33  return id_ == r.id_ && len_ == r.len_ && offset_ == r.offset_ && compressionCode_ == r.compressionCode_ &&
34  location_ == r.location_;
35  }
36 
37  bool CatalogEntry::write(std::ostream &of) const {
38  type().write(of);
39  write_pod(of, ioPrototype());
40  write_pod(of, name());
41  write_pod(of, category());
42  write_pod(of, id_);
43  write_pod(of, len_);
44  write_pod(of, compressionCode_);
45 
46  // Most items will not have offsets
47  unsigned char hasOffset = offset_ > 0ULL;
48  write_pod(of, hasOffset);
49  if (hasOffset)
50  write_pod(of, offset_);
51 
52  location_.write(of);
53 
54  return !of.fail();
55  }
56 
57  CatalogEntry *CatalogEntry::read(const ClassId &id, const ClassId &locId, std::istream &in) {
58  static const ClassId current(ClassId::makeId<CatalogEntry>());
59  current.ensureSameId(id);
60 
61  ClassId itemClass(in, 1);
62 
63  std::string ioPrototype, name, category;
64  read_pod(in, &ioPrototype);
65  read_pod(in, &name);
66  read_pod(in, &category);
67 
68  unsigned long long itemId = 0, itemLen = 0;
69  read_pod(in, &itemId);
70  read_pod(in, &itemLen);
71 
72  unsigned coCode;
73  read_pod(in, &coCode);
74 
75  unsigned long long offset = 0;
76  unsigned char hasOffset = 0;
77  read_pod(in, &hasOffset);
78  if (hasOffset)
79  read_pod(in, &offset);
80 
81  CatalogEntry *rec = nullptr;
82  if (!in.fail()) {
83  CPP11_auto_ptr<ItemLocation> loc(ItemLocation::read(locId, in));
84  if (loc.get())
85  rec = new CatalogEntry(ItemDescriptor(itemClass, ioPrototype.c_str(), name.c_str(), category.c_str()),
86  itemId,
87  coCode,
88  itemLen,
89  *loc,
90  offset);
91  }
92  return rec;
93  }
94 
95  bool CatalogEntry::humanReadable(std::ostream &os) const {
96  os << "Id: " << id_ << '\n'
97  << "Class: " << type().id() << '\n'
98  << "Name: " << name() << '\n'
99  << "Category: " << category() << '\n'
100  << "I/O prototype: " << ioPrototype() << '\n'
101  << "URI: " << location().URI() << '\n'
102  << "Cached: " << location().cachedItemURI() << '\n'
103  << "Compression: " << compressionCode_ << '\n'
104  << "Length: " << len_ << '\n'
105  << "Streampos: " << location().streamPosition() << '\n'
106  << "Offset: " << offset_ << std::endl;
107  return !os.fail();
108  }
109 } // namespace gs
taus_updatedMVAIds_cff.category
category
Definition: taus_updatedMVAIds_cff.py:31
gs
Definition: AbsArchive.cc:45
trackingPlots.other
other
Definition: trackingPlots.py:1460
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
recoMuon::in
Definition: RecoMuonEnumerators.h:6
gainCalibHelper::gainCalibPI::type
type
Definition: SiPixelGainCalibHelper.h:40
alignCSCRings.r
r
Definition: alignCSCRings.py:93
readEcalDQMStatus.read
read
Definition: readEcalDQMStatus.py:38
writeEcalDQMStatus.write
write
Definition: writeEcalDQMStatus.py:48
std
Definition: JetResolutionObject.h:76
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
EcalCondDBWriter_cfi.location
location
Definition: EcalCondDBWriter_cfi.py:63
hltrates_dqm_sourceclient-live_cfg.offset
offset
Definition: hltrates_dqm_sourceclient-live_cfg.py:82