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