ATLAS Offline Software
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
HLT::ComboIterator Class Reference

Iterator used to loop over multi-particle combinations. More...

#include <ComboIterator.h>

Inheritance diagram for HLT::ComboIterator:
Collaboration diagram for HLT::ComboIterator:

Public Member Functions

 ComboIterator (const std::vector< TEVec > &tes, const TrigNavStructure *nav)
 Constructor; gets a vector of TE vectors and a pointer to Navigation as arguments. More...
 
bool rewind ()
 Rewind method, resetting the iterator to the first element. More...
 
TEVecoperator* ()
 Unary * operator, used to recover the current combination. More...
 
bool isValid () const
 Validity check for the iterator. More...
 
TEVeccombination ()
 Accessor method for the current combination. More...
 
ComboIteratoroperator++ (int)
 Post increment operator. More...
 
ComboIteratoroperator++ ()
 Pre increment operator. More...
 

Protected Member Functions

virtual bool overlaps (const TriggerElement *t1, const TriggerElement *t2) const
 Method used to test overlaps between two TEs. More...
 
bool overlaps (const TriggerElement *t1, const TEVec &teVec, int idx=-1) const
 Method used to test overlaps between a TE and a vector of TEs. More...
 
bool incrementByOne (int pos, bool &ok)
 Private increment method. More...
 
bool increment (int pos)
 Private increment method. More...
 
bool reset (int pos)
 Private reset method. More...
 
void invalidate ()
 Method used to invalidate the current combination. More...
 
void print () const
 Debug dump to std::cout. More...
 

Protected Attributes

TEVec m_comb
 Current combination of TEs. More...
 
std::vector< int > m_idx
 Vector of indexes keeping track of the loop over combinations. More...
 
std::vector< TEVecm_tes
 Vector of vectors of TEs to be combined. More...
 
bool m_valid
 Validity status variable. More...
 
const TrigNavStructurem_nav
 Pointer to the navigation service. More...
 

Detailed Description

Iterator used to loop over multi-particle combinations.

Author
Nicolas Berger Nicol.nosp@m.as.B.nosp@m.erger.nosp@m.@cer.nosp@m.n.ch - CERN

This iterator class is used by HLT algorithms to iterate over multi-particle combinations. Given a set of TEs, passed in the constructor, the iterator can be used to move over all the possible combinations of TEs. These combinations are built taking one TE from each of the vector of TEs passed in the constructor. So, as an example, to build all possible couples of TEs of the same type, the starting point will be a vector containing twice the same vector of TEs.

Definition at line 74 of file ComboIterator.h.

Constructor & Destructor Documentation

◆ ComboIterator()

HLT::ComboIterator::ComboIterator ( const std::vector< TEVec > &  tes,
const TrigNavStructure nav 
)

Constructor; gets a vector of TE vectors and a pointer to Navigation as arguments.

Parameters
tesvector of subvectors of TEs, one for each input type. Each subvector is the list of all TEs of a given type in the event. The same type may appear multiple times in the case of identical input particle types.
navpointer to the navigation service.

Definition at line 15 of file ComboIterator.cxx.

16  : m_valid(true),
17  m_nav(nav)
18 
19 {
20  for (unsigned int i = 0; i < tes.size(); i++)
21  m_tes.push_back(tes[i]);
22 
23  rewind();
24 }

Member Function Documentation

◆ combination()

TEVec& HLT::ComboIterator::combination ( )
inlinevirtual

Accessor method for the current combination.

Implements HLT::ComboIteratorBase.

Definition at line 98 of file ComboIterator.h.

98 { return m_comb; }

◆ increment()

bool HLT::ComboIterator::increment ( int  pos)
protected

Private increment method.

Definition at line 69 of file ComboIterator.cxx.

70 {
71  if (!isValid()) return false;
72 
73  bool ok = false;
74  while (!ok) if (!incrementByOne(pos, ok)) return false;
75 
76  return ok;
77 }

◆ incrementByOne()

bool HLT::ComboIterator::incrementByOne ( int  pos,
bool &  ok 
)
protected

Private increment method.

Definition at line 80 of file ComboIterator.cxx.

81 {
82  // cout << "increment1 " << pos << endl;
83 
84  if (pos >= (int)m_comb.size() || pos < 0) return false;
85 
86  ok = false;
87 
88  // If we're at the end of the vector for this element, ...
89  if (m_idx[pos] == (int)m_tes[pos].size() - 1) {
90 
91  // ... if it's the first (innermost-loop) one, we're done...
92  if (pos == 0) return false;
93 
94  // ... otherwise increment the previous element by one...
95  if (!increment(pos - 1)) return false;
96 
97  // ... reset this one...
98  if (!reset(pos)) return false;
99 
100  // ... and increment it (from reset to valid).
101  if (!increment(pos)) return false;
102  }
103  else {
104  // else it's just the normal case,
105 
106  m_idx [pos]++;
107  m_comb[pos] = m_tes[pos][m_idx[pos]];
108  }
109 
110  ok = !overlaps(m_comb[pos], m_comb, pos);
111  // cout << "after increment (pos=" << pos << ", ok=" << ok << ")" << endl; print();
112 
113  return true;
114 }

