ATLAS Offline Software
ElementLinkCnv_p3.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 /** @file ElementLinkCnv_p3.icc
6  * @brief This file contains the implementation for the ElementLinkCnv_p3 template methods.
7  * @author Marcin.Nowak@cern.ch
8  **/
9 
10 #include <stdexcept>
11 
12 #include "AthLinks/ElementLink.h"
13 #include "AthenaKernel/ThinningCache.h"
14 #include "AthenaKernel/ThinningDecisionBase.h"
15 #include "AthenaKernel/getThinningCache.h"
16 //#define ELLINK_DEBUG
17 
18 
19 template <typename LINK_TYPE>
20 void ElementLinkCnv_p3<LINK_TYPE>::
21 transToPers(const Link_t& trans, PersLink_t& pers,
22  const SG::ThinningCache* cache,
23  [[maybe_unused]] MsgStream& msg ) const
24 {
25  if( !trans.isDefault() ) {
26  // Check for thinning.
27  if (cache) {
28  const SG::ThinningDecisionBase* dec = cache->thinning (trans.key());
29  if (dec) {
30  // here is the problem: in case the ElementLink was directly created w/
31  // only a pointer to the element, _and_ if the the pointed at element
32  // has been thinned away, EL::index() will throw b/c
33  // IndexingPolicy::setIndex will fail.
34  std::size_t idx = SG::ThinningDecisionBase::RemovedIdx;
35  try {
36  idx = trans.index();
37  } catch ( const SG::maybe_thinning_error& err ) {
38  // ok. that's the corner case we talked about above.
39 #ifdef ELLINK_DEBUG
40  msg << MSG::DEBUG << "caught a maybe_thinning_error: ["
41  << err.what() << "]"
42  << endmsg
43  << "(this is an expected case of the EL-state-phase-space "
44  << "when thinning is active)"
45  << endmsg;
46 #endif
47  }
48 
49  // Get the updated index:
50  const std::size_t persIdx = dec->index( idx );
51  if (SG::ThinningDecisionBase::RemovedIdx == persIdx)
52  {
53  pers = PersLink_t();
54  }
55  else {
56  Link_t tmp = trans;
57  tmp.toPersistent();
58  pers.m_SGKeyHash = tmp.key();
59  pers.m_elementIndex = persIdx;
60  }
61 #ifdef ELLINK_DEBUG
62  msg << MSG::INFO << "ElementLinkCnv_p3::transToPer(): SG Container="
63  << ", Key Hash=" << pers.m_SGKeyHash
64  << ", IDX=" << pers.m_elementIndex << endmsg;
65 #endif
66  return;
67  }
68  }
69 
70  // No thinning.
71  Link_t tmp = trans;
72  tmp.toPersistent();
73  pers.m_SGKeyHash = tmp.key();
74  pers.m_elementIndex = tmp.index();
75 #ifdef ELLINK_DEBUG
76  msg << MSG::INFO << "ElementLinkCnv_p3::transToPer(): SG Container="
77  << ", Key Hash=" << pers.m_SGKeyHash
78  << ", IDX=" << pers.m_elementIndex << endmsg;
79 #endif
80  }
81 }
82 
83 
84 template <typename LINK_TYPE>
85 void ElementLinkCnv_p3<LINK_TYPE>::
86 transToPers(const Link_t& trans, PersLink_t& pers,
87  MsgStream& msg ) const
88 {
89  transToPers (trans, pers,
90  SG::getThinningCache(),
91  msg);
92 }
93 
94 
95 template <typename LINK_TYPE >
96 void ElementLinkCnv_p3< LINK_TYPE >
97 ::persToTrans(const PersLink_t& pers, Link_t& trans,
98  [[maybe_unused]] MsgStream& msg) const
99 {
100  if( pers.m_SGKeyHash != 0 ) {
101 #ifdef ELLINK_DEBUG
102  msg << MSG::DEBUG << "ElementLinkCnv_p3::PersToTrans(): SGContainer hash="
103  << pers.m_SGKeyHash << ", IDX=" << pers.m_elementIndex << endmsg;
104 #endif
105  trans = Link_t( (typename Link_t::sgkey_t)pers.m_SGKeyHash, pers.m_elementIndex);
106  }
107  else {
108 #ifdef ELLINK_DEBUG
109  msg << MSG::DEBUG << "ElementLinkCnv_p3::PersToTrans(): reading EL in Default state" << endmsg;
110 #endif
111  // set the transient ELink to the default state.
112  trans.reset();
113  }
114 }
115 
116 
117 template <typename LINK_TYPE>
118 void ElementLinkCnv_p3<LINK_TYPE>::
119 transToPers(const Link_t* trans, PersLink_t* pers, MsgStream& msg ) const
120 {
121  return transToPers (*trans, *pers, msg);
122 }
123 
124 
125 template <typename LINK_TYPE >
126 void ElementLinkCnv_p3< LINK_TYPE >
127 ::persToTrans(const PersLink_t* pers, Link_t* trans, MsgStream& msg) const
128 {
129  return persToTrans (*pers, *trans, msg);
130 }