ATLAS Offline Software
xAODCnv.cxx
Go to the documentation of this file.
1 
3 /*
4  Copyright (C) 2002-2024 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"
15 #include "RootDataBucketBranch.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 
36 namespace {
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 
45 namespace Athena {
46 
48 // Public methods:
50 
51 // Constructors
53 xAODCnv::xAODCnv( const CLID& clid,
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 
66 xAODCnv::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 = ty;
118 
119  ATH_MSG_DEBUG("converter correctly initialized - clid=[" << objType() << "]");
120  return StatusCode::SUCCESS;
121 }
122 
124 // Const methods:
126 
127 long
129 {
130  ATH_MSG_DEBUG("Calling xAODCnv::repSvcType");
131  return POOL_ROOTTREE_StorageType;
132 }
133 
135 // Non-const methods:
137 
141 StatusCode
142 xAODCnv::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 
170 StatusCode
171 xAODCnv::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 
217 long
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
RootDataBucketBranch.h
Athena::xAODBranchAddress
Definition: xAODBranchAddress.h:31
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
DataBucketBase.h
initialize
void initialize()
Definition: run_EoverP.cxx:894
Athena::DataBucketBranch::allowMismatchCLID
bool allowMismatchCLID
Definition: RootDataBucketBranch.h:83
Athena::xAODCnv::storageType
static long storageType()
Definition: xAODCnv.cxx:218
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
Athena::xAODCnv::~xAODCnv
virtual ~xAODCnv()
Destructor:
Definition: xAODCnv.cxx:81
Athena::xAODCnv::repSvcType
long repSvcType() const
Definition: xAODCnv.cxx:128
Athena::xAODCnv::createObj
virtual StatusCode createObj(IOpaqueAddress *pAddr, DataObject *&pObj)
Create a transient object from a persistent representation.
Definition: xAODCnv.cxx:142
m_type
TokenType m_type
the type
Definition: TProperty.cxx:44
Athena::xAODBranchAddress::setTEventAddress
void setTEventAddress()
Definition: xAODBranchAddress.cxx:93
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
StdJOSetup.msgSvc
msgSvc
Provide convenience handles for various services.
Definition: StdJOSetup.py:36
Athena
Some weak symbol referencing magic...
Definition: AthLegacySequence.h:21
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
xAODBranchAddress.h
AthMessaging::msg
MsgStream & msg() const
The standard message stream.
Definition: AthMessaging.h:164
TScopeAdapter::Name
std::string Name(unsigned int mod=Reflex::SCOPED) const
Definition: RootType.cxx:607
Athena::xAODCnv::initialize
virtual StatusCode initialize()
Gaudi Service Implementation.
Definition: xAODCnv.cxx:88
Converter
Definition: Converter.h:27
xAODCnv.h
Athena::xAODCnv::createRep
virtual StatusCode createRep(DataObject *pObj, IOpaqueAddress *&pAddr)
Create a persistent representation for a transient object.
Definition: xAODCnv.cxx:171
Athena::xAODCnv::m_type
RootType m_type
the type we can convert
Definition: xAODCnv.h:89
Athena::DataBucketBranch
Definition: RootDataBucketBranch.h:26
IDictLoaderSvc.h
Athena::xAODCnv::xAODCnv
xAODCnv(const CLID &clid, ISvcLocator *pSvcLocator)
Constructor with parameters:
Definition: xAODCnv.cxx:53
TBranchElementClang.h
Include TBranchElement.h, suppressing clang warnings.
Athena::xAODBranchAddress::m_ptr
void * m_ptr
Definition: xAODBranchAddress.h:65
ServiceHandle< IDictLoaderSvc >
TScopeAdapter
Definition: RootType.h:119