ATLAS Offline Software
Loading...
Searching...
No Matches
T_AthenaPoolCreateFuncs.h
Go to the documentation of this file.
1// This file's extension implies that it's C, but it's really -*- C++ -*-.
2/*
3 * Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration.
4 */
22
23
24#ifndef ATHENAPOOLCNVSVC_T_ATHENAPOOLCREATEFUNCS_H
25#define ATHENAPOOLCNVSVC_T_ATHENAPOOLCREATEFUNCS_H
26
27
29#include "GaudiKernel/MsgStream.h"
30#include <memory>
31#include <type_traits>
32
36
37namespace AthenaPoolCnvSvc {
38
39
50template <class TPCNV,
51 typename std::enable_if_t<std::is_base_of_v<ITPConverter, TPCNV> >* = nullptr>
52std::unique_ptr<typename TPCNV::Pers_t>
53createPersistent (TPCNV& cnv,
54 const typename TPCNV::Trans_t* transObj,
55 const std::string& key,
56 MsgStream& log)
57{
58 return std::unique_ptr<typename TPCNV::Pers_t>
59 (cnv.createPersistentWithKey (transObj, key, log));
60}
61
62
73template <class TPCNV,
74 typename std::enable_if_t<!std::is_base_of_v<ITPConverter, TPCNV> >* = nullptr>
75std::unique_ptr<typename TPCNV::Pers_t>
76createPersistent (TPCNV& cnv,
77 const typename TPCNV::Trans_t* transObj,
78 const std::string& /*key*/,
79 MsgStream& log)
80{
81 auto pers = std::make_unique<typename TPCNV::Pers_t>();
82 cnv.transToPers(transObj, pers.get(), log);
83 return pers;
84}
85
86
97template <class TPCNV,
98 typename std::enable_if_t<std::is_base_of_v<ITPConverter, TPCNV> >* = nullptr>
99std::unique_ptr<typename TPCNV::Trans_t>
100createTransient (TPCNV& cnv,
101 const typename TPCNV::Pers_t* persObj,
102 const std::string& key,
103 MsgStream& log)
104{
105 return std::unique_ptr<typename TPCNV::Trans_t>
106 (cnv.createTransientWithKey (persObj, key, log));
107}
108
109
120template <class TPCNV,
121 typename std::enable_if_t<!std::is_base_of_v<ITPConverter, TPCNV> >* = nullptr>
122std::unique_ptr<typename TPCNV::Trans_t>
123createTransient (TPCNV& cnv,
124 const typename TPCNV::Pers_t* persObj,
125 const std::string& /*key*/,
126 MsgStream& log)
127{
128 typedef typename TPCNV::Trans_t Trans_t;
129 if constexpr(std::is_base_of< EventContainers::IdentifiableContainerBase, Trans_t>::value &&
130 !std::is_default_constructible<Trans_t>::value)
131 {
132 log << "IdentifiableContainerBase is not compatible with createTransient" << endmsg;
133 return std::unique_ptr<Trans_t>();
134 }
135
136 auto trans = std::make_unique<Trans_t>();
137 cnv.persToTrans(persObj, trans.get(), log);
138 return trans;
139}
140
141
142} // namespace AthenaPoolCnvSvc
143
144
145#endif // not ATHENAPOOLCNVSVC_T_ATHENAPOOLCREATEFUNCS_H
#define endmsg
Defines the base ITPConverter class interface for all TP converters.
std::unique_ptr< typename TPCNV::Trans_t > createTransient(TPCNV &cnv, const typename TPCNV::Pers_t *persObj, const std::string &key, MsgStream &log)
Create a transient object from a persistent object.
std::unique_ptr< typename TPCNV::Pers_t > createPersistent(TPCNV &cnv, const typename TPCNV::Trans_t *transObj, const std::string &key, MsgStream &log)
Create a persistent object from a transient object.