ATLAS Offline Software
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 
47  pointer operator->() {return &m_vals;}
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 
104 std::ostream& operator << (std::ostream& os, const CombinationsIterator& iter);
105 
106 
107 #endif
108 
CombinationsIterator::m_k
std::size_t m_k
Definition: CombinationsIterator.h:96
CombinationsIterator::operator<<
friend std::ostream & operator<<(std::ostream &, const CombinationsIterator &)
Definition: CombinationsIterator.cxx:3
CombinationsIterator::m_end
bool m_end
Definition: CombinationsIterator.h:101
HypoJetDefs.h
CombinationsIterator::iterator_category
std::forward_iterator_tag iterator_category
Definition: CombinationsIterator.h:29
Trk::indices
std::pair< long int, long int > indices
Definition: AlSymMatBase.h:24
CombinationsIterator::operator++
CombinationsIterator & operator++()
Definition: CombinationsIterator.h:50
CombinationsGenerator.h
CombinationsGenerator
Definition: CombinationsGenerator.h:24
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
CombinationsIterator::pointer
HypoJetVector * pointer
Definition: CombinationsIterator.h:33
CombinationsIterator::operator++
CombinationsIterator operator++(int)
Definition: CombinationsIterator.h:66
operator<<
std::ostream & operator<<(std::ostream &os, const CombinationsIterator &iter)
Definition: CombinationsIterator.cxx:3
CombinationsIterator::difference_type
std::ptrdiff_t difference_type
Definition: CombinationsIterator.h:30
CombinationsIterator::endIter
CombinationsIterator endIter() const
Definition: CombinationsIterator.cxx:39
CombinationsIterator::operator==
friend bool operator==(const CombinationsIterator &a, const CombinationsIterator &b)
Definition: CombinationsIterator.h:77
CombinationsIterator::m_vals
HypoJetVector m_vals
Definition: CombinationsIterator.h:99
CombinationsIterator::operator->
pointer operator->()
Definition: CombinationsIterator.h:47
Amg::transform
Amg::Vector3D transform(Amg::Vector3D &v, Amg::Transform3D &tr)
Transform a point from a Trasformation3D.
Definition: GeoPrimitivesHelpers.h:156
HypoJetVector
std::vector< pHypoJet > HypoJetVector
Definition: HypoJetDefs.h:27
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
CombinationsIterator::reference
HypoJetVector & reference
Definition: CombinationsIterator.h:32
CombinationsIterator::CombinationsIterator
CombinationsIterator()
Definition: CombinationsIterator.h:41
CombinationsIterator::m_gen
CombinationsGenerator m_gen
Definition: CombinationsIterator.h:95
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
CombinationsIterator::operator*
reference operator*()
Definition: CombinationsIterator.h:44
CombinationsIterator
Definition: CombinationsIterator.h:26
CombinationsIterator::value_type
HypoJetVector value_type
Definition: CombinationsIterator.h:31
a
TList * a
Definition: liststreamerinfos.cxx:10
CombinationsIterator::m_input_vals
HypoJetVector m_input_vals
Definition: CombinationsIterator.h:98
CombinationsIterator::operator!=
friend bool operator!=(const CombinationsIterator &a, const CombinationsIterator &b)
Definition: CombinationsIterator.h:88
checkFileSG.ind
list ind
Definition: checkFileSG.py:118
fitman.k
k
Definition: fitman.py:528