ATLAS Offline Software
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  */
24 #ifndef ATHENAPOOLCNVSVC_T_ATHENAPOOLCREATEFUNCS_H
25 #define ATHENAPOOLCNVSVC_T_ATHENAPOOLCREATEFUNCS_H
26 
27 
28 #include "TPTools/ITPConverter.h"
29 #include "GaudiKernel/MsgStream.h"
30 #include <memory>
31 #include <type_traits>
32 
33 namespace EventContainers{
35 }
36 
37 namespace AthenaPoolCnvSvc {
38 
39 
50 template <class TPCNV,
51  typename std::enable_if_t<std::is_base_of_v<ITPConverter, TPCNV> >* = nullptr>
52 std::unique_ptr<typename TPCNV::Pers_t>
53 createPersistent (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 
73 template <class TPCNV,
74  typename std::enable_if_t<!std::is_base_of_v<ITPConverter, TPCNV> >* = nullptr>
75 std::unique_ptr<typename TPCNV::Pers_t>
76 createPersistent (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 
97 template <class TPCNV,
98  typename std::enable_if_t<std::is_base_of_v<ITPConverter, TPCNV> >* = nullptr>
99 std::unique_ptr<typename TPCNV::Trans_t>
100 createTransient (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 
120 template <class TPCNV,
121  typename std::enable_if_t<!std::is_base_of_v<ITPConverter, TPCNV> >* = nullptr>
122 std::unique_ptr<typename TPCNV::Trans_t>
123 createTransient (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;
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
AthenaPoolCnvSvc::createTransient
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.
Definition: T_AthenaPoolCreateFuncs.h:100
athena.value
value
Definition: athena.py:124
EventContainers
Definition: T_AthenaPoolCreateFuncs.h:33
AthenaPoolCnvSvc::createPersistent
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.
Definition: T_AthenaPoolCreateFuncs.h:53
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
ITPConverter.h
Defines the base ITPConverter class interface for all TP converters. Also defines TPConverterTypeMap ...
EventContainers::IdentifiableContainerBase
Definition: IdentifiableContainerBase.h:14
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
AthenaPoolCnvSvc
Definition: Database/AthenaPOOL/AthenaPoolCnvSvc/AthenaPoolCnvSvc/debug.h:26