5 #include "Alignment/Geners/interface/CPP11_auto_ptr.hh"
6 #include "Alignment/Geners/interface/ContiguousCatalog.hh"
7 #include "Alignment/Geners/interface/binaryIO.hh"
8 #include "Alignment/Geners/interface/IOException.hh"
11 void ContiguousCatalog::findByName(
13 const SearchSpecifier& namePattern,
14 std::vector<unsigned long long>*
found)
const
16 typedef NameMap::const_iterator Nameiter;
18 if (namePattern.useRegex())
20 const Nameiter itend = m.end();
21 for (Nameiter it = m.begin(); it != itend; ++it)
22 if (namePattern.matches(it->first))
23 found->push_back(it->second);
27 const std::pair<Nameiter, Nameiter> limits =
28 m.equal_range(namePattern.pattern());
29 for (Nameiter it = limits.first; it != limits.second; ++it)
30 found->push_back(it->second);
34 unsigned long long ContiguousCatalog::makeEntry(
35 const ItemDescriptor& descriptor,
36 const unsigned compressionCode,
37 const unsigned long long itemLength,
38 const ItemLocation& loc,
39 const unsigned long long offset)
41 const unsigned long long nextId = records_.size() + firstId_;
42 lastEntry_ = SPtr(
new CatalogEntry(
43 descriptor, nextId, compressionCode, itemLength, loc, offset));
44 records_.push_back(lastEntry_);
45 recordMap_[descriptor.category()].insert(
46 std::make_pair(descriptor.name(), nextId));
52 const SearchSpecifier& categoryPattern,
53 std::vector<unsigned long long>* found)
const
55 typedef RecordMap::const_iterator Mapiter;
60 const Mapiter endMap = recordMap_.end();
61 if (categoryPattern.useRegex())
63 for (Mapiter it = recordMap_.begin(); it != endMap; ++it)
64 if (categoryPattern.matches(it->first))
65 findByName(it->second, namePattern, found);
69 Mapiter it = recordMap_.find(categoryPattern.pattern());
71 findByName(it->second, namePattern, found);
76 bool ContiguousCatalog::isEqual(
const AbsCatalog& other)
const
78 if ((
void*)
this == (
void*)(&other))
80 const ContiguousCatalog&
r =
static_cast<const ContiguousCatalog&
>(other);
81 if (firstId_ != r.firstId_)
83 if (recordMap_ != r.recordMap_)
85 const unsigned long nRecords = records_.size();
86 if (nRecords != r.records_.size())
88 for (
unsigned long i=0;
i<nRecords; ++
i)
89 if (*records_[
i] != *r.records_[
i])
107 const unsigned long long sz = records_.size();
108 long long nRecords = sz;
109 write_pod(os, nRecords);
110 bool status = !os.fail() && ClassId::makeId<CatalogEntry>().
write(os) &&
111 ClassId::makeId<ItemLocation>().
write(os);
112 for (
unsigned long long i=0;
i<sz &&
status; ++
i)
113 status = records_[
i]->
write(os);
120 static const ClassId
current(ClassId::makeId<ContiguousCatalog>());
122 cid.ensureVersionInRange(1,
version());
124 if (cid.version() == 1)
128 read_pod(in, &nRecords);
133 ClassId locId(in, 1);
135 CPP11_auto_ptr<ContiguousCatalog>
catalog(
new ContiguousCatalog());
136 bool firstEntry =
true;
137 for (
long long recnum=0; recnum<nRecords; ++recnum)
142 const unsigned long long id = rec->id();
150 const unsigned long long nextId =
155 throw IOInvalidData(
"In gs::ContiguousCatalog::read:"
156 " unexpected item id. "
157 "Catalog is corrupted.");
160 catalog->records_.push_back(SPtr(rec));
161 catalog->recordMap_[rec->category()].insert(
162 std::make_pair(rec->name(), id));
165 throw IOInvalidData(
"In gs::ContiguousCatalog::read:"
166 " failed to read catalog entry");
171 ContiguousCatalog* ContiguousCatalog::read_v1(std::istream& in)
174 ClassId locId(in, 1);
176 CPP11_auto_ptr<ContiguousCatalog>
catalog(
new ContiguousCatalog());
177 bool firstEntry =
true;
178 for (in.peek(); !in.eof(); in.peek())
183 const unsigned long long id = rec->id();
191 const unsigned long long nextId =
196 throw IOInvalidData(
"In gs::ContiguousCatalog::read_v1:"
197 " unexpected item id. "
198 "Catalog is corrupted.");
201 catalog->records_.push_back(SPtr(rec));
202 catalog->recordMap_[rec->category()].insert(
203 std::make_pair(rec->name(), id));
206 throw IOInvalidData(
"In gs::ContiguousCatalog::read_v1:"
207 " failed to read catalog entry");
212 CPP11_shared_ptr<const CatalogEntry> ContiguousCatalog::retrieveEntry(
213 const unsigned long long id)
const
215 if (
id >= firstId_ &&
id < records_.size() + firstId_)
216 return records_[
id - firstId_];
219 CatalogEntry* ptr = 0;
220 return CPP11_shared_ptr<const CatalogEntry>(ptr);
224 bool ContiguousCatalog::retrieveStreampos(
225 unsigned long long id,
unsigned* compressionCode,
226 unsigned long long* length, std::streampos* pos)
const
228 assert(compressionCode);
232 if (
id >= firstId_ &&
id < records_.size() + firstId_)
234 const CPP11_shared_ptr<const CatalogEntry>&
235 rec(records_[
id-firstId_]);
236 *compressionCode = rec->compressionCode();
237 *length = rec->itemLength();
238 *pos = rec->location().streamPosition();
unsigned int offset(bool)
std::vector< T >::const_iterator search(const cond::Time_t &val, const std::vector< T > &container)