2 Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
5 //////////////////////////////////////////////////////////////////////////////
7 // Navigable implementations //
9 //////////////////////////////////////////////////////////////////////////////
14 template <typename CONT, typename RPAR, typename COLL>
15 Navigable<CONT,RPAR,COLL>::Navigable() { }
17 //////////////////////////////////////////////
18 // Navigation query handling w/o parameters //
19 //////////////////////////////////////////////
21 //debug #include <iostream>
23 template <typename CONT, typename RPAR, typename COLL>
25 Navigable<CONT, RPAR, COLL>::fillToken(INavigationToken& navToken) const
27 //////////////////////////////////
28 // Check Object Type Query Only //
29 //////////////////////////////////
31 // token type comparison
32 NavigationToken<constituent_type>* noParToken =
33 dynamic_cast< NavigationToken<constituent_type>* >(&navToken);
35 // token type accepted
36 if ( noParToken != 0 )
38 this->apply(*noParToken);
39 this->toKidsAfterAccept(*noParToken);
40 //debug std::cout << "[Navigable::fillToken(token)] - honored "
41 //debug << "NavigationToken<CONSTITUENT_TYPE>"
46 /////////////////////////////////////////////////////////
47 // Check Object Type & Relational Parameter Type Query //
48 /////////////////////////////////////////////////////////
50 // token type comparison
51 NavigationToken<constituent_type, RPAR>* parToken =
52 dynamic_cast< NavigationToken<constituent_type, RPAR>* >(&navToken);
54 // token type accepted
57 this->apply(*parToken, RPAR());
58 this->toKidsAfterAccept(*parToken,RPAR());
59 //debug std::cout << "[Navigable::fillToken(token)] - honored "
60 //debug << "NavigableToken<CONSTITUENT_TYPE,REL_PARM>"
65 ///////////////////////////////
66 // Forward Query If No Match //
67 ///////////////////////////////
69 this->toKidsAfterReject(navToken);
72 /////////////////////////////////////////////
73 // Navigation query handling w/ parameters //
74 /////////////////////////////////////////////
76 template <typename CONT, typename RPAR, typename COLL>
78 Navigable<CONT, RPAR, COLL>::fillToken(INavigationToken& navToken,
79 const std::any& aParameter) const
81 //////////////////////////////////
82 // Check Object Type Query Only //
83 //////////////////////////////////
85 // token type comparison
86 NavigationToken<constituent_type>* noParToken =
87 dynamic_cast< NavigationToken<constituent_type>* >(&navToken);
89 // token type accepted
90 if ( noParToken != 0 )
92 this->apply(*noParToken);
93 this->toKidsAfterAccept(*noParToken);
94 //debug std::cout << "[Navigable::fillToken(token,weight)] - honored "
95 //debug << "NavigationToken<CONSTITUENT_TYPE>"
100 /////////////////////////////////////////////////////////
101 // Check Object Type & Relational Parameter Type Query //
102 /////////////////////////////////////////////////////////
104 // token type comparison
105 NavigationToken<constituent_type, RPAR>* parToken =
106 dynamic_cast< NavigationToken<constituent_type, RPAR>* >(&navToken);
108 // token type accepted
111 this->apply(*parToken, std::any_cast<RPAR>(aParameter));
112 this->toKidsAfterAccept(*parToken,aParameter);
113 //debug std::cout << "[Navigable::fillToken(token,weight)] - honored "
114 //debug << "NavigableToken<CONSTITUENT_TYPE,REL_PARM>"
115 //debug << std::endl;
119 ///////////////////////////////
120 // Forward Query If No Match //
121 ///////////////////////////////
123 this->toKidsAfterReject(navToken, aParameter);
127 /////////////////////////
128 // Insert Constituents //
129 /////////////////////////
131 // insert by object pointer
132 template <typename CONT, typename RPAR, typename COLL>
134 Navigable<CONT, RPAR, COLL>::putElement(const CONT*
136 const constituent_type*
142 // replacement insertion policy in
143 if ( this->contains(ptrObject) ) this->remove(ptrObject);
144 this->insertElement(ptrObjectContainer,ptrObject,refParameter,sizeHint);
147 // insert by object index
148 template <typename CONT, typename RPAR, typename COLL>
150 Navigable<CONT, RPAR, COLL>::putElement(const CONT*
152 const external_index_type&
159 if ( this->contains(ptrObjectContainer,refIndex) )
160 this->remove(ptrObjectContainer,refIndex);
161 this->insertElement(ptrObjectContainer,refIndex,refParameter,sizeHint);
164 // insert by pointer without check on multiple insertions
165 template<typename CONT, typename RPAR, typename COLL>
167 Navigable<CONT, RPAR, COLL>::insertElement(const CONT*
169 const constituent_type*
175 NavigationDefaults::DefaultChildColl<CONT, RPAR>::insert(
176 this->getConstituents(),
184 // insert by index without check on multiple insertions
185 template<typename CONT, typename RPAR, typename COLL>
187 Navigable<CONT, RPAR, COLL>::insertElement(const CONT*
189 const external_index_type&
195 NavigationDefaults::DefaultChildColl<CONT, RPAR>::insert(
196 this->getConstituents(),
204 // insert by index without check on multiple insertions
205 // store is supplied explicitly.
206 template<typename CONT, typename RPAR, typename COLL>
208 Navigable<CONT, RPAR, COLL>::insertElement(const CONT*
210 const external_index_type&
217 NavigationDefaults::DefaultChildColl<CONT, RPAR>::insert(
218 this->getConstituents(),
227 // insert by ElementLink without check on multiple insertions
228 template<typename CONT, typename RPAR, typename COLL>
230 Navigable<CONT, RPAR, COLL>::insertElement(const ElementLink<CONT>& el,
235 NavigationDefaults::DefaultChildColl<CONT, RPAR>::insert(
236 this->getConstituents(),
242 ////////////////////////////////
243 // Object Removal and Finding //
244 ////////////////////////////////
247 template<typename CONT, typename RPAR, typename COLL>
249 Navigable<CONT,RPAR,COLL>::reweight(const constituent_type* ptrObject,
252 NavigationDefaults::DefaultChildColl<CONT,RPAR>::
253 changeParm(this->getConstituents(),ptrObject,refParm);
255 template<typename CONT, typename RPAR, typename COLL>
257 Navigable<CONT,RPAR,COLL>::reweight(const CONT* ptrContainer,
258 const external_index_type& refIndex,
261 NavigationDefaults::DefaultChildColl<CONT,RPAR>::
262 changeParm(this->getConstituents(),ptrContainer,refIndex,refParm);
264 template<typename CONT, typename RPAR, typename COLL>
266 Navigable<CONT,RPAR,COLL>::reweight(object_iter& objectIter,
269 NavigationDefaults::DefaultChildColl<CONT,RPAR>::
270 changeParm(this->getConstituents(),(*objectIter),refParm);
274 // remove object by pointer
275 template<typename CONT, typename RPAR, typename COLL>
277 Navigable<CONT, RPAR, COLL>::remove(const constituent_type* ptrObject)
279 // needs to be the non-const ref!
280 constituent_coll& refConstituents = this->getConstituents();
282 NavigationDefaults::DefaultChildColl<CONT, RPAR>::remove(refConstituents,
286 // remove object by collection index
287 template<typename CONT, typename RPAR, typename COLL>
289 Navigable<CONT, RPAR, COLL>::remove( const CONT* ptrObjectContainer,
290 const external_index_type& refIndex)
292 return this->remove((*ptrObjectContainer)[refIndex]);
295 // replace old object container with a new container
296 template<typename CONT, typename RPAR, typename COLL>
298 Navigable<CONT, RPAR, COLL>::replace(const CONT* newObjectContainer)
300 // needs to be the non-const ref!
301 constituent_coll& refConstituents = this->getConstituents();
303 NavigationDefaults::DefaultChildColl<CONT, RPAR>::replace(refConstituents,
304 *newObjectContainer);
310 // test if object is in internal container
311 template<typename CONT, typename RPAR, typename COLL>
313 Navigable<CONT, RPAR, COLL>::contains(const constituent_type* ptrObject) const
316 NavigationDefaults::DefaultChildColl<CONT, RPAR>::contains(
317 this->getConstituents(),
322 // test if object is in internal container using index in external collection
323 template<typename CONT, typename RPAR, typename COLL>
325 Navigable<CONT, RPAR, COLL>::contains( const CONT* ptrObjectContainer,
326 const external_index_type&
329 const constituent_type* ptrObject =
330 (ptrObjectContainer->operator[])(refIndex);
331 return this->contains(ptrObject);
334 //////////////////////////
335 // Container Operations //
336 //////////////////////////
339 template<typename CONT, typename RPAR, typename COLL>
340 typename Navigable<CONT, RPAR, COLL>::object_iter
341 Navigable<CONT, RPAR, COLL>::begin() const
344 NavigableIterator<CONT, RPAR, COLL>(this->getConstituents()).begin();
348 template<typename CONT, typename RPAR, typename COLL>
349 typename Navigable<CONT, RPAR, COLL>::object_iter
350 Navigable<CONT, RPAR, COLL>::end() const
353 NavigableIterator<CONT, RPAR, COLL>(this->getConstituents()).end();
357 template<typename CONT, typename RPAR, typename COLL>
359 Navigable<CONT, RPAR, COLL>::size() const
361 return this->getConstituents().size();
364 // return pointer to original data object container by object pointer
365 template<typename CONT, typename RPAR, typename COLL>
367 Navigable<CONT, RPAR, COLL>::getContainer(const constituent_type*
371 NavigationDefaults::DefaultChildColl<CONT,RPAR>::getContPtr(
372 this->getConstituents(),
377 // return pointer to original data object container by internal iterator
378 template<typename CONT, typename RPAR, typename COLL>
380 Navigable<CONT, RPAR, COLL>::getContainer(constituent_const_iter anIter) const
383 NavigationDefaults::DefaultChildColl<CONT,RPAR>::getContPtr(anIter);
386 // return pointer to original data object container by object iterator
387 template<typename CONT, typename RPAR, typename COLL>
389 Navigable<CONT, RPAR, COLL>::getContainer(object_iter objectIter) const
391 return this->getContainer(objectIter.getInternalIterator());
394 // get index of data object in original container by object pointer
395 template<typename CONT, typename RPAR, typename COLL>
397 Navigable<CONT, RPAR, COLL>::getIndex(const constituent_type* aConstituent,
398 external_index_type& theIndex) const
402 DefaultChildColl<CONT,RPAR>::getContIndex(this->getConstituents(),
407 // get index of data object in original container by internal iterator
408 template<typename CONT, typename RPAR, typename COLL>
410 Navigable<CONT, RPAR, COLL>::getIndex(constituent_const_iter anIter,
411 external_index_type& theIndex) const
415 DefaultChildColl<CONT,RPAR>::getContIndex(anIter,theIndex);
419 // get index of data object in original container by object iterator
420 template<typename CONT, typename RPAR, typename COLL>
422 Navigable<CONT, RPAR, COLL>::getIndex(object_iter objectIter,
423 external_index_type& theIndex) const
425 return this->getIndex(objectIter.getInternalIterator(),theIndex);
428 /////////////////////////
429 // Retrieve Parameters //
430 /////////////////////////
433 template<typename CONT, typename RPAR, typename COLL>
435 Navigable<CONT, RPAR, COLL>::getParameter(const constituent_type*
440 NavigationDefaults::DefaultChildColl<CONT, RPAR>::find(getConstituents(),
445 // by collection index
446 template<typename CONT, typename RPAR, typename COLL>
448 Navigable<CONT, RPAR, COLL>::getParameter(const CONT* ptrObjectContainer,
449 const external_index_type&
452 const constituent_type* ptrObject = (*ptrObjectContainer)[refIndex];
453 return this->getParameter(ptrObject);
457 template<typename CONT, typename RPAR, typename COLL>
459 Navigable<CONT, RPAR, COLL>::getParameter(object_iter& refIter) const
461 return refIter.getParameter();
464 ///////////////////////////////////////////////////////////////////////////////
465 // Internally Used Methods //
466 ///////////////////////////////////////////////////////////////////////////////
468 //////////////////////////
469 // Query can be honored //
470 //////////////////////////
472 // fill token with object pointers (no parameters)
473 template <typename CONT, typename RPAR, typename COLL>
475 Navigable<CONT, RPAR, COLL>::apply(NavigationToken<constituent_type>&
479 const constituent_coll& coll = this->getConstituents();
480 constituent_const_iter iCtr(coll.begin());
481 constituent_const_iter iEnd(coll.end());
482 for (; iCtr != iEnd; ++iCtr)
484 const constituent_type* ptrObject = this->getConstituentPtr(iCtr);
486 navToken.setObject( ptrObject );
488 // setBackNavigationWarning();
492 // fill with parameter
493 template <typename CONT, typename RPAR, typename COLL>
495 Navigable<CONT, RPAR, COLL>::apply(NavigationToken<constituent_type, RPAR>&
497 const RPAR& aParameter) const
499 //debug std::cout << "[Navigable::apply(token,weight)] - invoked with "
500 //debug << "token @ " << &navToken
501 //debug << " and parameter " << aParameter
502 //debug << std::endl;
505 const constituent_coll& coll = this->getConstituents();
506 constituent_const_iter iCtr(coll.begin());
507 constituent_const_iter iEnd(coll.end());
508 for (; iCtr != iEnd; ++iCtr)
510 const constituent_type* ptrObject = this->getConstituentPtr(iCtr);
511 //debug std::cout << "[Navigable::apply(token,weight)] - set constituent @ "
512 //debug << ptrObject << ", incoming parameter "
513 //debug << aParameter
514 //debug << ", new parameter "
515 //debug << aParameter * this->getConstituentPar(iCtr)
516 //debug << std::endl;
519 navToken.setObject(ptrObject,
520 aParameter * this->getConstituentPar(iCtr));
522 // setBackNavigationWarning();
526 //////////////////////
527 // Forwarding query //
528 //////////////////////
530 // no parameter, query is honored
531 template <typename CONT, typename RPAR, typename COLL>
533 Navigable<CONT, RPAR,COLL>::toKidsAfterAccept(INavigationToken& navToken) const
536 const constituent_coll& coll = this->getConstituents();
537 constituent_const_iter iCtr(coll.begin());
538 constituent_const_iter iEnd(coll.end());
539 for (; iCtr != iEnd; ++iCtr)
541 const constituent_type* ptrObject = this->getConstituentPtr(iCtr);
543 ptrObject->fillToken( navToken ); // forward query
545 // setBackNavigationWarning();
549 // no parameter, query is not honored
550 template <typename CONT, typename RPAR, typename COLL>
552 Navigable<CONT, RPAR,COLL>::toKidsAfterReject(INavigationToken& navToken) const
555 const constituent_coll& coll = this->getConstituents();
556 constituent_const_iter iCtr(coll.begin());
557 constituent_const_iter iEnd(coll.end());
558 for (; iCtr != iEnd; ++iCtr)
560 const constituent_type* ptrObject = this->getConstituentPtr(iCtr);
562 navToken.trySetObject( ptrObject ); // navigating inheritance
563 ptrObject->fillToken( navToken ); // forward query
566 // setBackNavigationWarning();
570 // with parameter, query is honored
571 template <typename CONT, typename RPAR, typename COLL>
573 Navigable<CONT, RPAR, COLL>::toKidsAfterAccept(INavigationToken& navToken,
574 const std::any& aParameter) const
577 const constituent_coll& coll = this->getConstituents();
578 constituent_const_iter iCtr(coll.begin());
579 constituent_const_iter iEnd(coll.end());
580 // catch exception thrown by std::any_cast
582 // only identical parameter types can be forwarded!
583 RPAR parentPar(std::any_cast<RPAR>(aParameter));
585 // Do it like this to avoid creating and destroying a temp any object
586 // each time through the loop.
587 std::any arg (parentPar);
588 RPAR* argp = std::any_cast<RPAR> (&arg);
590 for (; iCtr != iEnd; ++iCtr)
592 const constituent_type* ptrObject = this->getConstituentPtr(iCtr);
594 *argp = parentPar * this->getConstituentPar(iCtr);
595 ptrObject->fillToken(navToken, arg);
598 // setBackNavigationWarning();
600 } catch(std::bad_any_cast&) {
601 // parameter type mismatch: terminate parameter forwarding only
602 for (; iCtr != iEnd; ++iCtr)
604 const constituent_type* ptrObject = this->getConstituentPtr(iCtr);
606 ptrObject->fillToken(navToken, aParameter);
608 // setBackNavigationWarning();
613 // with parameter, query is not honored
614 template <typename CONT, typename RPAR, typename COLL>
616 Navigable<CONT, RPAR, COLL>::toKidsAfterReject(INavigationToken& navToken,
617 const std::any& aParameter) const
620 const constituent_coll& coll = this->getConstituents();
621 constituent_const_iter iCtr(coll.begin());
622 constituent_const_iter iEnd(coll.end());
623 // catch exception thrown by std::any_cast
625 // only identical parameter types can be forwarded!
626 RPAR parentPar(std::any_cast<RPAR>(aParameter));
628 // Do it like this to avoid creating and destroying a temp any object
629 // each time through the loop.
630 std::any arg (parentPar);
631 RPAR* argp = std::any_cast<RPAR> (&arg);
633 for (; iCtr != iEnd; ++iCtr)
635 const constituent_type* ptrObject = this->getConstituentPtr(iCtr);
637 *argp = parentPar * this->getConstituentPar(iCtr);
638 navToken.trySetObject(ptrObject, arg);
639 ptrObject->fillToken(navToken, arg);
642 // setBackNavigationWarning();
645 } catch(std::bad_any_cast&) {
646 // parameter type mismatch: terminate parameter forwarding only
647 for (; iCtr != iEnd; ++iCtr)
649 const constituent_type* ptrObject = this->getConstituentPtr(iCtr);
651 ptrObject->fillToken(navToken, aParameter);
653 // setBackNavigationWarning();
658 ///////////////////////////////////
659 // Internal data object handling //
660 ///////////////////////////////////
662 // non-const access data objects by iterator
663 template <typename CONT, typename RPAR, typename COLL>
664 const typename Navigable<CONT, RPAR, COLL>::constituent_type*
665 Navigable<CONT, RPAR, COLL>::getConstituentPtr(constituent_iter
668 return NavigationDefaults::DefaultChildColl<CONT, RPAR>::getChildPtr(iter);
671 // access data objects by iterator
672 template <typename CONT, typename RPAR, typename COLL>
673 const typename Navigable<CONT, RPAR, COLL>::constituent_type*
674 Navigable<CONT, RPAR, COLL>::getConstituentPtr(constituent_const_iter
678 NavigationDefaults::DefaultChildColl<CONT, RPAR>::getChildPtr(iter);
681 // access relational parameter by iterator
682 template <typename CONT, typename RPAR, typename COLL>
684 Navigable<CONT, RPAR, COLL>::getConstituentPar(constituent_const_iter
687 return NavigationDefaults::DefaultChildColl<CONT, RPAR>::getChildPar(iter);
690 // access relational parameter by iterator
691 template <typename CONT, typename RPAR, typename COLL>
693 Navigable<CONT, RPAR, COLL>::getConstituentPar(constituent_iter
696 return NavigationDefaults::DefaultChildColl<CONT, RPAR>::getChildPar(iter);
704 template <typename CONT, typename RPAR, typename COLL>
706 Navigable<CONT, RPAR, COLL>::dumpStore() const
708 std::cout << " Navigable class <"
709 << (typeid(*this)).name()
710 << "> @" << this << " with "
712 << " referenced objects " << std::endl;
713 object_iter fObj = this->begin();
714 object_iter lObj = this->end();
715 for ( ; fObj != lObj; fObj++ )
717 external_index_type theIndex = size_t(-1);
718 if ( this->getIndex(fObj,theIndex) )
724 << this->getContainer(fObj)
727 << " ] with search indicator \042"
728 << this->contains(*fObj)
729 << "\042 and parameter "
730 << this->getParameter(fObj)
736 << "Cannot find object @"
738 << " in collection, search indicator \042"
739 << this->contains(*fObj)