ATLAS Offline Software
ComboIterator.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include <iostream>
6 
7 #include <algorithm>
8 
11 
13 using namespace std;
14 
15 HLT::ComboIterator::ComboIterator(const std::vector<TEVec>& tes, const HLT::TrigNavStructure* nav)
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 }
25 
26 
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 }
56 
57 
59 {
60  if (!increment((int)m_comb.size() - 1)) invalidate();
61  // cout << "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv" << endl;
62  // print();
63  // cout << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" << endl;
64 
65  return *this;
66 }
67 
68 
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 }
78 
79 
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 }
115 
116 
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 }
144 
145 
147  const TEVec& teVec, int idx) const
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 }
158 
159 
161  const TriggerElement* te2) const
162 {
163  if (te1 == te2) return true;
164  if (m_nav && m_nav->haveCommonRoI(te1, te2)) return true;
165 
166  return false;
167 }
168 
169 
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 }
187 
188 
190 {
191  // cout << "-------------------------------" << endl;
192  // cout << "Invalidate!" << endl;
193  // cout << "-------------------------------" << endl;
194  m_valid = false;
195  m_comb.clear();
196 }
197 
198 
199 HLT::ComboIteratorTopo::ComboIteratorTopo(const std::vector<TEVec>& tes, const TrigNavStructure* nav,
200  HLT::te_id_type topoSpan)
201  : ComboIterator(tes, nav),
202  m_spanId(topoSpan) {
203  rewind();
204 }
205 
206 void HLT::ComboIteratorTopo::traverseUntilSeedsTopo(const HLT::TriggerElement* start, std::set<const TriggerElement*>& topos) const {
207 
209  for ( auto successor : successors ) {
210  if ( successor->getActiveState() == true and successor->getId() == m_spanId ) {
211  topos.insert(successor);
212  }
213  }
214  if ( not topos.empty() )
215  return;
216 
217  // we need to digg deeper
219  for ( auto predecessor : predecessors ) {
220  // this next line is disabled because the predecessors of the L1Topo simulation output TE are exactly of type RoI-node (after discussion with Tomasz)
221  // if ( HLT::TrigNavStructure::isRoINode(predecessor) ) continue;
222  traverseUntilSeedsTopo(predecessor, topos);
223  if ( not topos.empty() )
224  return;
225  }
226 }
227 
229  if ( HLT::ComboIterator::overlaps(t1, t2) == true ) return true;
230 
231  // if above returned true it means TEs are from the same RoI, combiation is uninteresting
232  // if false it may still be uninteresting because it is joined by topo TE
233 
234  std::set<const TriggerElement*> te1span;
235  traverseUntilSeedsTopo(t1, te1span);
236  if ( te1span.empty() ) // empty set can not be from the same combination
237  return true;
238 
239  std::set<const TriggerElement*> te2span;
240  traverseUntilSeedsTopo(t2, te2span);
241  if ( te2span.empty() )
242  return true;
243  /*
244  for ( auto te : te1span )
245  cout << " t1 span TES " << te << " " << te->getId() << endl;
246  cout << endl;
247  for ( auto te : te2span )
248  cout << " t2 span TES " << te << " " << te->getId() << endl;
249  */
250  std::vector<const TriggerElement*> intersection;
251  std::set_intersection(te1span.begin(), te1span.end(), te2span.begin(), te2span.end(),
252  std::back_inserter(intersection));
253 
254  if ( not intersection.empty() )
255  return false; // there is genuine topo join, the pair is interesting
256  return true;
257 
258 }
259 
HLT::ComboIterator::operator++
ComboIterator & operator++()
Pre increment operator.
Definition: ComboIterator.cxx:58
HLT::ComboIterator::print
void print() const
Debug dump to std::cout.
Definition: ComboIterator.cxx:170
HLT::ComboIterator::invalidate
void invalidate()
Method used to invalidate the current combination.
Definition: ComboIterator.cxx:189
TrigNavStructure.h
mergePhysValFiles.start
start
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:14
ALFA_EventTPCnv_Dict::t1
std::vector< ALFA_RawDataCollection_p1 > t1
Definition: ALFA_EventTPCnvDict.h:43
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::ComboIteratorTopo::ComboIteratorTopo
ComboIteratorTopo(const std::vector< TEVec > &tes, const TrigNavStructure *nav, HLT::te_id_type topoSpan)
Definition: ComboIterator.cxx:199
isValid
bool isValid(const T &p)
Av: we implement here an ATLAS-sepcific convention: all particles which are 99xxxxx are fine.
Definition: AtlasPID.h:620
HLT::TrigNavStructure
Definition: TrigNavStructure.h:40
intersection
std::vector< std::string > intersection(std::vector< std::string > &v1, std::vector< std::string > &v2)
Definition: compareFlatTrees.cxx:25
ComboIterator.h
HLT::TrigNavStructure::getDirectSuccessors
static const std::vector< TriggerElement * > & getDirectSuccessors(const TriggerElement *te)
returns list of direct predecessors (nodes I seed)
Definition: TrigNavStructure.cxx:124
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
HLT::ComboIterator::increment
bool increment(int pos)
Private increment method.
Definition: ComboIterator.cxx:69
HLT::TrigNavStructure::getDirectPredecessors
static const std::vector< TriggerElement * > & getDirectPredecessors(const TriggerElement *te)
returns list of direct predecessors (nodes seeding me)
Definition: TrigNavStructure.cxx:120
lumiFormat.i
int i
Definition: lumiFormat.py:85
HLT::ComboIteratorTopo::traverseUntilSeedsTopo
void traverseUntilSeedsTopo(const TriggerElement *start, std::set< const TriggerElement * > &topos) const
Definition: ComboIterator.cxx:206
HLT::TriggerElement
TriggerElement is the basic ingreedient of the interface between HLT algorithms and the navigation It...
Definition: TrigNavStructure/TrigNavStructure/TriggerElement.h:27
TriggerElement.h
HLT::ComboIteratorTopo::overlaps
virtual bool overlaps(const TriggerElement *t1, const TriggerElement *t2) const
Method used to test overlaps between two TEs.
Definition: ComboIterator.cxx:228
HLT::ComboIterator
Iterator used to loop over multi-particle combinations.
Definition: ComboIterator.h:74
HLT::TEVec
std::vector< HLT::TriggerElement * > TEVec
Definition: ComboIterator.h:13
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
ALFA_EventTPCnv_Dict::t2
std::vector< ALFA_RawDataContainer_p1 > t2
Definition: ALFA_EventTPCnvDict.h:44
HLT::ComboIterator::m_tes
std::vector< TEVec > m_tes
Vector of vectors of TEs to be combined.
Definition: ComboIterator.h:146
HLT::ComboIterator::ComboIterator
ComboIterator(const std::vector< TEVec > &tes, const TrigNavStructure *nav)
Constructor; gets a vector of TE vectors and a pointer to Navigation as arguments.
Definition: ComboIterator.cxx:15
CxxUtils::reset
constexpr std::enable_if_t< is_bitmask_v< E >, E & > reset(E &lhs, E rhs)
Convenience function to clear bits in a class enum bitmask.
Definition: bitmask.h:251
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
set_intersection
Set * set_intersection(Set *set1, Set *set2)
Perform an intersection of two sets.
HLT::ComboIterator::rewind
bool rewind()
Rewind method, resetting the iterator to the first element.
Definition: ComboIterator.cxx:27
HLT::te_id_type
uint32_t te_id_type
Definition: Trigger/TrigEvent/TrigNavStructure/TrigNavStructure/Types.h:11