ATLAS Offline Software
Loading...
Searching...
No Matches
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
28// 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
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
84template <
85 typename CONT=
87 typename RPAR=
89 typename COLL=typename
91 >
92class Navigable : virtual public INavigable
93{
94 public:
95
97 // Type definitions //
99
100 // internal collection management helper types
101 typedef COLL constituent_coll;
102 typedef typename constituent_coll::iterator constituent_iter;
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;
150 typedef typename CONT::reference constituent_ptr_ref;
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; }
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;
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
360
369#endif
CaloCellContainer::value_type constituent_ptr
Definition Navigable.h:152
const constituent_coll & getConstituents() const
Definition Navigable.h:290
virtual const constituent_type * getConstituentPtr(constituent_const_iter iter) const
virtual void toKidsAfterReject(INavigationToken &navToken, const std::any &aParameter) const
typename NavigationDefaults::DefaultChildColl< CaloCellContainer, double >::type constituent_coll
Definition Navigable.h:101
virtual unsigned int size() const
virtual object_iter begin() const
bool removeAll()
Definition Navigable.h:237
virtual void apply(NavigationToken< constituent_type > &navToken) const
void putElement(const CONT *objectContainer, const external_index_type &theIndex, const RPAR &objectParameter=RPAR(), size_t sizeHint=0)
const constituent_coll * getPtrToConstituents() const
Definition Navigable.h:294
bool remove(const constituent_type *aConstituent)
void putElement(const CONT *objectContainer, const constituent_type *constituentObject, const RPAR &objectParameter=RPAR(), size_t sizeHint=0)
const CONT * getContainer(object_iter objectIter) const
bool contains(const CONT *objectContainer, const external_index_type &theIndex) const
void reweight(object_iter &objectIter, const RPAR &objectParameter=RPAR())
virtual void toKidsAfterReject(INavigationToken &navToken) const
NavigableIterator< CaloCellContainer, double, typename NavigationDefaults::DefaultChildColl< CaloCellContainer, double >::type > object_iter
Definition Navigable.h:159
constituent_coll::iterator constituent_iter
Definition Navigable.h:102
RPAR getParameter(const constituent_type *aConstituent) const
bool replace(const CONT *newObjectContainer)
replace old object container with a new container assumes that all objects have been or will be inser...
bool contains(const constituent_type *aConstituent) const
void reweight(const constituent_type *constituentObject, const RPAR &objectParameter=RPAR())
SG::GenerateIndexingPolicy< CaloCellContainer >::type::index_type external_index_type
Definition Navigable.h:156
constituent_coll m_constituents
Definition Navigable.h:345
constituent_coll * getPtrToConstituents()
Definition Navigable.h:296
void insertElement(const CONT *objectContainer, const constituent_type *constituentObject, const RPAR &objectParameter=RPAR(), size_t sizeHint=0)
RPAR getParameter(const CONT *objectContainer, const external_index_type &theIndex) const
void dumpStore() const
void insertElement(const CONT *objectContainer, const external_index_type &theIndex, IProxyDict *sg, const RPAR &objectParameter=RPAR(), size_t sizeHint=0)
virtual void toKidsAfterAccept(INavigationToken &navToken, const std::any &aParameter) const
virtual void fillToken(INavigationToken &navToken, const std::any &parentParameter) const
virtual object_iter end() const
virtual void apply(NavigationToken< constituent_type, RPAR > &navToken, const RPAR &aParameter) const
virtual const constituent_type * getConstituentPtr(constituent_iter iter) const
const CONT * getContainer(constituent_const_iter anIter) const
void reweight(const CONT *objectContainer, const external_index_type &theIndex, const RPAR &objectParameter=RPAR())
bool remove(const CONT *objectContainer, const external_index_type &theIndex)
virtual void toKidsAfterAccept(INavigationToken &navToken) const
CaloCellContainer::base_value_type constituent_type
Definition Navigable.h:149
constituent_coll & getConstituents()
Definition Navigable.h:291
RPAR getParameter(object_iter &theIter) const
virtual ~Navigable()=default
CaloCellContainer::reference constituent_ptr_ref
Definition Navigable.h:150
double parameter_type
Definition Navigable.h:112
CaloCellContainer container_type
Definition Navigable.h:110
CaloCellContainer::const_reference constituent_const_ptr_ref
Definition Navigable.h:151
bool getIndex(const constituent_type *aConstituent, external_index_type &theIndex) const
virtual RPAR getConstituentPar(constituent_const_iter iter) const
bool getIndex(object_iter objectIter, external_index_type &theIndex) const
bool getIndex(constituent_const_iter anIter, external_index_type &theIndex) const
constituent_coll::const_iterator constituent_const_iter
Definition Navigable.h:103
void insertElement(const CONT *objectContainer, const external_index_type &theIndex, const RPAR &objectParameter=RPAR(), size_t sizeHint=0)
virtual RPAR getConstituentPar(constituent_iter iter) const
const CONT * getContainer(const constituent_type *aConstituent) const
void insertElement(const ElementLink< CONT > &el, const RPAR &objectParameter=RPAR(), size_t sizeHint=0)
NavigationDefaults::DefaultChildColl< container_type, parameter_type > navhelper_t
Definition Navigable.h:114
virtual void fillToken(INavigationToken &navToken) const
DefaultContainer TerminalNode