ATLAS Offline Software
Loading...
Searching...
No Matches
xAODCnv.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// xAODCnv.cxx
8// Implementation file for class xAODCnv
9// Author: Johannes Elmsheuser, Will Buttinger
11
12// AthenaRootComps includes
13#include "xAODCnv.h"
14#include "xAODBranchAddress.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 << "AthenaRootxAODCnv_" << clid;
41 return o.str();
42 }
43}
44
45namespace Athena {
46
48// Public methods:
50
51// Constructors
54 ISvcLocator* pSvcLocator ) :
55 ::Converter( POOL_ROOTTREE_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
66xAODCnv::xAODCnv( ISvcLocator* pSvcLocator ) :
67 ::Converter ( POOL_ROOTTREE_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 ATH_MSG_DEBUG("Constructor xAODCnv...");
76
77}
78
79// Destructor
82{
83 ATH_MSG_DEBUG("Calling destructor");
84}
85
86// Athena Service's Hooks
89{
90 // configure our MsgStream
91 //msg().setLevel( MSG::INFO );
92
93 ATH_MSG_DEBUG("Initializing xAODCnv...");
94
95 ATH_MSG_DEBUG("Initializing base class...");
96 if ( ::Converter::initialize().isFailure() ) {
97 ATH_MSG_ERROR("Could not intialize base class !!");
98 return StatusCode::FAILURE;
99 } else {
100 ATH_MSG_VERBOSE("Base class initialized");
101 }
102
103 // retrieve the dict-loader-svc
104 typedef ServiceHandle<IDictLoaderSvc> IDictLoaderSvc_t;
105 IDictLoaderSvc_t dictSvc("AthDictLoaderSvc",
106 "Athena::xAODCnv");
107 // name_from_clid(objType()));
108 if ( !dictSvc.retrieve().isSuccess() ) {
109 ATH_MSG_ERROR("could not retrieve [" << dictSvc.typeAndName() << "] !");
110 return StatusCode::FAILURE;
111 }
112
113 RootType ty = dictSvc->load_type(this->objType());
114 ATH_MSG_VERBOSE("loaded dictionary for clid ["
115 << this->objType() << "]: name=["
116 << ty.Name() << "]");
117 m_type = std::move(ty);
118
119 ATH_MSG_DEBUG("converter correctly initialized - clid=[" << objType() << "]");
120 return StatusCode::SUCCESS;
121}
122
124// Const methods:
126
127long
129{
130 ATH_MSG_DEBUG("Calling xAODCnv::repSvcType");
131 return POOL_ROOTTREE_StorageType;
132}
133
135// Non-const methods:
137
141StatusCode
142xAODCnv::createObj(IOpaqueAddress* pAddr, DataObject*& pObj)
143{
144 ATH_MSG_DEBUG("::createObj(" << pAddr << ", " << pObj << ")");
145 Athena::xAODBranchAddress *rba = dynamic_cast<Athena::xAODBranchAddress*>(pAddr);
146 if (!rba) {
147 ATH_MSG_DEBUG(*pAddr->par() << " is NOT a GenericAddress!");
148 return StatusCode::FAILURE;
149 }
150 ATH_MSG_DEBUG("loading branch: [" << rba->par()[0]
151 << "/" << rba->par()[1] << "]...");
152 //rba->setBranchAddress(m_type);
153 ATH_MSG_DEBUG("xAODCnv::createObj 1");
154 // FIXME JE
155 rba->setTEventAddress();
156 ATH_MSG_DEBUG("loading branch: [" << rba->par()[0]
157 << "/" << rba->par()[1] << "]... [done]");
158 ATH_MSG_DEBUG("xAODCnv::createObj 2");
159 Athena::DataBucketBranch *dbb = new DataBucketBranch(rba->clID(), m_type, rba->m_ptr);
160 dbb->allowMismatchCLID = true; //FIXME WB : hack to allow requests from other clid types
161 ATH_MSG_DEBUG("xAODCnv::createObj 3");
162 pObj = dbb;
163 ATH_MSG_DEBUG("xAODCnv::createObj 4");
164 return StatusCode::SUCCESS;
165}
166
170StatusCode
171xAODCnv::createRep(DataObject* pObj, IOpaqueAddress*& pAddr)
172{
173 ATH_MSG_DEBUG("Calling xAODCnv::createRep");
174
175 ATH_MSG_INFO("::createRep(" << pObj << ", " << pAddr << ")");
176 if (0==pObj) {
177 ATH_MSG_ERROR("::createRep: received null ptr to dobj");
178 return StatusCode::FAILURE;
179 }
180 msg(MSG::INFO) << " -> clid: [" << pObj->clID() << "]" << endmsg
181 << " -> name: [" << pObj->name() << "]" << endmsg;
182
183 /*
184 Athena::DataBucketBranch *dbb = 0;
185 dbb = dynamic_cast<Athena::DataBucketBranch*>(pObj);
186 if (!dbb) {
187 ATH_MSG_INFO("dataobject at [" << pObj->name() << "] is not"
188 << " a DataBucketBranch ! [clid=" << pObj->clID() << "]");
189 return StatusCode::FAILURE;
190 }
191 */
192
193 // FIXME:
194 // Athena::RootBranchAddress* addr = new Athena::RootBranchAddress
195 // (POOL_ROOTTREE_StorageType,
196 // dbb->clID(),
197 // m_tupleName.value(),
198 // br_name,
199 // (unsigned long)(value_ptr),
200 // (unsigned long)(m_nbrEvts-1));
201#if 1
202 GenericAddress* addr = new GenericAddress(POOL_ROOTTREE_StorageType,
203 pObj->clID(),
204 pObj->name());
205#else
207 (POOL_ROOTTREE_StorageType, id,
208 "foo",//m_tupleName.value(),
209 dbb->name(),
210 (unsigned long)(value_ptr),
211 (unsigned long)(m_nbrEvts-1));
212#endif
213 pAddr = addr;
214 return StatusCode::SUCCESS;
215}
216
217long
219{
220 std::cout << "Calling xAODCnv::storageType" << std::endl;
221
222 return POOL_ROOTTREE_StorageType;
223
224}
225
227// Const methods:
229
231// Non-const methods:
233
235// Protected methods:
237
238} //> 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.
A simple class to do the retrieve from TEvent.
virtual ~xAODCnv()
Destructor:
Definition xAODCnv.cxx:81
static long storageType()
Definition xAODCnv.cxx:218
xAODCnv(const CLID &clid, ISvcLocator *pSvcLocator)
Constructor with parameters:
Definition xAODCnv.cxx:53
virtual StatusCode createObj(IOpaqueAddress *pAddr, DataObject *&pObj)
Create a transient object from a persistent representation.
Definition xAODCnv.cxx:142
virtual StatusCode initialize()
Gaudi Service Implementation.
Definition xAODCnv.cxx:88
long repSvcType() const
Definition xAODCnv.cxx:128
virtual StatusCode createRep(DataObject *pObj, IOpaqueAddress *&pAddr)
Create a persistent representation for a transient object.
Definition xAODCnv.cxx:171
RootType m_type
the type we can convert
Definition xAODCnv.h:89
std::string Name(unsigned int mod=Reflex::SCOPED) const
Definition RootType.cxx:612
Some weak symbol referencing magic... These are declared in AthenaKernel/getMessageSvc....