2 Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
7 * @file AthenaPoolCnvSvc/TPCnvList.h
8 * @author scott snyder <snyder@bnl.gov>
10 * @brief Helper for calling TP converters from an Athena converter.
14 namespace AthenaPoolCnvSvc {
19 * @param parent The parent Athena pool converter.
20 * @param key SG key of the object being read.
21 * @param msg MsgStream for error reporting.
23 template <class CNV, class TRANS, class ... TPCNVS>
25 TPCnvList<CNV, TRANS, TPCNVS...>::do_create_transient::do_create_transient (CNV& parent,
26 const std::string& key,
36 * @brief Worker for loop over TP converters calling @c createTransient.
37 * @param p Result of the iteration (pointer to transient object).
38 * @param elt The TPCnvElt instance to call.
40 * This function gets called once for each TP converter instance.
41 * It gets as arguments the wrapped TP converter and the result @c p
42 * from the previous TP converter call. If a previous TP converter
43 * has succeeded, then @c p will be non-null, so we just return it
44 * without calling anything. Otherwise, we call the TP converter
45 * and return the result.
47 template <class CNV, class TRANS, class ... TPCNVS>
50 typename ELT::Trans_t*
51 TPCnvList<CNV, TRANS, TPCNVS...>::do_create_transient::operator()
52 (typename ELT::Trans_t* p, ELT& elt)
55 return elt.createTransient (m_parent, m_key, m_msg).release();
61 * @param parent The parent Athena pool converter.
62 * @param trans The transient object to modify.
63 * @param key The SG key of the object being read.
64 * @param msg MsgStream for error reporting.
66 template <class CNV, class TRANS, class ... TPCNVS>
68 TPCnvList<CNV, TRANS, TPCNVS...>::do_pers_to_trans::do_pers_to_trans
69 (CNV& parent, TRANS* trans, const std::string& key, MsgStream& msg)
79 * @brief Worker for loop over TP converters calling @c persToTrans.
80 * @param found Result of the iteration (has a converter succeeded?).
81 * @param elt The TPCnvElt instance to call.
83 * This function gets called once for each TP converter instance.
84 * It gets as arguments the wrapped TP converter and a flag @c found
85 * telling whether any TP converer has succeeded so far. If one has,
86 * then we just return the flag again without calling anything.
87 * Otherwise, we call the TP converter and return the result.
89 template <class CNV, class TRANS, class ... TPCNVS>
92 bool TPCnvList<CNV, TRANS, TPCNVS...>::do_pers_to_trans::operator()
93 (bool found, ELT& elt)
95 if (found) return true;
96 return elt.persToTrans (m_parent, m_trans, m_key, m_msg);
102 * @brief Read the persistent object and convert it to transient.
103 * @param parent The top-level pool converter object.
104 * @param key The SG key of the object being read.
105 * @param msg MsgStream for error reporting.
107 * Returns a newly-allocated object.
108 * If the type of the persistent object on the file does not match the
109 * the type of any of our TP converters, return nullptr.
110 * Other errors are reported by raising exceptions.
112 template <class CNV, class TRANS, class ... TPCNVS>
113 std::unique_ptr<TRANS>
114 TPCnvList<CNV, TRANS, TPCNVS...>::createTransient (CNV& parent,
115 const std::string& key,
118 // Try createTransient on each TPCnv; stop when one succeeds.
120 p = boost::fusion::accumulate
121 (m_list, p, do_create_transient(parent, key, msg));
122 return std::unique_ptr<TRANS> (p);
129 * @brief Read the persistent object and convert it to transient.
130 * @param parent The top-level pool converter object.
131 * @param trans The transient object to modify.
132 * @param key The SG key of the object being read.
133 * @param msg MsgStream for error reporting.
135 * Overwrites the provided transient object.
136 * If the type of the persistent object on the file does not match the
137 * the type of any of our TP converters, return false.
138 * Other errors are reported by raising exceptions.
140 template <class CNV, class TRANS, class ... TPCNVS>
141 bool TPCnvList<CNV, TRANS, TPCNVS...>::persToTrans (CNV& parent,
143 const std::string& key,
146 // Try persToTrans on each TPCnv; stop when one succeeds.
147 return boost::fusion::accumulate
148 (m_list, false, do_pers_to_trans(parent, trans, key, msg));
153 } // namespace AthenaPoolCnvSvc