ATLAS Offline Software
Loading...
Searching...
No Matches
LeafCnv.cxx
Go to the documentation of this file.
1
2
3/*
4 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
5*/
6
7// LeafCnv.cxx
8// Implementation file for class LeafCnv
9// Author: S.Binet<binet@cern.ch>
11
12// AthenaRootComps includes
13#include "LeafCnv.h"
14#include "RootBranchAddress.h"
16
17// STL includes
18#include <sstream>
19#include <typeinfo>
20#include <stdexcept>
21
22// framework
23#include "GaudiKernel/DataObject.h"
24//#include "GaudiKernel/GenericAddress.h"
25#include "GaudiKernel/ServiceHandle.h"
26#include "GaudiKernel/System.h"
29
30// ROOT
31#include "TBranch.h"
33#include "TLeaf.h"
34#include "TTree.h"
35
36namespace {
37 std::string name_from_clid (const CLID clid)
38 {
39 std::ostringstream o;
40 o << "AthenaRootLeafCnv_" << clid;
41 return o.str();
42 }
43}
44
45namespace Athena {
46
48// Public methods:
50
51// Constructors
54 ISvcLocator* pSvcLocator ) :
55 ::Converter( ROOT_StorageType, clid, pSvcLocator ),
56 ::AthMessaging( msgSvc(), name_from_clid(clid) ),
57 m_type()
58{
59 //
60 // Property declaration
61 //
62 //declareProperty( "Property", m_nProperty );
63
64}
65
66LeafCnv::LeafCnv( ISvcLocator* pSvcLocator ) :
67 ::Converter ( ROOT_StorageType, CLID_NULL, pSvcLocator ),
68 ::AthMessaging( msgSvc(), name_from_clid(CLID_NULL) ),
69 m_type()
70{
71 //
72 // Property declaration
73 //
74 //declareProperty( "Property", m_nProperty );
75
76}
77
78// Destructor
81{
82 ATH_MSG_DEBUG("Calling destructor");
83}
84
85// Athena Service's Hooks
88{
89 // configure our MsgStream
90 msg().setLevel( MSG::INFO );
91
92 ATH_MSG_DEBUG("Initializing LeafCnv...");
93
94 ATH_MSG_DEBUG("Initializing base class...");
95 if ( ::Converter::initialize().isFailure() ) {
96 ATH_MSG_ERROR("Could not intialize base class !!");
97 return StatusCode::FAILURE;
98 } else {
99 ATH_MSG_VERBOSE("Base class initialized");
100 }
101
102 // retrieve the dict-loader-svc
103 typedef ServiceHandle<IDictLoaderSvc> IDictLoaderSvc_t;
104 IDictLoaderSvc_t dictSvc("AthDictLoaderSvc",
105 "Athena::LeafCnv");
106 // name_from_clid(objType()));
107 if ( !dictSvc.retrieve().isSuccess() ) {
108 ATH_MSG_ERROR("could not retrieve [" << dictSvc.typeAndName() << "] !");
109 return StatusCode::FAILURE;
110 }
111
112 RootType ty = dictSvc->load_type(this->objType());
113 ATH_MSG_VERBOSE("loaded dictionary for clid ["
114 << this->objType() << "]: name=["
115 << ty.Name() << "]");
116 m_type = std::move(ty);
117
118 ATH_MSG_DEBUG("converter correctly initialized - clid=[" << objType() << "]");
119 return StatusCode::SUCCESS;
120}
121
123// Const methods:
125
126long
128{
129 return ROOT_StorageType;
130}
131
133// Non-const methods:
135
139StatusCode
140LeafCnv::createObj(IOpaqueAddress* pAddr, DataObject*& pObj)
141{
142 ATH_MSG_DEBUG("::createObj(" << pAddr << ", " << pObj << ")");
143 Athena::RootBranchAddress *rba = dynamic_cast<Athena::RootBranchAddress*>(pAddr);
144 if (!rba) {
145 ATH_MSG_DEBUG(*pAddr->par() << " is NOT a GenericAddress!");
146 return StatusCode::FAILURE;
147 }
148 ATH_MSG_DEBUG("loading branch: [" << rba->par()[0]
149 << "/" << rba->par()[1] << "]...");
151 ATH_MSG_DEBUG("loading branch: [" << rba->par()[0]
152 << "/" << rba->par()[1] << "]... [done]");
153 Athena::DataBucketBranch *dbb = new DataBucketBranch(rba->clID(), rba->m_type, rba->m_ptr);
154 pObj = dbb;
155 return StatusCode::SUCCESS;
156}
157
161StatusCode
162LeafCnv::createRep(DataObject* pObj, IOpaqueAddress*& pAddr)
163{
164 ATH_MSG_INFO("::createRep(" << pObj << ", " << pAddr << ")");
165 if (0==pObj) {
166 ATH_MSG_ERROR("::createRep: received null ptr to dobj");
167 return StatusCode::FAILURE;
168 }
169 msg(MSG::INFO) << " -> clid: [" << pObj->clID() << "]" << endmsg
170 << " -> name: [" << pObj->name() << "]" << endmsg;
171
172 /*
173 Athena::DataBucketBranch *dbb = 0;
174 dbb = dynamic_cast<Athena::DataBucketBranch*>(pObj);
175 if (!dbb) {
176 ATH_MSG_INFO("dataobject at [" << pObj->name() << "] is not"
177 << " a DataBucketBranch ! [clid=" << pObj->clID() << "]");
178 return StatusCode::FAILURE;
179 }
180 */
181
182 // FIXME:
183 // Athena::RootBranchAddress* addr = new Athena::RootBranchAddress
184 // (ROOT_StorageType,
185 // dbb->clID(),
186 // m_tupleName.value(),
187 // br_name,
188 // (unsigned long)(value_ptr),
189 // (unsigned long)(m_nbrEvts-1));
190#if 1
191 GenericAddress* addr = new GenericAddress(ROOT_StorageType,
192 pObj->clID(),
193 pObj->name());
194#else
196 (ROOT_StorageType, id,
197 "foo",//m_tupleName.value(),
198 dbb->name(),
199 (unsigned long)(value_ptr),
200 (unsigned long)(m_nbrEvts-1));
201#endif
202 pAddr = addr;
203 return StatusCode::SUCCESS;
204}
205
206long
208{
209 return ROOT_StorageType;
210}
211
213// Const methods:
215
217// Non-const methods:
219
221// Protected methods:
223
224} //> end namespace Athena
#define endmsg
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
uint32_t CLID
The Class ID type.
TTypeAdapter RootType
Definition RootType.h:211
Include TBranchElement.h, suppressing clang warnings.
MsgStream & msg() const
The standard message stream.
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
static long storageType()
Definition LeafCnv.cxx:207
virtual StatusCode initialize()
Gaudi Service Implementation.
Definition LeafCnv.cxx:87
LeafCnv(const CLID &clid, ISvcLocator *pSvcLocator)
Constructor with parameters:
Definition LeafCnv.cxx:53
long repSvcType() const
Definition LeafCnv.cxx:127
virtual ~LeafCnv()
Destructor:
Definition LeafCnv.cxx:80
virtual StatusCode createRep(DataObject *pObj, IOpaqueAddress *&pAddr)
Create a persistent representation for a transient object.
Definition LeafCnv.cxx:162
RootType m_type
the type we can convert
Definition LeafCnv.h:89
virtual StatusCode createObj(IOpaqueAddress *pAddr, DataObject *&pObj)
Create a transient object from a persistent representation.
Definition LeafCnv.cxx:140
A simple class to hold the buffer of a TBranch from a TTree.
void setBranchAddress(const RootType &t)
setup the ROOT TTree internal address for the branch.
RootType m_type
the buffer for the TBranch
std::string Name(unsigned int mod=Reflex::SCOPED) const
Definition RootType.cxx:612
Some weak symbol referencing magic... These are declared in AthenaKernel/getMessageSvc....