ATLAS Offline Software
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 
14 namespace 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  */
23 template <class CNV, class TRANS, class ... TPCNVS>
24 inline
25 TPCnvList<CNV, TRANS, TPCNVS...>::do_create_transient::do_create_transient (CNV& parent,
26  const std::string& key,
27  MsgStream& msg)
28  : m_parent (parent),
29  m_key (key),
30  m_msg (msg)
31 {
32 }
33 
34 
35 /**
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.
39  *
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.
46  */
47 template <class CNV, class TRANS, class ... TPCNVS>
48 template <class ELT>
49 inline
50 typename ELT::Trans_t*
51 TPCnvList<CNV, TRANS, TPCNVS...>::do_create_transient::operator()
52  (typename ELT::Trans_t* p, ELT& elt)
53 {
54  if (p) return p;
55  return elt.createTransient (m_parent, m_key, m_msg).release();
56 }
57 
58 
59 /**
60  * @brief Constructor.
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.
65  */
66 template <class CNV, class TRANS, class ... TPCNVS>
67 inline
68 TPCnvList<CNV, TRANS, TPCNVS...>::do_pers_to_trans::do_pers_to_trans
69 (CNV& parent, TRANS* trans, const std::string& key, MsgStream& msg)
70  : m_parent (parent),
71  m_trans (trans),
72  m_key (key),
73  m_msg (msg)
74 {
75 }
76 
77 
78 /**
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.
82  *
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.
88  */
89 template <class CNV, class TRANS, class ... TPCNVS>
90 template <class ELT>
91 inline
92 bool TPCnvList<CNV, TRANS, TPCNVS...>::do_pers_to_trans::operator()
93  (bool found, ELT& elt)
94 {
95  if (found) return true;
96  return elt.persToTrans (m_parent, m_trans, m_key, m_msg);
97 }
98 
99 
100 #ifndef __COVERITY__
101 /**
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.
106  *
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.
111  */
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,
116  MsgStream& msg)
117 {
118  // Try createTransient on each TPCnv; stop when one succeeds.
119  TRANS* p = nullptr;
120  p = boost::fusion::accumulate
121  (m_list, p, do_create_transient(parent, key, msg));
122  return std::unique_ptr<TRANS> (p);
123 }
124 #endif
125 
126 
127 #ifndef __COVERITY__
128 /**
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.
134  *
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.
139  */
140 template <class CNV, class TRANS, class ... TPCNVS>
141 bool TPCnvList<CNV, TRANS, TPCNVS...>::persToTrans (CNV& parent,
142  TRANS* trans,
143  const std::string& key,
144  MsgStream& msg)
145 {
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));
149 }
150 #endif
151 
152 
153 } // namespace AthenaPoolCnvSvc