ATLAS Offline Software
T_AthenaPoolExtendingCnv.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
6 /** @file T_AthenaPoolExtendingCnv.icc
7  * @brief his file contains method definitions for the templated T_AthenaPoolExtendingCnv class.
8  * @author Marcin.Nowak@cern.ch
9  **/
10 
11 
12 
13 template <class TRANS, class PERS>
14 T_AthenaPoolExtendingCnv< TRANS, PERS >::T_AthenaPoolExtendingCnv(ISvcLocator* svcloc) :
15  T_AthenaPoolCustomCnv<TRANS, PERS>( svcloc ),
16  m_originalExtendingCnv( 0 )
17 {}
18 
19 
20 #include <sstream>
21 template <class TRANS, class PERS>
22 inline const std::string
23 T_AthenaPoolExtendingCnv< TRANS, PERS >::name() const
24 {
25  std::ostringstream ostr;
26  ostr << this->objType();
27  return ostr.str();
28 }
29 
30 
31 template <class TRANS, class PERS>
32 inline void
33 T_AthenaPoolExtendingCnv< TRANS, PERS >::
34 wasClonedFrom( AthenaConverterTLPExtension *converter )
35 {
36  if( !converter->needsCloning() ) {
37  // converter doesn't have any reference to an original converter - must be the original itself
38  m_originalExtendingCnv = dynamic_cast< BaseType* >(converter);
39  } else {
40  // in case of cloning a clone, get the real original converter
41  auto* extcnv = dynamic_cast< T_AthenaPoolExtendingCnv< TRANS, PERS >* >(converter);
42  if (!extcnv) std::abort();
43  m_originalExtendingCnv = extcnv->baseAthenaPoolCnv();
44  }
45 // std::cout << " TPCNVINFO: Registering clone source " << (void*)m_originalExtendingCnv << std::endl;
46 }
47 
48 
49 
50 template <class TRANS, class PERS>
51 inline void
52 T_AthenaPoolExtendingCnv< TRANS, PERS >::setToken(const std::string& token)
53 {
54  // set token in base, so local compareClassGuid() will work
55  BaseType::setToken( token );
56  // set token in the original converter so poolReadObject() will work
57  baseAthenaPoolCnv()->T_AthenaPoolExtendingCnv::BaseType::setToken( token );
58 }
59 
60 
61 
62 template <class TRANS, class PERS>
63 template <class P>
64 inline P*
65 T_AthenaPoolExtendingCnv< TRANS, PERS >::
66 poolReadObject()
67 {
68  // std::cout << " TPCNVINFO: redirecting poolReadObject() to original APcnv" << std::endl;
69  return baseAthenaPoolCnv()->template poolReadObject<P>();
70 }
71 
72 
73 
74 template <class TRANS, class PERS>
75 template <class P>
76 void
77 T_AthenaPoolExtendingCnv< TRANS, PERS >::
78 poolReadObject( TopLevelTPCnvBase& tlp_converter )
79 {
80  // set which Top level TP concerter will by used for reading
81  usingTPCnvForReading( tlp_converter );
82  // read the object
83  P* persObj = poolReadObject< P >();
84  // remember the object we just read
85  tlp_converter.setTLPersObject( persObj );
86 }
87 
88 
89 
90 template <class TRANS, class PERS>
91 const Token *
92 T_AthenaPoolExtendingCnv< TRANS, PERS >::writeObject(const std::string& key, const std::string& output)
93 {
94  Token* pTok = 0;
95  PERS *persObj = reinterpret_cast<PERS*>( getTopLevelTPCnv()->getTLPersObjectAsVoid() );
96  if( persObj ) {
97  //MN - do not pass SG key - this will put the object in a separate container
98  if( !baseAthenaPoolCnv()->objectToPool( persObj, pTok, key, output ).isSuccess() ) {
99  throw std::runtime_error("Component persistent object write failed");
100  }
101  getTopLevelTPCnv()->clearTLPersObject();
102  std::size_t cpos = output.find(':');
103  std::size_t bpos = output.find('[');
104  if (cpos == std::string::npos) {
105  cpos = 0;
106  } else {
107  cpos++;
108  }
109  if (bpos != std::string::npos) bpos = bpos - cpos;
110  baseAthenaPoolCnv()->keepPoolObj(persObj , output.substr(cpos, bpos));
111  }
112  return pTok;
113 }
114