ATLAS Offline Software
NavigableCnv_p2.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 /** @file NavigableCnv_p2.icc
6  * @brief This file contains the implementation for the NavigableCnv_p2 template methods.
7  * @author Marcin.Nowak@cern.ch
8  **/
9 
10 #include <stdexcept>
11 
12 #include "Navigation/Navigable.h"
13 #include "AthenaKernel/getThinningCache.h"
14 
15 //#include <iostream>
16 
17 //#define NAV_P2_DEBUG
18 
19 
20 template <typename NAV, typename RPAR>
21 void
22 NavigableCnv_p2<NAV, RPAR>
23 ::transToPers(const Navigable_t& trans,
24  PersNavigable_t& pers,
25  const SG::ThinningCache* cache,
26  MsgStream& msg) const
27 {
28  // collect all element links into a temporary vector
29  ElementLinkVect_t elv;
30  pers.m_parameters.clear();
31  elv.reserve( trans.size() );
32  pers.m_parameters.reserve( trans.size() );
33 
34  typename NAV::object_iter iter = trans.begin();
35  typename NAV::object_iter end = trans.end();
36 
37  while( iter != end ) {
38  #ifdef NAV_P2_DEBUG
39  msg << MSG::DEBUG << "NavigableCnv_p2::transToPers(): Weight["
40  << pers.m_parameters.size()-1 <<"]="
41  << pers.m_parameters[pers.m_parameters.size()-1] << endmsg;
42  #endif
43  elv.push_back( iter.getElement() );
44  pers.m_parameters.push_back( iter.getParameter() );
45  ++iter;
46  }
47  // convert the link vector to persistent
48  m_linkCnv.transToPers(elv, pers.m_links, cache, msg);
49 }
50 
51 
52 template <typename NAV, typename RPAR>
53 void
54 NavigableCnv_p2<NAV, RPAR>
55 ::transToPers(const Navigable_t& trans,
56  PersNavigable_t& pers,
57  MsgStream& msg) const
58 {
59  transToPers (trans, pers,
60  SG::getThinningCache(),
61  msg);
62 }
63 
64 
65 template <typename NAV, typename RPAR >
66 void NavigableCnv_p2<NAV, RPAR >::persToTrans(const PersNavigable_t& pers,
67  Navigable_t& trans,
68  MsgStream& msg) const
69 {
70  // create a temporary link vector from persistent
71  ElementLinkVect_t elv;
72  m_linkCnv.persToTrans(pers.m_links, elv, msg);
73 
74  // copy from link vector into navigable
75  size_t size = elv.size();
76  trans.removeAll();
77  for( size_t i = 0; i < size; ++i ) {
78  trans.insertElement (elv[i], pers.m_parameters[i], size);
79  #ifdef NAV_P2_DEBUG
80  msg << MSG::DEBUG << "NavigableCnv_p2::PersToTrans(): Weight[" <<i <<"]="
81  << pers.m_parameters[i] << endmsg;
82  #endif
83  }
84 }
85 
86 
87 template <typename NAV, typename RPAR>
88 inline
89 void
90 NavigableCnv_p2<NAV, RPAR>
91 ::transToPers(const Navigable_t* trans, PersNavigable_t* pers, MsgStream& msg) const
92 {
93  this->transToPers(*trans, *pers, msg);
94 }
95 
96 
97 template <typename NAV, typename RPAR >
98 inline
99 void
100 NavigableCnv_p2<NAV, RPAR >
101 ::persToTrans(const PersNavigable_t* pers, Navigable_t* trans, MsgStream& msg) const
102 {
103  this->persToTrans(*pers, *trans, msg);
104 }
105 
106 
107 //-----------------------------------------------------
108 // Specialized version of the converter for Navigables without weight parameters
109 
110 
111 template <typename NAV >
112 void
113 NavigableCnv_p2<NAV, NavigationDefaults::DefaultWeight >
114 ::transToPers(const Navigable_t& trans,
115  PersNavigable_t& pers,
116  const SG::ThinningCache* cache,
117  MsgStream& msg) const
118 {
119  // collect all element links into a temporary vector
120  ElementLinkVect_t elv;
121  elv.reserve( trans.size() );
122 
123  typename NAV::object_iter iter = trans.begin();
124  typename NAV::object_iter end = trans.end();
125 
126  while( iter != end ) {
127  elv.push_back( iter.getElement() );
128  iter++;
129  }
130  // convert the link vector to persistent
131  m_linkCnv.transToPers(elv, pers.m_links, cache, msg);
132 }
133 
134 
135 template <typename NAV >
136 void
137 NavigableCnv_p2<NAV, NavigationDefaults::DefaultWeight >
138 ::transToPers(const Navigable_t& trans,
139  PersNavigable_t& pers,
140  MsgStream& msg) const
141 {
142  transToPers (trans, pers,
143  SG::getThinningCache(),
144  msg);
145 }
146 
147 
148 template <typename NAV >
149 inline
150 void
151 NavigableCnv_p2<NAV, NavigationDefaults::DefaultWeight >
152 ::transToPers(const Navigable_t* trans, PersNavigable_t* pers, MsgStream& msg) const
153 {
154  this->transToPers(*trans, *pers, msg);
155 }
156 
157 
158 //-------------------- persToTrans() ----------------------------------
159 
160 template <typename NAV >
161 void
162 NavigableCnv_p2<NAV, NavigationDefaults::DefaultWeight >
163 ::persToTrans(const PersNavigable_t& pers,
164  Navigable_t& trans,
165  MsgStream& msg) const
166 {
167  // create a temporary link vector from persistent
168  ElementLinkVect_t elv;
169  m_linkCnv.persToTrans(pers.m_links, elv, msg);
170 
171  // copy from link vector into navigable
172  trans.removeAll();
173  size_t size = elv.size();
174  for( size_t i = 0; i < size; ++i ) {
175  trans.insertElement(elv[i], NavigationDefaults::DefaultWeight(), size);
176  }
177 }
178 
179 
180 template <typename NAV >
181 inline
182 void
183 NavigableCnv_p2<NAV, NavigationDefaults::DefaultWeight >
184 ::persToTrans(const PersNavigable_t* pers, Navigable_t* trans, MsgStream& msg) const
185 {
186  this->persToTrans(*pers, *trans, msg);
187 }