1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
#ifndef GENERS_GENERALCATALOG_HH_
#define GENERS_GENERALCATALOG_HH_
#include <map>
#include "Alignment/Geners/interface/AbsCatalog.hh"
namespace gs {
class GeneralCatalog : public AbsCatalog {
public:
// Default constructor creates an empty catalog
GeneralCatalog();
inline ~GeneralCatalog() override {}
inline unsigned long long size() const override { return records_.size(); }
inline unsigned long long smallestId() const override { return smallestId_; }
inline unsigned long long largestId() const override { return largestId_; }
inline bool isContiguous() const override { return false; }
inline bool itemExists(const unsigned long long id) const override { return records_.find(id) != records_.end(); }
std::shared_ptr<const CatalogEntry> retrieveEntry(const unsigned long long id) const override;
bool retrieveStreampos(unsigned long long id,
unsigned *compressionCode,
unsigned long long *length,
std::streampos *pos) const override;
// Add a new entry without an id (id will be generated internally
// and returned)
unsigned long long makeEntry(const ItemDescriptor &descriptor,
unsigned compressionCode,
unsigned long long itemLength,
const ItemLocation &loc,
unsigned long long offset = 0ULL) override;
inline const CatalogEntry *lastEntryMade() const override { return lastEntry_.get(); }
// Add a new entry with id (presumably, from another catalog).
// Returns "true" on success. The entry is not included (and "false"
// is returned) in case the entry with the given id already exists.
bool addEntry(std::shared_ptr<const CatalogEntry> ptr);
// Remove an entry with the given id. "false" is returned in case
// an entry with the specified id does not exist.
bool removeEntry(unsigned long long id);
// Search for matching entries based on item name and category
void search(const SearchSpecifier &namePattern,
const SearchSpecifier &categoryPattern,
std::vector<unsigned long long> *idsFound) const override;
// Methods needed for I/O
ClassId classId() const override { return ClassId(*this); }
bool write(std::ostream &os) const override;
static inline const char *classname() { return "gs::GeneralCatalog"; }
static inline unsigned version() { return 2; }
static GeneralCatalog *read(const ClassId &id, std::istream &in);
protected:
bool isEqual(const AbsCatalog &) const override;
private:
typedef std::shared_ptr<const CatalogEntry> SPtr;
// In the following multimap, item name is the key and
// catalog entry pointer is the value
typedef std::multimap<std::string, SPtr> NameMap;
// In the following map, item category is the key
typedef std::map<std::string, NameMap> RecordMap;
// In the following map, item id is the key
typedef std::map<unsigned long long, SPtr> IdMap;
void findByName(const NameMap &nmap,
const SearchSpecifier &namePattern,
std::vector<unsigned long long> *found) const;
IdMap records_;
RecordMap recordMap_;
unsigned long long smallestId_;
unsigned long long largestId_;
SPtr lastEntry_;
static GeneralCatalog *read_v1(std::istream &in);
};
} // namespace gs
#endif // GENERS_GENERALCATALOG_HH_
|