CMS 3D CMS Logo

Selection.h
Go to the documentation of this file.
1 #ifndef CommonTools_Utils_Selection_h
2 #define CommonTools_Utils_Selection_h
3 #include <vector>
4 
5 template <typename C, typename Selector, typename StoreContainer = std::vector<const typename C::value_type*> >
6 class Selection {
7 public:
8  typedef typename C::value_type value_type;
9  typedef typename C::size_type size_type;
11  typedef const value_type& const_reference;
12  Selection(const C& c, const Selector& sel) : select_(sel) {
13  for (typename C::const_iterator i = c.begin(); i != c.end(); ++i) {
14  if (select_(*i))
15  selected_.push_back(&*i);
16  }
17  }
19  public:
21  typedef value_type* pointer;
23  typedef std::ptrdiff_t difference_type;
24  typedef typename StoreContainer::const_iterator::iterator_category iterator_category;
25  const_iterator(const typename StoreContainer::const_iterator& it) : i(it) {}
26  const_iterator(const const_iterator& it) : i(it.i) {}
29  i = it.i;
30  return *this;
31  }
33  ++i;
34  return *this;
35  }
37  const_iterator ci = *this;
38  ++i;
39  return ci;
40  }
42  --i;
43  return *this;
44  }
46  const_iterator ci = *this;
47  --i;
48  return ci;
49  }
50  difference_type operator-(const const_iterator& o) const { return i - o.i; }
53  bool operator<(const const_iterator& o) const { return i < o.i; }
54  bool operator==(const const_iterator& ci) const { return i == ci.i; }
55  bool operator!=(const const_iterator& ci) const { return i != ci.i; }
56  const value_type& operator*() const { return **i; }
57  const value_type* operator->() const { return &(operator*()); }
59  i += d;
60  return *this;
61  }
63  i -= d;
64  return *this;
65  }
66 
67  private:
68  typename StoreContainer::const_iterator i;
69  };
70  const_iterator begin() const { return const_iterator(selected_.begin()); }
71  const_iterator end() const { return const_iterator(selected_.end()); }
72  size_type size() const { return selected_.size(); }
73  bool empty() const { return selected_.empty(); }
75 
76 private:
78  StoreContainer selected_;
79 };
80 
81 #endif
Selection::const_iterator::operator--
const_iterator & operator--()
Definition: Selection.h:41
Selection::const_iterator::operator-
difference_type operator-(const const_iterator &o) const
Definition: Selection.h:50
Selector
Functor that operates on <T>
Definition: Selector.h:22
mps_fire.i
i
Definition: mps_fire.py:428
Selection::const_iterator::value_type
Selection< C, Selector, StoreContainer >::value_type value_type
Definition: Selection.h:20
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
Selection::const_iterator::operator-=
const_iterator & operator-=(difference_type d)
Definition: Selection.h:62
Selection::size
size_type size() const
Definition: Selection.h:72
Selection::const_iterator::const_iterator
const_iterator(const const_iterator &it)
Definition: Selection.h:26
Selection::const_iterator::reference
value_type & reference
Definition: Selection.h:22
Selection::const_iterator::operator<
bool operator<(const const_iterator &o) const
Definition: Selection.h:53
Selection::const_iterator::operator=
const_iterator & operator=(const const_iterator &it)
Definition: Selection.h:28
Selection::operator[]
const_reference operator[](size_type i)
Definition: Selection.h:74
EcalTangentSkim_cfg.o
o
Definition: EcalTangentSkim_cfg.py:42
Selection
Definition: Selection.h:6
Selection::const_iterator::operator+
const_iterator operator+(difference_type n) const
Definition: Selection.h:51
Selection::end
const_iterator end() const
Definition: Selection.h:71
trigger::size_type
uint16_t size_type
Definition: TriggerTypeDefs.h:18
Selection::const_iterator::pointer
value_type * pointer
Definition: Selection.h:21
Selection::empty
bool empty() const
Definition: Selection.h:73
Selection::begin
const_iterator begin() const
Definition: Selection.h:70
Selection::const_iterator::operator->
const value_type * operator->() const
Definition: Selection.h:57
Selection::selected_
StoreContainer selected_
Definition: Selection.h:78
Selection::const_iterator::operator!=
bool operator!=(const const_iterator &ci) const
Definition: Selection.h:55
Selection::const_iterator::iterator_category
StoreContainer::const_iterator::iterator_category iterator_category
Definition: Selection.h:24
Selection::const_iterator::const_iterator
const_iterator(const typename StoreContainer::const_iterator &it)
Definition: Selection.h:25
Selection::const_iterator::operator++
const_iterator & operator++()
Definition: Selection.h:32
Selection::const_iterator::operator==
bool operator==(const const_iterator &ci) const
Definition: Selection.h:54
reco::JetExtendedAssociation::value_type
Container::value_type value_type
Definition: JetExtendedAssociation.h:30
Selection::const_iterator::const_iterator
const_iterator()
Definition: Selection.h:27
Selection::const_iterator::operator+=
const_iterator & operator+=(difference_type d)
Definition: Selection.h:58
Selection::const_iterator::operator--
const_iterator operator--(int)
Definition: Selection.h:45
Selection::select_
Selector select_
Definition: Selection.h:77
Selection::const_iterator
Definition: Selection.h:18
gen::C
C
Definition: PomwigHadronizer.cc:78
Selection::reference
value_type & reference
Definition: Selection.h:10
Selection::Selection
Selection(const C &c, const Selector &sel)
Definition: Selection.h:12
Selection::size_type
C::size_type size_type
Definition: Selection.h:9
Selection::const_reference
const typedef value_type & const_reference
Definition: Selection.h:11
Selection::const_iterator::operator-
const_iterator operator-(difference_type n) const
Definition: Selection.h:52
Selection::const_iterator::difference_type
std::ptrdiff_t difference_type
Definition: Selection.h:23
Selection::value_type
C::value_type value_type
Definition: Selection.h:8
ztail.d
d
Definition: ztail.py:151
EgammaValidation_Wenu_cff.sel
sel
Definition: EgammaValidation_Wenu_cff.py:33
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:46
Selection::const_iterator::i
StoreContainer::const_iterator i
Definition: Selection.h:68
Selection::const_iterator::operator++
const_iterator operator++(int)
Definition: Selection.h:36
Selection::const_iterator::operator*
const value_type & operator*() const
Definition: Selection.h:56