ATLAS Offline Software
Navigable.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef NAVIGATION_NAVIGABLE_H
6 #define NAVIGATION_NAVIGABLE_H
7 // Authors: P. Calafiura, P. Loch, S. Rajagopalan //
29 // Comments: Implements navigation query with honoring or forwarding the //
30 // client request for a given object type. The actual //
31 // implementation is in Navigable.icc //
32 // //
33 // Template Parameters: //
34 // //
35 // CONT - container type for given constituent object type. Needs //
36 // to provide a value_type declaration and the usual //
37 // container access methods. Defaulted to dummy //
38 // NavTerminator for terminal nodes in relational tree. //
39 // RPAR - parameter describing the relation between constituent //
40 // and composite object. Needs to provide +,-,+=,-=,= //
41 // operators to manage parameter evolution in the //
42 // relational tree. Defaulted to dummy parameter //
43 // DefaultWeight for trees without parameters. //
44 // COLL - allows to specify internal storage container. Needs to //
45 // provide typical container management like find(), //
46 // insert(), iterators... Defaulted to container type //
47 // DefaultChildColl<CONT,RPAR>. //
48 // There should be no need to provide an explicite internal //
49 // container! Be careful when using this parameter! //
50 // //
51 // Created: 07-Oct-03 Calafiura/Loch/Rajagopalan //
52 // Update: 18-Dec-03 Loch //
53 // - implement ElementLink -> change of template //
54 // parameters necessary! //
55 // //
57 
58 // package includes for the template
59 #include "Navigation/INavigable.h"
62 
63 // navigation token management
66 
67 // services etc.
69 
70 // STL includes
71 #include <vector>
72 #include <map>
73 #include <utility> // pair
74 
75 #include <any>
76 
77 // i/o
78 #include <iostream>
79 
81 // Base class for implementation of Navigation token handling //
83 
84 template <
85  typename CONT=
87  typename RPAR=
89  typename COLL=typename
91  >
92 class Navigable : virtual public INavigable
93 {
94  public:
95 
97  // Type definitions //
99 
100  // internal collection management helper types
101  typedef COLL constituent_coll;
103  typedef typename constituent_coll::const_iterator constituent_const_iter;
104 
105  // typedefs added to make the template parameter types accessible from outside the template
106  // needed for transient/persistent conversion
107  // Marcin.Nowak@cern.ch 06.2006
108 
110  typedef CONT container_type;
112  typedef RPAR parameter_type;
115 
116 
118  // //
119  // At this point we try to avoid an additional template parameter //
120  // specifying the object type in addition to the object container type. //
121  // We expect DataVector or any other object container to provide this //
122  // object type. Note that this is NOT DataVector<T>::value_type, which is //
123  // actually T*. We introduced another typedef //
124  // DataVector<T>::base_value_type, which is T. //
125  // //
126  // Within the Navigable the following types are available: //
127  // //
128  // constituent_type object type //
129  // constituent_ptr_ref object pointer reference //
130  // (constituent_type*&) //
131  // constituent_const_ptr_ref object const pointer reference //
132  // constituent_ptr object pointer (constituent_type*) //
133  // external_index_type object container index type //
134  // object_iter internal object container iterator //
135  // //
136  // Note that the internal object container is used to store pointers to //
137  // the constituents of a composite object, while the (external) object //
138  // container just holds a collection of objects. //
139  // //
140  // Template Parameters: Defaults: //
141  // //
142  // CONT TerminalNode external object collection //
143  // RPAR DefaultWeight relational parameter type //
144  // COLL DefaultChildColl internal object collection //
145  // //
147 
148  // some typedefs from the object container
149  typedef typename CONT::base_value_type constituent_type;
151  typedef typename CONT::const_reference constituent_const_ptr_ref;
152  typedef typename CONT::value_type constituent_ptr;
153 
154  // object container index type
157 
158  // external iterator access
160 
162  // Constructors and Destructor //
164 
166 
167  virtual ~Navigable() = default;
168 
170  // NavigationToken handling (INavigable interface implementation) //
172 
173  // no relational parameters
174  virtual void fillToken(INavigationToken& navToken) const;
175 
176  // forwarding of parameters included
177  virtual void fillToken(INavigationToken& navToken,
178  const std::any& parentParameter) const;
179 
181  // Add data objects or elements //
183 
184  // If sizeHint is non-zero, it should give the expected final size
185  // of the container. This may be used to optimize memory allocations.
186 
187  // add element to the Navigable: use element pointer (linear search!)
188  // template<typename OBJT>
189  void putElement(const CONT* objectContainer,
190  const constituent_type* constituentObject,
191  const RPAR& objectParameter=RPAR(),
192  size_t sizeHint = 0);
193  // add element to the Navigable: use element index (direct access!)
194  void putElement(const CONT* objectContainer,
195  const external_index_type& theIndex,
196  const RPAR& objectParameter=RPAR(),
197  size_t sizeHint = 0);
198  // insert element without checking if already in store: use element pointer
199  void insertElement(const CONT* objectContainer,
200  const constituent_type* constituentObject,
201  const RPAR& objectParameter=RPAR(),
202  size_t sizeHint = 0);
203  // insert element without checking if already in store: use index
204  void insertElement(const CONT* objectContainer,
205  const external_index_type& theIndex,
206  const RPAR& objectParameter=RPAR(),
207  size_t sizeHint = 0);
208  // insert element without checking if already in store: use index
209  // store is supplied explicitly.
210  void insertElement(const CONT* objectContainer,
211  const external_index_type& theIndex,
212  IProxyDict* sg,
213  const RPAR& objectParameter=RPAR(),
214  size_t sizeHint = 0);
215  // insert element without checking if already in store: use ElementLink.
217  const RPAR& objectParameter=RPAR(),
218  size_t sizeHint = 0);
219 
221  // Data manipulation //
223 
224  // re-weight (overwrite old weight)
225  void reweight(const constituent_type* constituentObject,
226  const RPAR& objectParameter=RPAR());
227  void reweight(const CONT* objectContainer,
228  const external_index_type& theIndex,
229  const RPAR& objectParameter=RPAR());
230  void reweight(object_iter& objectIter,
231  const RPAR& objectParameter=RPAR());
232 
233 
234  // remove object from the Navigable
235  bool remove(const constituent_type* aConstituent);
236  bool remove(const CONT* objectContainer, const external_index_type& theIndex);
237  bool removeAll() { m_constituents.clear(); return this->size() == 0 ; }
238 
242  bool replace(const CONT* newObjectContainer);
243 
244  // check if constituent is already there
245  bool contains(const constituent_type* aConstituent) const;
246  bool contains(const CONT* objectContainer,
247  const external_index_type& theIndex) const;
248 
250  // Access to Constituents //
252 
253  // public object access: iterators, sizes etc.
254  virtual object_iter begin() const;
255  virtual object_iter end() const;
256  virtual unsigned int size() const;
257 
258  // public link access
259  // virtual link_iter& beginLinks() const;
260  // virtual link_iter& endLinks() const;
261 
262  // public container access: relational parameter retrieval
263  RPAR getParameter(const constituent_type* aConstituent) const;
264  RPAR getParameter(const CONT* objectContainer,
265  const external_index_type& theIndex) const;
266  RPAR getParameter(object_iter& theIter) const;
267 
268  // RPAR getParameter(const ElementLink<CONT>* theLink) const;
269 
270  // public container access: retrieve ElementLink for given object pointer
271  const CONT* getContainer(const constituent_type* aConstituent) const;
272  const CONT* getContainer(constituent_const_iter anIter) const;
273  const CONT* getContainer(object_iter objectIter) const;
274 
275  // get index of child in original container
276  bool getIndex(const constituent_type* aConstituent,
277  external_index_type& theIndex) const;
279  external_index_type& theIndex) const;
280  bool getIndex(object_iter objectIter,
281  external_index_type& theIndex) const;
282 
284  // Protected data access //
286 
287  protected:
288 
289  // get collection of constituents
292 
293  // get pointers to collection
295  { return &m_constituents; }
297  { return &m_constituents; }
298 
299  // get pointer to constituent given its collection iterator
301  iter) const;
303  iter) const;
304 
305  // get the parameter associated with the child, if any
306  virtual RPAR getConstituentPar(constituent_iter iter) const;
307  virtual RPAR getConstituentPar(constituent_const_iter iter) const;
308 
309  // dump store
310  void dumpStore() const;
311 
313  // Internal query handling //
315 
316  private:
317 
319  // to be checked: constituent type is T* -> NavigationToken expects T!
321 
322  // honoring the query: filling token if type matches w/o parameter
323  virtual void apply(NavigationToken<constituent_type>& navToken) const;
324 
325  // honoring the query: filling token if type matches w/ parameter
327  const RPAR& aParameter) const;
328 
329  // forwarding the query to constituents: w/o parameter
330  virtual void toKidsAfterAccept(INavigationToken& navToken) const;
331  virtual void toKidsAfterReject(INavigationToken& navToken) const;
332 
333  // forwarding the query to constituents: w/ parameter
334  virtual void toKidsAfterAccept(INavigationToken& navToken,
335  const std::any& aParameter) const;
336  virtual void toKidsAfterReject(INavigationToken& navToken,
337  const std::any& aParameter) const;
338 
340  // Internal data storage //
342 
343  private:
344 
346 
347 };
348 
350 // Termination handling //
352 
354 
356 // Navigable implementation //
358 
359 #include "Navigation/Navigable.icc"
360 
369 #endif
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
INavigationToken.h
Navigable::m_constituents
constituent_coll m_constituents
Definition: Navigable.h:345
Navigable::apply
virtual void apply(NavigationToken< constituent_type, RPAR > &navToken, const RPAR &aParameter) const
Navigable::insertElement
void insertElement(const ElementLink< CONT > &el, const RPAR &objectParameter=RPAR(), size_t sizeHint=0)
INavigable.h
Navigable::toKidsAfterAccept
virtual void toKidsAfterAccept(INavigationToken &navToken) const
Navigable::toKidsAfterReject
virtual void toKidsAfterReject(INavigationToken &navToken) const
Navigable::constituent_const_ptr_ref
CONT::const_reference constituent_const_ptr_ref
Definition: Navigable.h:151
Navigable::getConstituentPtr
virtual const constituent_type * getConstituentPtr(constituent_iter iter) const
Navigable::getIndex
bool getIndex(const constituent_type *aConstituent, external_index_type &theIndex) const
Navigable::insertElement
void insertElement(const CONT *objectContainer, const external_index_type &theIndex, IProxyDict *sg, const RPAR &objectParameter=RPAR(), size_t sizeHint=0)
Navigable::external_index_type
SG::GenerateIndexingPolicy< CONT >::type::index_type external_index_type
Definition: Navigable.h:156
Navigable::putElement
void putElement(const CONT *objectContainer, const constituent_type *constituentObject, const RPAR &objectParameter=RPAR(), size_t sizeHint=0)
Navigable::removeAll
bool removeAll()
Definition: Navigable.h:237
NavigationDefaults::DefaultChildColl::type
std::vector< value_type > type
Definition: NavigationDefaults.h:73
Navigable::constituent_coll
COLL constituent_coll
Definition: Navigable.h:101
NavigationToken.h
Navigable::insertElement
void insertElement(const CONT *objectContainer, const constituent_type *constituentObject, const RPAR &objectParameter=RPAR(), size_t sizeHint=0)
Navigable::getPtrToConstituents
const constituent_coll * getPtrToConstituents() const
Definition: Navigable.h:294
Navigable::begin
virtual object_iter begin() const
Navigable::Navigable
Navigable()
Navigable::getConstituentPar
virtual RPAR getConstituentPar(constituent_iter iter) const
Navigable::fillToken
virtual void fillToken(INavigationToken &navToken, const std::any &parentParameter) const
Navigable::getIndex
bool getIndex(constituent_const_iter anIter, external_index_type &theIndex) const
IProxyDict
A proxy dictionary.
Definition: AthenaKernel/AthenaKernel/IProxyDict.h:47
Navigable::contains
bool contains(const constituent_type *aConstituent) const
Navigable::reweight
void reweight(const CONT *objectContainer, const external_index_type &theIndex, const RPAR &objectParameter=RPAR())
Navigable::apply
virtual void apply(NavigationToken< constituent_type > &navToken) const
Navigable::end
virtual object_iter end() const
NavigableIterator
Definition: NavigableIterator.h:24
Navigable::putElement
void putElement(const CONT *objectContainer, const external_index_type &theIndex, const RPAR &objectParameter=RPAR(), size_t sizeHint=0)
Navigable::toKidsAfterAccept
virtual void toKidsAfterAccept(INavigationToken &navToken, const std::any &aParameter) const
Navigable::getConstituents
const constituent_coll & getConstituents() const
Definition: Navigable.h:290
NavigationDefaults.h
GenerateIndexingPolicy.h
Navigable::parameter_type
RPAR parameter_type
\ brief Relational parameter type
Definition: Navigable.h:112
Navigable::constituent_type
CONT::base_value_type constituent_type
Definition: Navigable.h:149
Navigable::constituent_const_iter
constituent_coll::const_iterator constituent_const_iter
Definition: Navigable.h:103
Navigable::remove
bool remove(const constituent_type *aConstituent)
Navigable::getContainer
const CONT * getContainer(object_iter objectIter) const
Navigable::constituent_ptr_ref
CONT::reference constituent_ptr_ref
Definition: Navigable.h:150
Navigable::getParameter
RPAR getParameter(object_iter &theIter) const
Navigable::getPtrToConstituents
constituent_coll * getPtrToConstituents()
Definition: Navigable.h:296
Navigable::getParameter
RPAR getParameter(const CONT *objectContainer, const external_index_type &theIndex) const
plotIsoValidation.el
el
Definition: plotIsoValidation.py:197
Navigable::navhelper_t
NavigationDefaults::DefaultChildColl< container_type, parameter_type > navhelper_t
Collection manager type.
Definition: Navigable.h:114
INavigationToken
Definition: INavigationToken.h:24
Navigable::getIndex
bool getIndex(object_iter objectIter, external_index_type &theIndex) const
Navigable::getConstituentPtr
virtual const constituent_type * getConstituentPtr(constituent_const_iter iter) const
INavigable
Definition: INavigable.h:18
Navigable::reweight
void reweight(const constituent_type *constituentObject, const RPAR &objectParameter=RPAR())
Navigable::getContainer
const CONT * getContainer(constituent_const_iter anIter) const
Navigable::~Navigable
virtual ~Navigable()=default
Navigable::reweight
void reweight(object_iter &objectIter, const RPAR &objectParameter=RPAR())
NavigableTerminalNode.h
Navigable::getContainer
const CONT * getContainer(const constituent_type *aConstituent) const
NavigationToken
Definition: NavigationToken.h:50
NavigationDefaults::DefaultWeight
Definition: NavigationDefaults.h:52
Navigable::object_iter
NavigableIterator< CONT, RPAR, COLL > object_iter
Definition: Navigable.h:159
Navigable::toKidsAfterReject
virtual void toKidsAfterReject(INavigationToken &navToken, const std::any &aParameter) const
Navigable::insertElement
void insertElement(const CONT *objectContainer, const external_index_type &theIndex, const RPAR &objectParameter=RPAR(), size_t sizeHint=0)
Navigable
Navigable template generalization to handle navigation.
Definition: Navigable.h:93
Navigable::replace
bool replace(const CONT *newObjectContainer)
replace old object container with a new container assumes that all objects have been or will be inser...
Navigable::getConstituentPar
virtual RPAR getConstituentPar(constituent_const_iter iter) const
Navigable::container_type
CONT container_type
Object container type.
Definition: Navigable.h:110
Navigable::getParameter
RPAR getParameter(const constituent_type *aConstituent) const
Navigable::dumpStore
void dumpStore() const
NavigationDefaults::DefaultChildColl
Definition: NavigationDefaults.h:69
Navigable::remove
bool remove(const CONT *objectContainer, const external_index_type &theIndex)
Navigable::size
virtual unsigned int size() const
NavigableIterator.h
Navigable::fillToken
virtual void fillToken(INavigationToken &navToken) const
dq_make_web_display.reference
reference
Definition: dq_make_web_display.py:44
NavigationDefaults::TerminalNode
DefaultContainer TerminalNode
Definition: NavigationDefaults.h:42
Navigable::constituent_iter
constituent_coll::iterator constituent_iter
Definition: Navigable.h:102
SG::GenerateIndexingPolicy
Definition: GenerateIndexingPolicy.h:30
Navigable::getConstituents
constituent_coll & getConstituents()
Definition: Navigable.h:291
Navigable.icc
Navigable::contains
bool contains(const CONT *objectContainer, const external_index_type &theIndex) const
Navigable::constituent_ptr
CONT::value_type constituent_ptr
Definition: Navigable.h:152