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#include "StorageSvc/DbType.h"
30
31// ROOT
32#include "TBranch.h"
34#include "TLeaf.h"
35#include "TTree.h"
36
37namespace {
38 std::string name_from_clid (const CLID clid)
39 {
40 std::ostringstream o;
41 o << "AthenaRootxAODCnv_" << clid;
42 return o.str();
43 }
44}
45
46namespace Athena {
47
49// Public methods:
51
52// Constructors
55 ISvcLocator* pSvcLocator ) :
56 ::Converter( pool::ROOT_StorageType.type(), clid, pSvcLocator ),
57 ::AthMessaging( msgSvc(), name_from_clid(clid) ),
58 m_type()
59{
60 //
61 // Property declaration
62 //
63 //declareProperty( "Property", m_nProperty );
64
65}
66
67xAODCnv::xAODCnv( ISvcLocator* pSvcLocator ) :
68 ::Converter ( pool::ROOT_StorageType.type(), CLID_NULL, pSvcLocator ),
69 ::AthMessaging( msgSvc(), name_from_clid(CLID_NULL) ),
70 m_type()
71{
72 //
73 // Property declaration
74 //
75 //declareProperty( "Property", m_nProperty );
76 ATH_MSG_DEBUG("Constructor xAODCnv...");
77
78}
79
80// Destructor
83{
84 ATH_MSG_DEBUG("Calling destructor");
85}
86
87// Athena Service's Hooks
90{
91 // configure our MsgStream
92 //msg().setLevel( MSG::INFO );
93
94 ATH_MSG_DEBUG("Initializing xAODCnv...");
95
96 ATH_MSG_DEBUG("Initializing base class...");
97 if ( ::Converter::initialize().isFailure() ) {
98 ATH_MSG_ERROR("Could not intialize base class !!");
99 return StatusCode::FAILURE;
100 } else {
101 ATH_MSG_VERBOSE("Base class initialized");
102 }
103
104 // retrieve the dict-loader-svc
105 typedef ServiceHandle<IDictLoaderSvc> IDictLoaderSvc_t;
106 IDictLoaderSvc_t dictSvc("AthDictLoaderSvc",
107 "Athena::xAODCnv");
108 // name_from_clid(objType()));
109 if ( !dictSvc.retrieve().isSuccess() ) {
110 ATH_MSG_ERROR("could not retrieve [" << dictSvc.typeAndName() << "] !");
111 return StatusCode::FAILURE;
112 }
113
114 RootType ty = dictSvc->load_type(this->objType());
115 ATH_MSG_VERBOSE("loaded dictionary for clid ["
116 << this->objType() << "]: name=["
117 << ty.Name() << "]");
118 m_type = std::move(ty);
119
120 ATH_MSG_DEBUG("converter correctly initialized - clid=[" << objType() << "]");
121 return StatusCode::SUCCESS;
122}
123
125// Const methods:
127
128long
130{
131 ATH_MSG_DEBUG("Calling xAODCnv::repSvcType");
132 return pool::ROOT_StorageType.type();
133}
134
136// Non-const methods:
138
142StatusCode
143xAODCnv::createObj(IOpaqueAddress* pAddr, DataObject*& pObj)
144{
145 ATH_MSG_DEBUG("::createObj(" << pAddr << ", " << pObj << ")");
146 Athena::xAODBranchAddress *rba = dynamic_cast<Athena::xAODBranchAddress*>(pAddr);
147 if (!rba) {
148 ATH_MSG_DEBUG(*pAddr->par() << " is NOT a GenericAddress!");
149 return StatusCode::FAILURE;
150 }
151 ATH_MSG_DEBUG("loading branch: [" << rba->par()[0]
152 << "/" << rba->par()[1] << "]...");
153 //rba->setBranchAddress(m_type);
154 ATH_MSG_DEBUG("xAODCnv::createObj 1");
155 // FIXME JE
156 rba->setTEventAddress();
157 ATH_MSG_DEBUG("loading branch: [" << rba->par()[0]
158 << "/" << rba->par()[1] << "]... [done]");
159 ATH_MSG_DEBUG("xAODCnv::createObj 2");
160 Athena::DataBucketBranch *dbb = new DataBucketBranch(rba->clID(), m_type, rba->m_ptr);
161 dbb->allowMismatchCLID = true; //FIXME WB : hack to allow requests from other clid types
162 ATH_MSG_DEBUG("xAODCnv::createObj 3");
163 pObj = dbb;
164 ATH_MSG_DEBUG("xAODCnv::createObj 4");
165 return StatusCode::SUCCESS;
166}
167
171StatusCode
172xAODCnv::createRep(DataObject* pObj, IOpaqueAddress*& pAddr)
173{
174 ATH_MSG_DEBUG("Calling xAODCnv::createRep");
175
176 ATH_MSG_INFO("::createRep(" << pObj << ", " << pAddr << ")");
177 if (0==pObj) {
178 ATH_MSG_ERROR("::createRep: received null ptr to dobj");
179 return StatusCode::FAILURE;
180 }
181 msg(MSG::INFO) << " -> clid: [" << pObj->clID() << "]" << endmsg
182 << " -> name: [" << pObj->name() << "]" << endmsg;
183
184 /*
185 Athena::DataBucketBranch *dbb = 0;
186 dbb = dynamic_cast<Athena::DataBucketBranch*>(pObj);
187 if (!dbb) {
188 ATH_MSG_INFO("dataobject at [" << pObj->name() << "] is not"
189 << " a DataBucketBranch ! [clid=" << pObj->clID() << "]");
190 return StatusCode::FAILURE;
191 }
192 */
193
194 // FIXME:
195 // Athena::RootBranchAddress* addr = new Athena::RootBranchAddress
196 // (pool::ROOT_StorageType.type(),
197 // dbb->clID(),
198 // m_tupleName.value(),
199 // br_name,
200 // (unsigned long)(value_ptr),
201 // (unsigned long)(m_nbrEvts-1));
202#if 1
203 GenericAddress* addr = new GenericAddress(pool::ROOT_StorageType.type(),
204 pObj->clID(),
205 pObj->name());
206#else
209 "foo",//m_tupleName.value(),
210 dbb->name(),
211 (unsigned long)(value_ptr),
212 (unsigned long)(m_nbrEvts-1));
213#endif
214 pAddr = addr;
215 return StatusCode::SUCCESS;
216}
217
218long
220{
221 std::cout << "Calling xAODCnv::storageType" << std::endl;
222
223 return pool::ROOT_StorageType.type();
224
225}
226
228// Const methods:
230
232// Non-const methods:
234
236// Protected methods:
238
239} //> 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:82
static long storageType()
Definition xAODCnv.cxx:219
xAODCnv(const CLID &clid, ISvcLocator *pSvcLocator)
Constructor with parameters:
Definition xAODCnv.cxx:54
virtual StatusCode createObj(IOpaqueAddress *pAddr, DataObject *&pObj)
Create a transient object from a persistent representation.
Definition xAODCnv.cxx:143
virtual StatusCode initialize()
Gaudi Service Implementation.
Definition xAODCnv.cxx:89
long repSvcType() const
Definition xAODCnv.cxx:129
virtual StatusCode createRep(DataObject *pObj, IOpaqueAddress *&pAddr)
Create a persistent representation for a transient object.
Definition xAODCnv.cxx:172
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....
Definition AthDsoUtils.h:10
Framework include files.
Definition libname.h:15
static const DbType ROOT_StorageType
Definition DbType.h:85