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.
14namespace 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.
23template <class CNV, class TRANS, class ... TPCNVS>
25TPCnvList<CNV, TRANS, TPCNVS...>::do_create_transient::do_create_transient (CNV& parent,
27 const std::string& key,
38 * @brief Worker for loop over TP converters calling @c createTransient.
39 * @param p Result of the iteration (pointer to transient object).
40 * @param elt The TPCnvElt instance to call.
42 * This function gets called once for each TP converter instance.
43 * It gets as arguments the wrapped TP converter and the result @c p
44 * from the previous TP converter call. If a previous TP converter
45 * has succeeded, then @c p will be non-null, so we just return it
46 * without calling anything. Otherwise, we call the TP converter
47 * and return the result.
49template <class CNV, class TRANS, class ... TPCNVS>
53TPCnvList<CNV, TRANS, TPCNVS...>::do_create_transient::operator()
54 (typename ELT::Trans_t* p, ELT& elt)
57 return elt.createTransient (m_parent, m_token, m_key, m_msg).release();
63 * @param parent The parent Athena pool converter.
64 * @param trans The transient object to modify.
65 * @param key The SG key of the object being read.
66 * @param msg MsgStream for error reporting.
68template <class CNV, class TRANS, class ... TPCNVS>
70TPCnvList<CNV, TRANS, TPCNVS...>::do_pers_to_trans::do_pers_to_trans
71(CNV& parent, TRANS* trans, const Token* token, const std::string& key, MsgStream& msg)
82 * @brief Worker for loop over TP converters calling @c persToTrans.
83 * @param found Result of the iteration (has a converter succeeded?).
84 * @param elt The TPCnvElt instance to call.
86 * This function gets called once for each TP converter instance.
87 * It gets as arguments the wrapped TP converter and a flag @c found
88 * telling whether any TP converer has succeeded so far. If one has,
89 * then we just return the flag again without calling anything.
90 * Otherwise, we call the TP converter and return the result.
92template <class CNV, class TRANS, class ... TPCNVS>
95bool TPCnvList<CNV, TRANS, TPCNVS...>::do_pers_to_trans::operator()
96 (bool found, ELT& elt)
98 if (found) return true;
99 return elt.persToTrans (m_parent, m_trans, m_token, m_key, m_msg);
105 * @brief Read the persistent object and convert it to transient.
106 * @param parent The top-level pool converter object.
107 * @param key The SG key of the object being read.
108 * @param msg MsgStream for error reporting.
110 * Returns a newly-allocated object.
111 * If the type of the persistent object on the file does not match the
112 * the type of any of our TP converters, return nullptr.
113 * Other errors are reported by raising exceptions.
115template <class CNV, class TRANS, class ... TPCNVS>
116std::unique_ptr<TRANS>
117TPCnvList<CNV, TRANS, TPCNVS...>::createTransient (CNV& parent,
119 const std::string& key,
122 // Try createTransient on each TPCnv; stop when one succeeds.
124 p = boost::fusion::accumulate
125 (m_list, p, do_create_transient(parent, token, key, msg));
126 return std::unique_ptr<TRANS> (p);
133 * @brief Read the persistent object and convert it to transient.
134 * @param parent The top-level pool converter object.
135 * @param trans The transient object to modify.
136 * @param key The SG key of the object being read.
137 * @param msg MsgStream for error reporting.
139 * Overwrites the provided transient object.
140 * If the type of the persistent object on the file does not match the
141 * the type of any of our TP converters, return false.
142 * Other errors are reported by raising exceptions.
144template <class CNV, class TRANS, class ... TPCNVS>
145bool TPCnvList<CNV, TRANS, TPCNVS...>::persToTrans (CNV& parent,
148 const std::string& key,
151 // Try persToTrans on each TPCnv; stop when one succeeds.
152 return boost::fusion::accumulate
153 (m_list, false, do_pers_to_trans(parent, trans, token, key, msg));
158} // namespace AthenaPoolCnvSvc