ATLAS Offline Software
Loading...
Searching...
No Matches
AnalysisUtils::Combination< COLL > Class Template Reference

combination More...

#include <AnalysisCombination.h>

Collaboration diagram for AnalysisUtils::Combination< COLL >:

Public Member Functions

 Combination (COLL *coll, const unsigned int nElement)
 constructor
 ~Combination ()
 destructor
void reset ()
 reset internal indices
template<class OUT>
bool get (OUT &comb)
 get a combination.
template<class CALLER, class OUT, class CRITERIA>
bool goodOnes (CALLER *caller, OUT &comb, CRITERIA criteria)
 get a combination which passes a selection criteria
template<class OUT>
bool get (OUT &comb, OUT &remain)
 get a combination and the remaining elements
template<class CALLER, class OUT, class CRITERIA>
bool goodOnes (CALLER *caller, OUT &comb, OUT &remain, CRITERIA criteria)
 get a combination and the remaining elements.

Private Member Functions

bool setNewIndex (int iElement)
 set new index recursively

Private Attributes

COLL * m_coll
 collection
const unsigned int m_nElement
 number of elements to be selected
std::vector< unsigned int > m_index
 indices of elements
bool m_first
 flag to check if first

Detailed Description

template<class COLL>
class AnalysisUtils::Combination< COLL >

combination

Definition at line 20 of file AnalysisCombination.h.

Constructor & Destructor Documentation

◆ Combination()

template<class COLL>
Combination::Combination ( COLL * coll,
const unsigned int nElement )
inline

constructor

Parameters
coll[in] collection
nElement[in] number of element to be selected

Definition at line 153 of file AnalysisCombination.h.

155 {
156 // init indices
157 // internal indices are [0,1,2...] at beginning
158 for (unsigned int i=0; i<nElement; ++i)
159 m_index.push_back(i);
160 }
std::vector< unsigned int > m_index
indices of elements
bool m_first
flag to check if first
const unsigned int m_nElement
number of elements to be selected

◆ ~Combination()

template<class COLL>
AnalysisUtils::Combination< COLL >::~Combination ( )
inline

destructor

Definition at line 32 of file AnalysisCombination.h.

32{}

Member Function Documentation

◆ get() [1/2]

template<class COLL>
template<class OUT>
bool AnalysisUtils::Combination< COLL >::get ( OUT & comb)
inline

get a combination.

internal indices are incremented

Parameters
comb[out] combination of elements
Returns
true:success false:end of selection

Definition at line 43 of file AnalysisCombination.h.

44 {
45 // init returned combination
46 comb.clear();
47
48 if (m_first) {
49 if (m_index[m_nElement-1] >= m_coll->size()) return false;
50 m_first = false;
51 } else {
52 // increment indices
53 if (!setNewIndex(m_nElement-1)) return false;
54 }
55
56 // assign to returned combination
57 for (unsigned int i=0; i<m_nElement; ++i)
58 comb.push_back((*m_coll)[m_index[i]]);
59
60 return true;
61 }
bool setNewIndex(int iElement)
set new index recursively

◆ get() [2/2]

template<class COLL>
template<class OUT>
bool AnalysisUtils::Combination< COLL >::get ( OUT & comb,
OUT & remain )
inline

get a combination and the remaining elements

Definition at line 85 of file AnalysisCombination.h.

86 {
87 // init returned vector
88 remain.clear();
89
90 bool ret = get(comb);
91 if (!ret) return false;
92
93 // assigin to remain
94 unsigned int sIndex = 0;
97 for (; ; ++it)
98 {
99 unsigned int eIndex;
100 if (it!=itE)
101 eIndex = *it;
102 else
103 eIndex = m_coll->size();
104
105 for (unsigned int i=sIndex; i<eIndex; ++i)
106 remain.push_back((*m_coll)[i]);
107 sIndex = eIndex+1;
108
109 if (it == itE) break;
110 }
111
112 return true;
113 }
bool get(OUT &comb)
get a combination.

◆ goodOnes() [1/2]

template<class COLL>
template<class CALLER, class OUT, class CRITERIA>
bool AnalysisUtils::Combination< COLL >::goodOnes ( CALLER * caller,
OUT & comb,
CRITERIA criteria )
inline

get a combination which passes a selection criteria

Parameters
caller
comb[out] combination of elements
criteria[in] a function pointer of selection criteria
Returns
true:success false:end of selection

Definition at line 70 of file AnalysisCombination.h.

71 {
72 bool ret = get(comb);
73 if (!ret) return false;
74
75 // check if this passes the criteria
76 if (criteria(caller, comb)) return true;
77
78 // if not, look for next combination
79 return goodOnes(caller, comb, criteria);
80 }
bool goodOnes(CALLER *caller, OUT &comb, CRITERIA criteria)
get a combination which passes a selection criteria

◆ goodOnes() [2/2]

template<class COLL>
template<class CALLER, class OUT, class CRITERIA>
bool AnalysisUtils::Combination< COLL >::goodOnes ( CALLER * caller,
OUT & comb,
OUT & remain,
CRITERIA criteria )
inline

get a combination and the remaining elements.

the combination passes a selection criteria

Definition at line 119 of file AnalysisCombination.h.

120 {
121 bool ret = get(comb, remain);
122 if (!ret) return false;
123
124 // check if this passes the criteria
125 if (criteria(caller, comb)) return true;
126
127 // if not, look for next combination
129 }

◆ reset()

template<class COLL>
void Combination::reset ( )
inline

reset internal indices

Definition at line 162 of file AnalysisCombination.h.

163 {
164 // reset indices
165 m_index.clear();
166 for (unsigned int i=0; i<m_nElement; ++i)
167 m_index.push_back(i);
168
169 // set first flag
170 m_first = true;
171 }

◆ setNewIndex()

template<class COLL>
bool Combination::setNewIndex ( int iElement)
inlineprivate

set new index recursively

Definition at line 174 of file AnalysisCombination.h.

175 {
176 if (iElement < 0) return false;
177
178 if (iElement+1 == static_cast<int>(m_nElement))
179 {
180 if ((m_index[iElement]+1) < m_coll->size())
181 {
182 ++(m_index[iElement]);
183 return true;
184 }
185 }
186 else
187 {
188 if ((m_index[iElement]+1) < m_index[iElement+1])
189 {
190 ++(m_index[iElement]);
191 return true;
192 }
193 }
194
195 if (setNewIndex (iElement-1))
196 {
198 return true;
199 }
200
201 return false;
202 }

Member Data Documentation

◆ m_coll

template<class COLL>
COLL* AnalysisUtils::Combination< COLL >::m_coll
private

collection

Definition at line 134 of file AnalysisCombination.h.

◆ m_first

template<class COLL>
bool AnalysisUtils::Combination< COLL >::m_first
private

flag to check if first

Definition at line 143 of file AnalysisCombination.h.

◆ m_index

template<class COLL>
std::vector<unsigned int> AnalysisUtils::Combination< COLL >::m_index
private

indices of elements

Definition at line 140 of file AnalysisCombination.h.

◆ m_nElement

template<class COLL>
const unsigned int AnalysisUtils::Combination< COLL >::m_nElement
private

number of elements to be selected

Definition at line 137 of file AnalysisCombination.h.


The documentation for this class was generated from the following file: