ATLAS Offline Software
T_AthenaPoolAuxContainerCnv.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 /**
5  * @file AthenaPoolCnvSvc/T_AthenaPoolAuxContainerCnv.icc
6  * @author scott snyder <snyder@bnl.gov>
7  * @date Jan, 2016
8  * @brief Athena pool converter for aux store classes.
9  */
10 
11 
12 #include "AthenaPoolCnvSvc/exceptions.h"
13 #include "AthContainers/tools/copyThinned.h"
14 #include "AthenaKernel/getThinningCache.h"
15 
16 
17 /**
18  * @brief Constructor.
19  * @param svcLoc Gaudi service locator.
20  */
21 template <class AUXSTORE, class ... TPCNVS>
22 T_AthenaPoolAuxContainerCnv<AUXSTORE, TPCNVS...>::T_AthenaPoolAuxContainerCnv( ISvcLocator* svcLoc )
23  : Base( svcLoc ),
24  m_guid (AthenaPoolCnvSvc::guidFromTypeinfo (typeid (AUXSTORE)))
25 {
26 }
27 
28 
29 /**
30  * @brief Convert a transient object to persistent form.
31  * @param trans The transient object to convert.
32  * @param key The SG key of the object being written.
33  *
34  * Returns a newly-allocated persistent object.
35  */
36 template <class AUXSTORE, class ... TPCNVS>
37 AUXSTORE*
38 T_AthenaPoolAuxContainerCnv<AUXSTORE, TPCNVS...>::createPersistentWithKey( AUXSTORE* trans,
39  const std::string& key)
40 {
41  AthenaPoolCnvSvc::debugCreatePersistent (ClassID_traits<AUXSTORE>::ID());
42  std::string key2 = key;
43  if (key2.size() >= 4 && key2.substr (key2.size()-4, 4) == "Aux.")
44  {
45  key2.erase (key2.size()-4, 4);
46  }
47  try {
48  const SG::ThinningInfo* info = SG::getThinningInfo (key2);
49  return SG::copyThinned (*trans, info).release();
50  }
51  catch( const std::exception &ex ) {
52  AthenaPoolCnvSvc::throwExcCaughtException (__PRETTY_FUNCTION__,
53  "thinning aux container",
54  ex,
55  typeid(AUXSTORE),
56  key);
57  }
58 }
59 
60 
61 /**
62  * @brief Read the persistent object and convert it to transient.
63  * @param key The SG key of the object being written.
64  *
65  * Returns a newly-allocated transient object.
66  * Errors are reported by raising exceptions.
67  */
68 template <class AUXSTORE, class ... TPCNVS>
69 AUXSTORE*
70 T_AthenaPoolAuxContainerCnv<AUXSTORE, TPCNVS...>::createTransientWithKey (const std::string& key)
71 {
72  AthenaPoolCnvSvc::debugCreateTransient (ClassID_traits<AUXSTORE>::ID());
73  if ( this->compareClassGuid( m_guid ) ) {
74  // It's the latest version, read it directly:
75  return this->template poolReadObject< AUXSTORE >();
76  }
77 
78  // Try a converter.
79  std::unique_ptr<AUXSTORE> c = m_tpcnvs.createTransient (*this, key, this->msg());
80  if (c)
81  return c.release();
82 
83  // Didn't recognize the GUID.
84  AthenaPoolCnvSvc::throwExcUnsupportedVersion (typeid(AUXSTORE),
85  this->m_i_poolToken->classID());
86  return nullptr;
87 }
88 
89