ATLAS Offline Software
Loading...
Searching...
No Matches
TPCnvList.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/TPCnvList.h
8 * @author scott snyder <snyder@bnl.gov>
9 * @date Jan, 2016
10 * @brief Helper for calling TP converters from an Athena converter.
11 */
12
13
14namespace AthenaPoolCnvSvc {
15
16
17/**
18 * @brief Constructor.
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.
22 */
23template <class CNV, class TRANS, class ... TPCNVS>
24inline
25TPCnvList<CNV, TRANS, TPCNVS...>::do_create_transient::do_create_transient (CNV& parent,
26 const Token* token,
27 const std::string& key,
28 MsgStream& msg)
29 : m_parent (parent),
30 m_token (token),
31 m_key (key),
32 m_msg (msg)
33{
34}
35
36
37/**
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.
41 *
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.
48 */
49template <class CNV, class TRANS, class ... TPCNVS>
50template <class ELT>
51inline
52typename ELT::Trans_t*
53TPCnvList<CNV, TRANS, TPCNVS...>::do_create_transient::operator()
54 (typename ELT::Trans_t* p, ELT& elt)
55{
56 if (p) return p;
57 return elt.createTransient (m_parent, m_token, m_key, m_msg).release();
58}
59
60
61/**
62 * @brief Constructor.
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.
67 */
68template <class CNV, class TRANS, class ... TPCNVS>
69inline
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)
72 : m_parent (parent),
73 m_trans (trans),
74 m_token (token),
75 m_key (key),
76 m_msg (msg)
77{
78}
79
80
81/**
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.
85 *
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.
91 */
92template <class CNV, class TRANS, class ... TPCNVS>
93template <class ELT>
94inline
95bool TPCnvList<CNV, TRANS, TPCNVS...>::do_pers_to_trans::operator()
96 (bool found, ELT& elt)
97{
98 if (found) return true;
99 return elt.persToTrans (m_parent, m_trans, m_token, m_key, m_msg);
100}
101
102
103#ifndef __COVERITY__
104/**
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.
109 *
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.
114 */
115template <class CNV, class TRANS, class ... TPCNVS>
116std::unique_ptr<TRANS>
117TPCnvList<CNV, TRANS, TPCNVS...>::createTransient (CNV& parent,
118 const Token* token,
119 const std::string& key,
120 MsgStream& msg)
121{
122 // Try createTransient on each TPCnv; stop when one succeeds.
123 TRANS* p = nullptr;
124 p = boost::fusion::accumulate
125 (m_list, p, do_create_transient(parent, token, key, msg));
126 return std::unique_ptr<TRANS> (p);
127}
128#endif
129
130
131#ifndef __COVERITY__
132/**
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.
138 *
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.
143 */
144template <class CNV, class TRANS, class ... TPCNVS>
145bool TPCnvList<CNV, TRANS, TPCNVS...>::persToTrans (CNV& parent,
146 TRANS* trans,
147 const Token* token,
148 const std::string& key,
149 MsgStream& msg)
150{
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));
154}
155#endif
156
157
158} // namespace AthenaPoolCnvSvc