ATLAS Offline Software
NavigableCnv_p1.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_p1.icc
6  * @brief This file contains the implementation for the NavigableCnv_p1 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 
16 //#include <iostream>
17 
18 //#define NAV_P1_DEBUG
19 
20 
21 template <typename NAV, typename RPAR>
22 void
23 NavigableCnv_p1<NAV, RPAR>::transToPers(const Navigable_t& trans,
24  PersNavigable_t& pers,
25  const SG::ThinningCache* cache,
26  MsgStream& msg) const
27 {
28  pers.m_parameters.clear();
29 
30  // collect all element links into a temporary vector
31  ElementLinkVect_t elv;
32  elv.reserve(trans.size());
33  /// FIXME: should we also reserve some space for pers->m_parameters ?!?
34  //pers.m_parameters.reserve( pers.m_parameters.size() + link_coll.size() );
35 
36  typename NAV::object_iter iter = trans.begin();
37  typename NAV::object_iter end = trans.end();
38 
39  while( iter != end ) {
40  #ifdef NAV_P1_DEBUG
41  msg << MSG::DEBUG << "NavigableCnv_p1::transToPers(): Weight["
42  << pers.m_parameters.size()-1 <<"]="
43  << pers.m_parameters[pers.m_parameters.size()-1] << endmsg;
44  #endif
45  elv.push_back( iter.getElement() );
46  pers.m_parameters.push_back( iter.getParameter() );
47  ++iter;
48  }
49  // this is not needed (and might actually crash if thinning occurred!)
50  // as this is done by the ELVCnv::transToPers
51  //elv.toPersistent();
52 
53  // convert the link vector to persistent
54  m_linkCnv.transToPers(elv, pers.m_links, cache, msg);
55 }
56 
57 
58 template <typename NAV, typename RPAR>
59 void
60 NavigableCnv_p1<NAV, RPAR>::transToPers(const Navigable_t& trans,
61  PersNavigable_t& pers,
62  MsgStream& msg) const
63 {
64  transToPers (trans, pers,
65  SG::getThinningCache(),
66  msg);
67 }
68 
69 
70 template <typename NAV, typename RPAR >
71 void NavigableCnv_p1<NAV, RPAR >::persToTrans(const PersNavigable_t& pers,
72  Navigable_t& trans,
73  MsgStream& msg) const
74 {
75  // create a temporary link vector from persistent
76  ElementLinkVect_t elv;
77  m_linkCnv.persToTrans(pers.m_links, elv, msg);
78  elv.toTransient();
79 
80  // copy from link vector into navigable
81  size_t size = elv.size();
82  trans.removeAll();
83  for( size_t i = 0; i < size; ++i ) {
84  trans.insertElement (elv[i], pers.m_parameters[i], size);
85  #ifdef NAV_P1_DEBUG
86  msg << MSG::DEBUG << "NavigableCnv_p1::PersToTrans(): Weight[" <<i <<"]="
87  << pers.m_parameters[i] << endmsg;
88  #endif
89  }
90 }
91 
92 
93 template <typename NAV, typename RPAR>
94 inline
95 void
96 NavigableCnv_p1<NAV, RPAR>
97 ::transToPers(const Navigable_t* trans, PersNavigable_t* pers, MsgStream& msg) const
98 {
99  this->transToPers(*trans, *pers, msg);
100 }
101 
102 
103 template <typename NAV, typename RPAR >
104 inline
105 void
106 NavigableCnv_p1<NAV, RPAR >
107 ::persToTrans(const PersNavigable_t* pers, Navigable_t* trans, MsgStream& msg) const
108 {
109  this->persToTrans(*pers, *trans, msg);
110 }
111 
112 
113 //-----------------------------------------------------
114 // Specialized version of the converter for Navigables without weight parameters
115 
116 
117 template <typename NAV >
118 void
119 NavigableCnv_p1<NAV, NavigationDefaults::DefaultWeight >
120 ::transToPers(const Navigable_t& trans,
121  PersNavigable_t& pers,
122  const SG::ThinningCache* cache,
123  MsgStream& msg) const
124 {
125  // collect all element links into a temporary vector
126  ElementLinkVect_t elv;
127  elv.reserve(trans.size());
128  /// FIXME: should we also reserve some space for pers->m_parameters ?!?
129  //pers.m_parameters.reserve( pers.m_parameters.size() + link_coll.size() );
130 
131  typename NAV::object_iter iter = trans.begin();
132  typename NAV::object_iter end = trans.end();
133 
134  while( iter != end ) {
135  elv.push_back( iter.getElement() );
136  iter++;
137  }
138  // this is not needed (and might actually crash if thinning occurred!)
139  // as this is done by the ELVCnv::transToPers
140  //elv.toPersistent();
141 
142  // convert the link vector to persistent
143  m_linkCnv.transToPers(elv, pers.m_links, cache, msg);
144 }
145 
146 
147 template <typename NAV >
148 void
149 NavigableCnv_p1<NAV, NavigationDefaults::DefaultWeight >
150 ::transToPers(const Navigable_t& trans,
151  PersNavigable_t& pers,
152  MsgStream& msg) const
153 {
154  transToPers (trans, pers,
155  SG::getThinningCache(),
156  msg);
157 }
158 
159 
160 template <typename NAV >
161 inline
162 void
163 NavigableCnv_p1<NAV, NavigationDefaults::DefaultWeight >
164 ::transToPers(const Navigable_t* trans, PersNavigable_t* pers, MsgStream& msg) const
165 {
166  this->transToPers(*trans, *pers, msg);
167 }
168 
169 
170 //-------------------- persToTrans() ----------------------------------
171 
172 template <typename NAV >
173 void
174 NavigableCnv_p1<NAV, NavigationDefaults::DefaultWeight >
175 ::persToTrans(const PersNavigable_t& pers,
176  Navigable_t& trans,
177  MsgStream& msg) const
178 {
179  // create a temporary link vector from persistent
180  ElementLinkVect_t elv;
181  m_linkCnv.persToTrans(pers.m_links, elv, msg);
182  elv.toTransient();
183 
184  // copy from link vector into navigable
185  size_t size = elv.size();
186  trans.removeAll();
187  for( size_t i = 0; i < size; ++i ) {
188  trans.insertElement (elv[i], NavigationDefaults::DefaultWeight(), size);
189  }
190 }
191 
192 
193 template <typename NAV >
194 inline
195 void
196 NavigableCnv_p1<NAV, NavigationDefaults::DefaultWeight >
197 ::persToTrans(const PersNavigable_t* pers, Navigable_t* trans, MsgStream& msg) const
198 {
199  this->persToTrans(*pers, *trans, msg);
200 }