2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
5/** @file T_AthenaPoolCnvBase.icc
6 * @brief This file contains the implementation for the templated T_AthenaPoolCnvBase class.
7 * @author Peter van Gemmeren <gemmeren@anl.gov>
10#include "AthenaPoolCnvSvc/IAthenaPoolCnvSvc.h"
12#include "GaudiKernel/StatusCode.h"
13#include "GaudiKernel/DataObject.h"
14#include "GaudiKernel/IOpaqueAddress.h"
15#include "GaudiKernel/IRegistry.h"
16#include "PersistentDataModel/Placement.h"
17#include "PersistentDataModel/Token.h"
18#include "PersistentDataModel/TokenAddress.h"
20#include "DataModelRoot/RootType.h"
22#include "AthenaKernel/CLASS_DEF.h"
23#include "AthenaKernel/ClassName.h"
24#include "AthenaKernel/StorableConversions.h"
25#include "AthenaPoolCnvSvc/exceptions.h"
26#include "AthContainersInterfaces/ToTransient.h"
28//__________________________________________________________________________
30T_AthenaPoolCnvBase<T>::T_AthenaPoolCnvBase(ISvcLocator* svcloc,
32 : AthenaPoolConverter(classID(), svcloc, name) {
34//______________________________________________________________________________
36StatusCode T_AthenaPoolCnvBase<T>::initialize() {
37 ATH_MSG_DEBUG("initialize() in T_AthenaPoolCnvBase " << classID());
38 if (!AthenaPoolConverter::initialize().isSuccess()) {
39 ATH_MSG_FATAL("Failed to initialize AthenaPoolConverter base class.");
40 return(StatusCode::FAILURE);
42 const std::string className = ClassName<T>::name();
44 ATH_MSG_DEBUG("Retrieve class description for class " << className);
45 m_classDesc = RootType( typeid(T) );
47 return(StatusCode::SUCCESS);
49//__________________________________________________________________________
51CLID T_AthenaPoolCnvBase<T>::classID() {
52 return(ClassID_traits<T>::ID());
54//__________________________________________________________________________
56StatusCode T_AthenaPoolCnvBase<T>::DataObjectToPool(IOpaqueAddress* pAddr, DataObject* pObj) {
57 const std::string className = ClassName<T>::name();
59 bool success = SG::fromStorable(pObj, obj);
60 if (!success || obj == nullptr) {
61 ATH_MSG_ERROR("failed to cast to T for class (type/key) " << className << "/" << pObj->name());
62 return(StatusCode::FAILURE);
64 Placement placement = setPlacement(pObj->name(), *pAddr->par());
65 // No lock needed for m_classDesc, since set only in initialize()
66 std::unique_ptr<Token> token(m_athenaPoolCnvSvc->registerForWrite(&placement, obj, m_classDesc));
67 // Null/empty token means ERROR
68 if (token == nullptr || token->classID() == Guid::null()) {
69 ATH_MSG_ERROR("failed to get Token for class (type/key) " << className << "/" << pObj->name());
70 return(StatusCode::FAILURE);
72 // Update IOpaqueAddress for this object.
73 TokenAddress* tokAddr = dynamic_cast<TokenAddress*>(pAddr);
74 if (tokAddr != nullptr) {
75 tokAddr->setToken(std::move(token));
77 return(StatusCode::FAILURE);
79 return(StatusCode::SUCCESS);
81//__________________________________________________________________________
83StatusCode T_AthenaPoolCnvBase<T>::PoolToDataObject(DataObject*& pObj,
85 const std::string& key)
87 const std::string className = ClassName<T>::name();
88 void* voidPtr = nullptr;
90 m_athenaPoolCnvSvc->setObjPtr(voidPtr, token);
92 catch (const std::exception& ex) {
93 AthenaPoolCnvSvc::throwExcCaughtException (__PRETTY_FUNCTION__,
94 "converting to DataObject",
99 T* obj = reinterpret_cast<T*>(voidPtr);
100 // Call toTransient on the object we just read.
101 SG::ToTransient<T>::toTransient (*obj);
102 pObj = SG::asStorable(obj);
103 return(StatusCode::SUCCESS);
105//__________________________________________________________________________
107Placement T_AthenaPoolCnvBase<T>::setPlacement(const std::string& key, const std::string& output) {
108 const std::string typenm = ClassName<T>::name();
109 return(setPlacementWithType(typenm, key, output));