ATLAS Offline Software
Loading...
Searching...
No Matches
T_AthenaPoolAuxContainerCnv.icc
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 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#include "GaudiKernel/ThreadLocalContext.h"
16
17
18/**
19 * @brief Constructor.
20 * @param svcLoc Gaudi service locator.
21 */
22template <class AUXSTORE, class ... TPCNVS>
23T_AthenaPoolAuxContainerCnv<AUXSTORE, TPCNVS...>::T_AthenaPoolAuxContainerCnv( ISvcLocator* svcLoc )
24 : Base( svcLoc ),
25 m_guid (AthenaPoolCnvSvc::guidFromTypeinfo (typeid (AUXSTORE)))
26{
27}
28
29
30/**
31 * @brief Convert a transient object to persistent form.
32 * @param trans The transient object to convert.
33 * @param key The SG key of the object being written.
34 *
35 * Returns a newly-allocated persistent object.
36 */
37template <class AUXSTORE, class ... TPCNVS>
38AUXSTORE*
39T_AthenaPoolAuxContainerCnv<AUXSTORE, TPCNVS...>::createPersistentWithKey( AUXSTORE* trans,
40 const std::string& key)
41{
42 AthenaPoolCnvSvc::debugCreatePersistent (ClassID_traits<AUXSTORE>::ID());
43 std::string key2 = key;
44 if (key2.size() >= 4 && key2.substr (key2.size()-4, 4) == "Aux.")
45 {
46 key2.erase (key2.size()-4, 4);
47 }
48 try {
49 const SG::ThinningInfo* info = SG::getThinningInfo (key2);
50 return SG::copyThinned (*trans, info).release();
51 }
52 catch( const std::exception &ex ) {
53 AthenaPoolCnvSvc::throwExcCaughtException (__PRETTY_FUNCTION__,
54 "thinning aux container",
55 ex,
56 typeid(AUXSTORE),
57 key);
58 }
59}
60
61
62/**
63 * @brief Read the persistent object and convert it to transient.
64 * @param key The SG key of the object being written.
65 *
66 * Returns a newly-allocated transient object.
67 * Errors are reported by raising exceptions.
68 */
69template <class AUXSTORE, class ... TPCNVS>
70AUXSTORE*
71T_AthenaPoolAuxContainerCnv<AUXSTORE, TPCNVS...>::createTransientWithKey (const Token* token, const std::string& key)
72{
73 AthenaPoolCnvSvc::debugCreateTransient (ClassID_traits<AUXSTORE>::ID());
74 if ( this->compareClassGuid(token, m_guid ) ) {
75 // It's the latest version, read it directly:
76 AUXSTORE* c = this->template poolReadObject< AUXSTORE >(token);
77 // Call toTransient on the object we just read.
78 const EventContext& ctx = Gaudi::Hive::currentContext();
79 c->toTransient (ctx);
80 return c;
81 }
82
83 // Try a converter.
84 std::unique_ptr<AUXSTORE> c = m_tpcnvs.createTransient (*this, token, key, this->msg());
85 if (c) {
86 // Call toTransient on the object we just converted.
87 const EventContext& ctx = Gaudi::Hive::currentContext();
88 c->toTransient (ctx);
89 return c.release();
90 }
91
92 // Didn't recognize the GUID.
93 AthenaPoolCnvSvc::throwExcUnsupportedVersion (typeid(AUXSTORE),
94 token->classID());
95 return nullptr;
96}
97
98