ATLAS Offline Software
TPCnvElt.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 // $Id$
6 /**
7  * @file AthenaPoolCnvSvc/TPCnvElt.icc
8  * @author scott snyder <snyder@bnl.gov>
9  * @date Jan, 2016
10  * @brief Helper for calling a TP converter from an Athena converter.
11  */
12 
13 
14 namespace AthenaPoolCnvSvc {
15 
16 
17 /**
18  * @brief Constructor.
19  */
20 template <class CNV, class TPCNV>
21 TPCnvElt<CNV, TPCNV>::TPCnvElt()
22  // Remember the guid for our persistent type.
23  : m_guid (guidFromTypeinfo (typeid (Pers_t)))
24 {
25 }
26 
27 
28 /**
29  * @brief Read the persistent object and convert it to transient.
30  * @param parent The top-level pool converter object.
31  * @param key The SG key of the object being read.
32  * @param msg MsgStream for error reporting.
33  *
34  * Returns a newly-allocated object.
35  * If the type of the persistent object on the file does not match the
36  * type that this converter handles, return nullptr.
37  * Other errors are reported by raising exceptions.
38  */
39 template <class CNV, class TPCNV>
40 std::unique_ptr<typename TPCnvElt<CNV, TPCNV>::Trans_t>
41 TPCnvElt<CNV, TPCNV>::createTransient (CNV& parent,
42  const std::string& key,
43  MsgStream& msg)
44 {
45  if (!parent.compareClassGuid (m_guid))
46  return std::unique_ptr<typename TPCnvElt<CNV, TPCNV>::Trans_t>();
47 
48  std::unique_ptr<Pers_t> old (parent.template poolReadObject<Pers_t>() );
49  return AthenaPoolCnvSvc::createTransient (m_cnv, old.get(), key, msg);
50 }
51 
52 
53 /**
54  * @brief Read the persistent object and convert it to transient.
55  * @param parent The top-level pool converter object.
56  * @param trans The transient object to modify.
57  * @param key The SG key of the object being read.
58  * @param msg MsgStream for error reporting.
59  *
60  * Overwrites the provided transient object.
61  * If the type of the persistent object on the file does not match the
62  * type that this converter handles, returns false.
63  * Other errors are reported by raising exceptions.
64  */
65 template <class CNV, class TPCNV>
66 bool
67 TPCnvElt<CNV, TPCNV>::persToTrans (CNV& parent, Trans_t* trans,
68  const std::string& /*key*/,
69  MsgStream& msg)
70 {
71  if (!parent.compareClassGuid (m_guid))
72  return false;
73 
74  std::unique_ptr<Pers_t> old ( parent.template poolReadObject<Pers_t>() );
75  m_cnv.persToTrans (old.get(), trans, msg);
76  return true;
77 }
78 
79 
80 //*************************************************************************
81 
82 
83 /**
84  * @brief Constructor.
85  *
86  * Specialization for the case of no conversion.
87  */
88 template <class CNV, class TRANS>
89 TPCnvElt<CNV, T_TPCnvNull<TRANS> >::TPCnvElt()
90  // Remember the guid for our persistent type.
91  : m_guid (guidFromTypeinfo (typeid (Pers_t)))
92 {
93 }
94 
95 
96 /**
97  * @brief Read the persistent object and convert it to transient.
98  * @param parent The top-level pool converter object.
99  * @param key The SG key of the object being read.
100  * @param msg MsgStream for error reporting.
101  *
102  * Specialization for the case of no conversion.
103  *
104  * Returns a newly-allocated object.
105  * If the type of the persistent object on the file does not match the
106  * type that this converter handles, return nullptr.
107  * Other errors are reported by raising exceptions.
108  */
109 template <class CNV, class TRANS>
110 std::unique_ptr<typename TPCnvElt<CNV, T_TPCnvNull<TRANS> >::Trans_t>
111 TPCnvElt<CNV, T_TPCnvNull<TRANS> >::createTransient (CNV& parent,
112  const std::string& /*key*/,
113  MsgStream& /*msg*/)
114 {
115  Pers_t* p = nullptr;
116  if (parent.compareClassGuid (m_guid)) {
117  p = parent.template poolReadObject<Pers_t>();
118  }
119  return std::unique_ptr<typename TPCnvElt<CNV, T_TPCnvNull<TRANS> >::Trans_t>(p);
120 }
121 
122 
123 /**
124  * @brief Read the persistent object and convert it to transient.
125  * @param parent The top-level pool converter object.
126  * @param trans The transient object to modify.
127  * @param key The SG key of the object being read.
128  * @param msg MsgStream for error reporting.
129  *
130  * Specialization for the case of no conversion.
131  *
132  * Overwrites the provided transient object.
133  * If the type of the persistent object on the file does not match the
134  * type that this converter handles, returns false.
135  * Other errors are reported by raising exceptions.
136  */
137 template <class CNV, class TRANS>
138 bool
139 TPCnvElt<CNV, T_TPCnvNull<TRANS> >::persToTrans (CNV& parent,
140  Trans_t* trans,
141  const std::string& /*key*/,
142  MsgStream& /*msg*/)
143 {
144  if (!parent.compareClassGuid (m_guid))
145  return false;
146 
147  std::unique_ptr<Pers_t> old ( parent.template poolReadObject<Pers_t>() );
148  *trans = *old;
149  return true;
150 }
151 
152 
153 } // namespace AthenaPoolCnvSvc