ATLAS Offline Software
Loading...
Searching...
No Matches
NavigationToken.h
Go to the documentation of this file.
1// This file's extension implies that it's C, but it's really -*- C++ -*-.
2
3/*
4 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
5*/
6
7#ifndef NAVIGATIONTOKEN_H
8#define NAVIGATIONTOKEN_H
10//
11// Navigation Token Template Class
12//
13// Comments: (P.Loch, January 15, 2003)
14//
15// The basic idea of the system is that each composite object can be queried
16// for constituents of one (or many) given object types. If this query can
17// be honored, pointers to the constituent objects are stored in the token,
18// together with a kinematic weight. Otherwise the query is forwarded, if
19// the constituent objects are of composite nature themselves.
20//
22
25
28
32#include <unordered_map>
33
34#include <map>
35#include <list>
36#include <iterator>
37#include <typeinfo>
38
39#include <any>
40
42 : public std::bidirectional_iterator_tag
43{
44};
45
46template <typename CHILD,
47 typename CHILDPAR=NavigationDefaults::DefaultWeight,
50{
51
52 public:
53
54 typedef const CHILD* const_child_ptr;
55 typedef std::unordered_map<const_child_ptr,
56 CHILDPAR,
57 HASH,
58 std::equal_to<const_child_ptr>,
60 std::pair<const const_child_ptr, CHILDPAR> >
61 >
63 typedef typename tokenStore::iterator tokenIterator;
64 typedef typename tokenStore::const_iterator tokenConstIterator;
65 typedef CHILDPAR tokenParameter;
66
68 // Iterator access //
70
72 {
73 public:
74
77 using difference_type = std::ptrdiff_t;
80
81 typedef CHILDPAR tokenParameter;
82
85 : m_store(&aStore)
86 , m_actual(aStore.begin()) { };
87
89 {
90 m_actual = m_store->begin();
91 return *this;
92 }
93
95 {
96 m_actual = m_store->end();
97 return *this;
98 }
99
102 { NavigationTokenIterator tmp = *this; ++m_actual; return tmp; }
105 { NavigationTokenIterator tmp = *this; --m_actual; return tmp; }
107 {
108 return m_actual == anOtherToken.m_actual;
109 }
110 bool operator==(const NavigationTokenIterator& anOtherIterator) const
111 {
112 return m_actual == anOtherIterator.m_actual;
113 }
114
116 {
117 return m_actual != anOtherToken.m_actual;
118 }
119 bool operator!=(const NavigationTokenIterator& anOtherIterator) const
120 {
121 return m_actual != anOtherIterator.m_actual;
122 }
124 {
125 return (*m_actual).first;
126 }
128 {
129 return (*m_actual).first;
130 }
131 const_child_ptr operator[](unsigned int theIndex) const
132 {
133 if ( theIndex >= m_store->size() ) return 0;
134 m_actual = m_store->begin();
135 unsigned int indexCtr = 0;
136 while ( indexCtr != theIndex )
137 {
138 ++indexCtr; ++m_actual;
139 }
140 return (*m_actual).first;
141 }
143 {
144 return (*m_actual).second;
145 }
146
147 private:
148
151 };
152
154
156 // Constructors and destructors //
158
159 // default constructor
160 NavigationToken(size_t size_hint = 10) :
161 m_data (size_hint),
163 m_navSelector(0),
164 m_lastReject(0)
165 { };
166
167 // constructor with navigation selector argument
169 size_t size_hint = 10,
170 const HASH& hf = HASH()) :
171 m_data (size_hint, hf),
173 m_navSelector(thisSelector),
174 m_lastReject(0)
175 { };
176
177 // constructor with navigation condition argument
179 size_t size_hint = 0,
180 const HASH& hf = HASH()) :
181 m_data (size_hint, hf),
182 m_navCondition(thisCondition),
183 m_navSelector(0),
184 m_lastReject(0)
185 { };
186
187 // constructor with navigation condition and selector
189 INavigationCondition* thisCondition,
190 size_t size_hint = 0,
191 const HASH& hf = HASH()) :
192 m_data (size_hint, hf),
193 m_navCondition(thisCondition),
194 m_navSelector(thisSelector),
195 m_lastReject(0)
196 { };
197
198 // destructor
200 { };
201
203 // Fill conditions //
205
206 // check if query is to be forwarded
207 virtual bool pushQuery( const INavigable& parent,
208 const INavigable& child );
209
211 // Access to object containers and objects in Token //
213
214 // return reference to object store (map)
215 const tokenStore& objectMap() { return m_data; };
216
217 // return pointer to object store
218 // tokenStore const * operator->() { return &m_data; };
219
220 // return iterators for object access (obsolete - no list anymore)
221 // tokenListIterator firstObject() { return m_list.begin(); };
222 // tokenListIterator lastObject() { return m_list.end(); };
223
224 // return iterators for object and weight access
227
228 // direct type-safe iterators
231 unsigned int size() { return m_data.size(); }
232
233 // return weight for a given object in container
235 CHILDPAR getParameter( const_iterator& anIter) const;
236
237 // clear/reset token
238 void clear();
239 void reset() { this->clear(); }
240
241 // find out if a certain object is stored in the token
242 bool contains( const_child_ptr data )
243 {
244 return ( m_data.find(data) != m_data.end() );
245 }
246
248 // Store object data //
250
251 // objects with default weight
253 {
254 this->setObject( data, CHILDPAR() );
255 }
256
257 void setObject( const CHILD& /*data*/ ) { };
258 void setObject( const CHILD& /*data*/, const CHILDPAR& /*weight*/ ) { };
259
260 // objects with variable weight FIXME!!!!!!!!!!
261 void setObject( const_child_ptr data, CHILDPAR weight );
262
263 // check if queried object is of requested type itself
264 virtual bool trySetObject( const INavigable* theObject );
265
266 virtual bool trySetObject( const INavigable* theObject,
267 const std::any& theWeight);
268
269
271 // Operations on Token object //
273
274 // copy operator
276 {
277 if ( this != &anotherToken && anotherToken.m_data != 0 )
278 {
279 m_data = anotherToken.m_data;
280 m_navCondition = anotherToken.m_navCondition;
281 m_navSelector = anotherToken.m_navSelector;
282 m_lastReject = anotherToken.m_lastReject;
283 }
284 return *this;
285 }
286
287 // move operator
289 {
290 if ( this != &anotherToken && anotherToken.m_data != 0 )
291 {
292 m_data = std::move (anotherToken.m_data);
293 m_navCondition = anotherToken.m_navCondition;
294 m_navSelector = anotherToken.m_navSelector;
295 m_lastReject = anotherToken.m_lastReject;
296 }
297 return *this;
298 }
299
300 // dump
301 void dumpStore();
302
303 private:
304
306
307 // internal pointer to associated navigation processor
310
311 // Used to cache dynamic_cast results.
312 const std::type_info* m_lastReject{};
313};
314
316
317#endif
318
STL-style allocator wrapper for ArenaPoolAllocator.
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
Allow overriding the default hash function used within NavigationToken.
@ HASH
Definition RegSelEnums.h:51
NavigationTokenIteratorTag iterator_category
NavigationTokenIterator(const tokenStore &aStore)
NavigationTokenIterator operator++(int)
const_child_ptr operator[](unsigned int theIndex) const
bool operator==(const NavigationTokenIterator &anOtherIterator) const
bool operator!=(const NavigationTokenIterator &anOtherIterator) const
bool operator!=(NavigationTokenIterator &anOtherToken)
const tokenParameter & getParameter() const
bool operator==(NavigationTokenIterator &anOtherToken)
NavigationTokenIterator operator--(int)
NavigationToken(size_t size_hint=10)
const_iterator begin() const
virtual bool pushQuery(const INavigable &parent, const INavigable &child)
tokenConstIterator firstMappedObject()
CHILDPAR getParameter(const_child_ptr data) const
CHILDPAR getParameter(const_iterator &anIter) const
tokenConstIterator lastMappedObject()
virtual bool trySetObject(const INavigable *theObject, const std::any &theWeight)
INavigationSelector< CHILD, CHILDPAR > * m_navSelector
void setObject(const CHILD &)
NavigationToken(INavigationSelector< CHILD, CHILDPAR > *thisSelector, INavigationCondition *thisCondition, size_t size_hint=0, const HASH &hf=HASH())
NavigationToken & operator=(NavigationToken &&anotherToken)
void setObject(const_child_ptr data)
NavigationTokenIterator const_iterator
const std::type_info * m_lastReject
const tokenStore & objectMap()
void setObject(const CHILD &, const CHILDPAR &)
const_iterator end() const
virtual ~NavigationToken()
CHILDPAR tokenParameter
void setObject(const_child_ptr data, CHILDPAR weight)
tokenStore::const_iterator tokenConstIterator
virtual bool trySetObject(const INavigable *theObject)
bool contains(const_child_ptr data)
INavigationCondition * m_navCondition
std::unordered_map< const_child_ptr, CHILDPAR, HASH, std::equal_to< const_child_ptr >, SG::ArenaPoolSTLAllocator< std::pair< const const_child_ptr, CHILDPAR > > > tokenStore
NavigationToken & operator=(const NavigationToken &anotherToken)
NavigationToken(INavigationSelector< CHILD, CHILDPAR > *thisSelector, size_t size_hint=10, const HASH &hf=HASH())
NavigationToken(INavigationCondition *thisCondition, size_t size_hint=0, const HASH &hf=HASH())
unsigned int size()
tokenStore::iterator tokenIterator
const CHILD * const_child_ptr
STL-style allocator wrapper for ArenaPoolAllocator.