ATLAS Offline Software
SelectObject.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef EVENTCONTAINERS_SELECTOBJECT_H
6 #define EVENTCONTAINERS_SELECTOBJECT_H
7 
8 // This is a Selection class that provides iterator over selected
9 // objects contained in the IdentifiableContainer. The Identifiable in the
10 // Container is presumed to be a DigitCollection (DC). DC
11 // should define OBJECT class in its scope, as well as const_iterator
12 // class for accessing the OBJECTs.
13 //
14 // The concrete class should implement the select methods, applied to
15 // both the collection and the objects.
16 //
17 // The const_iterator classes, both in DC and DCC, should follow the
18 // standard STL iterator syntax.
19 
20 template < class DCC, typename OBJECT = typename DCC::IDENTIFIABLE::DIGIT >
22 {
23 public:
24 
25  typedef typename DCC::IDENTIFIABLE DC;
26 // typedef typename DC::OBJECT OBJECT;
27 // typedef OBJECT OBJECT;
29  typedef typename DCC::const_iterator DC_const_iterator;
30  typedef typename DC::const_iterator Object_const_iterator;
31 
33  {
34  public:
37  { m_dcc = it.m_dcc;
38  m_digit_it = it.m_digit_it;
39  m_dc_it = it.m_dc_it;
40  m_dc = it.m_dc;
41  return *this;
42  }
43 
44  const_iterator& operator ++ () // pre increment
45  {
46  ++m_digit_it;
47  advanceObject();
48  return *this;
49  }
50 
51  void advanceObject(){
52 
53  for(; m_digit_it!=m_dc->end();++m_digit_it) {
54  // check if this digit is accepted.
55  if(m_select->select(*m_digit_it)){
56  return ;
57  }
58  }
59  // reached end of a collection,
60  ++m_dc_it;
62  return ;
63  }
64 
66  for( ; m_dc_it != m_dcc->end();++m_dc_it)
67  {
68  m_dc = *m_dc_it ;
69  if(m_select->select(m_dc)){
70  for(m_digit_it = m_dc->begin() ;
71  m_digit_it!=m_dc->end();++m_digit_it) {
72  // check if this digit is accepted.
73  if(m_select->select(*m_digit_it))
74  return ;
75  }
76  }
77  }
78  // reach here only when mc_dc_it == end
79  return ;
80 
81  }
82 
83  const_iterator operator ++ ( int ) // post increment
84  { const_iterator tmp = *this;
85  ++*this;
86  return tmp;
87  }
88 
89  const OBJECT* operator * ()
90  { return *m_digit_it; }
91 
92  // comparison operator.
93  // if m_dc_it == end, don't compare digit_it
94  bool operator != ( const const_iterator it ) const
95  { if( it.m_dcc != m_dcc || it.m_dc_it != m_dc_it )
96  return true;
97  if( m_dcc && m_dc_it != m_dcc->end()) {
98  // check digit_it only if it is not end
99  if(it.m_digit_it != m_digit_it) return true;
100  return false;
101  }
102  return false;
103  }
104  bool operator == ( const const_iterator it ) const
105  { return it.m_dcc == m_dcc
106  && it.m_dc_it == m_dc_it
107  && ((it.m_digit_it == m_digit_it) ||
108  (m_dcc && (m_dc_it==m_dcc->end())));
109  // if both dc_it == end, then don't check digit_it
110  }
111 
112  // protected:
113  // friend class MyType;
114  friend class SelectObject<DCC,OBJECT> ;
115 
116  const_iterator( MyType* s, const DCC* dcc, DC_const_iterator& dc_it )
117  : m_dcc(dcc), m_dc_it(dc_it),m_select(s)
118  {
119  if(m_dcc && m_dc_it!=m_dcc->end())
120  {
122  }
123 
124  }
125 
126  const DCC* m_dcc;
128  const DC* m_dc; // cache DC
131  };
132 
133  // friend class const_iterator;
134  // Constructor initializes the DataLinkVector
135  SelectObject(const DCC* dcc) : m_dcc(dcc)
136  { }
137 
138  // return iterator on first entry
140  { DC_const_iterator dc_it = m_dcc->begin();
141  return const_iterator ( this, m_dcc, dc_it );
142  }
143 
145  { DC_const_iterator dc_it = m_dcc->end();
146  return const_iterator ( this, m_dcc, dc_it );
147  }
148 
149  // apply selection to the collection
150  virtual bool select(const DC* dc) = 0 ;
151  // apply selection to the object
152  virtual bool select(const OBJECT* dc) = 0 ;
153 
154 private:
156  { }
157 
158  // pointer to the container it is processing.
159  const DCC* m_dcc;
160 
161 };
162 
163 #endif
SelectObject::const_iterator::const_iterator
const_iterator()
Definition: SelectObject.h:35
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
SelectObject::const_iterator::operator!=
bool operator!=(const const_iterator it) const
Definition: SelectObject.h:94
SelectObject::const_iterator::operator=
const_iterator & operator=(const const_iterator &it)
Definition: SelectObject.h:36
SelectObject::DC
DCC::IDENTIFIABLE DC
Definition: SelectObject.h:25
SelectObject::const_iterator::operator*
const OBJECT * operator*()
Definition: SelectObject.h:89
SelectObject::const_iterator::operator==
bool operator==(const const_iterator it) const
Definition: SelectObject.h:104
skel.it
it
Definition: skel.GENtoEVGEN.py:396
SelectObject::select
virtual bool select(const OBJECT *dc)=0
SelectObject::MyType
SelectObject< DCC, OBJECT > MyType
Definition: SelectObject.h:28
SelectObject::const_iterator::m_dc_it
DC_const_iterator m_dc_it
Definition: SelectObject.h:127
SelectObject::const_iterator::m_dcc
const DCC * m_dcc
Definition: SelectObject.h:126
SelectObject::SelectObject
SelectObject()
Definition: SelectObject.h:155
SelectObject::SelectObject
SelectObject(const DCC *dcc)
Definition: SelectObject.h:135
SelectObject::const_iterator::m_digit_it
Object_const_iterator m_digit_it
Definition: SelectObject.h:129
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
SelectObject::Object_const_iterator
DC::const_iterator Object_const_iterator
Definition: SelectObject.h:30
SelectObject::const_iterator::advanceCollection
void advanceCollection()
Definition: SelectObject.h:65
SelectObject::const_iterator
Definition: SelectObject.h:33
SelectObject::end
const_iterator end()
Definition: SelectObject.h:144
SelectObject::const_iterator::operator++
const_iterator & operator++()
Definition: SelectObject.h:44
SelectObject::begin
const_iterator begin()
Definition: SelectObject.h:139
SelectObject
Definition: SelectObject.h:22
SelectObject::const_iterator::advanceObject
void advanceObject()
Definition: SelectObject.h:51
SelectObject::const_iterator::const_iterator
const_iterator(MyType *s, const DCC *dcc, DC_const_iterator &dc_it)
Definition: SelectObject.h:116
SelectObject::DC_const_iterator
DCC::const_iterator DC_const_iterator
Definition: SelectObject.h:29
SelectObject::const_iterator::m_select
MyType * m_select
Definition: SelectObject.h:130
SelectObject::const_iterator::m_dc
const DC * m_dc
Definition: SelectObject.h:128
SelectObject::select
virtual bool select(const DC *dc)=0
SelectObject::m_dcc
const DCC * m_dcc
Definition: SelectObject.h:159