◆ invalidate()

void HLT::ComboIterator::invalidate ( )
protected

Method used to invalidate the current combination.

Definition at line 189 of file ComboIterator.cxx.

190 {
191  // cout << "-------------------------------" << endl;
192  // cout << "Invalidate!" << endl;
193  // cout << "-------------------------------" << endl;
194  m_valid = false;
195  m_comb.clear();
196 }

◆ isValid()

bool HLT::ComboIterator::isValid ( ) const
inlinevirtual

Validity check for the iterator.

Returns
result of the validity check; returns false if iterator is at end, true otherwise.

Implements HLT::ComboIteratorBase.

Definition at line 95 of file ComboIterator.h.

95 { return m_valid; }

◆ operator*()

TEVec& HLT::ComboIterator::operator* ( )
inlinevirtual

Unary * operator, used to recover the current combination.

Implements HLT::ComboIteratorBase.

Definition at line 90 of file ComboIterator.h.

90 { return combination(); }

◆ operator++() [1/2]

HLT::ComboIterator & HLT::ComboIterator::operator++ ( )
virtual

Pre increment operator.

Implements HLT::ComboIteratorBase.

Definition at line 58 of file ComboIterator.cxx.

59 {
60  if (!increment((int)m_comb.size() - 1)) invalidate();
61  // cout << "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv" << endl;
62  // print();
63  // cout << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" << endl;
64 
65  return *this;
66 }

◆ operator++() [2/2]

ComboIterator& HLT::ComboIterator::operator++ ( int  )
inlinevirtual

Post increment operator.

Implements HLT::ComboIteratorBase.

Definition at line 101 of file ComboIterator.h.

101 { return operator++(); }

◆ overlaps() [1/2]

bool HLT::ComboIterator::overlaps ( const TriggerElement t1,
const TEVec teVec,
int  idx = -1 
) const
protected

Method used to test overlaps between a TE and a vector of TEs.

Returns
result of the overlap test; returns true if the TE corresponds to the same RoI as one of the TEs in the vector, false otherwise.
Parameters
t1TE to check.
teVecTE vector to check.
idxoptional integer parameter, limiting the check over the 0..idx-1 range of the vector.

Definition at line 146 of file ComboIterator.cxx.

148 {
149  if (idx < 0) idx = teVec.size();
150 
151  for (int i = 0; i < idx; i++) {
152  if (!teVec[i]) return false;
153  if (overlaps(te1, teVec[i])) return true;
154  }
155 
156  return false;
157 }

◆ overlaps() [2/2]

bool HLT::ComboIterator::overlaps ( const TriggerElement t1,
const TriggerElement t2 
) const
protectedvirtual

Method used to test overlaps between two TEs.

Returns
result of the overlap test; returns true if the two TEs correspond to the same RoI, false otherwise.
Parameters
t1first TE to check.
t2second TE to check.

Reimplemented in HLT::ComboIteratorTopo.

Definition at line 160 of file ComboIterator.cxx.

162 {
163  if (te1 == te2) return true;
164  if (m_nav && m_nav->haveCommonRoI(te1, te2)) return true;
165 
166  return false;
167 }

◆ print()

void HLT::ComboIterator::print ( ) const
protected

Debug dump to std::cout.

Definition at line 170 of file ComboIterator.cxx.

171 {
172  cout << endl;
173  cout << "TEs:" << endl;
174  cout << "{" << endl;
175  for (unsigned int i = 0; i < m_tes.size(); i++) {
176  cout << " [ ";
177  for (unsigned int j = 0; j < m_tes[i].size(); j++) cout << m_tes[i][j] << " ";
178  cout << "]" << endl;
179  }
180  cout << "}" << endl << endl << "Comb = [ ";
181  for (unsigned int i = 0; i < m_comb.size(); i++) cout << m_comb[i] << " ";
182  cout << "]" << endl << "Idxs = [ ";
183  for (unsigned int i = 0; i < m_idx.size(); i++) cout << m_idx[i] << " ";
184  cout << "]" << endl;
185  cout << (isValid() ? "Valid" : "Invalid") << endl << endl;
186 }

◆ reset()

bool HLT::ComboIterator::reset ( int  pos)
protected

Private reset method.

Definition at line 117 of file ComboIterator.cxx.

