ATLAS Offline Software
Loading...
Searching...
No Matches
RootCnv.cxx
Go to the documentation of this file.
1
2
3/*
4 Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
5*/
6
7// RootCnv.cxx
8// Implementation file for class Athena::RootCnv
9// Author: Peter van Gemmeren <gemmeren@anl.gov>
10// Author: S.Binet<binet@cern.ch>
12
13// AthenaRootComps includes
14#include "RootCnv.h"
15
16// AthenaRootKernel includes
19
20// stl includes
21#include <string>
22
23// fwk includes
24#include "GaudiKernel/DataObject.h"
25#include "GaudiKernel/IOpaqueAddress.h"
26#include "GaudiKernel/IRegistry.h"
32
33
34namespace {
35 std::string name_from_clid(const CLID clid) {
36 std::ostringstream o;
37 o << "AthenaRootCnv_" << clid;
38 return o.str();
39 }
40}
41
42namespace Athena {
43
44RootCnv::RootCnv(const CLID& id, ISvcLocator* pSvcLocator) : ::Converter(ROOT_StorageType, id, pSvcLocator),
45 ::AthMessaging((pSvcLocator != 0 ? msgSvc() : 0), ::name_from_clid(id)),
46 m_cnvSvc("Athena::RootCnvSvc/AthenaRootCnvSvc", ::name_from_clid(id)),
47 m_ttype(),
48 m_ptype(),
49 m_tpcnv(0) {
50}
51
52RootCnv::RootCnv(ISvcLocator* pSvcLocator) : ::Converter(ROOT_StorageType, CLID_NULL, pSvcLocator),
53 ::AthMessaging( msgSvc(), ::name_from_clid(CLID_NULL)),
54 m_cnvSvc("Athena::RootCnvSvc/AthenaRootCnvSvc", ::name_from_clid(CLID_NULL)),
55 m_ttype(),
56 m_ptype(),
57 m_tpcnv(0) {
58}
59
62
63StatusCode RootCnv::initialize() {
64 if (!::Converter::initialize().isSuccess()) {
65 ATH_MSG_FATAL("Cannot initialize Converter base class.");
66 return StatusCode::FAILURE;
67 }
68 // Get the AthenaRootCnvSvc
69 ATH_CHECK(m_cnvSvc.retrieve());
70 CLID clid = this->objType();
71 m_tpcnv = m_cnvSvc->getTPConverter(clid);
72 if (!m_ttype) {
73 m_ttype = m_cnvSvc->getType(clid);
74 }
75 if (!m_ptype) {
76 if (m_tpcnv == 0) {
77 // only warn if not a builtin
78 if (!m_ttype.IsFundamental()) {
79 ATH_MSG_INFO("Cannot get T/P converter, will write transient type [" << m_ttype.Name() << ", clid = " << clid << "]");
80 }
81 m_ptype = m_cnvSvc->getType(clid);
82 } else {
83 m_ptype = m_cnvSvc->getType(m_tpcnv->persistentTInfo());
84 }
85 if (!m_ptype) {
86 ATH_MSG_ERROR("Cannot get RootType for DataObject.");
87 return StatusCode::FAILURE;
88 }
89 }
90 return StatusCode::SUCCESS;
91}
92
93StatusCode RootCnv::finalize() {
94 return ::Converter::finalize();
95}
96
97long RootCnv::repSvcType() const {
98 return ROOT_StorageType;
99}
100
102 return ROOT_StorageType;
103}
104
105StatusCode RootCnv::createObj(IOpaqueAddress* pAddr, DataObject*& pObj) {
106 ATH_MSG_DEBUG("createObj(" << pAddr << ", " << pObj << ")");
107 /*
108 Athena::RootBranchAddress* rba = dynamic_cast<Athena::RootBranchAddress*>(pAddr);
109 if (!rba) {
110 ATH_MSG_DEBUG(*pAddr->par() << " is NOT a GenericAddress!");
111 return StatusCode::FAILURE;
112 }
113 ATH_MSG_DEBUG("loading branch: [" << rba->par()[0] << "/" << rba->par()[1] << "]...");
114 rba->setBranchAddress(m_type);
115 ATH_MSG_DEBUG("loading branch: [" << rba->par()[0] << "/" << rba->par()[1] << "]... [done]");
116 Athena::DataBucketBranch* dbb = new DataBucketBranch(rba->clID(), rba->m_ptr);
117 pObj = dbb;
118 return StatusCode::SUCCESS;
119 */
120 return StatusCode::FAILURE;
121}
122
123StatusCode RootCnv::fillObjRefs(IOpaqueAddress* pAddr, DataObject* pObj) {
124 ATH_MSG_VERBOSE("fillObjRefs(pAddr = " << pAddr << ", " << "pObj = " << pObj << ")...");
125 return StatusCode::FAILURE;
126}
127
128StatusCode RootCnv::createRep(DataObject* pObj, IOpaqueAddress*& pAddr) {
129 ATH_MSG_VERBOSE("createRep pObj = " << pObj);
130 pAddr = 0;
131 if (pObj == 0) {
132 ATH_MSG_ERROR("createRep called without DataObject.");
133 return StatusCode::FAILURE;
134 }
135 CLID clid = pObj->clID();
136 IRegistry* pR = pObj->registry();
137 if (pR == 0) {
138 ATH_MSG_ERROR("createRep no registry for DataObject.");
139 return StatusCode::FAILURE;
140 }
141 std::string p[2] = { "", pR->identifier() };
142 unsigned long ip[2] = { 0, 0 };
143 void* trans = SG::fromStorable(pObj, clid);
144 ATH_MSG_DEBUG("writing [" << objType() << "/" << p[1] << "]");
145 ATH_MSG_DEBUG("p-type: [" << m_ptype.Name() << "]");
146 std::unique_ptr<const Token> token (m_cnvSvc->writeObject(p[1], m_ptype, trans, m_tpcnv));
147 if (token == 0 || !m_cnvSvc->createAddress(this->repSvcType(), clid, p, ip, pAddr).isSuccess()) {
148 ATH_MSG_ERROR("problem creating opaque address");
149 return StatusCode::FAILURE;
150 }
151 ATH_MSG_DEBUG("writing [" << objType() << "/" << p[1] << "] [done], entry = " << ip[0]);
152 return StatusCode::SUCCESS;
153}
154
155StatusCode RootCnv::fillRepRefs(IOpaqueAddress* pAddr, DataObject* pObj) {
156 ATH_MSG_VERBOSE("fillRepRefs(pAddr = " << pAddr << ", " << "pObj = " << pObj << ")...");
157 return StatusCode::FAILURE;
158}
159
160} //< end namespace Athena
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
uint32_t CLID
The Class ID type.
This file contains the class definition for the IAthenaRootCnvSvc interface class.
This file contains the class definition for the IRootSvc interface class.
This file contains the class definition for the Placement class (migrated from POOL).
This file contains the class definition for the Athena::RootCnv class.
convert to and from a SG storable
This file contains the class definition for the Token class (migrated from POOL).
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
virtual StatusCode initialize()
Gaudi Service Interface method implementations:
Definition RootCnv.cxx:63
virtual StatusCode fillObjRefs(IOpaqueAddress *pAddr, DataObject *pObj)
Resolve the references of the created transient object.
Definition RootCnv.cxx:123
RootType m_ttype
transient type
Definition RootCnv.h:93
virtual StatusCode createObj(IOpaqueAddress *pAddr, DataObject *&pObj)
Create a transient object from a ROOT persistent representation.
Definition RootCnv.cxx:105
virtual StatusCode fillRepRefs(IOpaqueAddress *pAddr, DataObject *pObj)
Resolve the references of the created transient object.
Definition RootCnv.cxx:155
virtual StatusCode createRep(DataObject *pObj, IOpaqueAddress *&pAddr)
Create a ROOT persistent representation for a transient object.
Definition RootCnv.cxx:128
ServiceHandle< ::IAthenaRootCnvSvc > m_cnvSvc
ServiceHandle to the conversion service.
Definition RootCnv.h:89
virtual StatusCode finalize()
Definition RootCnv.cxx:93
virtual ~RootCnv()
Destructor.
Definition RootCnv.cxx:60
ITPCnvBase * m_tpcnv
Definition RootCnv.h:98
RootCnv()
Default constructor:
long repSvcType() const
Retrieve the class type of the data store the converter uses.
Definition RootCnv.cxx:97
static long storageType()
Definition RootCnv.cxx:101
RootType m_ptype
persistent type
Definition RootCnv.h:96
Some weak symbol referencing magic... These are declared in AthenaKernel/getMessageSvc....
bool fromStorable(DataObject *pDObj, T *&pTrans, bool quiet=false, IRegisterTransient *irt=0, bool isConst=true)