ATLAS Offline Software
Loading...
Searching...
No Matches
CombinationsIterator.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef TRIG_HLTJETHYPO_COMBINATIONSITERATOR_H
6#define TRIG_HLTJETHYPO_COMBINATIONSITERATOR_H
7
10
11#include <vector>
12#include <iterator>
13
14/*
15 * CombinatonsIterator is a forward iterator. It iterates over
16 * combinations (n choose k) gnerated by a CombinationsGenerator instance.
17 * of a HypoJetVector.
18 *
19 * Dereferencing the iterator returns a HypoJetVector corresponding
20 * to the current combination.
21 *
22 * CombinationsIterator can generates the
23 * end of iteration CombinationsIterator
24 */
25
27
28 public:
29 using iterator_category = std::forward_iterator_tag;
30 using difference_type = std::ptrdiff_t;
34
35
36 friend std::ostream& operator << (std::ostream&, const CombinationsIterator&);
37 CombinationsIterator(std::size_t k,
38 const HypoJetVector& input_vals,
39 bool end=false);
40
42
43
45
46
48
49 // pre-increment
51 m_end = m_gen.bump();
52 auto indices = m_gen.get();
53
54 // overwrite m_vals according to the combinations indicies
55 std::transform(indices.cbegin(),
56 indices.cend(),
57 m_vals.begin(),
58 [iv = this->m_input_vals](const auto& ind) {
59 return iv.at(ind);
60 });
61
62 return *this;
63 }
64
65 // post-increment
67 CombinationsIterator tmp = *this;
68 ++(*this);
69 return tmp;
70 }
71
72
73 // create an end of iteration marker from a CombinationsIterator
75
76 // enable an equality test with an end iterator
77 friend bool operator==(const CombinationsIterator& a,
78 const CombinationsIterator& b) {
79 return a.m_end == b.m_end and
80 a.m_k == b.m_k and
81 a.m_input_vals == b.m_input_vals;
82
83
84 }
85
86
87 // enable an inequality test with an end iterator
88 friend bool operator!=(const CombinationsIterator& a,
89 const CombinationsIterator& b) {
90 return !(a==b);
91 }
92
93
94 private:
96 std::size_t m_k{0};
97
100
101 bool m_end{false};
102};
103
104std::ostream& operator << (std::ostream& os, const CombinationsIterator& iter);
105
106
107#endif
108
std::ostream & operator<<(std::ostream &os, const CombinationsIterator &iter)
std::vector< pHypoJet > HypoJetVector
Definition HypoJetDefs.h:27
static Double_t a
generate all possible combinations of objects
friend std::ostream & operator<<(std::ostream &, const CombinationsIterator &)
CombinationsIterator operator++(int)
std::forward_iterator_tag iterator_category
CombinationsIterator(std::size_t k, const HypoJetVector &input_vals, bool end=false)
friend bool operator==(const CombinationsIterator &a, const CombinationsIterator &b)
friend bool operator!=(const CombinationsIterator &a, const CombinationsIterator &b)
CombinationsGenerator m_gen
CombinationsIterator endIter() const
CombinationsIterator & operator++()