118 {
119  // cout << "Reset : " << pos << endl;
120 
121  if (pos >= (int)m_comb.size() || pos < 0) return false;
122 
123  m_comb[pos] = 0;
124  m_idx [pos] = -1;
125 
126 
127  // Find the previous element of the same type (if any), and get its index
128  // in the vector of TEs of this type...
129 
130  for (unsigned int j = pos; j > 0; j--) {
131 
132  if (!m_comb[j - 1]) continue;
133 
134  // Find the TE of the same type with the highest index
135  if (m_comb[j - 1]->getId() == m_tes[pos][0]->getId()) {
136  m_idx[pos] = m_idx[j - 1];
137  break;
138  }
139  }
140 
141  // cout << "reset to index = " << m_idx[pos] << endl;
142  return 1;
143 }

◆ rewind()

bool HLT::ComboIterator::rewind ( )
virtual

Rewind method, resetting the iterator to the first element.

Implements HLT::ComboIteratorBase.

Definition at line 27 of file ComboIterator.cxx.

28 {
29  m_comb.clear();
30  m_idx.clear();
31 
32  // cout << "Construct" << endl;
33 
34  for (unsigned int i = 0; i < m_tes.size(); i++) {
35 
36  if (m_tes[i].size() == 0) {
37  invalidate();
38  return 0;
39  }
40 
41  m_comb.push_back(0);
42  m_idx.push_back(-1);
43 
44  if (!reset(i) || !increment(i)) {
45  invalidate();
46  return 0;
47  }
48  }
49 
50  // cout << "After setup: " << endl;
51  // cout << "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv" << endl;
52  // print();
53  // cout << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" << endl;
54  return isValid();
55 }

Member Data Documentation

◆ m_comb

TEVec HLT::ComboIterator::m_comb
protected

Current combination of TEs.

Definition at line 140 of file ComboIterator.h.

◆ m_idx

std::vector<int> HLT::ComboIterator::m_idx
protected

Vector of indexes keeping track of the loop over combinations.

Definition at line 143 of file ComboIterator.h.

◆ m_nav

const TrigNavStructure* HLT::ComboIterator::m_nav
protected

Pointer to the navigation service.

Definition at line 152 of file ComboIterator.h.

◆ m_tes

std::vector<TEVec> HLT::ComboIterator::m_tes
protected

Vector of vectors of TEs to be combined.

Definition at line 146 of file ComboIterator.h.

◆ m_valid

bool HLT::ComboIterator::m_valid
protected

Validity status variable.

Definition at line 149 of file ComboIterator.h.


The documentation for this class was generated from the following files:
HLT::ComboIterator::operator++
ComboIterator & operator++()
Pre increment operator.
Definition: ComboIterator.cxx:58
HLT::ComboIterator::invalidate
void invalidate()
Method used to invalidate the current combination.
Definition: ComboIterator.cxx:189
HLT::ComboIterator::m_nav
const TrigNavStructure * m_nav
Pointer to the navigation service.
Definition: ComboIterator.h:152
HLT::ComboIterator::combination
TEVec & combination()
Accessor method for the current combination.
Definition: ComboIterator.h:98
HLT::ComboIterator::m_comb
TEVec m_comb
Current combination of TEs.
Definition: ComboIterator.h:140
HLT::ComboIterator::incrementByOne
bool incrementByOne(int pos, bool &ok)
Private increment method.
Definition: ComboIterator.cxx:80
HLT::ComboIterator::reset
bool reset(int pos)
Private reset method.
Definition: ComboIterator.cxx:117
HLT::TrigNavStructure::haveCommonRoI
static bool haveCommonRoI(const TriggerElement *te1, const TriggerElement *te2)
does this 2 share RoI
Definition: TrigNavStructure.cxx:416
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
HLT::ComboIterator::increment
bool increment(int pos)
Private increment method.
Definition: ComboIterator.cxx:69
lumiFormat.i
int i
Definition: lumiFormat.py:85
HLT::ComboIterator::overlaps
virtual bool overlaps(const TriggerElement *t1, const TriggerElement *t2) const
Method used to test overlaps between two TEs.
Definition: ComboIterator.cxx:160
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
HLT::ComboIterator::m_tes
std::vector< TEVec > m_tes
Vector of vectors of TEs to be combined.
Definition: ComboIterator.h:146
HLT::ComboIterator::m_valid
bool m_valid
Validity status variable.
Definition: ComboIterator.h:149
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
HLT::ComboIterator::m_idx
std::vector< int > m_idx
Vector of indexes keeping track of the loop over combinations.
Definition: ComboIterator.h:143
HLT::ComboIterator::rewind
bool rewind()
Rewind method, resetting the iterator to the first element.
Definition: ComboIterator.cxx:27
HLT::ComboIterator::isValid
bool isValid() const
Validity check for the iterator.
Definition: ComboIterator.h:95