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