5 #include "Alignment/Geners/interface/CPP11_auto_ptr.hh" 6 #include "Alignment/Geners/interface/ContiguousCatalog.hh" 7 #include "Alignment/Geners/interface/IOException.hh" 8 #include "Alignment/Geners/interface/binaryIO.hh" 11 void ContiguousCatalog::findByName(
const NameMap &
m,
12 const SearchSpecifier &namePattern,
13 std::vector<unsigned long long> *
found)
const {
14 typedef NameMap::const_iterator Nameiter;
16 if (namePattern.useRegex()) {
17 const Nameiter itend =
m.end();
18 for (Nameiter it =
m.begin(); it != itend; ++it)
19 if (namePattern.matches(it->first))
20 found->push_back(it->second);
22 const std::pair<Nameiter, Nameiter>
limits =
m.equal_range(namePattern.pattern());
23 for (Nameiter it =
limits.first; it !=
limits.second; ++it)
24 found->push_back(it->second);
28 unsigned long long ContiguousCatalog::makeEntry(
const ItemDescriptor &descriptor,
29 const unsigned compressionCode,
30 const unsigned long long itemLength,
31 const ItemLocation &loc,
32 const unsigned long long offset) {
33 const unsigned long long nextId = records_.size() + firstId_;
34 lastEntry_ = SPtr(
new CatalogEntry(descriptor, nextId, compressionCode, itemLength, loc,
offset));
35 records_.push_back(lastEntry_);
36 recordMap_[descriptor.category()].insert(std::make_pair(descriptor.name(), nextId));
42 const SearchSpecifier &categoryPattern,
43 std::vector<unsigned long long> *
found)
const {
44 typedef RecordMap::const_iterator Mapiter;
49 const Mapiter endMap = recordMap_.end();
50 if (categoryPattern.useRegex()) {
51 for (Mapiter it = recordMap_.begin(); it != endMap; ++it)
52 if (categoryPattern.matches(it->first))
53 findByName(it->second, namePattern,
found);
55 Mapiter it = recordMap_.find(categoryPattern.pattern());
57 findByName(it->second, namePattern,
found);
62 bool ContiguousCatalog::isEqual(
const AbsCatalog &
other)
const {
63 if ((
void *)
this == (
void *)(&
other))
65 const ContiguousCatalog &
r =
static_cast<const ContiguousCatalog &
>(
other);
66 if (firstId_ !=
r.firstId_)
68 if (recordMap_ !=
r.recordMap_)
70 const unsigned long nRecords = records_.size();
71 if (nRecords !=
r.records_.size())
73 for (
unsigned long i = 0;
i < nRecords; ++
i)
74 if (*records_[
i] != *
r.records_[
i])
91 const unsigned long long sz = records_.size();
92 long long nRecords = sz;
93 write_pod(os, nRecords);
94 bool status = !os.fail() && ClassId::makeId<CatalogEntry>().
write(os) && ClassId::makeId<ItemLocation>().
write(os);
95 for (
unsigned long long i = 0;
i < sz &&
status; ++
i)
101 static const ClassId current(ClassId::makeId<ContiguousCatalog>());
102 cid.ensureSameName(current);
103 cid.ensureVersionInRange(1,
version());
105 if (cid.version() == 1)
109 read_pod(
in, &nRecords);
114 ClassId locId(
in, 1);
116 CPP11_auto_ptr<ContiguousCatalog>
catalog(
new ContiguousCatalog());
118 for (
long long recnum = 0; recnum < nRecords; ++recnum) {
121 const unsigned long long id = rec->id();
126 const unsigned long long nextId =
catalog->records_.size() +
catalog->firstId_;
130 "In gs::ContiguousCatalog::read:" 131 " unexpected item id. " 132 "Catalog is corrupted.");
135 catalog->records_.push_back(SPtr(rec));
136 catalog->recordMap_[rec->category()].insert(std::make_pair(rec->name(),
id));
139 "In gs::ContiguousCatalog::read:" 140 " failed to read catalog entry");
145 ContiguousCatalog *ContiguousCatalog::read_v1(std::istream &
in) {
147 ClassId locId(
in, 1);
149 CPP11_auto_ptr<ContiguousCatalog>
catalog(
new ContiguousCatalog());
151 for (
in.peek(); !
in.eof();
in.peek()) {
154 const unsigned long long id = rec->id();
159 const unsigned long long nextId =
catalog->records_.size() +
catalog->firstId_;
163 "In gs::ContiguousCatalog::read_v1:" 164 " unexpected item id. " 165 "Catalog is corrupted.");
168 catalog->records_.push_back(SPtr(rec));
169 catalog->recordMap_[rec->category()].insert(std::make_pair(rec->name(),
id));
172 "In gs::ContiguousCatalog::read_v1:" 173 " failed to read catalog entry");
178 std::shared_ptr<const CatalogEntry> ContiguousCatalog::retrieveEntry(
const unsigned long long id)
const {
179 if (
id >= firstId_ &&
id < records_.size() + firstId_)
180 return records_[
id - firstId_];
182 CatalogEntry *ptr =
nullptr;
183 return std::shared_ptr<const CatalogEntry>(ptr);
187 bool ContiguousCatalog::retrieveStreampos(
unsigned long long id,
188 unsigned *compressionCode,
189 unsigned long long *length,
190 std::streampos *
pos)
const {
195 if (
id >= firstId_ &&
id < records_.size() + firstId_) {
196 const std::shared_ptr<const CatalogEntry> &rec(records_[
id - firstId_]);
197 *compressionCode = rec->compressionCode();
198 *length = rec->itemLength();
199 *
pos = rec->location().streamPosition();
std::vector< T >::const_iterator search(const cond::Time_t &val, const std::vector< T > &container)