CMS 3D CMS Logo

IDVectorMap.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_IDVectorMap_h
2 #define DataFormats_Common_IDVectorMap_h
3 #include <map>
4 
5 namespace edm {
6 
7  template <typename ID, typename C, typename P>
8  class IDVectorMap {
9  public:
10  typedef typename C::value_type value_type;
11  typedef typename C::const_iterator container_iterator;
12  typedef std::map<ID, C> map;
13  typedef typename map::const_iterator map_iterator;
14  struct const_iterator {
16  typedef value_type* pointer;
18  typedef typename map_iterator::iterator_category iterator_category;
20  const_iterator(const map_iterator& e, const map_iterator& m, const container_iterator& c) : im(m), em(e), ic(c) {}
21  const_iterator(const map_iterator& e) : im(e), em(e) {}
23  im = it.im;
24  em = it.em;
25  ic = it.ic;
26  return *this;
27  }
29  ++ic;
30  while (ic == im->second.end()) {
31  ++im;
32  if (im == em)
33  return *this;
34  ic = im->second.begin();
35  }
36  return *this;
37  }
39  const_iterator ci = *this;
40  operator++();
41  return ci;
42  }
44  if (im == em) {
45  --im;
46  ic = im->second.end();
47  }
48  while (ic == im->second.begin()) {
49  --im;
50  ic = im->second.end();
51  }
52  --ic;
53  return *this;
54  }
56  const_iterator ci = *this;
57  operator--();
58  return ci;
59  }
60  bool operator==(const const_iterator& ci) const {
61  if (im == em && ci.im == im && ci.em == em)
62  return true;
63  return im == ci.im && ic == ci.ic;
64  }
65  bool operator!=(const const_iterator& ci) const { return !operator==(ci); }
66  const value_type& operator*() const { return *ic; }
67 
68  private:
71  };
72 
74  const_iterator begin() const { return const_iterator(map_.end(), map_.begin(), map_.begin()->second.begin()); }
75  const_iterator end() const { return const_iterator(map_.end()); }
76  void insert(ID id, const value_type& t) { map_[id].push_back(P::clone(t)); }
77  template <typename CI>
78  void insert(ID id, CI begin, CI end) {
79  C& c = map_[id];
80  for (CI i = begin; i != end; ++i)
81  c.push_back(P::clone(*i));
82  }
83 
84  struct range {
87  };
88  range get(ID id) const {
90  map_iterator i = map_.find(id);
91  if (i != map_.end()) {
92  begin = i->second.begin();
93  end = i->second.end();
94  } else {
95  begin = end;
96  }
97  return range(begin, end);
98  }
99 
100  template <typename M>
101  struct match_iterator {
103  typedef value_type* pointer;
105  typedef typename map_iterator::iterator_category iterator_category;
107  match_iterator(const M& ma, const map_iterator& e, const map_iterator& m, const container_iterator& c)
108  : match(ma), im(m), em(e), ic(c) {}
109  match_iterator(const M& ma, const map_iterator& e) : match(ma), im(e), em(e) {}
111  match = it.match;
112  im = it.im;
113  em = it.em;
114  ic = it.ic;
115  return *this;
116  }
118  ++ic;
119  while (ic == im->second.end()) {
120  do {
121  ++im;
122  } while (!match(im->first) && im != em);
123  if (im == em)
124  return *this;
125  ic = im->second.begin();
126  }
127  return *this;
128  }
130  match_iterator ci = *this;
131  operator++();
132  return ci;
133  }
134  bool operator==(const match_iterator& ci) const {
135  if (im == em && ci.im == im && ci.em == em)
136  return true;
137  return im == ci.im && ic == ci.ic;
138  }
139  bool operator!=(const match_iterator& ci) const { return !operator==(ci); }
140  const value_type& operator*() const { return *ic; }
141 
142  private:
143  M match;
146  };
147 
148  template <typename M>
149  match_iterator<M> begin(const M& m) const {
150  return match_iterator<M>(m, map_.end(), map_.begin(), map_.begin()->second.begin());
151  }
152  template <typename M>
153  match_iterator<M> end(const M& m) const {
154  return match_iterator<M>(m, map_.end());
155  }
156 
157  struct id_iterator {
158  typedef ID value_type;
159  typedef ID* pointer;
160  typedef ID& reference;
161  typedef typename map_iterator::iterator_category iterator_category;
165  i = it.i;
166  return *this;
167  }
169  ++i;
170  return *this;
171  }
173  id_iterator ci = *this;
174  ++i;
175  return ci;
176  }
178  --i;
179  return *this;
180  }
182  id_iterator ci = *this;
183  --i;
184  return ci;
185  }
186  bool operator==(const id_iterator& ci) const { return i == ci.i; }
187  bool operator!=(const id_iterator& ci) const { return i != ci.i; }
188  const ID operator*() const { return i->first; }
189 
190  private:
192  };
193  id_iterator id_begin() const { return id_iterator(map_.begin()); }
194  id_iterator id_end() const { return id_iterator(map_.end()); }
195  size_t id_size() const { return map_.size(); }
196  void swap(IDVectorMap& other);
197  IDVectorMap& operator=(IDVectorMap const& rhs);
198 
199  private:
202  };
203 
204  template <typename ID, typename C, typename P>
206  collection_.swap(other.collection_);
207  map_.swap(other.map_);
208  }
209 
210  template <typename ID, typename C, typename P>
213  this->swap(temp);
214  return *this;
215  }
216 
217  // free swap function
218  template <typename ID, typename C, typename P>
220  a.swap(b);
221  }
222 
223 } // namespace edm
224 
225 #endif
edm::IDVectorMap::const_iterator::em
map_iterator em
Definition: IDVectorMap.h:69
edm::IDVectorMap::match_iterator::value_type
IDVectorMap::value_type value_type
Definition: IDVectorMap.h:102
edm::IDVectorMap::match_iterator::operator!=
bool operator!=(const match_iterator &ci) const
Definition: IDVectorMap.h:139
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
edm::IDVectorMap::id_iterator
Definition: IDVectorMap.h:157
edm::IDVectorMap::const_iterator::const_iterator
const_iterator(const map_iterator &e, const map_iterator &m, const container_iterator &c)
Definition: IDVectorMap.h:20
edm::IDVectorMap::const_iterator::reference
value_type & reference
Definition: IDVectorMap.h:17
mps_fire.i
i
Definition: mps_fire.py:428
edm::IDVectorMap::match_iterator::operator++
match_iterator & operator++()
Definition: IDVectorMap.h:117
edm::IDVectorMap::id_iterator::operator!=
bool operator!=(const id_iterator &ci) const
Definition: IDVectorMap.h:187
edm::IDVectorMap::range::end
container_iterator end
Definition: IDVectorMap.h:86
edm::IDVectorMap::insert
void insert(ID id, const value_type &t)
Definition: IDVectorMap.h:76
edm::IDVectorMap::id_iterator::id_iterator
id_iterator()
Definition: IDVectorMap.h:162
edm::IDVectorMap::const_iterator::operator--
const_iterator operator--(int)
Definition: IDVectorMap.h:55
edm::IDVectorMap::id_iterator::id_iterator
id_iterator(map_iterator o)
Definition: IDVectorMap.h:163
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::swap
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:117
edm::IDVectorMap::range
Definition: IDVectorMap.h:84
edm::IDVectorMap::insert
void insert(ID id, CI begin, CI end)
Definition: IDVectorMap.h:78
edm::IDVectorMap::const_iterator::operator!=
bool operator!=(const const_iterator &ci) const
Definition: IDVectorMap.h:65
edm::IDVectorMap::match_iterator::operator++
match_iterator operator++(int)
Definition: IDVectorMap.h:129
edm::IDVectorMap::id_iterator::i
map_iterator i
Definition: IDVectorMap.h:191
edm::IDVectorMap::match_iterator::pointer
value_type * pointer
Definition: IDVectorMap.h:103
edm::IDVectorMap::id_iterator::iterator_category
map_iterator::iterator_category iterator_category
Definition: IDVectorMap.h:161
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
edm::IDVectorMap::id_iterator::value_type
ID value_type
Definition: IDVectorMap.h:158
EcalTangentSkim_cfg.o
o
Definition: EcalTangentSkim_cfg.py:42
edm::IDVectorMap::match_iterator
Definition: IDVectorMap.h:101
edm::IDVectorMap::id_begin
id_iterator id_begin() const
Definition: IDVectorMap.h:193
edm::IDVectorMap::begin
const_iterator begin() const
Definition: IDVectorMap.h:74
edm::IDVectorMap::const_iterator::operator--
const_iterator & operator--()
Definition: IDVectorMap.h:43
edm::IDVectorMap::const_iterator::const_iterator
const_iterator(const map_iterator &e)
Definition: IDVectorMap.h:21
edm::IDVectorMap::match_iterator::ic
container_iterator ic
Definition: IDVectorMap.h:145
edm::IDVectorMap::const_iterator::const_iterator
const_iterator()
Definition: IDVectorMap.h:19
clone
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
edm::IDVectorMap::get
range get(ID id) const
Definition: IDVectorMap.h:88
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:78
edm::IDVectorMap::range::begin
container_iterator begin
Definition: IDVectorMap.h:86
edm::IDVectorMap::begin
match_iterator< M > begin(const M &m) const
Definition: IDVectorMap.h:149
edm::IDVectorMap::match_iterator::match
M match
Definition: IDVectorMap.h:143
edm::IDVectorMap::match_iterator::em
map_iterator em
Definition: IDVectorMap.h:144
trackingPlots.other
other
Definition: trackingPlots.py:1464
edm::IDVectorMap::map
std::map< ID, C > map
Definition: IDVectorMap.h:12
edm::IDVectorMap::id_size
size_t id_size() const
Definition: IDVectorMap.h:195
b
double b
Definition: hdecay.h:118
edm::IDVectorMap::end
const_iterator end() const
Definition: IDVectorMap.h:75
edm::IDVectorMap::match_iterator::reference
value_type & reference
Definition: IDVectorMap.h:104
edm::IDVectorMap::const_iterator::operator++
const_iterator operator++(int)
Definition: IDVectorMap.h:38
edm::IDVectorMap::map_
map map_
Definition: IDVectorMap.h:201
edm::IDVectorMap::swap
void swap(IDVectorMap &other)
Definition: IDVectorMap.h:205
a
double a
Definition: hdecay.h:119
align::ID
uint32_t ID
Definition: Definitions.h:24
edm::IDVectorMap::const_iterator::operator*
const value_type & operator*() const
Definition: IDVectorMap.h:66
edm::IDVectorMap::operator=
IDVectorMap & operator=(IDVectorMap const &rhs)
Definition: IDVectorMap.h:211
edm::IDVectorMap::match_iterator::im
map_iterator im
Definition: IDVectorMap.h:144
edm::IDVectorMap::const_iterator::pointer
value_type * pointer
Definition: IDVectorMap.h:16
edm::IDVectorMap::const_iterator
Definition: IDVectorMap.h:14
edm::IDVectorMap::const_iterator::value_type
IDVectorMap::value_type value_type
Definition: IDVectorMap.h:15
edm::IDVectorMap::id_iterator::reference
ID & reference
Definition: IDVectorMap.h:160
edm::IDVectorMap::const_iterator::ic
container_iterator ic
Definition: IDVectorMap.h:70
edm::IDVectorMap::id_iterator::pointer
ID * pointer
Definition: IDVectorMap.h:159
edm::IDVectorMap::id_iterator::operator*
const ID operator*() const
Definition: IDVectorMap.h:188
edm::IDVectorMap::id_iterator::operator++
id_iterator operator++(int)
Definition: IDVectorMap.h:172
reco::JetExtendedAssociation::value_type
Container::value_type value_type
Definition: JetExtendedAssociation.h:30
edm::IDVectorMap::const_iterator::im
map_iterator im
Definition: IDVectorMap.h:69
edm::IDVectorMap::id_iterator::operator++
id_iterator & operator++()
Definition: IDVectorMap.h:168
edm::IDVectorMap::const_iterator::operator++
const_iterator & operator++()
Definition: IDVectorMap.h:28
edm::IDVectorMap::match_iterator::match_iterator
match_iterator()
Definition: IDVectorMap.h:106
edm::IDVectorMap::range::range
range(const container_iterator &b, const container_iterator &e)
Definition: IDVectorMap.h:85
edm::IDVectorMap::id_iterator::operator=
id_iterator & operator=(const id_iterator &it)
Definition: IDVectorMap.h:164
edm::IDVectorMap::collection_
C collection_
Definition: IDVectorMap.h:200
gen::C
C
Definition: PomwigHadronizer.cc:78
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
edm::IDVectorMap
Definition: IDVectorMap.h:8
edm::IDVectorMap::match_iterator::operator=
match_iterator & operator=(const match_iterator &it)
Definition: IDVectorMap.h:110
edm::IDVectorMap::const_iterator::operator=
const_iterator & operator=(const const_iterator &it)
Definition: IDVectorMap.h:22
edm::IDVectorMap::match_iterator::operator==
bool operator==(const match_iterator &ci) const
Definition: IDVectorMap.h:134
edm::IDVectorMap::value_type
C::value_type value_type
Definition: IDVectorMap.h:10
edm::IDVectorMap::const_iterator::operator==
bool operator==(const const_iterator &ci) const
Definition: IDVectorMap.h:60
edm::IDVectorMap::match_iterator::match_iterator
match_iterator(const M &ma, const map_iterator &e)
Definition: IDVectorMap.h:109
edm::IDVectorMap::map_iterator
map::const_iterator map_iterator
Definition: IDVectorMap.h:13
edm::IDVectorMap::match_iterator::iterator_category
map_iterator::iterator_category iterator_category
Definition: IDVectorMap.h:105
edm::IDVectorMap::container_iterator
C::const_iterator container_iterator
Definition: IDVectorMap.h:11
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:56
edm::IDVectorMap::id_end
id_iterator id_end() const
Definition: IDVectorMap.h:194
edm::IDVectorMap::id_iterator::operator--
id_iterator & operator--()
Definition: IDVectorMap.h:177
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
edm::IDVectorMap::match_iterator::match_iterator
match_iterator(const M &ma, const map_iterator &e, const map_iterator &m, const container_iterator &c)
Definition: IDVectorMap.h:107
edm::IDVectorMap::end
match_iterator< M > end(const M &m) const
Definition: IDVectorMap.h:153
edm::IDVectorMap::id_iterator::operator--
id_iterator operator--(int)
Definition: IDVectorMap.h:181
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
edm::IDVectorMap::match_iterator::operator*
const value_type & operator*() const
Definition: IDVectorMap.h:140
edm::IDVectorMap::IDVectorMap
IDVectorMap()
Definition: IDVectorMap.h:73
edm::IDVectorMap::const_iterator::iterator_category
map_iterator::iterator_category iterator_category
Definition: IDVectorMap.h:18
edm::IDVectorMap::id_iterator::operator==
bool operator==(const id_iterator &ci) const
Definition: IDVectorMap.h:186