ATLAS Offline Software
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-2022 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 #ifndef NAVIGATIONTOKEN_H
8 #define NAVIGATIONTOKEN_H
9 //
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 
24 #include "Navigation/INavigable.h"
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 
46 template <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  >
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;
78  using pointer = value_type*;
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),
162  m_navCondition(0),
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),
172  m_navCondition(0),
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
199  virtual ~NavigationToken()
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
234  CHILDPAR getParameter( const_child_ptr data ) const;
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!!!!!!!!!!
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 
NavigationToken::tokenParameter
CHILDPAR tokenParameter
Definition: NavigationToken.h:65
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
INavigationToken.h
INavigable.h
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
NavigationToken::firstMappedObject
tokenConstIterator firstMappedObject()
Definition: NavigationToken.h:225
NavigationToken::reset
void reset()
Definition: NavigationToken.h:239
NavigationToken::getParameter
CHILDPAR getParameter(const_iterator &anIter) const
NavigationTokenIteratorTag
Definition: NavigationToken.h:43
NavigationToken::operator=
NavigationToken & operator=(const NavigationToken &anotherToken)
Definition: NavigationToken.h:275
NavigationToken::NavigationTokenIterator::difference_type
std::ptrdiff_t difference_type
Definition: NavigationToken.h:77
NavigationToken::NavigationToken
NavigationToken(INavigationSelector< CHILD, CHILDPAR > *thisSelector, INavigationCondition *thisCondition, size_t size_hint=0, const HASH &hf=HASH())
Definition: NavigationToken.h:188
NavigationToken::tokenConstIterator
tokenStore::const_iterator tokenConstIterator
Definition: NavigationToken.h:64
NavigationToken::const_child_ptr
const CHILD * const_child_ptr
Definition: NavigationToken.h:54
NavigationToken::NavigationTokenIterator::m_store
const tokenStore * m_store
Definition: NavigationToken.h:149
reference
Definition: hcg.cxx:437
NavigationToken.icc
NavigationToken::NavigationToken
NavigationToken(INavigationSelector< CHILD, CHILDPAR > *thisSelector, size_t size_hint=10, const HASH &hf=HASH())
Definition: NavigationToken.h:168
NavigationToken::NavigationTokenIterator::operator!=
bool operator!=(NavigationTokenIterator &anOtherToken)
Definition: NavigationToken.h:115
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:189
NavigationToken::NavigationTokenIterator::operator++
NavigationTokenIterator operator++()
Definition: NavigationToken.h:100
NavigationToken::NavigationTokenIterator::m_actual
tokenConstIterator m_actual
Definition: NavigationToken.h:150
NavigationToken::NavigationTokenIterator::NavigationTokenIterator
NavigationTokenIterator(const tokenStore &aStore)
Definition: NavigationToken.h:84
NavigationTokenHash
Definition: NavigationTokenHash.h:47
NavigationToken::NavigationTokenIterator::NavigationTokenIterator
NavigationTokenIterator()
Definition: NavigationToken.h:83
ArenaPoolSTLAllocator.h
STL-style allocator wrapper for ArenaPoolAllocator.
NavigationToken::tokenIterator
tokenStore::iterator tokenIterator
Definition: NavigationToken.h:63
NavigationToken::dumpStore
void dumpStore()
NavigationTokenHash.h
Allow overriding the default hash function used within NavigationToken.
NavigationDefaults.h
NavigationToken::trySetObject
virtual bool trySetObject(const INavigable *theObject, const std::any &theWeight)
NavigationToken::~NavigationToken
virtual ~NavigationToken()
Definition: NavigationToken.h:199
NavigationToken::NavigationTokenIterator::operator==
bool operator==(const NavigationTokenIterator &anOtherIterator) const
Definition: NavigationToken.h:110
NavigationToken::NavigationTokenIterator::tokenParameter
CHILDPAR tokenParameter
Definition: NavigationToken.h:81
NavigationToken::NavigationTokenIterator::end
NavigationTokenIterator end()
Definition: NavigationToken.h:94
NavigationToken::NavigationTokenIterator::operator[]
const_child_ptr operator[](unsigned int theIndex) const
Definition: NavigationToken.h:131
test_pyathena.parent
parent
Definition: test_pyathena.py:15
NavigationToken::NavigationTokenIterator::pointer
value_type * pointer
Definition: NavigationToken.h:78
INavigationToken
Definition: INavigationToken.h:24
NavigationToken::NavigationTokenIterator::operator!=
bool operator!=(const NavigationTokenIterator &anOtherIterator) const
Definition: NavigationToken.h:119
NavigationToken::NavigationTokenIterator::operator==
bool operator==(NavigationTokenIterator &anOtherToken)
Definition: NavigationToken.h:106
INavigable
Definition: INavigable.h:18
NavigationToken::NavigationTokenIterator::operator++
NavigationTokenIterator operator++(int)
Definition: NavigationToken.h:101
NavigationToken::trySetObject
virtual bool trySetObject(const INavigable *theObject)
NavigationToken::setObject
void setObject(const_child_ptr data)
Definition: NavigationToken.h:252
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
NavigationToken::m_data
tokenStore m_data
Definition: NavigationToken.h:305
HASH
@ HASH
Definition: RegSelEnums.h:51
INavigationSelector.h
NavigationToken::begin
const_iterator begin() const
Definition: NavigationToken.h:229
NavigationToken::NavigationTokenIterator::operator--
NavigationTokenIterator operator--()
Definition: NavigationToken.h:103
NavigationToken::setObject
void setObject(const CHILD &, const CHILDPAR &)
Definition: NavigationToken.h:258
NavigationToken::m_navSelector
INavigationSelector< CHILD, CHILDPAR > * m_navSelector
Definition: NavigationToken.h:309
NavigationToken::m_navCondition
INavigationCondition * m_navCondition
Definition: NavigationToken.h:308
NavigationToken::NavigationTokenIterator::operator*
const_child_ptr operator*() const
Definition: NavigationToken.h:123
NavigationToken::pushQuery
virtual bool pushQuery(const INavigable &parent, const INavigable &child)
NavigationToken
Definition: NavigationToken.h:50
NavigationDefaults::DefaultWeight
Definition: NavigationDefaults.h:52
NavigationToken::NavigationToken
NavigationToken(INavigationCondition *thisCondition, size_t size_hint=0, const HASH &hf=HASH())
Definition: NavigationToken.h:178
INavigationCondition
Definition: INavigationCondition.h:17
NavigationToken::end
const_iterator end() const
Definition: NavigationToken.h:230
NavigationToken::contains
bool contains(const_child_ptr data)
Definition: NavigationToken.h:242
NavigationToken::NavigationTokenIterator::operator->
const_child_ptr operator->() const
Definition: NavigationToken.h:127
NavigationToken::m_lastReject
const std::type_info * m_lastReject
Definition: NavigationToken.h:312
NavigationToken::NavigationTokenIterator
Definition: NavigationToken.h:72
NavigationToken::setObject
void setObject(const CHILD &)
Definition: NavigationToken.h:257
NavigationToken::lastMappedObject
tokenConstIterator lastMappedObject()
Definition: NavigationToken.h:226
INavigationCondition.h
SG::ArenaPoolSTLAllocator
STL-style allocator wrapper for ArenaPoolAllocator.
Definition: ArenaPoolSTLAllocator.h:106
NavigationToken::clear
void clear()
NavigationToken::const_iterator
NavigationTokenIterator const_iterator
Definition: NavigationToken.h:153
NavigationToken::objectMap
const tokenStore & objectMap()
Definition: NavigationToken.h:215
NavigationToken::NavigationTokenIterator::begin
NavigationTokenIterator begin()
Definition: NavigationToken.h:88
NavigationToken::operator=
NavigationToken & operator=(NavigationToken &&anotherToken)
Definition: NavigationToken.h:288
NavigationToken::NavigationToken
NavigationToken(size_t size_hint=10)
Definition: NavigationToken.h:160
NavigationToken::tokenStore
std::unordered_map< const_child_ptr, CHILDPAR, HASH, std::equal_to< const_child_ptr >, SG::ArenaPoolSTLAllocator< std::pair< const const_child_ptr, CHILDPAR > > > tokenStore
Definition: NavigationToken.h:62
NavigationToken::getParameter
CHILDPAR getParameter(const_child_ptr data) const
NavigationToken::NavigationTokenIterator::operator--
NavigationTokenIterator operator--(int)
Definition: NavigationToken.h:104
NavigationToken::NavigationTokenIterator::getParameter
const tokenParameter & getParameter() const
Definition: NavigationToken.h:142
value_type
Definition: EDM_MasterSearch.h:11
NavigationToken::setObject
void setObject(const_child_ptr data, CHILDPAR weight)
NavigationToken::size
unsigned int size()
Definition: NavigationToken.h:231
INavigationSelector
Definition: INavigationSelector.h:16