ATLAS Offline Software
xAODCnv.cxx
Go to the documentation of this file.
1 
3 /*
4  Copyright (C) 2002-2018 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 
123 // StatusCode xAODCnv::finalize()
124 // {
125 // m_msg << MSG::INFO
126 // << "Finalizing " << name() << "..."
127 // << endmsg;
128 
129 // return StatusCode::SUCCESS;
130 // }
131 
132 // Query the interfaces.
133 // Input: riid, Requested interface ID
134 // ppvInterface, Pointer to requested interface
135 // Return: StatusCode indicating SUCCESS or FAILURE.
136 // N.B. Don't forget to release the interface after use!!!
137 // StatusCode
138 // xAODCnv::queryInterface(const InterfaceID& riid, void** ppvInterface)
139 // {
140 // if ( IConverter::interfaceID().versionMatch(riid) ) {
141 // *ppvInterface = dynamic_cast<IConverter*>(this);
142 // } else {
143 // // Interface is not directly available : try out a base class
144 // return ::Service::queryInterface(riid, ppvInterface);
145 // }
146 // addRef();
147 // return StatusCode::SUCCESS;
148 // }
149 
151 // Const methods:
153 
154 long
156 {
157  ATH_MSG_DEBUG("Calling xAODCnv::repSvcType");
158  return POOL_ROOTTREE_StorageType;
159 }
160 
162 // Non-const methods:
164 
168 StatusCode
169 xAODCnv::createObj(IOpaqueAddress* pAddr, DataObject*& pObj)
170 {
171  ATH_MSG_DEBUG("::createObj(" << pAddr << ", " << pObj << ")");
172  Athena::xAODBranchAddress *rba = dynamic_cast<Athena::xAODBranchAddress*>(pAddr);
173  if (!rba) {
174  ATH_MSG_DEBUG(*pAddr->par() << " is NOT a GenericAddress!");
175  return StatusCode::FAILURE;
176  }
177  ATH_MSG_DEBUG("loading branch: [" << rba->par()[0]
178  << "/" << rba->par()[1] << "]...");
179  //rba->setBranchAddress(m_type);
180  ATH_MSG_DEBUG("xAODCnv::createObj 1");
181  // FIXME JE
182  rba->setTEventAddress();
183  ATH_MSG_DEBUG("loading branch: [" << rba->par()[0]
184  << "/" << rba->par()[1] << "]... [done]");
185  ATH_MSG_DEBUG("xAODCnv::createObj 2");
186  Athena::DataBucketBranch *dbb = new DataBucketBranch(rba->clID(), m_type, rba->m_ptr);
187  dbb->allowMismatchCLID = true; //FIXME WB : hack to allow requests from other clid types
188  ATH_MSG_DEBUG("xAODCnv::createObj 3");
189  pObj = dbb;
190  ATH_MSG_DEBUG("xAODCnv::createObj 4");
191  return StatusCode::SUCCESS;
192 }
193 
197 StatusCode
198 xAODCnv::createRep(DataObject* pObj, IOpaqueAddress*& pAddr)
199 {
200  ATH_MSG_DEBUG("Calling xAODCnv::createRep");
201 
202  ATH_MSG_INFO("::createRep(" << pObj << ", " << pAddr << ")");
203  if (0==pObj) {
204  ATH_MSG_ERROR("::createRep: received null ptr to dobj");
205  return StatusCode::FAILURE;
206  }
207  msg(MSG::INFO) << " -> clid: [" << pObj->clID() << "]" << endmsg
208  << " -> name: [" << pObj->name() << "]" << endmsg;
209 
210  /*
211  Athena::DataBucketBranch *dbb = 0;
212  dbb = dynamic_cast<Athena::DataBucketBranch*>(pObj);
213  if (!dbb) {
214  ATH_MSG_INFO("dataobject at [" << pObj->name() << "] is not"
215  << " a DataBucketBranch ! [clid=" << pObj->clID() << "]");
216  return StatusCode::FAILURE;
217  }
218  */
219 
220  // FIXME:
221  // Athena::RootBranchAddress* addr = new Athena::RootBranchAddress
222  // (POOL_ROOTTREE_StorageType,
223  // dbb->clID(),
224  // m_tupleName.value(),
225  // br_name,
226  // (unsigned long)(value_ptr),
227  // (unsigned long)(m_nbrEvts-1));
228 #if 1
229  GenericAddress* addr = new GenericAddress(POOL_ROOTTREE_StorageType,
230  pObj->clID(),
231  pObj->name());
232 #else
234  (POOL_ROOTTREE_StorageType, id,
235  "foo",//m_tupleName.value(),
236  dbb->name(),
237  (unsigned long)(value_ptr),
238  (unsigned long)(m_nbrEvts-1));
239 #endif
240  pAddr = addr;
241  return StatusCode::SUCCESS;
242 }
243 
244 long
246 {
247  std::cout << "Calling xAODCnv::storageType" << std::endl;
248 
249  return POOL_ROOTTREE_StorageType;
250 
251 }
252 
254 // Const methods:
256 
258 // Non-const methods:
260 
262 // Protected methods:
264 
265 } //> 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:245
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:155
Athena::xAODCnv::createObj
virtual StatusCode createObj(IOpaqueAddress *pAddr, DataObject *&pObj)
Create a transient object from a persistent representation.
Definition: xAODCnv.cxx:169
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:198
Athena::xAODCnv::m_type
RootType m_type
the type we can convert
Definition: xAODCnv.h:91
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