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