ATLAS Offline Software
Loading...
Searching...
No Matches
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
20template < class DCC, typename OBJECT = typename DCC::IDENTIFIABLE::DIGIT >
22{
23public:
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;
48 return *this;
49 }
50
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 {
121 advanceCollection();
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
139 const_iterator begin()
140 { DC_const_iterator dc_it = m_dcc->begin();
141 return const_iterator ( this, m_dcc, dc_it );
142 }
143
144 const_iterator end()
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
154private:
156 { }
157
158 // pointer to the container it is processing.
159 const DCC* m_dcc;
160
161};
162
163#endif
bool operator==(const const_iterator it) const
const_iterator(MyType *s, const DCC *dcc, DC_const_iterator &dc_it)
const_iterator & operator++()
Object_const_iterator m_digit_it
bool operator!=(const const_iterator it) const
const_iterator & operator=(const const_iterator &it)
virtual bool select(const DC *dc)=0
const_iterator begin()
SelectObject< DCC, OBJECT > MyType
const_iterator end()
DCC::IDENTIFIABLE DC
DCC::const_iterator DC_const_iterator
virtual bool select(const OBJECT *dc)=0
SelectObject(const DCC *dcc)
DC::const_iterator Object_const_iterator