ATLAS Offline Software
TileTT_Selector.icc
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 "TileRawUtils/TileRoI_Map.h"
6 
7 // Implementation of const_iterator
8 
9 // constructor
10 
11 template <class CONTAINER >
12 TileTT_Selector<CONTAINER>::const_iterator::const_iterator
13 (const VEC_ITPAIR* v)
14 {
15  m_vec_itpair = v;
16  m_pair_it = v->begin() ;
17  if(m_pair_it != v->end()){
18  m_obj_it = (*m_pair_it).first ;
19  m_obj_it_end = (*m_pair_it).second ;
20  }
21 
22  return;
23 }
24 
25 // constructor for end iterator
26 template <class CONTAINER >
27 TileTT_Selector<CONTAINER>::const_iterator::const_iterator
28 (const VEC_ITPAIR* v, const ITPAIR_IT& it)
29 {
30  m_vec_itpair = v;
31  m_pair_it = it ;
32 
33  return;
34 }
35 
36 template <class CONTAINER >
37 TileTT_Selector<CONTAINER>::const_iterator::const_iterator
38 ()
39 {
40  m_vec_itpair = NULL ;
41  return;
42 }
43 
44 
45 // = operator
46 template <class CONTAINER >
47 TileTT_Selector<CONTAINER>::const_iterator&
48 TileTT_Selector<CONTAINER>::const_iterator:: operator =
49  ( const TileTT_Selector<CONTAINER>::const_iterator & it )
50 {
51 
52  m_vec_itpair = it.m_vec_itpair ;
53  m_pair_it = it.m_pair_it ;
54  m_obj_it = it.m_obj_it ;
55  m_obj_it_end = it.m_obj_it_end ;
56 
57  return *this;
58 }
59 
60 
61 // ++ operator
62 template <class CONTAINER >
63 TileTT_Selector<CONTAINER>::const_iterator&
64 TileTT_Selector<CONTAINER>::const_iterator:: operator ++ ()
65 {
66  ++m_obj_it;
67  if(m_obj_it == m_obj_it_end) {
68  // end of this RoI, get next RoI
69  ++m_pair_it;
70  if(m_pair_it != m_vec_itpair->end() )
71  {
72  m_obj_it = (*m_pair_it).first;
73  m_obj_it_end = (*m_pair_it).second;
74  }
75  }
76 
77  return *this;
78 }
79 
80 
81 // ++ operator
82 template <class CONTAINER >
83 TileTT_Selector<CONTAINER>::const_iterator
84 TileTT_Selector<CONTAINER>::const_iterator:: operator ++ (int )
85 {
86  const_iterator tmp = *this;
87  ++tmp;
88  return tmp;
89 }
90 
91 
92 // != operator
93 template <class CONTAINER >
94 bool
95 TileTT_Selector<CONTAINER>::const_iterator:: operator !=
96  ( const TileTT_Selector<CONTAINER>::const_iterator & it ) const
97 {
98  // compare m_pair_it first because for end, m_pair_it is end.
99  if(it.m_pair_it == it.m_vec_itpair->end() )
100  { return m_pair_it != it.m_pair_it ;
101  } else
102  return
103  m_pair_it != it.m_pair_it ||
104  m_obj_it != it.m_obj_it ||
105  m_obj_it_end != it.m_obj_it_end ||
106  m_vec_itpair != it.m_vec_itpair ;
107 
108 }
109 
110 // == operator
111 template <class CONTAINER >
112 bool
113 TileTT_Selector<CONTAINER>::const_iterator:: operator ==
114  ( const TileTT_Selector<CONTAINER>::const_iterator & it ) const
115 {
116  // compare m_map_it first because for end, m_map_it is end.
117 
118  // if m_pair_it is end, only compare the pair iterator
119  if(m_pair_it == m_vec_itpair->end() )
120  return m_pair_it == it.m_pair_it ;
121 
122  return
123  m_pair_it == it.m_pair_it &&
124  m_obj_it == it.m_obj_it &&
125  m_obj_it_end == it.m_obj_it_end &&
126  m_vec_itpair == it.m_vec_itpair ;
127 }
128 
129 
130 // == operator
131 template <class CONTAINER >
132 const TileTT_Selector<CONTAINER>::OBJECT *
133 TileTT_Selector<CONTAINER>::const_iterator:: operator * ()
134 {
135  return *m_obj_it;
136 }
137 /*************** Implementation of TileTT_Selector<CONTAINER>
138 *
139 */
140 
141 // Constructor
142 template <class CONTAINER >
143 TileTT_Selector<CONTAINER> ::TileTT_Selector ( const TileRoI_Map* m,
144  const CONTAINER* c ):
145 m_roiMap(m),
146 m_container(c)
147 {
148 
149 }
150 
151 
152 // set methods
153 template <class CONTAINER >
154 void TileTT_Selector<CONTAINER> :: setMap(const TileRoI_Map* m) {
155  m_roiMap = m;
156 }
157 
158 
159 template <class CONTAINER >
160 void TileTT_Selector<CONTAINER>::setContainer(const CONTAINER* c) {
161  m_container = c;
162 }
163 
164 
165 template <class CONTAINER >
166 void TileTT_Selector<CONTAINER> :: setRoIs( const VEC_TT_ID& ids)
167 {
168 
169  // clean it up.
170  if(m_vecItPair.size() > 0 ) {
171  m_vecItPair.erase(m_vecItPair.begin(), m_vecItPair.end());
172  }
173 
174  TT_ID_IT it = ids.begin();
175  TT_ID_IT it_end = ids.end() ;
176 
177  // cout <<" Number of TTs "<<ids.size()<<endl;
178 
179  for(; it!=it_end; ++it){
180  //
181  const TT_ID& rId = (*it);
182  std::vector<COLL_ID> cIDs = m_roiMap->CollectionID(rId);
183  COLL_ID_IT cId_it = cIDs.begin();
184  COLL_ID_IT cId_it_end = cIDs.end();
185  // cout<< " Number of Collections for this RoI"<<cIDs.size()<<endl;
186  for(; cId_it!=cId_it_end;++cId_it){
187  const COLL_ID& cId = (*cId_it);
188  // cout<< " Collections id "<<cId.id()<<endl;
189  COLL_IT coll_it = m_container->find(cId);
190  if(coll_it!=m_container->end()){
191  // Collection exist
192  const COLLECTION* coll = (*coll_it);
193  OBJ_IT b;
194  OBJ_IT e;
195  coll->getTT(rId,b,e);
196  if(b!=e){
197  m_vecItPair.push_back(ITPAIR(b,e) ) ;
198  }
199  // else
200  // cout <<" Nothing in this Collections "<<endl;
201  }
202  }
203  }
204 
205 
206 }
207 
208 
209 template <class CONTAINER >
210  TileTT_Selector<CONTAINER>::const_iterator
211  TileTT_Selector<CONTAINER> ::begin() const
212 {
213  return const_iterator(&m_vecItPair);
214 }
215 
216 template <class CONTAINER >
217  TileTT_Selector<CONTAINER>::const_iterator
218  TileTT_Selector<CONTAINER> ::end() const
219 {
220  return const_iterator(&m_vecItPair, m_vecItPair.end() );
221 }